Skip to content

Commit

Permalink
Merge pull request #25
Browse files Browse the repository at this point in the history
Release v0.1.10
  • Loading branch information
bsrinivas8687 authored Dec 30, 2022
2 parents c750785 + 2e5bf94 commit 1cc3f0b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.8.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
)

replace (
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -881,7 +880,6 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -894,9 +892,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
36 changes: 6 additions & 30 deletions services/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (w *WireGuard) IsUp() bool {
return false
}

output, err := exec.Command("wg", strings.Split(
output, err := exec.Command(w.ExecFile("wg"), strings.Split(
fmt.Sprintf("show %s", shellescape.Quote(iFace)), " ")...).CombinedOutput()
if err != nil {
return false
Expand All @@ -57,40 +57,16 @@ func (w *WireGuard) PreUp() error {
return w.cfg.WriteToFile(w.Home())
}

func (w *WireGuard) Up() error {
var (
path = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command("wg-quick", strings.Split(
fmt.Sprintf("up %s", shellescape.Quote(path)), " ")...)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (w *WireGuard) PostUp() error { return nil }
func (w *WireGuard) PreDown() error { return nil }

func (w *WireGuard) Down() error {
var (
path = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command("wg-quick", strings.Split(
fmt.Sprintf("down %s", shellescape.Quote(path)), " ")...)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (w *WireGuard) PostDown() error {
path := filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
if _, err := os.Stat(path); err == nil {
return os.Remove(path)
cfgFilePath := filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
if _, err := os.Stat(cfgFilePath); err != nil {
return nil
}

return nil
return os.Remove(cfgFilePath)
}

func (w *WireGuard) Transfer() (u int64, d int64, err error) {
Expand All @@ -99,7 +75,7 @@ func (w *WireGuard) Transfer() (u int64, d int64, err error) {
return 0, 0, err
}

output, err := exec.Command("wg", strings.Split(
output, err := exec.Command(w.ExecFile("wg"), strings.Split(
fmt.Sprintf("show %s transfer", shellescape.Quote(iFace)), " ")...).Output()
if err != nil {
return 0, 0, err
Expand Down
34 changes: 31 additions & 3 deletions services/wireguard/wireguard_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/alessio/shellescape"
Expand All @@ -16,9 +18,7 @@ func (w *WireGuard) RealInterface() (string, error) {
return "", err
}

var (
scanner = bufio.NewReader(nameFile)
)
scanner := bufio.NewReader(nameFile)

line, err := scanner.ReadString('\n')
if err != nil {
Expand All @@ -27,3 +27,31 @@ func (w *WireGuard) RealInterface() (string, error) {

return strings.Trim(line, "\n"), nil
}

func (w *WireGuard) ExecFile(name string) string {
return name
}

func (w *WireGuard) Up() error {
var (
cfgFilePath = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command(w.ExecFile("wg-quick"), strings.Split(
fmt.Sprintf("up %s", shellescape.Quote(cfgFilePath)), " ")...)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (w *WireGuard) Down() error {
var (
cfgFilePath = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command(w.ExecFile("wg-quick"), strings.Split(
fmt.Sprintf("down %s", shellescape.Quote(cfgFilePath)), " ")...)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
40 changes: 40 additions & 0 deletions services/wireguard/wireguard_linux.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
package wireguard

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/alessio/shellescape"
)

func (w *WireGuard) RealInterface() (string, error) {
return w.cfg.Name, nil
}

func (w *WireGuard) ExecFile(name string) string {
return name
}

func (w *WireGuard) Up() error {
var (
cfgFilePath = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command(w.ExecFile("wg-quick"), strings.Split(
fmt.Sprintf("up %s", shellescape.Quote(cfgFilePath)), " ")...)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (w *WireGuard) Down() error {
iFace, err := w.RealInterface()
if err != nil {
return err
}

cmd := exec.Command(w.ExecFile("wg-quick"), strings.Split(
fmt.Sprintf("down %s", shellescape.Quote(iFace)), " ")...)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
46 changes: 46 additions & 0 deletions services/wireguard/wireguard_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package wireguard

import (
"fmt"
"os"
"os/exec"
"path/filepath"
)

func (w *WireGuard) RealInterface() (string, error) {
return w.cfg.Name, nil
}

func (w *WireGuard) ExecFile(name string) string {
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"),
"/installtunnelservice", cfgFilePath,
)
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func (w *WireGuard) Down() error {
iFace, err := w.RealInterface()
if err != nil {
return err
}

cmd := exec.Command(
w.ExecFile("wireguard.exe"),
"/uninstalltunnelservice", iFace,
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

0 comments on commit 1cc3f0b

Please sign in to comment.