Skip to content

Commit

Permalink
fix subtle bugs, remove bad code
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-nettica committed Jun 25, 2024
1 parent 580a220 commit 5c1626f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
5 changes: 0 additions & 5 deletions core/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ func CreateNet(net *model.Network) (*model.Network, error) {
if err != nil {
return nil, err
}
if util.IsIPv6(ip) {
ip = ip + "/64"
} else {
ip = ip + "/24"
}
ips = append(ips, ip)
}

Expand Down
80 changes: 44 additions & 36 deletions core/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,54 @@ func CreateVPN(vpn *model.VPN) (*model.VPN, error) {
vpn.Id = "vpn-" + vpn.Id

// read the nets and configure the default values
nets, err := ReadNetworks(vpn.CreatedBy)
net, err := ReadNet(vpn.NetId)
if err != nil {
return nil, err
}

for _, net := range nets {
if net.NetName == vpn.NetName {
vpn.Default = net.Default
current := vpn.Current
vpn.Current = net.Default
vpn.Current.ListenPort = current.ListenPort
vpn.Current.Endpoint = current.Endpoint
vpn.Current.PrivateKey = current.PrivateKey
vpn.Current.PublicKey = current.PublicKey
vpn.Current.PostUp = current.PostUp
vpn.Current.PostDown = current.PostDown
vpn.Current.PersistentKeepalive = current.PersistentKeepalive
vpn.NetId = net.Id
vpn.AccountID = net.AccountID
vpn.Current.AllowedIPs = current.AllowedIPs
vpn.Current.Dns = net.Default.Dns
if current.FailSafe {
vpn.Current.FailSafe = current.FailSafe
}
if current.EnableDns {
vpn.Current.EnableDns = current.EnableDns
}
if current.UPnP {
vpn.Current.UPnP = current.UPnP
}
if current.SyncEndpoint && current.Endpoint != "" {
vpn.Current.SyncEndpoint = current.SyncEndpoint
}
if current.HasRDP {
vpn.Current.HasRDP = current.HasRDP
}
if current.HasSSH {
vpn.Current.HasSSH = current.HasSSH
}
}
if vpn.Default == nil {
vpn.Default = &model.Settings{}
}

if vpn.Current == nil {
vpn.Current = &model.Settings{}
}

if net.Default == nil {
return nil, errors.New("network default settings not found")
}

*vpn.Default = *net.Default
current := *vpn.Current
*vpn.Current = *net.Default
vpn.Current.ListenPort = current.ListenPort
vpn.Current.Endpoint = current.Endpoint
vpn.Current.PrivateKey = current.PrivateKey
vpn.Current.PublicKey = current.PublicKey
vpn.Current.PostUp = current.PostUp
vpn.Current.PostDown = current.PostDown
vpn.Current.PersistentKeepalive = current.PersistentKeepalive
vpn.NetId = net.Id
vpn.AccountID = net.AccountID
vpn.Current.AllowedIPs = current.AllowedIPs
vpn.Current.Dns = net.Default.Dns
if current.FailSafe {
vpn.Current.FailSafe = current.FailSafe
}
if current.EnableDns {
vpn.Current.EnableDns = current.EnableDns
}
if current.UPnP {
vpn.Current.UPnP = current.UPnP
}
if current.SyncEndpoint && current.Endpoint != "" {
vpn.Current.SyncEndpoint = current.SyncEndpoint
}
if current.HasRDP {
vpn.Current.HasRDP = current.HasRDP
}
if current.HasSSH {
vpn.Current.HasSSH = current.HasSSH
}

// if the vpn data already has a public key and empty private key,
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetNetworkAddress(cidr string) (string, error) {
if err != nil {
return "", err
}
networkAddr := ipnet.IP.String()
networkAddr := ipnet.String()

return networkAddr, nil

Expand Down

0 comments on commit 5c1626f

Please sign in to comment.