| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | package ncutilsimport (	"fmt"	"os/exec"	"strconv"	"strings"	"github.com/gravitl/netmaker/models"	"golang.zx2c4.com/wireguard/wgctrl/wgtypes")// RunCmd - runs a local commandfunc RunCmd(command string, printerr bool) (string, error) {	args := strings.Fields(command)	cmd := exec.Command(args[0], args[1:]...)	cmd.Wait()	out, err := cmd.CombinedOutput()	if err != nil && printerr {		Log(fmt.Sprintf("error running command: %s", command))		Log(strings.TrimSuffix(string(out), "\n"))	}	return string(out), err}// RunCmdFormatted - does nothing for linuxfunc RunCmdFormatted(command string, printerr bool) (string, error) {	return "", nil}// GetEmbedded - if files required for linux, put herefunc GetEmbedded() error {	return nil}// CreateWireGuardConf - creates a user space WireGuard conffunc CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) {	peersString, err := parsePeers(node.PersistentKeepalive, peers)	var listenPortString, postDownString, postUpString string	if node.MTU <= 0 {		node.MTU = 1280	}	if node.PostDown != "" {		postDownString = fmt.Sprintf("PostDown = %s", node.PostDown)	}	if node.PostUp != "" {		postUpString = fmt.Sprintf("PostUp = %s", node.PostUp)	}	if listenPort != "" {		listenPortString = fmt.Sprintf("ListenPort = %s", listenPort)	}	if err != nil {		return "", err	}	config := fmt.Sprintf(`[Interface]Address = %sPrivateKey = %sMTU = %s%s%s%s%s`,		node.Address+"/32",		privatekey,		strconv.Itoa(int(node.MTU)),		postDownString,		postUpString,		listenPortString,		peersString)	return config, nil}
 |