diff options
Diffstat (limited to 'internal/api.go')
| -rw-r--r-- | internal/api.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/api.go b/internal/api.go index b615976..45e025b 100644 --- a/internal/api.go +++ b/internal/api.go @@ -96,23 +96,33 @@ func APIInfo(server Server) error { return nil } -func APIConnectWireguard(server Server, profile_id string, pubkey string) (string, string, error) { +func APIConnectWireguard(server Server, profile_id string, pubkey string, supportsOpenVPN bool) (string, string, string, error) { headers := http.Header{ "content-type": {"application/x-www-form-urlencoded"}, "accept": {"application/x-wireguard-profile"}, } + if supportsOpenVPN { + headers.Add("accept", "application/x-openvpn-profile") + } + urlForm := url.Values{ "profile_id": {profile_id}, "public_key": {pubkey}, } header, connectBody, connectErr := apiAuthorizedRetry(server, http.MethodPost, "/connect", &HTTPOptionalParams{Headers: headers, Body: urlForm}) if connectErr != nil { - return "", "", &APIConnectWireguardError{Err: connectErr} + return "", "", "", &APIConnectWireguardError{Err: connectErr} } expires := header.Get("expires") - return string(connectBody), expires, nil + contentType := header.Get("content-type") + + content := "openvpn" + if contentType == "application/x-wireguard-profile" { + content = "wireguard" + } + return string(connectBody), content, expires, nil } func APIConnectOpenVPN(server Server, profile_id string) (string, string, error) { @@ -124,6 +134,7 @@ func APIConnectOpenVPN(server Server, profile_id string) (string, string, error) urlForm := url.Values{ "profile_id": {profile_id}, } + header, connectBody, connectErr := apiAuthorizedRetry(server, http.MethodPost, "/connect", &HTTPOptionalParams{Headers: headers, Body: urlForm}) if connectErr != nil { return "", "", &APIConnectOpenVPNError{Err: connectErr} |
