mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-08 02:06:06 +08:00
embedded file to windows, cleaned up logs
This commit is contained in:
19
go.mod
19
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/gravitl/netmaker
|
module github.com/gravitl/netmaker
|
||||||
|
|
||||||
go 1.15
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
@@ -28,3 +28,20 @@ require (
|
|||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
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
|
||||||
|
)
|
||||||
|
@@ -2,10 +2,8 @@ package daemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -23,13 +21,7 @@ func SetupWindowsDaemon() error {
|
|||||||
|
|
||||||
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.exe") {
|
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.exe") {
|
||||||
ncutils.Log("performing first time daemon setup")
|
ncutils.Log("performing first time daemon setup")
|
||||||
if !ncutils.FileExists(".\\winsw.exe") {
|
err := ncutils.GetEmbedded()
|
||||||
err := downloadWinsw()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := copyWinswOver()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -90,56 +82,57 @@ func RemoveWindowsDaemon() {
|
|||||||
ncutils.Log("uninstalled Windows, Netclient daemon")
|
ncutils.Log("uninstalled Windows, Netclient daemon")
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyWinswOver() error {
|
// func copyWinswOver() error {
|
||||||
|
|
||||||
input, err := ioutil.ReadFile(".\\winsw.exe")
|
// input, err := ioutil.ReadFile(".\\winsw.exe")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ncutils.Log("failed to find winsw.exe")
|
// ncutils.Log("failed to find winsw.exe")
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil {
|
// if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil {
|
||||||
ncutils.Log("failed to copy winsw.exe to " + ncutils.GetNetclientPath())
|
// ncutils.Log("failed to copy winsw.exe to " + ncutils.GetNetclientPath())
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
if err = os.Remove(".\\winsw.exe"); err != nil {
|
// if err = os.Remove(".\\winsw.exe"); err != nil {
|
||||||
ncutils.Log("failed to cleanup local winsw.exe, feel free to delete it")
|
// ncutils.Log("failed to cleanup local winsw.exe, feel free to delete it")
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
ncutils.Log("finished copying winsw.exe")
|
// ncutils.Log("finished copying winsw.exe")
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func downloadWinsw() error {
|
// func downloadWinsw() error {
|
||||||
fullURLFile := "https://github.com/winsw/winsw/releases/download/v2.11.0/WinSW-x64.exe"
|
// fullURLFile := "https://github.com/winsw/winsw/releases/download/v2.11.0/WinSW-x64.exe"
|
||||||
fileName := "winsw.exe"
|
// fileName := "winsw.exe"
|
||||||
|
|
||||||
// Create the file
|
// // Create the file
|
||||||
file, err := os.Create(fileName)
|
// file, err := os.Create(fileName)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ncutils.Log("could not create file on OS for Winsw")
|
// ncutils.Log("could not create file on OS for Winsw")
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
client := http.Client{
|
// defer file.Close()
|
||||||
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)
|
// client := http.Client{
|
||||||
if err != nil {
|
// CheckRedirect: func(r *http.Request, via []*http.Request) error {
|
||||||
ncutils.Log("could not mount winsw.exe")
|
// r.URL.Opaque = r.URL.Path
|
||||||
return err
|
// return nil
|
||||||
}
|
// },
|
||||||
defer file.Close()
|
// }
|
||||||
ncutils.Log("finished downloading Winsw")
|
// // Put content on file
|
||||||
return nil
|
// 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
|
||||||
|
// }
|
||||||
|
@@ -110,7 +110,7 @@ func GenPass() string {
|
|||||||
rand.NewSource(time.Now().UnixNano()))
|
rand.NewSource(time.Now().UnixNano()))
|
||||||
|
|
||||||
length := 16
|
length := 16
|
||||||
charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
|
||||||
b := make([]byte, length)
|
b := make([]byte, length)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
|
@@ -23,10 +23,16 @@ func RunCmd(command string, printerr bool) (string, error) {
|
|||||||
return string(out), err
|
return string(out), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunCmdFormatted - run a command formatted for MacOS
|
||||||
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEmbedded - if files required for MacOS, put here
|
||||||
|
func GetEmbedded() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
|
@@ -12,10 +12,16 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RunCmdFormatted - run a command formatted for freebsd
|
||||||
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEmbedded - if files required for freebsd, put here
|
||||||
|
func GetEmbedded() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Runs Commands for FreeBSD
|
// Runs Commands for FreeBSD
|
||||||
func RunCmd(command string, printerr bool) (string, error) {
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
args := strings.Fields(command)
|
args := strings.Fields(command)
|
||||||
|
@@ -23,10 +23,16 @@ func RunCmd(command string, printerr bool) (string, error) {
|
|||||||
return string(out), err
|
return string(out), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunCmdFormatted - does nothing for linux
|
||||||
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEmbedded - if files required for linux, put here
|
||||||
|
func GetEmbedded() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package ncutils
|
package ncutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,6 +13,9 @@ import (
|
|||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed windowsdaemon/winsw.exe
|
||||||
|
var winswContent embed.FS
|
||||||
|
|
||||||
// RunCmd - runs a local command
|
// RunCmd - runs a local command
|
||||||
func RunCmd(command string, printerr bool) (string, error) {
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
args := strings.Fields(command)
|
args := strings.Fields(command)
|
||||||
@@ -72,3 +76,18 @@ MTU = %s
|
|||||||
peersString)
|
peersString)
|
||||||
return config, nil
|
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
|
||||||
|
}
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user