2021-12-28 02:28:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-08-22 08:49:05 +00:00
|
|
|
"context"
|
|
|
|
"github.com/xvzc/SpoofDPI/util/log"
|
2021-12-29 17:08:30 +00:00
|
|
|
"os"
|
2022-01-04 08:38:36 +00:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2021-12-28 06:10:06 +00:00
|
|
|
|
2022-01-03 15:13:42 +00:00
|
|
|
"github.com/xvzc/SpoofDPI/proxy"
|
2022-01-04 08:38:36 +00:00
|
|
|
"github.com/xvzc/SpoofDPI/util"
|
2024-08-06 22:32:35 +00:00
|
|
|
"github.com/xvzc/SpoofDPI/version"
|
2021-12-28 02:28:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-08-21 08:19:59 +00:00
|
|
|
args := util.ParseArgs()
|
2024-08-15 06:19:45 +00:00
|
|
|
if *args.Version {
|
2024-08-06 22:49:06 +00:00
|
|
|
version.PrintVersion()
|
2024-07-22 10:59:11 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2023-04-20 19:41:23 +00:00
|
|
|
|
2024-08-15 06:19:45 +00:00
|
|
|
config := util.GetConfig()
|
2024-08-21 08:19:59 +00:00
|
|
|
config.Load(args)
|
2024-08-15 06:19:45 +00:00
|
|
|
|
2024-08-22 08:49:05 +00:00
|
|
|
log.InitLogger(config)
|
|
|
|
ctx := util.GetCtxWithScope(context.Background(), "MAIN")
|
|
|
|
logger := log.GetCtxLogger(ctx)
|
2022-01-11 15:05:16 +00:00
|
|
|
|
2024-08-22 08:49:05 +00:00
|
|
|
pxy := proxy.New(config)
|
2022-01-11 18:06:14 +00:00
|
|
|
|
2023-09-08 08:35:41 +00:00
|
|
|
if *config.NoBanner {
|
2023-05-07 05:57:52 +00:00
|
|
|
util.PrintSimpleInfo()
|
2023-09-08 08:35:41 +00:00
|
|
|
} else {
|
|
|
|
util.PrintColoredBanner()
|
2022-11-29 07:54:28 +00:00
|
|
|
}
|
2022-01-03 15:13:42 +00:00
|
|
|
|
2024-08-05 07:18:12 +00:00
|
|
|
if *config.SystemProxy {
|
|
|
|
if err := util.SetOsProxy(*config.Port); err != nil {
|
2024-08-22 08:49:05 +00:00
|
|
|
logger.Fatal().Msgf("error while changing proxy settings: %s", err)
|
2024-08-05 07:18:12 +00:00
|
|
|
}
|
2024-08-22 10:29:54 +00:00
|
|
|
defer func() {
|
|
|
|
if err := util.UnsetOsProxy(); err != nil {
|
|
|
|
logger.Fatal().Msgf("error while disabling proxy: %s", err)
|
|
|
|
}
|
|
|
|
}()
|
2022-01-04 08:38:36 +00:00
|
|
|
}
|
2022-01-03 15:13:42 +00:00
|
|
|
|
2024-08-22 08:49:05 +00:00
|
|
|
go pxy.Start(context.Background())
|
2022-01-03 17:36:27 +00:00
|
|
|
|
2022-01-08 17:40:05 +00:00
|
|
|
// Handle signals
|
2022-01-04 08:38:36 +00:00
|
|
|
sigs := make(chan os.Signal, 1)
|
2022-01-03 17:36:27 +00:00
|
|
|
done := make(chan bool, 1)
|
|
|
|
|
2022-01-04 08:38:36 +00:00
|
|
|
signal.Notify(
|
|
|
|
sigs,
|
|
|
|
syscall.SIGKILL,
|
|
|
|
syscall.SIGINT,
|
|
|
|
syscall.SIGTERM,
|
|
|
|
syscall.SIGQUIT,
|
|
|
|
syscall.SIGHUP)
|
|
|
|
|
|
|
|
go func() {
|
2022-01-03 17:36:27 +00:00
|
|
|
_ = <-sigs
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
|
2022-01-04 08:38:36 +00:00
|
|
|
<-done
|
2021-12-28 02:28:43 +00:00
|
|
|
}
|