60 lines
908 B
Go
Raw Normal View History

2021-12-28 11:28:43 +09:00
package main
import (
2021-12-30 02:08:30 +09:00
"os"
2022-01-04 17:38:36 +09:00
"os/signal"
"syscall"
2021-12-28 15:10:06 +09:00
2022-01-12 03:06:14 +09:00
"github.com/sirupsen/logrus"
2022-01-12 00:05:16 +09:00
log "github.com/sirupsen/logrus"
2022-01-10 23:41:31 +09:00
"github.com/xvzc/SpoofDPI/doh"
2022-01-04 00:13:42 +09:00
"github.com/xvzc/SpoofDPI/proxy"
2022-01-04 17:38:36 +09:00
"github.com/xvzc/SpoofDPI/util"
2021-12-28 11:28:43 +09:00
)
func main() {
2022-01-09 00:48:19 +09:00
port, dns, debug := util.ParseArgs()
2022-01-04 00:30:15 +09:00
p := proxy.New(port)
2022-01-12 00:05:16 +09:00
doh.Init(dns)
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
2022-01-12 03:06:14 +09:00
log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
2022-01-10 23:59:31 +09:00
util.PrintWelcome(port, dns, debug)
2022-01-04 00:13:42 +09:00
if err := util.SetOsProxy(port); err != nil {
2022-01-04 17:38:36 +09:00
log.Fatal(err)
}
2022-01-04 00:13:42 +09:00
2022-01-09 00:48:19 +09:00
go p.Start()
2022-01-04 02:36:27 +09:00
2022-01-09 02:40:05 +09:00
// Handle signals
2022-01-04 17:38:36 +09:00
sigs := make(chan os.Signal, 1)
2022-01-04 02:36:27 +09:00
done := make(chan bool, 1)
2022-01-04 17:38:36 +09:00
signal.Notify(
sigs,
syscall.SIGKILL,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGHUP)
go func() {
2022-01-04 02:36:27 +09:00
_ = <-sigs
done <- true
}()
2022-01-04 17:38:36 +09:00
<-done
if err := util.UnsetOsProxy(); err != nil {
2022-01-04 17:38:36 +09:00
log.Fatal(err)
}
2021-12-28 11:28:43 +09:00
}