summaryrefslogtreecommitdiff
path: root/src/server.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-23 18:15:13 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-23 18:15:13 +0100
commit40053552852cf8c27fe7658b64df001d65b0a65e (patch)
tree6f48e819eaec926c894af6d6225ea6d8b36de657 /src/server.go
parentf1e5096b7827d82ab5b2df10080a2ad9223f2665 (diff)
Add getting profiles and add openvpn config support
Diffstat (limited to 'src/server.go')
-rw-r--r--src/server.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/server.go b/src/server.go
index 8f8706e..1dc0f88 100644
--- a/src/server.go
+++ b/src/server.go
@@ -1,6 +1,7 @@
package eduvpn
import (
+ "errors"
"encoding/json"
)
@@ -8,6 +9,21 @@ type Server struct {
BaseURL string `json:"base_url"`
Endpoints *ServerEndpoints `json:"endpoints"`
OAuth *OAuth `json:"oauth"`
+ Profiles *ServerProfileInfo `json:"profiles"`
+}
+
+type ServerProfile struct {
+ ID string `json:"profile_id"`
+ DisplayName string `json:"display_name"`
+ VPNProtoList []string `json:"vpn_proto_list"`
+ DefaultGateway bool `json:"default_gateway"`
+}
+
+type ServerProfileInfo struct {
+ Current uint8 `json:"current_profile"`
+ Info struct {
+ ProfileList []ServerProfile `json:"profile_list"`
+ } `json:"info"`
}
type ServerEndpointList struct {
@@ -58,3 +74,50 @@ func (server *Server) GetEndpoints() error {
return nil
}
+
+func (profiles *ServerProfileInfo) getCurrentProfile() (*ServerProfile, error) {
+ if profiles.Info.ProfileList == nil {
+ return nil, errors.New("No server profiles")
+ }
+
+ if (int)(profiles.Current) >= len(profiles.Info.ProfileList) {
+ return nil, errors.New("Invalid profile")
+ }
+ return &profiles.Info.ProfileList[profiles.Current], nil
+}
+
+func (profile *ServerProfile) supportsWireguard() bool {
+ for _, proto := range profile.VPNProtoList {
+ if proto == "wireguard" {
+ return true
+ }
+ }
+ return false
+}
+
+func (server *Server) GetCurrentProfile() (*ServerProfile, error) {
+ if server.Profiles == nil {
+ return nil, errors.New("No server profiles found")
+ }
+
+ return server.Profiles.getCurrentProfile()
+}
+
+func (server *Server) GetConfig() (string, error) {
+ infoErr := server.APIInfo()
+
+ if infoErr != nil {
+ return "", infoErr
+ }
+
+ profile, profileErr := server.GetCurrentProfile()
+
+ if profileErr != nil {
+ return "", profileErr
+ }
+
+ if profile.supportsWireguard() {
+ return server.WireguardGetConfig()
+ }
+ return server.OpenVPNGetConfig()
+}