From c5640a51a7e1e783f10dd3889dc81b2a3d28acb8 Mon Sep 17 00:00:00 2001 From: xvzc Date: Tue, 11 Jan 2022 00:14:51 +0900 Subject: [PATCH] Fix dependency issues followed by refactoring util module --- cmd/spoof-dpi/main.go | 7 +++--- proxy/os-settings.go | 52 ------------------------------------------- proxy/proxy.go | 10 +++------ 3 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 proxy/os-settings.go diff --git a/cmd/spoof-dpi/main.go b/cmd/spoof-dpi/main.go index b838643..76a0bea 100644 --- a/cmd/spoof-dpi/main.go +++ b/cmd/spoof-dpi/main.go @@ -4,7 +4,6 @@ import ( "log" "os" "os/signal" - "runtime" "syscall" "github.com/xvzc/SpoofDPI/doh" @@ -15,10 +14,10 @@ import ( func main() { port, dns, debug := util.ParseArgs() - p := proxy.New(port, runtime.GOOS, debug) + p := proxy.New(port) util.PrintWelcome(port, dns, debug) - if err := p.SetOsProxy(); err != nil { + if err := util.SetOsProxy(port); err != nil { log.Fatal(err) } @@ -44,7 +43,7 @@ func main() { }() <-done - if err := p.UnsetOsProxy(); err != nil { + if err := util.UnsetOsProxy(); err != nil { log.Fatal(err) } } diff --git a/proxy/os-settings.go b/proxy/os-settings.go deleted file mode 100644 index e08d695..0000000 --- a/proxy/os-settings.go +++ /dev/null @@ -1,52 +0,0 @@ -package proxy - -import ( - "os/exec" - "strings" -) - -func (p *Proxy) SetOsProxy() error { - if p.OS != "darwin" { - return nil - } - - network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f2").Output() - if err != nil { - return err - } - - _, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+strings.TrimSpace(string(network))+" 127.0.0.1 "+p.Port).Output() - if err != nil { - return err - } - - _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+strings.TrimSpace(string(network))+" 127.0.0.1 "+p.Port).Output() - if err != nil { - return err - } - - return nil -} - -func (p *Proxy) UnsetOsProxy() error { - if p.OS != "darwin" { - return nil - } - - network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f2").Output() - if err != nil { - return err - } - - _, err = exec.Command("sh", "-c", "networksetup -setwebproxystate "+strings.TrimSpace(string(network))+" off").Output() - if err != nil { - return err - } - - _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate "+strings.TrimSpace(string(network))+" off").Output() - if err != nil { - return err - } - - return nil -} diff --git a/proxy/proxy.go b/proxy/proxy.go index bcd0c4c..5055bfd 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -10,16 +10,12 @@ import ( ) type Proxy struct { - Port string - OS string - Debug bool + Port string } -func New(port string, os string, debug bool) *Proxy { +func New(port string) *Proxy { return &Proxy{ - Port: port, - OS: os, - Debug: debug, + Port: port, } }