diff --git a/go.mod b/go.mod index 7259aa36..a39e3434 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gravitl/netmaker -go 1.15 +go 1.17 require ( github.com/davecgh/go-spew v1.1.1 // indirect @@ -28,3 +28,20 @@ require ( google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) + +require ( + cloud.google.com/go v0.34.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/felixge/httpsnoop v1.0.1 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/google/go-cmp v0.5.5 // indirect + github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/mdlayher/genetlink v1.0.0 // indirect + github.com/mdlayher/netlink v1.4.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + google.golang.org/appengine v1.4.0 // indirect +) diff --git a/netclient/daemon/windows.go b/netclient/daemon/windows.go index 952d9884..9855f54a 100644 --- a/netclient/daemon/windows.go +++ b/netclient/daemon/windows.go @@ -2,10 +2,8 @@ package daemon import ( "fmt" - "io" "io/ioutil" "log" - "net/http" "os" "strings" @@ -23,13 +21,7 @@ func SetupWindowsDaemon() error { if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.exe") { ncutils.Log("performing first time daemon setup") - if !ncutils.FileExists(".\\winsw.exe") { - err := downloadWinsw() - if err != nil { - return err - } - } - err := copyWinswOver() + err := ncutils.GetEmbedded() if err != nil { return err } @@ -90,56 +82,57 @@ func RemoveWindowsDaemon() { ncutils.Log("uninstalled Windows, Netclient daemon") } -func copyWinswOver() error { +// func copyWinswOver() error { - input, err := ioutil.ReadFile(".\\winsw.exe") - if err != nil { - ncutils.Log("failed to find winsw.exe") - return err - } - if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil { - ncutils.Log("failed to copy winsw.exe to " + ncutils.GetNetclientPath()) - return err - } - if err = os.Remove(".\\winsw.exe"); err != nil { - ncutils.Log("failed to cleanup local winsw.exe, feel free to delete it") - return err - } - ncutils.Log("finished copying winsw.exe") - return nil -} +// input, err := ioutil.ReadFile(".\\winsw.exe") +// if err != nil { +// ncutils.Log("failed to find winsw.exe") +// return err +// } +// if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil { +// ncutils.Log("failed to copy winsw.exe to " + ncutils.GetNetclientPath()) +// return err +// } +// if err = os.Remove(".\\winsw.exe"); err != nil { +// ncutils.Log("failed to cleanup local winsw.exe, feel free to delete it") +// return err +// } +// ncutils.Log("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" +// 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 { - ncutils.Log("could not create file on OS for Winsw") - return err - } - client := http.Client{ - CheckRedirect: func(r *http.Request, via []*http.Request) error { - r.URL.Opaque = r.URL.Path - return nil - }, - } - // Put content on file - ncutils.Log("downloading service tool...") - resp, err := client.Get(fullURLFile) - if err != nil { - ncutils.Log("could not GET Winsw") - return err - } - defer resp.Body.Close() +// // Create the file +// file, err := os.Create(fileName) +// if err != nil { +// ncutils.Log("could not create file on OS for Winsw") +// return err +// } +// defer file.Close() - _, err = io.Copy(file, resp.Body) - if err != nil { - ncutils.Log("could not mount winsw.exe") - return err - } - defer file.Close() - ncutils.Log("finished downloading Winsw") - return nil -} +// client := http.Client{ +// CheckRedirect: func(r *http.Request, via []*http.Request) error { +// r.URL.Opaque = r.URL.Path +// return nil +// }, +// } +// // Put content on file +// ncutils.Log("downloading service tool...") +// resp, err := client.Get(fullURLFile) +// if err != nil { +// ncutils.Log("could not GET Winsw") +// return err +// } +// defer resp.Body.Close() + +// _, err = io.Copy(file, resp.Body) +// if err != nil { +// ncutils.Log("could not mount winsw.exe") +// return err +// } +// ncutils.Log("finished downloading Winsw") +// return nil +// } diff --git a/netclient/ncutils/netclientutils.go b/netclient/ncutils/netclientutils.go index 565f579e..b9e79f89 100644 --- a/netclient/ncutils/netclientutils.go +++ b/netclient/ncutils/netclientutils.go @@ -110,7 +110,7 @@ func GenPass() string { rand.NewSource(time.Now().UnixNano())) length := 16 - charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" b := make([]byte, length) for i := range b { diff --git a/netclient/ncutils/netclientutils_darwin.go b/netclient/ncutils/netclientutils_darwin.go index 3ec98950..79fc85d7 100644 --- a/netclient/ncutils/netclientutils_darwin.go +++ b/netclient/ncutils/netclientutils_darwin.go @@ -23,10 +23,16 @@ func RunCmd(command string, printerr bool) (string, error) { return string(out), err } +// RunCmdFormatted - run a command formatted for MacOS func RunCmdFormatted(command string, printerr bool) (string, error) { return "", nil } +// GetEmbedded - if files required for MacOS, put here +func GetEmbedded() error { + return nil +} + // CreateUserSpaceConf - creates a user space WireGuard conf func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { peersString, err := parsePeers(perskeepalive, peers) diff --git a/netclient/ncutils/netclientutils_freebsd.go b/netclient/ncutils/netclientutils_freebsd.go index 1cc6746e..19d3aa19 100644 --- a/netclient/ncutils/netclientutils_freebsd.go +++ b/netclient/ncutils/netclientutils_freebsd.go @@ -12,10 +12,16 @@ import ( "time" ) +// RunCmdFormatted - run a command formatted for freebsd func RunCmdFormatted(command string, printerr bool) (string, error) { return "", nil } +// GetEmbedded - if files required for freebsd, put here +func GetEmbedded() error { + return nil +} + // Runs Commands for FreeBSD func RunCmd(command string, printerr bool) (string, error) { args := strings.Fields(command) diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index 3ec98950..4b2f3204 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -23,10 +23,16 @@ func RunCmd(command string, printerr bool) (string, error) { return string(out), err } +// RunCmdFormatted - does nothing for linux func RunCmdFormatted(command string, printerr bool) (string, error) { return "", nil } +// GetEmbedded - if files required for linux, put here +func GetEmbedded() error { + return nil +} + // CreateUserSpaceConf - creates a user space WireGuard conf func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { peersString, err := parsePeers(perskeepalive, peers) diff --git a/netclient/ncutils/netclientutils_windows.go b/netclient/ncutils/netclientutils_windows.go index 4abedf17..45974297 100644 --- a/netclient/ncutils/netclientutils_windows.go +++ b/netclient/ncutils/netclientutils_windows.go @@ -1,6 +1,7 @@ package ncutils import ( + "embed" "fmt" "log" "os" @@ -12,6 +13,9 @@ import ( "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) +//go:embed windowsdaemon/winsw.exe +var winswContent embed.FS + // RunCmd - runs a local command func RunCmd(command string, printerr bool) (string, error) { args := strings.Fields(command) @@ -72,3 +76,18 @@ MTU = %s peersString) return config, nil } + +// GetEmbedded - Gets the Windows daemon creator +func GetEmbedded() error { + data, err := winswContent.ReadFile("windowsdaemon/winsw.exe") + if err != nil { + return err + } + fileName := fmt.Sprintf("%swinsw.exe", GetNetclientPathSpecific()) + err = os.WriteFile(fileName, data, 0700) + if err != nil { + Log("could not mount winsw.exe") + return err + } + return nil +} diff --git a/netclient/netclient.syso b/netclient/netclient.syso deleted file mode 100644 index d76c53a5..00000000 Binary files a/netclient/netclient.syso and /dev/null differ