summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/server/api.go35
-rw-r--r--internal/server/base.go6
-rw-r--r--internal/server/server.go27
-rw-r--r--internal/server/servers.go13
4 files changed, 39 insertions, 42 deletions
diff --git a/internal/server/api.go b/internal/server/api.go
index dfa8e14..145d24e 100644
--- a/internal/server/api.go
+++ b/internal/server/api.go
@@ -18,9 +18,7 @@ func APIGetEndpoints(baseURL string) (*Endpoints, error) {
return nil, errors.WrapPrefix(err, "failed getting server endpoints", 0)
}
- wk := "/.well-known/vpn-user-portal"
-
- u.Path = path.Join(u.Path, wk)
+ u.Path = path.Join(u.Path, "/.well-known/vpn-user-portal")
_, body, err := httpw.Get(u.String())
if err != nil {
return nil, errors.WrapPrefix(err, "failed getting server endpoints", 0)
@@ -44,22 +42,23 @@ func apiAuthorized(
if opts == nil {
opts = &httpw.OptionalParams{}
}
+ errorMessage := "failed API authorized"
b, err := srv.Base()
if err != nil {
- return nil, nil, errors.WrapPrefix(err, "failed API authorized", 0)
+ return nil, nil, errors.WrapPrefix(err, errorMessage, 0)
}
// Join the paths
u, err := url.Parse(b.Endpoints.API.V3.API)
if err != nil {
- return nil, nil, errors.WrapPrefix(err, "failed API authorized", 0)
+ return nil, nil, errors.WrapPrefix(err, errorMessage, 0)
}
u.Path = path.Join(u.Path, endpoint)
// Make sure the tokens are valid, this will return an error if re-login is needed
t, err := HeaderToken(srv)
if err != nil {
- return nil, nil, errors.WrapPrefix(err, "failed API authorized", 0)
+ return nil, nil, errors.WrapPrefix(err, errorMessage, 0)
}
key := "Authorization"
@@ -98,8 +97,8 @@ func APIInfo(srv Server) error {
if err != nil {
return err
}
- pi := ProfileInfo{}
- if err = json.Unmarshal(body, &pi); err != nil {
+ profiles := ProfileInfo{}
+ if err = json.Unmarshal(body, &profiles); err != nil {
return errors.WrapPrefix(err, "failed API /info", 0)
}
@@ -110,7 +109,7 @@ func APIInfo(srv Server) error {
// Store the profiles and make sure that the current profile is not overwritten
prev := b.Profiles.Current
- b.Profiles = pi
+ b.Profiles = profiles
b.Profiles.Current = prev
return nil
}
@@ -154,18 +153,18 @@ func APIConnectWireguard(
exp := h.Get("expires")
- ptm, err := http.ParseTime(exp)
+ expTime, err := http.ParseTime(exp)
if err != nil {
return "", "", time.Time{}, errors.WrapPrefix(err, "failed obtaining a WireGuard configuration", 0)
}
- ct := h.Get("content-type")
- c := "openvpn"
- if ct == "application/x-wireguard-profile" {
- c = "wireguard"
+ contentH := h.Get("content-type")
+ content := "openvpn"
+ if contentH == "application/x-wireguard-profile" {
+ content = "wireguard"
}
- return string(body), c, ptm, nil
+ return string(body), content, expTime, nil
}
func APIConnectOpenVPN(srv Server, profileID string, preferTCP bool) (string, time.Time, error) {
@@ -185,13 +184,13 @@ func APIConnectOpenVPN(srv Server, profileID string, preferTCP bool) (string, ti
return "", time.Time{}, err
}
- exp := h.Get("expires")
- ptm, err := http.ParseTime(exp)
+ expH := h.Get("expires")
+ expT, err := http.ParseTime(expH)
if err != nil {
return "", time.Time{}, errors.WrapPrefix(err, "failed obtaining an OpenVPN configuration", 0)
}
- return string(body), ptm, nil
+ return string(body), expT, nil
}
// APIDisconnect disconnects from the API.
diff --git a/internal/server/base.go b/internal/server/base.go
index 81049cf..6eb305b 100644
--- a/internal/server/base.go
+++ b/internal/server/base.go
@@ -26,17 +26,17 @@ func (b *Base) InitializeEndpoints() error {
}
func (b *Base) ValidProfiles(wireguardSupport bool) ProfileInfo {
- var vps []Profile
+ var valid []Profile
for _, p := range b.Profiles.Info.ProfileList {
// Not a valid profile because it does not support openvpn
// Also the client does not support wireguard
if !p.supportsOpenVPN() && !wireguardSupport {
continue
}
- vps = append(vps, p)
+ valid = append(valid, p)
}
return ProfileInfo{
Current: b.Profiles.Current,
- Info: ProfileListInfo{ProfileList: vps},
+ Info: ProfileListInfo{ProfileList: valid},
}
}
diff --git a/internal/server/server.go b/internal/server/server.go
index de0fa9a..1637d35 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -67,9 +67,9 @@ func ShouldRenewButton(srv Server) bool {
}
// Session duration is less than 24 hours but not 75% has passed
- d := b.EndTime.Sub(b.StartTime)
- pct := b.StartTime.Add((d / 4) * 3)
- if d < 24*time.Hour && !now.After(pct) {
+ delta := b.EndTime.Sub(b.StartTime)
+ passed := b.StartTime.Add((delta / 4) * 3)
+ if delta < 24*time.Hour && !now.After(passed) {
return false
}
@@ -110,14 +110,14 @@ func CurrentProfile(srv Server) (*Profile, error) {
if err != nil {
return nil, err
}
- pid := b.Profiles.Current
+ pID := b.Profiles.Current
for _, profile := range b.Profiles.Info.ProfileList {
- if profile.ID == pid {
+ if profile.ID == pID {
return &profile, nil
}
}
- return nil, errors.Errorf("profile not found: " + pid)
+ return nil, errors.Errorf("profile not found: " + pID)
}
func ValidProfiles(srv Server, wireguardSupport bool) (*ProfileInfo, error) {
@@ -139,14 +139,14 @@ func wireguardGetConfig(srv Server, preferTCP bool, openVPNSupport bool) (string
return "", "", err
}
- pid := b.Profiles.Current
+ pID := b.Profiles.Current
key, err := wireguard.GenerateKey()
if err != nil {
return "", "", err
}
pub := key.PublicKey().String()
- cfg, ct, exp, err := APIConnectWireguard(srv, pid, pub, preferTCP, openVPNSupport)
+ cfg, proto, exp, err := APIConnectWireguard(srv, pID, pub, preferTCP, openVPNSupport)
if err != nil {
return "", "", err
}
@@ -155,7 +155,7 @@ func wireguardGetConfig(srv Server, preferTCP bool, openVPNSupport bool) (string
b.StartTime = time.Now()
b.EndTime = exp
- if ct == "wireguard" {
+ if proto == "wireguard" {
// 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
@@ -163,7 +163,7 @@ func wireguardGetConfig(srv Server, preferTCP bool, openVPNSupport bool) (string
cfg = wireguard.ConfigAddKey(cfg, key)
}
- return cfg, ct, nil
+ return cfg, proto, nil
}
func openVPNGetConfig(srv Server, preferTCP bool) (string, string, error) {
@@ -173,15 +173,14 @@ func openVPNGetConfig(srv Server, preferTCP bool) (string, string, error) {
}
pid := b.Profiles.Current
cfg, exp, err := APIConnectOpenVPN(srv, pid, preferTCP)
+ if err != nil {
+ return "", "", err
+ }
// Store start and end time
b.StartTime = time.Now()
b.EndTime = exp
- if err != nil {
- return "", "", err
- }
-
return cfg, "openvpn", nil
}
diff --git a/internal/server/servers.go b/internal/server/servers.go
index b34dcff..5ede005 100644
--- a/internal/server/servers.go
+++ b/internal/server/servers.go
@@ -43,12 +43,11 @@ func (ss *Servers) GetCurrentServer() (Server, error) {
if ss.IsType == CustomServerType {
srvs = &ss.CustomServers
}
- bs := srvs.Map
- if bs == nil {
+ if srvs.Map == nil {
return nil, errors.Errorf("srvs.Map is nil")
}
- if srv, ok := bs[srvs.CurrentURL]; !ok || srv == nil {
+ if srv, ok := srvs.Map[srvs.CurrentURL]; !ok || srv == nil {
return nil, errors.Errorf("server not found")
} else {
return srv, nil
@@ -59,7 +58,7 @@ func (ss *Servers) addInstituteAndCustom(
discoServer *types.DiscoveryServer,
isCustom bool,
) (Server, error) {
- url := discoServer.BaseURL
+ URL := discoServer.BaseURL
srvs := &ss.InstituteServers
srvType := InstituteAccessServerType
@@ -72,17 +71,17 @@ func (ss *Servers) addInstituteAndCustom(
srvs.Map = make(map[string]*InstituteAccessServer)
}
- srv, ok := srvs.Map[url]
+ srv, ok := srvs.Map[URL]
// initialize the server if it doesn't exist yet
if !ok {
srv = &InstituteAccessServer{}
}
- if err := srv.init(url, discoServer.DisplayName, discoServer.Type, discoServer.SupportContact); err != nil {
+ if err := srv.init(URL, discoServer.DisplayName, discoServer.Type, discoServer.SupportContact); err != nil {
return nil, err
}
- srvs.Map[url] = srv
+ srvs.Map[URL] = srv
ss.IsType = srvType
return srv, nil
}