feat: 加入对直接访问https api的支持

This commit is contained in:
Mmx233
2022-03-01 23:24:57 +08:00
parent 7867a99f3b
commit d0f9ea488c
9 changed files with 43 additions and 17 deletions

View File

@@ -37,7 +37,7 @@ func Guardian(output bool) {
util.Log.Println("Error: ", e) util.Log.Println("Error: ", e)
} }
} else { } else {
if global.Config.Settings.Basic.DemoMode { if global.Config.Settings.Debug.Enable {
util.Log.Println("Network ok") util.Log.Println("Network ok")
} }
} }

View File

@@ -10,7 +10,9 @@ import (
// Login 登录逻辑 // Login 登录逻辑
func Login(output bool, skipCheck bool, localAddr net.Addr) error { func Login(output bool, skipCheck bool, localAddr net.Addr) error {
return BitSrun.Login(&srunTransfer.Login{ 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, OutPut: output,
CheckNet: !skipCheck, CheckNet: !skipCheck,
LoginInfo: srunTransfer.LoginInfo{ LoginInfo: srunTransfer.LoginInfo{

View File

@@ -37,7 +37,7 @@ func readConfig() error {
Duration: 300, Duration: 300,
}, },
Debug: srunModels.Debug{ Debug: srunModels.Debug{
Path: "./", LogPath: "./",
}, },
}) })

10
main.go
View File

@@ -7,8 +7,12 @@ import (
) )
func main() { func main() {
util.Log.Demo = global.Config.Settings.Basic.DemoMode util.Log.Init(
util.Log.OutPut = true global.Config.Settings.Debug.Enable,
global.Config.Settings.Debug.WriteLog,
true,
global.Config.Settings.Debug.LogPath,
)
defer util.Log.CatchRecover() defer util.Log.CatchRecover()
if global.Flags.RunningDaemon { if global.Flags.RunningDaemon {
@@ -22,7 +26,7 @@ func main() {
if global.Config.Settings.Basic.Interfaces == "" { //单网卡 if global.Config.Settings.Basic.Interfaces == "" { //单网卡
if err := controllers.Login(true, global.Config.Settings.Basic.SkipNetCheck, nil); err != nil { if err := controllers.Login(true, global.Config.Settings.Basic.SkipNetCheck, nil); err != nil {
util.Log.Println("运行出错,状态异常") util.Log.Println("运行出错,状态异常")
if global.Config.Settings.Basic.DemoMode { if global.Config.Settings.Debug.Enable {
util.Log.Fatalln(err) util.Log.Fatalln(err)
} else { } else {
util.Log.Println(err) util.Log.Println(err)

View File

@@ -13,6 +13,7 @@ type Guardian struct {
} }
type Basic struct { type Basic struct {
Https bool `json:"https"`
Timeout uint `json:"timeout"` Timeout uint `json:"timeout"`
Interfaces string `json:"interfaces"` Interfaces string `json:"interfaces"`
SkipNetCheck bool `json:"skip_net_check" yaml:"skip_net_check"` SkipNetCheck bool `json:"skip_net_check" yaml:"skip_net_check"`
@@ -26,8 +27,9 @@ type Settings struct {
} }
type Debug struct { type Debug struct {
Enable bool `json:"enable"` Enable bool `json:"enable"`
Path string `json:"path"` WriteLog bool `json:"write_log" yaml:"write_log"`
LogPath string `json:"log_path" yaml:"log_path"`
} }
type Config struct { type Config struct {

View File

@@ -5,12 +5,17 @@ import (
"github.com/Mmx233/BitSrunLoginGo/v1/transfer" "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{ return &srunModels.LoginInfo{
UrlLoginPage: "http://" + Form.Domain + "/srun_portal_success", UrlLoginPage: portal + Form.Domain + "/srun_portal_success",
UrlGetChallengeApi: "http://" + Form.Domain + "/cgi-bin/get_challenge", UrlGetChallengeApi: portal + Form.Domain + "/cgi-bin/get_challenge",
UrlLoginApi: "http://" + Form.Domain + "/cgi-bin/srun_portal", UrlLoginApi: portal + Form.Domain + "/cgi-bin/srun_portal",
UrlCheckApi: "http://" + Form.Domain + "/cgi-bin/rad_user_info", UrlCheckApi: portal + Form.Domain + "/cgi-bin/rad_user_info",
Meta: Meta, Meta: Meta,
Form: &srunTransfer.LoginForm{ Form: &srunTransfer.LoginForm{
UserName: Form.UserName + "@" + Form.UserType, UserName: Form.UserName + "@" + Form.UserType,

View File

@@ -2,7 +2,6 @@ package util
import ( import (
"fmt" "fmt"
"github.com/Mmx233/BitSrunLoginGo/global"
"github.com/Mmx233/tool" "github.com/Mmx233/tool"
"log" "log"
"os" "os"
@@ -13,12 +12,24 @@ import (
type loG struct { type loG struct {
timeStamp string timeStamp string
WriteFile bool WriteFile bool
Path string
Debug bool Debug bool
OutPut bool OutPut bool
} }
var Log loG 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{}) { func (c *loG) WriteLog(name string, a ...interface{}) {
if !(c.Debug && c.WriteFile) { if !(c.Debug && c.WriteFile) {
return return
@@ -30,7 +41,7 @@ func (c *loG) WriteLog(name string, a ...interface{}) {
t += " " 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 { if err != nil {
log.Println("Write log error: ", err) log.Println("Write log error: ", err)
} }
@@ -38,7 +49,7 @@ func (c *loG) WriteLog(name string, a ...interface{}) {
func (c *loG) genTimeStamp() { func (c *loG) genTimeStamp() {
if c.timeStamp == "" { if c.timeStamp == "" {
c.timeStamp = time.Now().Format("2006.01.02-15.04.05") c.timeStamp = c.time()
} }
} }

View File

@@ -14,7 +14,7 @@ func Login(c *srunTransfer.Login) error {
util.Log.WriteFile = c.WriteLog util.Log.WriteFile = c.WriteLog
util.Log.OutPut = c.OutPut 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 { if c.CheckNet {
util.Log.Println("Step0: 检查状态…") util.Log.Println("Step0: 检查状态…")
if util.Checker.NetOk(c.Transport) { if util.Checker.NetOk(c.Transport) {

View File

@@ -22,6 +22,8 @@ type LoginInfo struct {
} }
type Login struct { type Login struct {
//调用API时直接访问https URL
Https bool
//Debug模式 //Debug模式
Debug bool Debug bool
//输出日志文件 //输出日志文件