lucky/main.go

132 lines
3.0 KiB
Go
Raw Normal View History

2022-07-14 07:39:54 +08:00
//Copyright 2022 gdy, 272288813@qq.com
package main
import (
"flag"
"log"
"os"
2023-08-23 22:14:42 +08:00
"os/signal"
"syscall"
2022-07-14 07:39:54 +08:00
"time"
2022-07-26 20:16:14 +08:00
"github.com/gdy666/lucky/config"
2023-08-23 22:14:42 +08:00
"github.com/gdy666/lucky/ddns"
"github.com/gdy666/lucky/reverseproxy"
"github.com/gdy666/lucky/socketproxy"
2022-07-14 07:39:54 +08:00
)
var (
listenPort = flag.Int("p", 16601, "http Admin Web listen port ")
configureFileURL = flag.String("c", "", "configure file url")
)
var (
runMode = "prod"
2022-07-26 20:16:14 +08:00
version = "dev"
2022-07-14 07:39:54 +08:00
commit = "none"
date = "2022-07-27T17:54:45Z"
2022-07-14 07:39:54 +08:00
)
var runTime time.Time
func init() {
var cstZone = time.FixedZone("CST", 8*3600) // 东八
time.Local = cstZone
}
2022-07-14 07:39:54 +08:00
func main() {
flag.Parse()
2022-07-26 20:16:14 +08:00
config.InitAppInfo(version, date)
2022-07-14 07:39:54 +08:00
err := config.Read(*configureFileURL)
if err != nil {
log.Printf("%s", err.Error())
log.Printf("载入默认配置以及命令行设定的参数")
2022-10-26 18:38:27 +08:00
config.LoadDefault(*listenPort)
2022-07-14 07:39:54 +08:00
if len(*configureFileURL) > 0 {
err = config.Save()
if err != nil {
log.Printf("保存配置到%s出错:%s", *configureFileURL, err.Error())
}
}
}
gcf := config.GetConfig()
2023-08-23 22:14:42 +08:00
config.BlackListInit()
config.WhiteListInit()
config.SSLCertficateListInit()
2023-08-23 22:14:42 +08:00
//fmt.Printf("*gcf:%v\n", *gcf)
2022-07-14 07:39:54 +08:00
2023-08-23 22:14:42 +08:00
socketproxy.SetSafeCheck(config.SafeCheck)
//socketproxy.SetGlobalMaxConnections(gcf.BaseConfigure.GlobalMaxConnections)
//socketproxy.SetGlobalMaxProxyCount(gcf.BaseConfigure.ProxyCountLimit)
2022-07-14 07:39:54 +08:00
config.SetRunMode(runMode)
config.SetVersion(version)
log.Printf("RunMode:%s\n", runMode)
log.Printf("version:%s\tcommit %s, built at %s\n", version, commit, date)
2022-10-26 18:38:27 +08:00
RunAdminWeb(&gcf.BaseConfigure)
2022-07-14 07:39:54 +08:00
2022-10-26 18:38:27 +08:00
runTime = time.Now()
2022-07-14 07:39:54 +08:00
2023-08-23 22:14:42 +08:00
//LoadRuleFromConfigFile(gcf)
config.PortForwardsRuleListInit()
2022-07-26 20:16:14 +08:00
2023-08-23 22:14:42 +08:00
//config.DDNSTaskListTaskDetailsInit()
config.DDNSTaskListConfigureCheck()
ddnsConf := config.GetDDNSConfigure()
2022-07-26 20:16:14 +08:00
if ddnsConf.Enable {
2022-10-26 18:38:27 +08:00
go ddns.Run(time.Duration(ddnsConf.FirstCheckDelay)*time.Second, time.Duration(ddnsConf.Intervals)*time.Second)
2022-07-26 20:16:14 +08:00
}
reverseproxy.InitReverseProxyServer()
2023-08-23 22:14:42 +08:00
//ddns.RunTimer(time.Second, time.Second*30)
//initProxyList()
2022-07-14 07:39:54 +08:00
2023-08-23 22:14:42 +08:00
//*****************
// time.Sleep(time.Microsecond * 50)
// cruuentPath, _ := fileutils.GetCurrentDirectory()
// panicFile := fmt.Sprintf("%s/relayport_panic.log", cruuentPath)
// fileutils.PanicRedirect(panicFile)
//*****************
//main goroutine wait
sigs := make(chan os.Signal, 1)
exit := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
exit <- true
}()
<-exit
}
2023-08-23 22:14:42 +08:00
// func LoadRuleFromConfigFile(pc *config.ProgramConfigure) {
// if pc == nil {
// return
// }
// for i := range pc.RelayRuleList {
// relayRule, err := rule.CreateRuleByConfigureAndOptions(
// pc.RelayRuleList[i].Name,
// pc.RelayRuleList[i].Configurestr,
// pc.RelayRuleList[i].Options)
// if err != nil {
// continue
// }
// relayRule.From = "configureFile" //规则来源
// relayRule.IsEnable = pc.RelayRuleList[i].Enable
// _, e := rule.AddRuleToGlobalRuleList(false, *relayRule)
// if e != nil {
// log.Printf("%s\n", e)
// }
// }
// }