Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Nov 10, 2023
1 parent f37642d commit eea9f50
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
1 change: 0 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/eduvpn/eduvpn-common/internal/fsm"
"github.com/eduvpn/eduvpn-common/internal/http"
"github.com/eduvpn/eduvpn-common/internal/log"
"github.com/eduvpn/eduvpn-common/internal/oauth"
"github.com/eduvpn/eduvpn-common/internal/server"
"github.com/eduvpn/eduvpn-common/types/cookie"
discotypes "github.com/eduvpn/eduvpn-common/types/discovery"
Expand Down
7 changes: 3 additions & 4 deletions internal/api/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Info struct {
Info ListInfo `json:"info"`
}

func (i Info) Len() bool {
func (i Info) Len() int {
return len(i.Info.ProfileList)
}

Expand Down Expand Up @@ -52,16 +52,15 @@ func HasWireGuard(protos []string) bool {
}

func (i Info) FilterWireGuard() Info {
list := i.Info.ProfileList
var ret []Profile
for _, p := range i.Info.ProfileList {
if !hasOpenVPN(p.VPNProtoList) {
if !HasOpenVPN(p.VPNProtoList) {
continue
}
}
return Info{
Info: ListInfo{
ProfileList: ret,
}
},
}
}
2 changes: 1 addition & 1 deletion internal/api/profiles/profiles_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package profile
package profiles

import "testing"

Expand Down
69 changes: 35 additions & 34 deletions internal/config/v2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Servers struct {
}

type Connection struct {
// LastConnectedType is the identifier of the server that was last connected to
LastConnectedType string `json:"last_connected_type,omitempty"`
// LastConnectedType is the type of server that was last connected to
LastConnectedType server.Type `json:"last_connected_type,omitempty"`
// LastAuthorizeTime is the last time the user authorized the client manually in the browser
LastAuthorizeTime time.Time `json:"start_time,omitempty"`
// ExpireTime is the time when the connection expires
Expand Down Expand Up @@ -73,68 +73,69 @@ type Joined struct {
V2 *V2 `json:"v2"`
}

func convertV1Server(list v1.InstituteServers, iscurrent bool, t server.Type, m map[string]Server) *Connection {
func convertV1Server(list v1.InstituteServers, iscurrent bool, t server.Type) (ServerList, *Connection) {
ret := ServerList{LastChosenID: list.CurrentURL, List: make(map[string]Server)}
var conn *Connection
for k, v := range list.Map {
if list.CurrentURL == k && iscurrent {
if iscurrent && k == list.CurrentURL {
conn = &Connection{
LastConnectedID: k,
StartTime: v.Base.StartTime,
EndTime: v.Base.EndTime,
LastConnectedType: t,
ExpireTime: v.Base.EndTime,
}
}
var currP *string = nil
if v.Base.Profiles.Current != "" {
currP = &v.Base.Profiles.Current
}
m[k] = Server{
ProfileID: currP,
Type: t,
ret.List[k] = Server{
ProfileID: v.Base.Profiles.Current,
}
}
return conn
return ret, conn
}

func fromV1(ver1 *v1.V1) *V2 {
srvs := make(map[string]Server)
var inst ServerList
var cust ServerList
gsrvs := ver1.Servers

conn := convertV1Server(gsrvs.Custom, gsrvs.IsType == server.TypeCustom, server.TypeCustom, srvs)
conn = convertV1Server(gsrvs.Institute, gsrvs.IsType == server.TypeInstituteAccess, server.TypeInstituteAccess, srvs)
var conn *Connection
cust, gconn := convertV1Server(gsrvs.Custom, gsrvs.IsType == server.TypeCustom, server.TypeCustom)
if conn == nil {
conn = gconn
}
inst, gconn = convertV1Server(gsrvs.Institute, gsrvs.IsType == server.TypeInstituteAccess, server.TypeInstituteAccess)
if conn == nil {
conn = gconn
}
sec := gsrvs.SecureInternetHome
// if the home organization ID is filled we have secure internet present
if sec.HomeOrganizationID == "" {
return &V2{
Servers: Servers{
List: srvs,
InstituteAccess: inst,
Custom: cust,
},
Connection: conn,
}
}
sh := &sec.HomeOrganizationID
k := sec.CurrentLocation
v, ok := sec.BaseMap[k]
var secRet *SecureInternet
v, ok := sec.BaseMap[sec.CurrentLocation]
if v != nil && ok {
var currP *string = nil
if v.Profiles.Current != "" {
currP = &v.Profiles.Current
}
srvs[k] = Server{
ProfileID: currP,
Type: server.TypeSecureInternet,
secRet = &SecureInternet{
Server: Server{
ProfileID: v.Profiles.Current,
},
SecureHome: sec.HomeOrganizationID,
}
if gsrvs.IsType == server.TypeSecureInternet {
conn = &Connection{
LastConnectedID: k,
StartTime: v.StartTime,
EndTime: v.EndTime,
LastConnectedType: server.TypeSecureInternet,
ExpireTime: v.EndTime,
}
}
}
return &V2{
Servers: Servers{
List: srvs,
SecureHome: sh,
InstituteAccess: inst,
Custom: cust,
SecureInternet: secRet,
},
Connection: conn,
}
Expand Down

0 comments on commit eea9f50

Please sign in to comment.