|
@@ -23,6 +23,7 @@ const (
|
|
|
type L2TPManager struct {
|
|
type L2TPManager struct {
|
|
|
mu sync.Mutex
|
|
mu sync.Mutex
|
|
|
instances []L2TPInstance
|
|
instances []L2TPInstance
|
|
|
|
|
+ pppServer *PPPServerManager
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func NewL2TPManager() *L2TPManager {
|
|
func NewL2TPManager() *L2TPManager {
|
|
@@ -33,6 +34,10 @@ func NewL2TPManager() *L2TPManager {
|
|
|
return m
|
|
return m
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (m *L2TPManager) SetPPPServer(ps *PPPServerManager) {
|
|
|
|
|
+ m.pppServer = ps
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (m *L2TPManager) load() {
|
|
func (m *L2TPManager) load() {
|
|
|
data, err := os.ReadFile(L2TPInstancesStorePath)
|
|
data, err := os.ReadFile(L2TPInstancesStorePath)
|
|
|
if err == nil {
|
|
if err == nil {
|
|
@@ -168,6 +173,11 @@ func (m *L2TPManager) regenerateXl2tpdConf() error {
|
|
|
if prof == "" {
|
|
if prof == "" {
|
|
|
prof = "default-encryption"
|
|
prof = "default-encryption"
|
|
|
}
|
|
}
|
|
|
|
|
+ var profObj *PPPProfile
|
|
|
|
|
+ if m.pppServer != nil {
|
|
|
|
|
+ profObj = m.pppServer.GetProfile(prof)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
optFile := fmt.Sprintf("/etc/ppp/options.l2tpd.%s", inst.Name)
|
|
optFile := fmt.Sprintf("/etc/ppp/options.l2tpd.%s", inst.Name)
|
|
|
sb.WriteString(fmt.Sprintf("[lac %s]\n", inst.Name))
|
|
sb.WriteString(fmt.Sprintf("[lac %s]\n", inst.Name))
|
|
|
sb.WriteString(fmt.Sprintf("lns = %s\n", inst.ConnectTo))
|
|
sb.WriteString(fmt.Sprintf("lns = %s\n", inst.ConnectTo))
|
|
@@ -185,11 +195,42 @@ func (m *L2TPManager) regenerateXl2tpdConf() error {
|
|
|
optSb.WriteString("ipcp-accept-remote\n")
|
|
optSb.WriteString("ipcp-accept-remote\n")
|
|
|
optSb.WriteString("refuse-eap\n")
|
|
optSb.WriteString("refuse-eap\n")
|
|
|
optSb.WriteString("require-mschap-v2\n")
|
|
optSb.WriteString("require-mschap-v2\n")
|
|
|
- if strings.EqualFold(prof, "default") {
|
|
|
|
|
- optSb.WriteString("nomppe\n")
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if profObj != nil {
|
|
|
|
|
+ switch strings.ToLower(profObj.UseEncryption) {
|
|
|
|
|
+ case "no":
|
|
|
|
|
+ optSb.WriteString("nomppe\n")
|
|
|
|
|
+ case "yes":
|
|
|
|
|
+ optSb.WriteString("mppe-128\n")
|
|
|
|
|
+ default:
|
|
|
|
|
+ optSb.WriteString("require-mppe-128\n")
|
|
|
|
|
+ }
|
|
|
|
|
+ if profObj.DNSServers != "" {
|
|
|
|
|
+ for _, dns := range strings.Split(profObj.DNSServers, ",") {
|
|
|
|
|
+ dns = strings.TrimSpace(dns)
|
|
|
|
|
+ if dns != "" {
|
|
|
|
|
+ optSb.WriteString(fmt.Sprintf("ms-dns %s\n", dns))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if profObj.LocalAddress != "" && profObj.RemoteAddress != "" {
|
|
|
|
|
+ local := strings.TrimSpace(profObj.LocalAddress)
|
|
|
|
|
+ remote := strings.TrimSpace(profObj.RemoteAddress)
|
|
|
|
|
+ if strings.Contains(remote, "-") {
|
|
|
|
|
+ remote = strings.TrimSpace(strings.Split(remote, "-")[0])
|
|
|
|
|
+ }
|
|
|
|
|
+ if local != "" && remote != "" {
|
|
|
|
|
+ optSb.WriteString(fmt.Sprintf("%s:%s\n", local, remote))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- optSb.WriteString("require-mppe-128\n")
|
|
|
|
|
|
|
+ if strings.EqualFold(prof, "default") {
|
|
|
|
|
+ optSb.WriteString("nomppe\n")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ optSb.WriteString("require-mppe-128\n")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
optSb.WriteString("noccp\n")
|
|
optSb.WriteString("noccp\n")
|
|
|
optSb.WriteString("noauth\n")
|
|
optSb.WriteString("noauth\n")
|
|
|
optSb.WriteString("mtu 1410\n")
|
|
optSb.WriteString("mtu 1410\n")
|