about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/http.go b/src/http.go
index d1e3507..81d55b7 100644
--- a/src/http.go
+++ b/src/http.go
@@ -316,10 +316,19 @@ func getAccessHandler(w http.ResponseWriter, r *http.Request) {
 			errorString = err.Error()
 		}
 
-		jsonAnswer, _ := json.Marshal(map[string]string{
-			"error": errorString,
-			"credentials": credentials,
-		})
-		w.Write([]byte(jsonAnswer))
+		// Check if we are asked to prepare the config file as download...
+		if errorString == "" && r.URL.Query().Get("download") == "true" {
+			// We are asked to do so, and we didn't encounter an error either
+			w.Header().Set("Content-Disposition", "attachment; filename=config.ovpn")
+			w.Header().Set("Content-Type", "x-openvpn-config")
+			w.Write([]byte(credentials))
+		} else {
+			// Normal operation - provide JSON formatted data
+			jsonAnswer, _ := json.Marshal(map[string]string{
+				"error":       errorString,
+				"credentials": credentials,
+			})
+			w.Write([]byte(jsonAnswer))
+		}
 	}
 }