mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 09:22:42 +08:00
Merge branch 'feature_v0.8_initial_qa' of https://github.com/gravitl/netmaker into feature_v0.8_userspace
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,6 +9,8 @@ netclient/netclient-amd64
|
||||
netclient/netclient-arm
|
||||
netclient/netclient-arm64
|
||||
netclient/netclient-32
|
||||
netclient/netclient32
|
||||
netclient/netclient.exe
|
||||
config/dnsconfig/
|
||||
winsw.exe
|
||||
data/
|
||||
|
@@ -108,9 +108,9 @@ func CreateServerToken(netID string) (string, error) {
|
||||
GRPCSSL: "off",
|
||||
}
|
||||
}
|
||||
log.Println("APIConnString:",servervals.APIConnString)
|
||||
log.Println("GRPCConnString:",servervals.GRPCConnString)
|
||||
log.Println("GRPCSSL:",servervals.GRPCSSL)
|
||||
log.Println("APIConnString:", servervals.APIConnString)
|
||||
log.Println("GRPCConnString:", servervals.GRPCConnString)
|
||||
log.Println("GRPCSSL:", servervals.GRPCSSL)
|
||||
accessToken.ServerConfig = servervals
|
||||
accessToken.ClientConfig.Network = netID
|
||||
accessToken.ClientConfig.Key = GenKey()
|
||||
@@ -123,7 +123,7 @@ func CreateServerToken(netID string) (string, error) {
|
||||
return accesskey.AccessString, err
|
||||
}
|
||||
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(tokenjson))
|
||||
log.Println("accessstring:",accesskey.AccessString)
|
||||
log.Println("accessstring:", accesskey.AccessString)
|
||||
network.AccessKeys = append(network.AccessKeys, accesskey)
|
||||
if data, err := json.Marshal(network); err != nil {
|
||||
return "", err
|
||||
@@ -235,6 +235,7 @@ func UpdateNetworkNodeAddresses(networkName string) error {
|
||||
}
|
||||
|
||||
node.Address = ipaddr
|
||||
node.PullChanges = "yes"
|
||||
data, err := json.Marshal(&node)
|
||||
if err != nil {
|
||||
return err
|
||||
|
2
go.mod
2
go.mod
@@ -28,7 +28,7 @@ require (
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
golang.zx2c4.com/wireguard v0.0.0-20210805125648-3957e9b9dd19 // indirect
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de
|
||||
golang.zx2c4.com/wireguard/windows v0.4.5 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 // indirect
|
||||
google.golang.org/grpc v1.35.0
|
||||
|
2
go.sum
2
go.sum
@@ -340,6 +340,8 @@ golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b h1:l4mBVCYi
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b/go.mod h1:UdS9frhv65KTfwxME1xE8+rHYoFpbm36gOud1GhBe9c=
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c h1:ADNrRDI5NR23/TUCnEmlLZLt4u9DnZ2nwRkPrAcFvto=
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c/go.mod h1:+1XihzyZUBJcSc5WO9SwNA7v26puQwOEDwanaxfNXPQ=
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de h1:M9Jc92kgqmVmidpnOeegP2VgO2DfHEcsUWtWMmBwNFQ=
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de/go.mod h1:+1XihzyZUBJcSc5WO9SwNA7v26puQwOEDwanaxfNXPQ=
|
||||
golang.zx2c4.com/wireguard/windows v0.4.5 h1:btpw+5IM8UrSl5SILCODt1bXTM2qYpcaYArM6wDlwHA=
|
||||
golang.zx2c4.com/wireguard/windows v0.4.5/go.mod h1:LdS2bRTWu//RpztraGz5ZkPZul60cCbmgtLTPSKrS50=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
|
@@ -26,7 +26,7 @@ const NODE_NOOP = "noop"
|
||||
var seededRand *rand.Rand = rand.New(
|
||||
rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
//node struct
|
||||
// node struct
|
||||
type Node struct {
|
||||
ID string `json:"id,omitempty" bson:"id,omitempty"`
|
||||
Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"`
|
||||
|
@@ -64,7 +64,7 @@ func RunUserspaceDaemon() {
|
||||
if err := CheckIn(cfg); err != nil {
|
||||
// pass
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
time.Sleep(15 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,9 +35,9 @@ func SetupWindowsDaemon() error {
|
||||
ncutils.Log("finished daemon setup")
|
||||
}
|
||||
// install daemon, will not overwrite
|
||||
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, true)
|
||||
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, false)
|
||||
// start daemon, will not restart or start another
|
||||
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, true)
|
||||
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
|
||||
ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
|
||||
return nil
|
||||
}
|
||||
|
@@ -131,15 +131,10 @@ func LeaveNetwork(network string) error {
|
||||
} else {
|
||||
wcclient = nodepb.NewNodeServiceClient(conn)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, err = auth.SetJWT(wcclient, network)
|
||||
ctx, err := auth.SetJWT(wcclient, network)
|
||||
if err != nil {
|
||||
log.Printf("Failed to authenticate: %v", err)
|
||||
} else {
|
||||
if !ncutils.IsKernel() {
|
||||
//wireguard.RemoveConf(node.Interface, true)
|
||||
//ncutils.PrintLog("removed network tunnel "+node.Interface, 1)
|
||||
}
|
||||
node.SetID()
|
||||
var header metadata.MD
|
||||
_, err = wcclient.DeleteNode(
|
||||
|
@@ -352,7 +352,7 @@ func main() {
|
||||
}
|
||||
if !ncutils.IsKernel() {
|
||||
if !local.IsWGInstalled() {
|
||||
log.Fatal("Please install Windows WireGuard before using Gravitl Netclient. https://download.wireguard.com")
|
||||
log.Fatal("Please install WireGuard before using Gravitl Netclient. https://download.wireguard.com")
|
||||
}
|
||||
}
|
||||
if len(os.Args) == 1 && ncutils.IsWindows() {
|
||||
|
@@ -323,7 +323,9 @@ func Copy(src, dst string) (int64, error) {
|
||||
|
||||
func RunCmd(command string, printerr bool) (string, error) {
|
||||
args := strings.Fields(command)
|
||||
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
cmd.Wait()
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil && printerr {
|
||||
log.Println("error running command:", command)
|
||||
log.Println(strings.TrimSuffix(string(out), "\n"))
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/netclient/config"
|
||||
@@ -27,6 +28,7 @@ func SetPeers(iface string, keepalive int32, peers []wgtypes.PeerConfig) error {
|
||||
ncutils.PrintLog("failed to start wgctrl", 0)
|
||||
return err
|
||||
}
|
||||
|
||||
device, err := client.Device(iface)
|
||||
if err != nil {
|
||||
ncutils.PrintLog("failed to parse interface", 0)
|
||||
@@ -174,7 +176,12 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||
return err
|
||||
}
|
||||
// spin up userspace / windows interface + apply the conf file
|
||||
_ = RemoveConf(ifacename, false) // remove interface first
|
||||
d, _ := wgclient.Device(ifacename)
|
||||
for d != nil && d.Name == ifacename {
|
||||
_ = RemoveConf(ifacename, false) // remove interface first
|
||||
time.Sleep(time.Second >> 2)
|
||||
d, _ = wgclient.Device(ifacename)
|
||||
}
|
||||
err = ApplyConf(confPath)
|
||||
if err != nil {
|
||||
ncutils.PrintLog("failed to create wireguard interface", 1)
|
||||
@@ -274,10 +281,6 @@ func SetWGConfig(network string, peerupdate bool) error {
|
||||
} else {
|
||||
err = InitWireguard(&nodecfg, privkey, peers, hasGateway, gateways)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -299,7 +302,7 @@ func ApplyConf(confPath string) error {
|
||||
var err error
|
||||
switch os {
|
||||
case "windows":
|
||||
err = ApplyWindowsConf(confPath)
|
||||
_ = ApplyWindowsConf(confPath)
|
||||
default:
|
||||
err = ApplyWGQuickConf(confPath)
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package wireguard
|
||||
import "github.com/gravitl/netmaker/netclient/ncutils"
|
||||
|
||||
func ApplyWindowsConf(confPath string) error {
|
||||
if _, err := ncutils.RunCmd("wireguard.exe /installtunnelservice "+confPath, true); err != nil {
|
||||
if _, err := ncutils.RunCmd("wireguard.exe /installtunnelservice "+confPath, false); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user