fixing windows

This commit is contained in:
afeiszli
2021-11-17 21:57:27 -05:00
parent 20a939b188
commit ccbd6f90f7
8 changed files with 162 additions and 48 deletions

View File

@@ -18,3 +18,39 @@ func RunCmd(command string, printerr bool) (string, error) {
}
return string(out), err
}
// CreateUserSpaceConf - creates a user space WireGuard conf
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, fwmark int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(perskeepalive, peers)
var listenPortString string
var fwmarkString string
if mtu <= 0 {
mtu = 1280
}
if listenPort != "" {
listenPortString += "ListenPort = " + listenPort
}
if fwmark != 0 {
fwmarkString += "FWMark = " + strconv.Itoa(int(fwmark))
}
if err != nil {
return "", err
}
config := fmt.Sprintf(`[Interface]
Address = %s
PrivateKey = %s
MTU = %s
%s
%s
%s
`,
address+"/32",
privatekey,
strconv.Itoa(int(mtu)),
listenPortString,
fwmarkString,
peersString)
return config, nil
}