feat: acid 自动嗅探逻辑
This commit is contained in:
@@ -9,6 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if global.Flags.AutoAcid {
|
||||||
|
//todo detect acid
|
||||||
|
}
|
||||||
|
|
||||||
if global.Config.Settings.Guardian.Enable {
|
if global.Config.Settings.Guardian.Enable {
|
||||||
//进入守护模式
|
//进入守护模式
|
||||||
controllers.Guardian()
|
controllers.Guardian()
|
||||||
|
|||||||
@@ -11,18 +11,18 @@ import (
|
|||||||
|
|
||||||
// Login 登录逻辑
|
// Login 登录逻辑
|
||||||
func Login(eth *tools.Eth, debugOutput bool) error {
|
func Login(eth *tools.Eth, debugOutput bool) error {
|
||||||
// 登录状态检查
|
// 登录配置初始化
|
||||||
|
|
||||||
httpClient := tools.HttpPackSelect(eth).Client
|
httpClient := tools.HttpPackSelect(eth).Client
|
||||||
conf := &srun.Conf{
|
conf := &srun.Conf{
|
||||||
Https: global.Config.Settings.Basic.Https,
|
Https: global.Config.Settings.Basic.Https,
|
||||||
LoginInfo: srun.LoginInfo{
|
LoginInfo: srun.LoginInfo{
|
||||||
Form: &global.Config.Form,
|
Form: global.Config.Form,
|
||||||
Meta: &global.Config.Meta,
|
Meta: global.Config.Meta,
|
||||||
},
|
},
|
||||||
Client: httpClient,
|
Client: httpClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 选择输出函数
|
||||||
var output func(args ...interface{})
|
var output func(args ...interface{})
|
||||||
if debugOutput {
|
if debugOutput {
|
||||||
output = log.Debugln
|
output = log.Debugln
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func readConfig() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
//生成配置文件
|
// 生成配置文件
|
||||||
if exist, e := tool.File.Exists(Flags.Path); e != nil {
|
if exist, e := tool.File.Exists(Flags.Path); e != nil {
|
||||||
log.Fatalln("[init] 读取配置文件失败:", e)
|
log.Fatalln("[init] 读取配置文件失败:", e)
|
||||||
} else if !exist {
|
} else if !exist {
|
||||||
@@ -55,7 +55,7 @@ func readConfig() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取配置文件
|
// 读取配置文件
|
||||||
viper.SetConfigFile(Flags.Path)
|
viper.SetConfigFile(Flags.Path)
|
||||||
if e := viper.ReadInConfig(); e != nil {
|
if e := viper.ReadInConfig(); e != nil {
|
||||||
log.Fatalln("[init] 读取配置失败:", e)
|
log.Fatalln("[init] 读取配置失败:", e)
|
||||||
@@ -63,4 +63,12 @@ func readConfig() {
|
|||||||
if e := viper.Unmarshal(&Config); e != nil {
|
if e := viper.Unmarshal(&Config); e != nil {
|
||||||
log.Fatalln("[init] 解析配置失败:", e)
|
log.Fatalln("[init] 解析配置失败:", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// flag 配置覆写
|
||||||
|
if Flags.Debug {
|
||||||
|
Config.Settings.Log.DebugLevel = true
|
||||||
|
}
|
||||||
|
if Flags.Acid != "" {
|
||||||
|
Config.Meta.Acid = Flags.Acid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Flags struct {
|
var Flags struct {
|
||||||
//配置文件路径
|
// 配置文件路径
|
||||||
Path string
|
Path string
|
||||||
|
|
||||||
|
// settings overwrite
|
||||||
Interface string
|
Interface string
|
||||||
Debug bool
|
Debug bool
|
||||||
|
AutoAcid bool
|
||||||
|
Acid string
|
||||||
}
|
}
|
||||||
|
|
||||||
func initFlags() {
|
func initFlags() {
|
||||||
flag.StringVar(&Flags.Path, "config", "Config.yaml", "config path")
|
flag.StringVar(&Flags.Path, "config", "Config.yaml", "config path")
|
||||||
|
|
||||||
flag.StringVar(&Flags.Interface, "interface", "", "specify the eth name")
|
flag.StringVar(&Flags.Interface, "interface", "", "specify the eth name")
|
||||||
flag.BoolVar(&Flags.Debug, "debug", false, "enable debug mode")
|
flag.BoolVar(&Flags.Debug, "debug", false, "enable debug mode")
|
||||||
|
flag.BoolVar(&Flags.AutoAcid, "auto-acid", false, "auto detect acid")
|
||||||
|
flag.StringVar(&Flags.Acid, "acid", "", "specify acid value")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func initLog() {
|
func initLog() {
|
||||||
if Flags.Debug {
|
|
||||||
Config.Settings.Log.DebugLevel = true
|
|
||||||
}
|
|
||||||
if Config.Settings.Log.DebugLevel {
|
if Config.Settings.Log.DebugLevel {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
inited bool
|
inited bool
|
||||||
|
|
||||||
BaseUrl string
|
BaseUrl string
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
Header http.Header
|
// 禁用自动重定向
|
||||||
|
NoDirect *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Api) Init(https bool, domain string, client *http.Client) {
|
func (a *Api) Init(https bool, domain string, client *http.Client) {
|
||||||
@@ -29,7 +32,12 @@ func (a *Api) Init(https bool, domain string, client *http.Client) {
|
|||||||
}
|
}
|
||||||
a.BaseUrl = a.BaseUrl + "://" + domain + "/"
|
a.BaseUrl = a.BaseUrl + "://" + domain + "/"
|
||||||
|
|
||||||
|
// 初始化 http client
|
||||||
a.Client = client
|
a.Client = client
|
||||||
|
a.NoDirect = &(*client)
|
||||||
|
a.NoDirect.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
|
||||||
|
return http.ErrUseLastResponse
|
||||||
|
}
|
||||||
|
|
||||||
a.inited = true
|
a.inited = true
|
||||||
}
|
}
|
||||||
@@ -53,10 +61,6 @@ func (a *Api) request(path string, query map[string]interface{}) (map[string]int
|
|||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range a.Header {
|
|
||||||
req.Header[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, e := httpTool.Client.Do(req)
|
resp, e := httpTool.Client.Do(req)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Debugln(e)
|
log.Debugln(e)
|
||||||
@@ -83,6 +87,35 @@ func (a *Api) GetUserInfo() (map[string]interface{}, error) {
|
|||||||
return a.request("cgi-bin/rad_user_info", nil)
|
return a.request("cgi-bin/rad_user_info", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DetectAcid error 为 nil 的情况下 acid 可能为空
|
||||||
|
func (a *Api) DetectAcid() (string, error) {
|
||||||
|
fmt.Println("开始嗅探 Acid")
|
||||||
|
addr := a.BaseUrl
|
||||||
|
for {
|
||||||
|
log.Debugln("HTTP GET ", addr)
|
||||||
|
res, e := a.NoDirect.Get(addr)
|
||||||
|
if e != nil {
|
||||||
|
return "", e
|
||||||
|
}
|
||||||
|
_ = res.Body.Close()
|
||||||
|
loc := res.Header.Get("location")
|
||||||
|
if res.StatusCode == 302 && loc != "" {
|
||||||
|
if strings.HasPrefix(loc, "/") {
|
||||||
|
addr = a.BaseUrl + strings.TrimPrefix(loc, "/")
|
||||||
|
} else {
|
||||||
|
addr = loc
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
u, e := url.Parse(addr)
|
||||||
|
if e != nil {
|
||||||
|
return "", e
|
||||||
|
}
|
||||||
|
return u.Query().Get(`ac_id`), e
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Api) Login(
|
func (a *Api) Login(
|
||||||
Username,
|
Username,
|
||||||
Password,
|
Password,
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ type LoginMeta struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LoginInfo struct {
|
type LoginInfo struct {
|
||||||
Form *LoginForm
|
Form LoginForm
|
||||||
Meta *LoginMeta
|
Meta LoginMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user