feat: 加入对直接访问https api的支持
This commit is contained in:
@@ -37,7 +37,7 @@ func Guardian(output bool) {
|
||||
util.Log.Println("Error: ", e)
|
||||
}
|
||||
} else {
|
||||
if global.Config.Settings.Basic.DemoMode {
|
||||
if global.Config.Settings.Debug.Enable {
|
||||
util.Log.Println("Network ok")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
// Login 登录逻辑
|
||||
func Login(output bool, skipCheck bool, localAddr net.Addr) error {
|
||||
return BitSrun.Login(&srunTransfer.Login{
|
||||
Demo: global.Config.Settings.Basic.DemoMode,
|
||||
Https: global.Config.Settings.Basic.Https,
|
||||
Debug: global.Config.Settings.Debug.Enable,
|
||||
WriteLog: global.Config.Settings.Debug.WriteLog,
|
||||
OutPut: output,
|
||||
CheckNet: !skipCheck,
|
||||
LoginInfo: srunTransfer.LoginInfo{
|
||||
|
||||
@@ -37,7 +37,7 @@ func readConfig() error {
|
||||
Duration: 300,
|
||||
},
|
||||
Debug: srunModels.Debug{
|
||||
Path: "./",
|
||||
LogPath: "./",
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
10
main.go
10
main.go
@@ -7,8 +7,12 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
util.Log.Demo = global.Config.Settings.Basic.DemoMode
|
||||
util.Log.OutPut = true
|
||||
util.Log.Init(
|
||||
global.Config.Settings.Debug.Enable,
|
||||
global.Config.Settings.Debug.WriteLog,
|
||||
true,
|
||||
global.Config.Settings.Debug.LogPath,
|
||||
)
|
||||
defer util.Log.CatchRecover()
|
||||
|
||||
if global.Flags.RunningDaemon {
|
||||
@@ -22,7 +26,7 @@ func main() {
|
||||
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
|
||||
if err := controllers.Login(true, global.Config.Settings.Basic.SkipNetCheck, nil); err != nil {
|
||||
util.Log.Println("运行出错,状态异常")
|
||||
if global.Config.Settings.Basic.DemoMode {
|
||||
if global.Config.Settings.Debug.Enable {
|
||||
util.Log.Fatalln(err)
|
||||
} else {
|
||||
util.Log.Println(err)
|
||||
|
||||
@@ -13,6 +13,7 @@ type Guardian struct {
|
||||
}
|
||||
|
||||
type Basic struct {
|
||||
Https bool `json:"https"`
|
||||
Timeout uint `json:"timeout"`
|
||||
Interfaces string `json:"interfaces"`
|
||||
SkipNetCheck bool `json:"skip_net_check" yaml:"skip_net_check"`
|
||||
@@ -26,8 +27,9 @@ type Settings struct {
|
||||
}
|
||||
|
||||
type Debug struct {
|
||||
Enable bool `json:"enable"`
|
||||
Path string `json:"path"`
|
||||
Enable bool `json:"enable"`
|
||||
WriteLog bool `json:"write_log" yaml:"write_log"`
|
||||
LogPath string `json:"log_path" yaml:"log_path"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
||||
@@ -5,12 +5,17 @@ import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/v1/transfer"
|
||||
)
|
||||
|
||||
func GenerateLoginInfo(Form *srunTransfer.LoginForm, Meta *srunTransfer.LoginMeta) *srunModels.LoginInfo {
|
||||
func GenerateLoginInfo(https bool, Form *srunTransfer.LoginForm, Meta *srunTransfer.LoginMeta) *srunModels.LoginInfo {
|
||||
portal := "http"
|
||||
if https {
|
||||
portal += "s"
|
||||
}
|
||||
portal += "://"
|
||||
return &srunModels.LoginInfo{
|
||||
UrlLoginPage: "http://" + Form.Domain + "/srun_portal_success",
|
||||
UrlGetChallengeApi: "http://" + Form.Domain + "/cgi-bin/get_challenge",
|
||||
UrlLoginApi: "http://" + Form.Domain + "/cgi-bin/srun_portal",
|
||||
UrlCheckApi: "http://" + Form.Domain + "/cgi-bin/rad_user_info",
|
||||
UrlLoginPage: portal + Form.Domain + "/srun_portal_success",
|
||||
UrlGetChallengeApi: portal + Form.Domain + "/cgi-bin/get_challenge",
|
||||
UrlLoginApi: portal + Form.Domain + "/cgi-bin/srun_portal",
|
||||
UrlCheckApi: portal + Form.Domain + "/cgi-bin/rad_user_info",
|
||||
Meta: Meta,
|
||||
Form: &srunTransfer.LoginForm{
|
||||
UserName: Form.UserName + "@" + Form.UserType,
|
||||
|
||||
17
util/log.go
17
util/log.go
@@ -2,7 +2,6 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Mmx233/BitSrunLoginGo/global"
|
||||
"github.com/Mmx233/tool"
|
||||
"log"
|
||||
"os"
|
||||
@@ -13,12 +12,24 @@ import (
|
||||
type loG struct {
|
||||
timeStamp string
|
||||
WriteFile bool
|
||||
Path string
|
||||
Debug bool
|
||||
OutPut bool
|
||||
}
|
||||
|
||||
var Log loG
|
||||
|
||||
func (c *loG) Init(debug, logFile, outPut bool, path string) {
|
||||
c.Debug = debug
|
||||
c.WriteFile = logFile
|
||||
c.OutPut = outPut
|
||||
c.Path = path
|
||||
}
|
||||
|
||||
func (c *loG) time() string {
|
||||
return time.Now().Format("2006/01/02 15:04:05")
|
||||
}
|
||||
|
||||
func (c *loG) WriteLog(name string, a ...interface{}) {
|
||||
if !(c.Debug && c.WriteFile) {
|
||||
return
|
||||
@@ -30,7 +41,7 @@ func (c *loG) WriteLog(name string, a ...interface{}) {
|
||||
t += " "
|
||||
}
|
||||
}
|
||||
err := tool.File.Add(global.Config.Settings.Debug.Path+name, fmt.Sprintf(time.Now().Format("2006/01/02 15:04:05 "))+t, 700)
|
||||
err := tool.File.Add(c.Path+name, c.time()+" "+t, 700)
|
||||
if err != nil {
|
||||
log.Println("Write log error: ", err)
|
||||
}
|
||||
@@ -38,7 +49,7 @@ func (c *loG) WriteLog(name string, a ...interface{}) {
|
||||
|
||||
func (c *loG) genTimeStamp() {
|
||||
if c.timeStamp == "" {
|
||||
c.timeStamp = time.Now().Format("2006.01.02-15.04.05")
|
||||
c.timeStamp = c.time()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func Login(c *srunTransfer.Login) error {
|
||||
util.Log.WriteFile = c.WriteLog
|
||||
util.Log.OutPut = c.OutPut
|
||||
|
||||
G := util.GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta)
|
||||
G := util.GenerateLoginInfo(c.Https, c.LoginInfo.Form, c.LoginInfo.Meta)
|
||||
if c.CheckNet {
|
||||
util.Log.Println("Step0: 检查状态…")
|
||||
if util.Checker.NetOk(c.Transport) {
|
||||
|
||||
@@ -22,6 +22,8 @@ type LoginInfo struct {
|
||||
}
|
||||
|
||||
type Login struct {
|
||||
//调用API时直接访问https URL
|
||||
Https bool
|
||||
//Debug模式
|
||||
Debug bool
|
||||
//输出日志文件
|
||||
|
||||
Reference in New Issue
Block a user