mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 06:15:51 +00:00
786d31cbb7
* feat: add quiet option to arguments * docs: fit docs to new feature * chore: rename the quiet option to silent, fix docs * docs: remove mentions of the banner option * feat!: remove the banner option BREAKING CHANGES: the banner option is no longer supported * chore: remove the useless PrintSimpleInfo function * docs: improve the wording of the silent option
68 lines
1.1 KiB
Go
68 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/xvzc/SpoofDPI/util/log"
|
|
|
|
"github.com/xvzc/SpoofDPI/proxy"
|
|
"github.com/xvzc/SpoofDPI/util"
|
|
"github.com/xvzc/SpoofDPI/version"
|
|
)
|
|
|
|
func main() {
|
|
args := util.ParseArgs()
|
|
if args.Version {
|
|
version.PrintVersion()
|
|
os.Exit(0)
|
|
}
|
|
|
|
config := util.GetConfig()
|
|
config.Load(args)
|
|
|
|
log.InitLogger(config)
|
|
ctx := util.GetCtxWithScope(context.Background(), "MAIN")
|
|
logger := log.GetCtxLogger(ctx)
|
|
|
|
pxy := proxy.New(config)
|
|
|
|
if !config.Silent {
|
|
util.PrintColoredBanner()
|
|
}
|
|
|
|
if config.SystemProxy {
|
|
if err := util.SetOsProxy(uint16(config.Port)); err != nil {
|
|
logger.Fatal().Msgf("error while changing proxy settings: %s", err)
|
|
}
|
|
defer func() {
|
|
if err := util.UnsetOsProxy(); err != nil {
|
|
logger.Fatal().Msgf("error while disabling proxy: %s", err)
|
|
}
|
|
}()
|
|
}
|
|
|
|
go pxy.Start(context.Background())
|
|
|
|
// Handle signals
|
|
sigs := make(chan os.Signal, 1)
|
|
done := make(chan bool, 1)
|
|
|
|
signal.Notify(
|
|
sigs,
|
|
syscall.SIGKILL,
|
|
syscall.SIGINT,
|
|
syscall.SIGTERM,
|
|
syscall.SIGQUIT,
|
|
syscall.SIGHUP)
|
|
|
|
go func() {
|
|
_ = <-sigs
|
|
done <- true
|
|
}()
|
|
|
|
<-done
|
|
}
|