Fix dependency issues followed by refactoring util module

This commit is contained in:
xvzc 2022-01-11 00:14:51 +09:00
parent 510f2f9835
commit c5640a51a7
3 changed files with 6 additions and 63 deletions

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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,
}
}