From 9e3e7f22892c3504e6de9827af0fabd9b4b098ea Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 10 May 2022 11:53:08 +0200 Subject: API/Server: Correctly handle multiple protocol preference --- internal/wireguard.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'internal/wireguard.go') diff --git a/internal/wireguard.go b/internal/wireguard.go index 318e0dc..7f8da38 100644 --- a/internal/wireguard.go +++ b/internal/wireguard.go @@ -30,7 +30,7 @@ func wireguardConfigAddKey(config string, key wgtypes.Key) string { return interface_re.ReplaceAllString(config, to_replace) } -func WireguardGetConfig(server Server) (string, error) { +func WireguardGetConfig(server Server, supportsOpenVPN bool) (string, error) { base, baseErr := server.GetBase() if baseErr != nil { @@ -45,20 +45,22 @@ func WireguardGetConfig(server Server) (string, error) { } wireguardPublicKey := wireguardKey.PublicKey().String() - configWireguard, _, configErr := APIConnectWireguard(server, profile_id, wireguardPublicKey) + config, content, _, configErr := APIConnectWireguard(server, profile_id, wireguardPublicKey, supportsOpenVPN) if configErr != nil { return "", &WireguardGetConfigError{Err: wireguardErr} } - // FIXME: Store expiry - // This needs the go code a way to identify a connection - // Use the uuid of the connection e.g. on Linux - // This needs the client code to call the go code + if content == "wireguard" { + // FIXME: Store expiry + // This needs the go code a way to identify a connection + // Use the uuid of the connection e.g. on Linux + // This needs the client code to call the go code - configWireguardKey := wireguardConfigAddKey(configWireguard, wireguardKey) + config = wireguardConfigAddKey(config, wireguardKey) + } - return configWireguardKey, nil + return config, nil } type WireguardGenerateKeyError struct { -- cgit v1.2.3