From 41f61a2a4f352b9069babea5bda5a6d787588a40 Mon Sep 17 00:00:00 2001 From: pibragimov Date: Sun, 18 Aug 2024 00:05:35 +0300 Subject: [PATCH 1/9] feat: add error messages on proxy start and end --- .idea/.gitignore | 8 ++++++++ .idea/SpoofDPI.iml | 9 +++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ cmd/spoof-dpi/main.go | 8 ++++---- go.mod | 1 + go.sum | 2 ++ util/os.go | 12 ++++++------ 8 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/SpoofDPI.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/SpoofDPI.iml b/.idea/SpoofDPI.iml new file mode 100644 index 00000000..5e764c4f --- /dev/null +++ b/.idea/SpoofDPI.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..b0cbe10f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cmd/spoof-dpi/main.go b/cmd/spoof-dpi/main.go index 7f1cd0e0..3a600112 100644 --- a/cmd/spoof-dpi/main.go +++ b/cmd/spoof-dpi/main.go @@ -13,14 +13,14 @@ import ( ) func main() { - args := util.ParseArgs() + args := util.ParseArgs() if *args.Version { version.PrintVersion() os.Exit(0) } config := util.GetConfig() - config.Load(args) + config.Load(args) pxy := proxy.New(config) if *config.Debug { @@ -41,7 +41,7 @@ func main() { if *config.SystemProxy { if err := util.SetOsProxy(*config.Port); err != nil { - log.Fatal("error while changing proxy settings") + log.Fatalf("error while changing proxy settings: %v", err) } } @@ -68,7 +68,7 @@ func main() { if *config.SystemProxy { if err := util.UnsetOsProxy(); err != nil { - log.Fatal(err) + log.Fatalf("error while unsetting os proxy: %v", err) } } } diff --git a/go.mod b/go.mod index 1b45c004..5d9e4104 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/gookit/color v1.5.4 // indirect github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/mod v0.18.0 // indirect diff --git a/go.sum b/go.sum index c98a4e40..e0510c01 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs= github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= diff --git a/util/os.go b/util/os.go index 9c402dca..998c9dc8 100644 --- a/util/os.go +++ b/util/os.go @@ -2,6 +2,7 @@ package util import ( "fmt" + "github.com/pkg/errors" "os/exec" "runtime" "strings" @@ -13,19 +14,18 @@ func SetOsProxy(port int) error { } 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 ' ' -f 2-").Output() - if err != nil { - return err + return errors.Wrapf(err, "failed to get network interfaces, stdout: %s", string(network)) } - _, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output() + out, err := exec.Command("sh", "-c", "networksetup -setwebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output() if err != nil { - return err + return errors.Wrapf(err, "failed to set web proxy, stdout: %s", string(out)) } - _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output() + out, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output() if err != nil { - return err + return errors.Wrapf(err, "failed to set secure web proxy, stdout: %s", string(out)) } return nil From e5749a34ab6a1849e8348f3e1eb4ef965fdb28c6 Mon Sep 17 00:00:00 2001 From: pibragimov Date: Sun, 18 Aug 2024 00:10:18 +0300 Subject: [PATCH 2/9] ref: remove .idea --- .gitignore | 1 + .idea/.gitignore | 8 ------ .idea/SpoofDPI.iml | 9 ------- .idea/modules.xml | 8 ------ .idea/vcs.xml | 6 ----- .idea/workspace.xml | 62 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 31 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/SpoofDPI.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 9baf0dbb..d07fe672 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ spoof-dpi.* !*/spoof-dpi/ .DS_Store out/** +#.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/SpoofDPI.iml b/.idea/SpoofDPI.iml deleted file mode 100644 index 5e764c4f..00000000 --- a/.idea/SpoofDPI.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b0cbe10f..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..a07e96ed --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + \ No newline at end of file From fc09c7a5f99f6924ba6f3073ef6e15c6c4922547 Mon Sep 17 00:00:00 2001 From: pibragimov Date: Sun, 18 Aug 2024 00:10:29 +0300 Subject: [PATCH 3/9] ref: add .idea to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d07fe672..ba2ee4ab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ spoof-dpi.* !*/spoof-dpi/ .DS_Store out/** -#.idea \ No newline at end of file +.idea \ No newline at end of file From bd5fbc7c44b407aa28ba5f81c200a6b40107482f Mon Sep 17 00:00:00 2001 From: Ledorub Date: Tue, 20 Aug 2024 02:56:06 +0300 Subject: [PATCH 4/9] Add .idea dir created by JetBrains IDEs to .gitignore. (#167) --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9baf0dbb..45559121 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ spoof-dpi spoof-dpi-* spoof-dpi.* !*/spoof-dpi/ -.DS_Store out/** + +.DS_Store +.idea/ From c9b840ca3191d55cc29a03493547931e3e2c711d Mon Sep 17 00:00:00 2001 From: pibragimov Date: Wed, 21 Aug 2024 21:35:17 +0300 Subject: [PATCH 5/9] ref: rewrite errors.Wrap to fmt.Errorf --- .idea/workspace.xml | 44 +++++++++++++++++++++----------------------- go.mod | 1 - go.sum | 15 +++++++++++++++ util/os.go | 17 ++++++++--------- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a07e96ed..5abffe48 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,11 +5,9 @@ - - - - - + + +