|
@@ -2,7 +2,6 @@ package wireguard
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
- "log"
|
|
|
|
"net"
|
|
"net"
|
|
"runtime"
|
|
"runtime"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -52,7 +51,7 @@ func SetPeers(iface string, node *models.Node, peers []wgtypes.PeerConfig) error
|
|
currentPeer.PublicKey.String() != peer.PublicKey.String() {
|
|
currentPeer.PublicKey.String() != peer.PublicKey.String() {
|
|
_, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
_, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println("error removing peer", peer.Endpoint.String())
|
|
|
|
|
|
+ logger.Log(0, "error removing peer", peer.Endpoint.String())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -82,7 +81,7 @@ func SetPeers(iface string, node *models.Node, peers []wgtypes.PeerConfig) error
|
|
" allowed-ips "+allowedips, true)
|
|
" allowed-ips "+allowedips, true)
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println("error setting peer", peer.PublicKey.String())
|
|
|
|
|
|
+ logger.Log(0, "error setting peer", peer.PublicKey.String())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,7 +103,7 @@ func SetPeers(iface string, node *models.Node, peers []wgtypes.PeerConfig) error
|
|
if shouldDelete {
|
|
if shouldDelete {
|
|
output, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
output, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println(output, "error removing peer", currentPeer.PublicKey.String())
|
|
|
|
|
|
+ logger.Log(0, output, "error removing peer", currentPeer.PublicKey.String())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, ip := range currentPeer.AllowedIPs {
|
|
for _, ip := range currentPeer.AllowedIPs {
|
|
@@ -341,11 +340,24 @@ func WriteWgConfig(node *models.Node, privateKey string, peers []wgtypes.PeerCon
|
|
//if node.DNSOn == "yes" {
|
|
//if node.DNSOn == "yes" {
|
|
// wireguard.Section(section_interface).Key("DNS").SetValue(cfg.Server.CoreDNSAddr)
|
|
// wireguard.Section(section_interface).Key("DNS").SetValue(cfg.Server.CoreDNSAddr)
|
|
//}
|
|
//}
|
|
|
|
+ //need to split postup/postdown because ini lib adds a ` and the ` breaks freebsd
|
|
if node.PostUp != "" {
|
|
if node.PostUp != "" {
|
|
- wireguard.Section(section_interface).Key("PostUp").SetValue(node.PostUp)
|
|
|
|
|
|
+ parts := strings.Split(node.PostUp, " ; ")
|
|
|
|
+ for i, part := range parts {
|
|
|
|
+ if i == 0 {
|
|
|
|
+ wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
|
|
|
+ }
|
|
|
|
+ wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if node.PostDown != "" {
|
|
if node.PostDown != "" {
|
|
- wireguard.Section(section_interface).Key("PostDown").SetValue(node.PostDown)
|
|
|
|
|
|
+ parts := strings.Split(node.PostDown, " ; ")
|
|
|
|
+ for i, part := range parts {
|
|
|
|
+ if i == 0 {
|
|
|
|
+ wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
|
|
|
+ }
|
|
|
|
+ wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if node.MTU != 0 {
|
|
if node.MTU != 0 {
|
|
wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
|
|
wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
|
|
@@ -451,11 +463,24 @@ func UpdateWgInterface(file, privateKey, nameserver string, node models.Node) er
|
|
//if node.DNSOn == "yes" {
|
|
//if node.DNSOn == "yes" {
|
|
// wireguard.Section(section_interface).Key("DNS").SetValue(nameserver)
|
|
// wireguard.Section(section_interface).Key("DNS").SetValue(nameserver)
|
|
//}
|
|
//}
|
|
|
|
+ //need to split postup/postdown because ini lib adds a quotes which breaks freebsd
|
|
if node.PostUp != "" {
|
|
if node.PostUp != "" {
|
|
- wireguard.Section(section_interface).Key("PostUp").SetValue(node.PostUp)
|
|
|
|
|
|
+ parts := strings.Split(node.PostUp, " ; ")
|
|
|
|
+ for i, part := range parts {
|
|
|
|
+ if i == 0 {
|
|
|
|
+ wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
|
|
|
+ }
|
|
|
|
+ wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if node.PostDown != "" {
|
|
if node.PostDown != "" {
|
|
- wireguard.Section(section_interface).Key("PostDown").SetValue(node.PostDown)
|
|
|
|
|
|
+ parts := strings.Split(node.PostDown, ";")
|
|
|
|
+ for i, part := range parts {
|
|
|
|
+ if i == 0 {
|
|
|
|
+ wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
|
|
|
+ }
|
|
|
|
+ wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if node.MTU != 0 {
|
|
if node.MTU != 0 {
|
|
wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
|
|
wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
|