mirror of
https://github.com/luscis/openlan.git
synced 2025-12-24 11:10:54 +08:00
fix: correct openvpn clients
This commit is contained in:
@@ -90,10 +90,7 @@ func (n *Network) Correct(sw *Switch) {
|
||||
CorrectRoutes(n.Routes, ipAddr)
|
||||
|
||||
if n.OpenVPN != nil {
|
||||
n.OpenVPN.Network = n.Name
|
||||
obj := DefaultOpenVPN()
|
||||
n.OpenVPN.Merge(obj)
|
||||
n.OpenVPN.Correct(sw)
|
||||
n.OpenVPN.Correct(sw.AddrPool, n.Name)
|
||||
}
|
||||
|
||||
for key, value := range n.FindHop {
|
||||
|
||||
@@ -50,10 +50,6 @@ var defaultVpn = &OpenVPN{
|
||||
Script: "/usr/bin/openlan",
|
||||
}
|
||||
|
||||
func DefaultOpenVPN() *OpenVPN {
|
||||
return defaultVpn
|
||||
}
|
||||
|
||||
func (o *OpenVPN) AuthBin(obj *OpenVPN) string {
|
||||
bin := obj.Script
|
||||
bin += " -l " + obj.Url
|
||||
@@ -62,63 +58,59 @@ func (o *OpenVPN) AuthBin(obj *OpenVPN) string {
|
||||
return bin
|
||||
}
|
||||
|
||||
func (o *OpenVPN) Merge(obj *OpenVPN) {
|
||||
if obj == nil {
|
||||
return
|
||||
}
|
||||
if o.Network == "" {
|
||||
o.Network = obj.Network
|
||||
}
|
||||
func (o *OpenVPN) Correct(pool, network string) {
|
||||
o.Network = network
|
||||
|
||||
if o.Auth == "" {
|
||||
o.Auth = obj.Auth
|
||||
o.Auth = defaultVpn.Auth
|
||||
}
|
||||
if o.Protocol == "" {
|
||||
o.Protocol = obj.Protocol
|
||||
o.Protocol = defaultVpn.Protocol
|
||||
}
|
||||
if o.DhPem == "" {
|
||||
o.DhPem = obj.DhPem
|
||||
o.DhPem = defaultVpn.DhPem
|
||||
}
|
||||
if o.RootCa == "" {
|
||||
o.RootCa = obj.RootCa
|
||||
o.RootCa = defaultVpn.RootCa
|
||||
}
|
||||
if o.ServerCrt == "" {
|
||||
o.ServerCrt = obj.ServerCrt
|
||||
o.ServerCrt = defaultVpn.ServerCrt
|
||||
}
|
||||
if o.ServerKey == "" {
|
||||
o.ServerKey = obj.ServerKey
|
||||
o.ServerKey = defaultVpn.ServerKey
|
||||
}
|
||||
if o.TlsAuth == "" {
|
||||
o.TlsAuth = obj.TlsAuth
|
||||
o.TlsAuth = defaultVpn.TlsAuth
|
||||
}
|
||||
if o.Cipher == "" {
|
||||
o.Cipher = obj.Cipher
|
||||
o.Cipher = defaultVpn.Cipher
|
||||
}
|
||||
|
||||
if o.Script == "" {
|
||||
o.Script = o.AuthBin(defaultVpn)
|
||||
}
|
||||
if len(o.Routes) == 0 {
|
||||
o.Routes = append(o.Routes, obj.Routes...)
|
||||
}
|
||||
if len(o.Push) == 0 {
|
||||
o.Push = append(o.Push, obj.Push...)
|
||||
}
|
||||
if o.Script == "" {
|
||||
o.Script = o.AuthBin(obj)
|
||||
}
|
||||
if len(o.Clients) == 0 {
|
||||
o.Clients = append(o.Clients, obj.Clients...)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OpenVPN) Correct(sw *Switch) {
|
||||
o.Directory = VarDir("openvpn", o.Network)
|
||||
if !strings.Contains(o.Listen, ":") {
|
||||
o.Listen += ":1194"
|
||||
}
|
||||
|
||||
_, port := libol.GetHostPort(o.Listen)
|
||||
o.Device = fmt.Sprintf("tun%s", port)
|
||||
pool := sw.AddrPool
|
||||
|
||||
if o.Subnet == "" {
|
||||
value, _ := strconv.Atoi(port)
|
||||
o.Subnet = fmt.Sprintf("%s.%d.0/24", pool, value&0xff)
|
||||
}
|
||||
|
||||
for _, c := range o.Clients {
|
||||
if c.Name == "" || c.Address == "" {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(c.Name, "@") {
|
||||
c.Name = c.Name + "@" + o.Network
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OpenVPN) AddRedirectDef1() bool {
|
||||
|
||||
@@ -127,8 +127,7 @@ func (s *Switch) Correct() {
|
||||
}
|
||||
s.Http.Correct()
|
||||
|
||||
vpn := DefaultOpenVPN()
|
||||
vpn.Url = s.Http.GetUrl()
|
||||
defaultVpn.Url = s.Http.GetUrl()
|
||||
|
||||
if s.Timeout == 0 {
|
||||
s.Timeout = 120
|
||||
|
||||
Reference in New Issue
Block a user