feat:允许设定首次登录失败后是否进入守护
This commit is contained in:
39
README.md
39
README.md
@@ -14,25 +14,26 @@ Config.json说明:
|
|||||||
|
|
||||||
```json5
|
```json5
|
||||||
{
|
{
|
||||||
"from": {
|
"from": {
|
||||||
"domain": "www.msftconnecttest.com", //登录地址ip或域名
|
"domain": "www.msftconnecttest.com", //登录地址ip或域名
|
||||||
"username": "", //账号
|
"username": "", //账号
|
||||||
"user_type": "cmcc", //运营商类型,详情看下方
|
"user_type": "cmcc", //运营商类型,详情看下方
|
||||||
"password": "" //密码
|
"password": "" //密码
|
||||||
},
|
},
|
||||||
"meta": { //登录参数
|
"meta": { //登录参数
|
||||||
"n": "200",
|
"n": "200",
|
||||||
"type": "1",
|
"type": "1",
|
||||||
"acid": "5",
|
"acid": "5",
|
||||||
"enc": "srun_bx1"
|
"enc": "srun_bx1"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"quit_if_net_ok": false, //登陆前是否检查网络
|
"quit_if_net_ok": false, //登陆前是否检查网络
|
||||||
"demo_mode": false, //测试模式,报错更详细,且生成运行日志与错误日志
|
"demo_mode": false, //测试模式,报错更详细,且生成运行日志与错误日志
|
||||||
"dns": "1.2.4.8", //检查网络用的DNS地址,建议设为网关分发的内网DNS地址
|
"dns": "1.2.4.8", //检查网络用的DNS地址,建议设为网关分发的内网DNS地址
|
||||||
"guardian": 0, //守护网络,值为网络检查周期(秒),设为0关闭守护
|
"guardian": 0, //守护网络,值为网络检查周期(秒),设为0关闭守护
|
||||||
"daemon": false //将守护挂入后台
|
"daemon": false, //将守护挂入后台
|
||||||
}
|
"force_guardian_even_failed": false //若为false,首次认证失败后不会进入守护
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ func Login(output bool) error {
|
|||||||
}
|
}
|
||||||
G.Ip, err = util.GetIp(body)
|
G.Ip, err = util.GetIp(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrHandler(err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
main.go
13
main.go
@@ -2,15 +2,24 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"autoLogin/controllers"
|
"autoLogin/controllers"
|
||||||
|
"autoLogin/global"
|
||||||
"autoLogin/util"
|
"autoLogin/util"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer util.Log.CatchRecover()
|
defer util.Log.CatchRecover()
|
||||||
|
|
||||||
if err := controllers.Login(true); err != nil {
|
if err := controllers.Login(true); err != nil {
|
||||||
util.ErrHandler(err)
|
util.Log.Println("运行出错,状态异常")
|
||||||
return
|
if global.Config.Settings.ForceGuardianEvenFailed {
|
||||||
|
util.Log.Println(err)
|
||||||
|
} else if global.Config.Settings.DemoMode {
|
||||||
|
util.Log.Fatalln(err)
|
||||||
|
} else {
|
||||||
|
util.Log.Println(err)
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controllers.EnterGuardian()
|
controllers.EnterGuardian()
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
QuitIfNetOk bool `json:"quit_if_net_ok"`
|
QuitIfNetOk bool `json:"quit_if_net_ok"`
|
||||||
DemoMode bool `json:"demo_mode"`
|
DemoMode bool `json:"demo_mode"`
|
||||||
Dns string `json:"dns"`
|
Dns string `json:"dns"`
|
||||||
Guardian uint `json:"guardian"`
|
Guardian uint `json:"guardian"`
|
||||||
Daemon bool `json:"daemon"`
|
Daemon bool `json:"daemon"`
|
||||||
|
ForceGuardianEvenFailed bool `json:"force_guardian_even_failed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ func (a *file) WriteJson(path string, receiver interface{}) error {
|
|||||||
func (*file) GetRootPath() (string, error) {
|
func (*file) GetRootPath() (string, error) {
|
||||||
t, err := os.Executable()
|
t, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrHandler(err)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return filepath.Dir(t) + "/", nil
|
return filepath.Dir(t) + "/", nil
|
||||||
|
|||||||
12
util/util.go
12
util/util.go
@@ -9,7 +9,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -51,17 +50,6 @@ func Sha1(content string) string {
|
|||||||
return fmt.Sprintf("%x\n", bs)
|
return fmt.Sprintf("%x\n", bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrHandler(err error) {
|
|
||||||
if !global.Status.Output {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Log.Println("运行出错,状态异常")
|
|
||||||
if global.Config.Settings.DemoMode {
|
|
||||||
Log.Fatalln(err)
|
|
||||||
}
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NetDailEr() func(ctx context.Context, network, address string) (net.Conn, error) {
|
func NetDailEr() func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
d := net.Dialer{
|
d := net.Dialer{
|
||||||
|
|||||||
Reference in New Issue
Block a user