removing windows installer portions

This commit is contained in:
afeiszli
2022-05-15 20:26:38 -04:00
parent d2d8f47346
commit bc1eb17bad
6 changed files with 41 additions and 149 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@ netmaker-arm64
netmaker-32 netmaker-32
netmaker-amd64 netmaker-amd64
netclient/netclient netclient/netclient
netclient/netclient.syso
netclient/build netclient/build
netclient/build/ netclient/build/
!netclient/build/netclient.service !netclient/build/netclient.service

View File

@@ -7,68 +7,6 @@ import (
// "os" // "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 // StoreSecret - stores auth secret locally
func StoreSecret(key string, network string) error { func StoreSecret(key string, network string) error {
d1 := []byte(key) d1 := []byte(key)

View File

@@ -49,13 +49,7 @@ func Join(cfg *config.ClientConfig, privateKey string) error {
return err return err
} }
logger.Log(1, "joined ", cfg.Network) 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 return err
} }

View File

@@ -59,7 +59,7 @@ func Stop() error {
switch os { switch os {
case "windows": case "windows":
StopWindowsDaemon() RunWinSWCMD("stop")
case "darwin": case "darwin":
StopLaunchD() StopLaunchD()
case "linux": case "linux":

View File

@@ -5,6 +5,7 @@ import (
"log" "log"
"os" "os"
"strings" "strings"
"time"
"github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/ncutils"
@@ -27,19 +28,19 @@ func SetupWindowsDaemon() error {
} }
logger.Log(0, "finished daemon setup") logger.Log(0, "finished daemon setup")
} }
// install daemon, will not overwrite //get exact formatted commands
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, false) RunWinSWCMD("install")
// start daemon, will not restart or start another time.Sleep(1)
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false) RunWinSWCMD("start")
logger.Log(0, strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`)
return nil return nil
} }
// RestartWindowsDaemon - restarts windows service // RestartWindowsDaemon - restarts windows service
func RestartWindowsDaemon() { func RestartWindowsDaemon() {
StopWindowsDaemon() RunWinSWCMD("stop")
// start daemon, will not restart or start another time.Sleep(1)
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false) RunWinSWCMD("start")
} }
// CleanupWindows - cleans up windows files // CleanupWindows - cleans up windows files
@@ -47,8 +48,8 @@ func CleanupWindows() {
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") { if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {
writeServiceConfig() writeServiceConfig()
} }
StopWindowsDaemon() RunWinSWCMD("stop")
RemoveWindowsDaemon() RunWinSWCMD("uninstall")
os.RemoveAll(ncutils.GetNetclientPath()) os.RemoveAll(ncutils.GetNetclientPath())
log.Println("Netclient on Windows, uninstalled") log.Println("Netclient on Windows, uninstalled")
} }
@@ -74,73 +75,31 @@ func writeServiceConfig() error {
return nil return nil
} }
// == Daemon == // RunWinSWCMD - Run a command with the winsw.exe tool (start, stop, install, uninstall)
func RunWinSWCMD(command string) {
// StopWindowsDaemon - stops the Windows daemon // check if command allowed
func StopWindowsDaemon() { allowedCommands := map[string]bool{
logger.Log(0, "stopping Windows, Netclient daemon") "start": true,
// stop daemon, will not overwrite "stop": true,
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true) "install": true,
"uninstall": true,
}
if !allowedCommands[command] {
logger.Log(0, "command "+command+" unsupported by winsw")
return
}
// format command
dirPath := strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)
winCmd := fmt.Sprintf(`"%swinsw.exe" "%s"`, dirPath, command)
logger.Log(0, "running "+command+" of Windows Netclient daemon")
// run command and log for success/failure
out, err := ncutils.RunCmdFormatted(winCmd, true)
if err != nil {
logger.Log(0, "error with "+command+" of Windows Netclient daemon: "+err.Error()+" : "+out)
} else {
logger.Log(0, "successfully ran "+command+" of Windows Netclient daemon")
}
} }
// RemoveWindowsDaemon - removes the Windows daemon
func RemoveWindowsDaemon() {
// uninstall daemon, will not restart or start another
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe uninstall`, true)
logger.Log(0, "uninstalled Windows, Netclient daemon")
}
// func copyWinswOver() error {
// input, err := ioutil.ReadFile(".\\winsw.exe")
// if err != nil {
// logger.Log(0, "failed to find winsw.exe")
// return err
// }
// if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil {
// logger.Log(0, "failed to copy winsw.exe to " + ncutils.GetNetclientPath())
// return err
// }
// if err = os.Remove(".\\winsw.exe"); err != nil {
// logger.Log(0, "failed to cleanup local winsw.exe, feel free to delete it")
// return err
// }
// logger.Log(0, "finished copying winsw.exe")
// return nil
// }
// func downloadWinsw() error {
// fullURLFile := "https://github.com/winsw/winsw/releases/download/v2.11.0/WinSW-x64.exe"
// fileName := "winsw.exe"
// // Create the file
// file, err := os.Create(fileName)
// if err != nil {
// logger.Log(0, "could not create file on OS for Winsw")
// return err
// }
// defer file.Close()
// client := http.Client{
// CheckRedirect: func(r *http.Request, via []*http.Request) error {
// r.URL.Opaque = r.URL.Path
// return nil
// },
// }
// // Put content on file
// logger.Log(0, "downloading service tool...")
// resp, err := client.Get(fullURLFile)
// if err != nil {
// logger.Log(0, "could not GET Winsw")
// return err
// }
// defer resp.Body.Close()
// _, err = io.Copy(file, resp.Body)
// if err != nil {
// logger.Log(0, "could not mount winsw.exe")
// return err
// }
// logger.Log(0, "finished downloading Winsw")
// return nil
// }

View File

@@ -42,7 +42,7 @@ const NO_DB_RECORDS = "could not find any records"
const LINUX_APP_DATA_PATH = "/etc/netclient" const LINUX_APP_DATA_PATH = "/etc/netclient"
// WINDOWS_APP_DATA_PATH - windows path // WINDOWS_APP_DATA_PATH - windows path
const WINDOWS_APP_DATA_PATH = "C:\\ProgramData\\Netclient" const WINDOWS_APP_DATA_PATH = "C:\\Program Files (x86)\\Netclient"
// WINDOWS_APP_DATA_PATH - windows path // WINDOWS_APP_DATA_PATH - windows path
//const WINDOWS_WG_DPAPI_PATH = "C:\\Program Files\\WireGuard\\Data\\Configurations" //const WINDOWS_WG_DPAPI_PATH = "C:\\Program Files\\WireGuard\\Data\\Configurations"