mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
use RunCmd for postup/postdown
This commit is contained in:
@@ -659,8 +659,7 @@ func deleteInterface(ifacename string, postdown string) error {
|
|||||||
}
|
}
|
||||||
_, err = ncutils.RunCmd(ipExec+" link del "+ifacename, false)
|
_, err = ncutils.RunCmd(ipExec+" link del "+ifacename, false)
|
||||||
if postdown != "" {
|
if postdown != "" {
|
||||||
runcmds := strings.Split(postdown, "; ")
|
_, err = ncutils.RunCmd(postdown, false)
|
||||||
err = ncutils.RunCmds(runcmds, false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@@ -191,8 +191,7 @@ func removeLocalServer(node *models.Node) error {
|
|||||||
logger.Log(1, out)
|
logger.Log(1, out)
|
||||||
}
|
}
|
||||||
if node.PostDown != "" {
|
if node.PostDown != "" {
|
||||||
runcmds := strings.Split(node.PostDown, "; ")
|
ncutils.RunCmd(node.PostDown, false)
|
||||||
_ = ncutils.RunCmds(runcmds, false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -437,6 +437,10 @@ func Copy(src, dst string) error {
|
|||||||
func RunCmds(commands []string, printerr bool) error {
|
func RunCmds(commands []string, printerr bool) error {
|
||||||
var err error
|
var err error
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
|
//prevent panic
|
||||||
|
if command == " " {
|
||||||
|
continue
|
||||||
|
}
|
||||||
args := strings.Fields(command)
|
args := strings.Fields(command)
|
||||||
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
||||||
if err != nil && printerr {
|
if err != nil && printerr {
|
||||||
|
@@ -335,22 +335,31 @@ func WriteWgConfig(node *models.Node, privateKey string, peers []wgtypes.PeerCon
|
|||||||
// 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
|
//need to split postup/postdown because ini lib adds a ` and the ` breaks freebsd
|
||||||
|
//works fine on others
|
||||||
if node.PostUp != "" {
|
if node.PostUp != "" {
|
||||||
parts := strings.Split(node.PostUp, " ; ")
|
if node.OS == "freebsd" {
|
||||||
for i, part := range parts {
|
parts := strings.Split(node.PostUp, " ; ")
|
||||||
if i == 0 {
|
for i, part := range parts {
|
||||||
wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
if i == 0 {
|
||||||
|
wireguard.Section(section_interface).Key("PostUp").SetValue(part)
|
||||||
|
}
|
||||||
|
wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
||||||
}
|
}
|
||||||
wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
|
} else {
|
||||||
|
wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.PostDown != "" {
|
if node.PostDown != "" {
|
||||||
parts := strings.Split(node.PostDown, " ; ")
|
if node.OS == "freebsd" {
|
||||||
for i, part := range parts {
|
parts := strings.Split(node.PostDown, " ; ")
|
||||||
if i == 0 {
|
for i, part := range parts {
|
||||||
wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
if i == 0 {
|
||||||
|
wireguard.Section(section_interface).Key("PostDown").SetValue(part)
|
||||||
|
}
|
||||||
|
wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
||||||
}
|
}
|
||||||
wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
|
} else {
|
||||||
|
wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.MTU != 0 {
|
if node.MTU != 0 {
|
||||||
|
@@ -19,8 +19,7 @@ func WgQuickDownMac(node *models.Node, iface string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if node.PostDown != "" {
|
if node.PostDown != "" {
|
||||||
runcmds := strings.Split(node.PostDown, "; ")
|
ncutils.RunCmd(node.PostDown, true)
|
||||||
ncutils.RunCmds(runcmds, true)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -85,8 +84,7 @@ func WgQuickUpMac(node *models.Node, iface string, confPath string) error {
|
|||||||
//next, wg-quick runs monitor_daemon
|
//next, wg-quick runs monitor_daemon
|
||||||
time.Sleep(time.Second / 2)
|
time.Sleep(time.Second / 2)
|
||||||
if node.PostUp != "" {
|
if node.PostUp != "" {
|
||||||
runcmds := strings.Split(node.PostUp, "; ")
|
ncutils.RunCmd(node.PostUp, true)
|
||||||
ncutils.RunCmds(runcmds, true)
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -99,8 +99,7 @@ func ApplyWithoutWGQuick(node *models.Node, ifacename, confPath string, isConnec
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if node.PostDown != "" {
|
if node.PostDown != "" {
|
||||||
runcmds := strings.Split(node.PostDown, "; ")
|
ncutils.RunCmd(node.PostDown, false)
|
||||||
_ = ncutils.RunCmds(runcmds, false)
|
|
||||||
}
|
}
|
||||||
// set MTU of node interface
|
// set MTU of node interface
|
||||||
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
|
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
|
||||||
@@ -108,8 +107,7 @@ func ApplyWithoutWGQuick(node *models.Node, ifacename, confPath string, isConnec
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if node.PostUp != "" {
|
if node.PostUp != "" {
|
||||||
runcmds := strings.Split(node.PostUp, "; ")
|
ncutils.RunCmd(node.PostUp, false)
|
||||||
_ = ncutils.RunCmds(runcmds, true)
|
|
||||||
}
|
}
|
||||||
if node.Address6 != "" {
|
if node.Address6 != "" {
|
||||||
logger.Log(1, "adding address: ", node.Address6)
|
logger.Log(1, "adding address: ", node.Address6)
|
||||||
@@ -139,8 +137,7 @@ func RemoveWithoutWGQuick(ifacename string) error {
|
|||||||
nodeconf, err := config.ReadConfig(network)
|
nodeconf, err := config.ReadConfig(network)
|
||||||
if nodeconf != nil && err == nil {
|
if nodeconf != nil && err == nil {
|
||||||
if nodeconf.Node.PostDown != "" {
|
if nodeconf.Node.PostDown != "" {
|
||||||
runcmds := strings.Split(nodeconf.Node.PostDown, "; ")
|
ncutils.RunCmd(nodeconf.Node.PostDown, false)
|
||||||
_ = ncutils.RunCmds(runcmds, false)
|
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
logger.Log(1, "error retrieving config: ", err.Error())
|
logger.Log(1, "error retrieving config: ", err.Error())
|
||||||
|
Reference in New Issue
Block a user