|
@@ -196,6 +196,8 @@ func Install(accesskey string, password string, server string, network string, n
|
|
var privatekey wgtypes.Key
|
|
var privatekey wgtypes.Key
|
|
var privkeystring string
|
|
var privkeystring string
|
|
var endpoint string
|
|
var endpoint string
|
|
|
|
+ var postup string
|
|
|
|
+ var postdown string
|
|
var name string
|
|
var name string
|
|
var wginterface string
|
|
var wginterface string
|
|
|
|
|
|
@@ -274,6 +276,17 @@ func Install(accesskey string, password string, server string, network string, n
|
|
}
|
|
}
|
|
fmt.Println(" Interface: " + wginterface)
|
|
fmt.Println(" Interface: " + wginterface)
|
|
|
|
|
|
|
|
+ if nodecfg.PostUp != "" {
|
|
|
|
+ postup = nodecfg.PostUp
|
|
|
|
+ }
|
|
|
|
+ fmt.Println(" PostUp: " + postup)
|
|
|
|
+
|
|
|
|
+ if nodecfg.PostDown!= "" {
|
|
|
|
+ postdown = nodecfg.PostDown
|
|
|
|
+ }
|
|
|
|
+ fmt.Println(" PostDown: " + postdown)
|
|
|
|
+
|
|
|
|
+
|
|
if nodecfg.KeepAlive != 0 {
|
|
if nodecfg.KeepAlive != 0 {
|
|
keepalive = nodecfg.KeepAlive
|
|
keepalive = nodecfg.KeepAlive
|
|
}
|
|
}
|
|
@@ -347,6 +360,8 @@ func Install(accesskey string, password string, server string, network string, n
|
|
Accesskey: accesskey,
|
|
Accesskey: accesskey,
|
|
Nodenetwork: network,
|
|
Nodenetwork: network,
|
|
Listenport: listenport,
|
|
Listenport: listenport,
|
|
|
|
+ Postup: postup,
|
|
|
|
+ Postdown: postdown,
|
|
Keepalive: keepalive,
|
|
Keepalive: keepalive,
|
|
Localaddress: localaddress,
|
|
Localaddress: localaddress,
|
|
Interface: wginterface,
|
|
Interface: wginterface,
|
|
@@ -384,6 +399,8 @@ func Install(accesskey string, password string, server string, network string, n
|
|
fmt.Println(" Local Address: " + node.Localaddress)
|
|
fmt.Println(" Local Address: " + node.Localaddress)
|
|
fmt.Println(" Name: " + node.Name)
|
|
fmt.Println(" Name: " + node.Name)
|
|
fmt.Println(" Interface: " + node.Interface)
|
|
fmt.Println(" Interface: " + node.Interface)
|
|
|
|
+ fmt.Println(" PostUp: " + node.Postup)
|
|
|
|
+ fmt.Println(" PostDown: " + node.Postdown)
|
|
fmt.Println(" Port: " + strconv.FormatInt(int64(node.Listenport), 10))
|
|
fmt.Println(" Port: " + strconv.FormatInt(int64(node.Listenport), 10))
|
|
fmt.Println(" KeepAlive: " + strconv.FormatInt(int64(node.Keepalive), 10))
|
|
fmt.Println(" KeepAlive: " + strconv.FormatInt(int64(node.Keepalive), 10))
|
|
fmt.Println(" Public Key: " + node.Publickey)
|
|
fmt.Println(" Public Key: " + node.Publickey)
|
|
@@ -483,6 +500,12 @@ func modConfig(node *nodepb.Node) error{
|
|
if node.Localaddress != ""{
|
|
if node.Localaddress != ""{
|
|
nodecfg.LocalAddress = node.Localaddress
|
|
nodecfg.LocalAddress = node.Localaddress
|
|
}
|
|
}
|
|
|
|
+ if node.Postup != ""{
|
|
|
|
+ nodecfg.PostUp = node.Postup
|
|
|
|
+ }
|
|
|
|
+ if node.Postdown != ""{
|
|
|
|
+ nodecfg.PostDown = node.Postdown
|
|
|
|
+ }
|
|
if node.Listenport != 0{
|
|
if node.Listenport != 0{
|
|
nodecfg.Port = node.Listenport
|
|
nodecfg.Port = node.Listenport
|
|
}
|
|
}
|
|
@@ -655,12 +678,41 @@ func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig
|
|
Stderr: os.Stdout,
|
|
Stderr: os.Stdout,
|
|
}
|
|
}
|
|
err = cmdIPLinkDown.Run()
|
|
err = cmdIPLinkDown.Run()
|
|
- err = cmdIPLinkUp.Run()
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if nodecfg.PostDown != "" {
|
|
|
|
+ runcmds := strings.Split(nodecfg.PostDown, "; ")
|
|
|
|
+ err = runCmds(runcmds)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error encountered running PostDown: " + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = cmdIPLinkUp.Run()
|
|
|
|
+ if nodecfg.PostUp != "" {
|
|
|
|
+ runcmds := strings.Split(nodecfg.PostUp, "; ")
|
|
|
|
+ err = runCmds(runcmds)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error encountered running PostUp: " + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+func runCmds(commands []string) error {
|
|
|
|
+ var err error
|
|
|
|
+ for _, command := range commands {
|
|
|
|
+ fmt.Println("Running command: " + command)
|
|
|
|
+ args := strings.Fields(command)
|
|
|
|
+ out, err := exec.Command(args[0], args[1:]...).Output()
|
|
|
|
+ fmt.Println(string(out))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return err
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
func setWGKeyConfig(network string, serveraddr string) error {
|
|
func setWGKeyConfig(network string, serveraddr string) error {
|
|
|
|
|
|
@@ -936,7 +988,7 @@ func CheckIn(network string) error {
|
|
if ifaceupdate {
|
|
if ifaceupdate {
|
|
fmt.Println("Interface update: " + currentiface +
|
|
fmt.Println("Interface update: " + currentiface +
|
|
" >>>> " + newinterface)
|
|
" >>>> " + newinterface)
|
|
- err := DeleteInterface(currentiface)
|
|
|
|
|
|
+ err := DeleteInterface(currentiface, nodecfg.PostDown)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("ERROR DELETING INTERFACE: " + currentiface)
|
|
fmt.Println("ERROR DELETING INTERFACE: " + currentiface)
|
|
}
|
|
}
|
|
@@ -1183,12 +1235,19 @@ func WipeLocal(network string) error{
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
|
|
+ if nodecfg.PostDown != "" {
|
|
|
|
+ runcmds := strings.Split(nodecfg.PostDown, "; ")
|
|
|
|
+ err = runCmds(runcmds)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error encountered running PostDown: " + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return err
|
|
return err
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func DeleteInterface(ifacename string) error{
|
|
|
|
|
|
+func DeleteInterface(ifacename string, postdown string) error{
|
|
ipExec, err := exec.LookPath("ip")
|
|
ipExec, err := exec.LookPath("ip")
|
|
|
|
|
|
cmdIPLinkDel := &exec.Cmd {
|
|
cmdIPLinkDel := &exec.Cmd {
|
|
@@ -1201,6 +1260,13 @@ func DeleteInterface(ifacename string) error{
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
|
|
+ if postdown != "" {
|
|
|
|
+ runcmds := strings.Split(postdown, "; ")
|
|
|
|
+ err = runCmds(runcmds)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Error encountered running PostDown: " + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1260,7 +1326,7 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
break
|
|
break
|
|
}
|
|
}
|
|
- spew.Dump(res)
|
|
|
|
|
|
+ spew.Dump(res)
|
|
|
|
|
|
// if err, return an error
|
|
// if err, return an error
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -1272,6 +1338,13 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
|
return peers, err
|
|
return peers, err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("Got Peer: " + res.Peers.Publickey)
|
|
|
|
+ fmt.Println(" Address: " +res.Peers.Address)
|
|
|
|
+ fmt.Printf(" ListenPort: ",res.Peers.Listenport)
|
|
|
|
+ fmt.Println("")
|
|
|
|
+ fmt.Printf(" Gateway?: ",res.Peers.Isgateway)
|
|
|
|
+ fmt.Println("")
|
|
|
|
+ fmt.Println(" Gate Range: " + res.Peers.Gatewayrange)
|
|
pubkey, err := wgtypes.ParseKey(res.Peers.Publickey)
|
|
pubkey, err := wgtypes.ParseKey(res.Peers.Publickey)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("error parsing key")
|
|
fmt.Println("error parsing key")
|
|
@@ -1292,6 +1365,7 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
|
fmt.Println("NOT SETTING GATEWAY")
|
|
fmt.Println("NOT SETTING GATEWAY")
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
} else {
|
|
} else {
|
|
|
|
+ fmt.Println(" Gateway Range: " + res.Peers.Gatewayrange)
|
|
allowedips = append(allowedips, *ipnet)
|
|
allowedips = append(allowedips, *ipnet)
|
|
}
|
|
}
|
|
}
|
|
}
|