From 2e5bf948c0ca95f36d39ba3cea354affc57ee2ae Mon Sep 17 00:00:00 2001 From: Srinivas Baride Date: Fri, 30 Dec 2022 22:05:31 +0530 Subject: [PATCH] Fixed command issues due to shellescape in Windows --- Makefile | 2 ++ services/wireguard/wireguard.go | 5 ++++- services/wireguard/wireguard_windows.go | 17 +++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 0bf78a4..c244d25 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ build: -o ./build/sentinelcli-${VERSION}-darwin-amd64 main.go GOOS=linux GOARCH=amd64 go build -mod=readonly -tags="${BUILD_TAGS}" -ldflags="${LD_FLAGS}" \ -o ./build/sentinelcli-${VERSION}-linux-amd64 main.go + GOOS=windows GOARCH=amd64 go build -mod=readonly -tags="${BUILD_TAGS}" -ldflags="${LD_FLAGS}" \ + -o ./build/sentinelcli-${VERSION}-windows-amd64.exe main.go .PHONY: install install: diff --git a/services/wireguard/wireguard.go b/services/wireguard/wireguard.go index 83c764b..25c1ed5 100644 --- a/services/wireguard/wireguard.go +++ b/services/wireguard/wireguard.go @@ -46,8 +46,11 @@ func (w *WireGuard) IsUp() bool { if err != nil { return false } + if strings.Contains(string(output), "No such device") { + return false + } - return strings.Contains(string(output), "No such device") + return true } func (w *WireGuard) PreUp() error { diff --git a/services/wireguard/wireguard_windows.go b/services/wireguard/wireguard_windows.go index 3008447..7f92022 100644 --- a/services/wireguard/wireguard_windows.go +++ b/services/wireguard/wireguard_windows.go @@ -5,9 +5,6 @@ import ( "os" "os/exec" "path/filepath" - "strings" - - "github.com/alessio/shellescape" ) func (w *WireGuard) RealInterface() (string, error) { @@ -15,14 +12,16 @@ func (w *WireGuard) RealInterface() (string, error) { } func (w *WireGuard) ExecFile(name string) string { - return filepath.Join(w.Home(), "WireGuard", name) + return ".\\" + filepath.Join("WireGuard", name) } func (w *WireGuard) Up() error { var ( cfgFilePath = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name)) - cmd = exec.Command(w.ExecFile("wireguard.exe"), strings.Split( - fmt.Sprintf("/installtunnelservice %s", shellescape.Quote(cfgFilePath)), " ")...) + cmd = exec.Command( + w.ExecFile("wireguard.exe"), + "/installtunnelservice", cfgFilePath, + ) ) cmd.Stdout = os.Stdout @@ -36,8 +35,10 @@ func (w *WireGuard) Down() error { return err } - cmd := exec.Command(w.ExecFile("wireguard.exe"), strings.Split( - fmt.Sprintf("/uninstalltunnelservice %s", shellescape.Quote(iFace)), " ")...) + cmd := exec.Command( + w.ExecFile("wireguard.exe"), + "/uninstalltunnelservice", iFace, + ) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr