feat: 变更解析方式,打包Srun请求包

This commit is contained in:
Mmx233
2022-03-11 17:47:13 +08:00
parent 371e774cc1
commit 0613dc6311
13 changed files with 165 additions and 188 deletions

View File

@@ -1,39 +0,0 @@
package util
import (
"github.com/Mmx233/tool"
"net/http"
)
type checker struct {
url string
set bool
}
var Checker = checker{
url: "https://www.baidu.com/",
}
func (a *checker) SetUrl(url string) {
if a.set {
return
}
a.url = url
a.set = true
}
// NetOk 网络状况检查
func (a *checker) NetOk(transport *http.Transport) bool {
Log.Debug("GET ", a.url)
res, e := tool.HTTP.GetReader(&tool.GetRequest{
Url: a.url,
Redirect: false,
Transport: transport,
})
if e != nil {
Log.Debug(e)
return false
}
_ = res.Body.Close()
return res.Header.Get("Location") == ""
}

View File

@@ -5,18 +5,9 @@ import (
"github.com/Mmx233/BitSrunLoginGo/v1/transfer"
)
func GenerateLoginInfo(https bool, Form *srunTransfer.LoginForm, Meta *srunTransfer.LoginMeta) *srunModels.LoginInfo {
portal := "http"
if https {
portal += "s"
}
portal += "://"
func GenerateLoginInfo(Form *srunTransfer.LoginForm, Meta *srunTransfer.LoginMeta) *srunModels.LoginInfo {
return &srunModels.LoginInfo{
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,
Meta: Meta,
Form: &srunTransfer.LoginForm{
UserName: Form.UserName + "@" + Form.UserType,
PassWord: Form.PassWord,

View File

@@ -3,43 +3,10 @@ package util
import (
"crypto/md5"
"crypto/sha1"
"errors"
"fmt"
"io"
"regexp"
)
func Search(reg string, content string) (string, error) {
r := regexp.MustCompile(reg)
if r == nil {
return "", errors.New("解析正则表达式失败")
}
if s := r.FindStringSubmatch(content); len(s) < 2 {
return "", errors.New("无匹配")
} else {
return s[1], nil
}
}
// GetIp 从响应获取本机分配到的IP
func GetIp(body string) (string, error) {
//判断原正则是否有匹配,如果无就使用新正则尝试
if ip, e := Search("id=\"user_ip\" value=\"(.*?)\"", body); e == nil {
return ip, nil
}
return Search("ip : \"(.*?)\"", body)
}
// GetToken 从响应获取token
func GetToken(body string) (string, error) {
return Search("\"challenge\":\"(.*?)\"", body)
}
// GetResult 从响应获取登录结果
func GetResult(body string) (string, error) {
return Search("\"error\":\"(.+?)\"", body)
}
// Md5 编码
func Md5(content string) string {
w := md5.New()