Kaynağa Gözat

using program files (x86) for windows

afeiszli 3 yıl önce
ebeveyn
işleme
25b60b1597

+ 0 - 62
netclient/auth/auth.go

@@ -7,68 +7,6 @@ import (
 	//    "os"
 )
 
-// SetJWT func will used to create the JWT while signing in and signing out
-//func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) {
-//	home := ncutils.GetNetclientPathSpecific()
-//	tokentext, err := os.ReadFile(home + "nettoken-" + network)
-//	if err != nil {
-//		err = AutoLogin(client, network)
-//		if err != nil {
-//			return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong with Auto Login: %v", err))
-//		}
-//		tokentext, err = ncutils.GetFileWithRetry(home+"nettoken-"+network, 1)
-//		if err != nil {
-//			return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong: %v", err))
-//		}
-//	}
-//	token := string(tokentext)
-//
-//	// Anything linked to this variable will transmit request headers.
-//	md := metadata.New(map[string]string{"authorization": token})
-//	ctx := context.Background()
-//	ctx = metadata.NewOutgoingContext(ctx, md)
-//	return ctx, nil
-//}
-
-// AutoLogin - auto logins whenever client needs to request from server
-//func AutoLogin(client nodepb.NodeServiceClient, network string) error {
-//	home := ncutils.GetNetclientPathSpecific()
-//	cfg, err := config.ReadConfig(network)
-//	if err != nil {
-//		return err
-//	}
-//	pass, err := RetrieveSecret(network)
-//	if err != nil {
-//		return err
-//	}
-//	node := models.Node{
-//		Password:   pass,
-//		MacAddress: cfg.Node.MacAddress,
-//		ID:         cfg.Node.ID,
-//		Network:    network,
-//	}
-//	data, err := json.Marshal(&node)
-//	if err != nil {
-//		return nil
-//	}
-//
-//	login := &nodepb.Object{
-//		Data: string(data),
-//		Type: nodepb.NODE_TYPE,
-//	}
-//	// RPC call
-//	res, err := client.Login(context.TODO(), login)
-//	if err != nil {
-//		return err
-//	}
-//	tokenstring := []byte(res.Data)
-//	err = os.WriteFile(home+"nettoken-"+network, tokenstring, 0600)
-//	if err != nil {
-//		return err
-//	}
-//	return err
-//}
-
 // StoreSecret - stores auth secret locally
 func StoreSecret(key string, network string) error {
 	d1 := []byte(key)

+ 1 - 7
netclient/command/commands.go

@@ -49,13 +49,7 @@ func Join(cfg *config.ClientConfig, privateKey string) error {
 		return err
 	}
 	logger.Log(1, "joined ", cfg.Network)
-	/*
-		if ncutils.IsWindows() {
-			logger.Log("setting up WireGuard app", 0)
-			time.Sleep(time.Second >> 1)
-			functions.Pull(cfg.Network, true)
-		}
-	*/
+
 	return err
 }
 

+ 17 - 3
netclient/daemon/windows.go

@@ -1,6 +1,7 @@
 package daemon
 
 import (
+	"fmt"
 	"strings"
 
 	"github.com/gravitl/netmaker/logger"
@@ -11,14 +12,27 @@ import (
 func RestartWindowsDaemon() {
 	StopWindowsDaemon()
 	// start daemon, will not restart or start another
-	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
+	dirPath := strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)
+	winCmd := fmt.Sprintf(`"%swinsw.exe" "start"`, dirPath)
+	out, err := ncutils.RunCmdFormatted(winCmd, true)
+	if err != nil {
+		logger.Log(0, "error starting Windows, Netclient daemon: "+err.Error()+" : "+out)
+	} else {
+		logger.Log(0, "started Windows Netclient daemon")
+	}
 }
 
 // == Daemon ==
 
 // StopWindowsDaemon - stops the Windows daemon
 func StopWindowsDaemon() {
-	logger.Log(0, "stopping Windows, Netclient daemon")
 	// stop daemon, will not overwrite
-	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true)
+	dirPath := strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)
+	winCmd := fmt.Sprintf(`"%swinsw.exe" "stop"`, dirPath)
+	out, err := ncutils.RunCmdFormatted(winCmd, true)
+	if err != nil {
+		logger.Log(0, "error stopping Windows, Netclient daemon: "+err.Error()+" : "+out)
+	} else {
+		logger.Log(0, "stopped Windows Netclient daemon")
+	}
 }

+ 1 - 4
netclient/main.go

@@ -11,7 +11,6 @@ import (
 	"github.com/gravitl/netmaker/netclient/cli_options"
 	"github.com/gravitl/netmaker/netclient/config"
 	"github.com/gravitl/netmaker/netclient/ncutils"
-	"github.com/gravitl/netmaker/netclient/ncwindows"
 	"github.com/urfave/cli/v2"
 )
 
@@ -30,9 +29,7 @@ func main() {
 
 	setGarbageCollection()
 
-	if ncutils.IsWindows() {
-		ncwindows.InitWindows()
-	} else {
+	if !ncutils.IsWindows() {
 		ncutils.CheckUID()
 		ncutils.CheckWG()
 	}

+ 0 - 46
netclient/ncwindows/windows.go

@@ -1,46 +0,0 @@
-package ncwindows
-
-import (
-	"log"
-	"os"
-
-	"github.com/gravitl/netmaker/logger"
-	"github.com/gravitl/netmaker/netclient/ncutils"
-)
-
-// InitWindows - Initialize windows directory & files and such
-func InitWindows() {
-
-	_, directoryErr := os.Stat(ncutils.GetNetclientPath()) // Check if data directory exists or not
-	if os.IsNotExist(directoryErr) {                       // create a data directory
-		os.Mkdir(ncutils.GetNetclientPath(), 0755)
-	}
-	wdPath, wdErr := os.Getwd() // get the current working directory
-	if wdErr != nil {
-		log.Fatal("failed to get current directory..")
-	}
-
-	dataPath := ncutils.GetNetclientPathSpecific() + "netclient.exe"
-	currentPath := wdPath + "\\netclient.exe"
-	_, dataNetclientErr := os.Stat(dataPath)
-	_, currentNetclientErr := os.Stat(currentPath)
-
-	if currentPath == dataPath && currentNetclientErr == nil {
-		logger.Log(0, "netclient.exe is in proper location, "+currentPath)
-	} else if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
-		if currentNetclientErr == nil { // copy it if it exists locally
-			input, err := os.ReadFile(currentPath)
-			if err != nil {
-				log.Println("failed to find netclient.exe")
-				return
-			}
-			if err = os.WriteFile(dataPath, input, 0700); err != nil {
-				log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
-				return
-			}
-		} else {
-			log.Fatalf("[netclient] netclient.exe not found in current working directory: %s \nexiting.", wdPath)
-		}
-	}
-	log.Println("Gravitl Netclient on Windows started")
-}

BIN
netclient/netclient.syso