summaryrefslogtreecommitdiff
path: root/internal/server/profile.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 15:14:17 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 15:14:17 +0100
commit5143ed35f2af2fe0e725c2a466c86f1cf929333c (patch)
treeb6c19f466226fa1c25534404f9935464af7cb314 /internal/server/profile.go
parent3934d75ac516a530ceb9f494f7ce0de12cb1b5de (diff)
Server: Split more into multiple implementation files
Diffstat (limited to 'internal/server/profile.go')
-rw-r--r--internal/server/profile.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/server/profile.go b/internal/server/profile.go
new file mode 100644
index 0000000..42f0e52
--- /dev/null
+++ b/internal/server/profile.go
@@ -0,0 +1,46 @@
+package server
+
+type Profile struct {
+ ID string `json:"profile_id"`
+ DisplayName string `json:"display_name"`
+ VPNProtoList []string `json:"vpn_proto_list"`
+ DefaultGateway bool `json:"default_gateway"`
+}
+
+type ProfileListInfo struct {
+ ProfileList []Profile `json:"profile_list"`
+}
+
+type ProfileInfo struct {
+ Current string `json:"current_profile"`
+ Info ProfileListInfo `json:"info"`
+}
+
+func (info ProfileInfo) GetCurrentProfileIndex() int {
+ index := 0
+ for _, profile := range info.Info.ProfileList {
+ if profile.ID == info.Current {
+ return index
+ }
+ index++
+ }
+ // Default is 'first' profile
+ return 0
+}
+
+func (profile *Profile) supportsProtocol(protocol string) bool {
+ for _, proto := range profile.VPNProtoList {
+ if proto == protocol {
+ return true
+ }
+ }
+ return false
+}
+
+func (profile *Profile) supportsWireguard() bool {
+ return profile.supportsProtocol("wireguard")
+}
+
+func (profile *Profile) supportsOpenVPN() bool {
+ return profile.supportsProtocol("openvpn")
+}