Skip to content

Commit

Permalink
fix(kick, info): move to https and fix regex about mac info(#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer authored Nov 5, 2021
1 parent f2a568a commit 632ca55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pkg/handler/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@ func (d *DashboardHandler) Login(account *model.Account) error {
if err != nil {
return err
}
_, err = d.client.Get("http://ipgw.neu.edu.cn:8800/sso/neusoft/index") // 统一认证获取cookie
_, err = d.client.Get("https://ipgw.neu.edu.cn:8800/sso/neusoft/index") // 统一认证获取cookie
if err != nil {
return err
}
return nil
}

func (d *DashboardHandler) fetchDashboardIndexBody() (string, error) {
resp, err := d.client.Get("http://ipgw.neu.edu.cn:8800/home")
resp, err := d.client.Get("https://ipgw.neu.edu.cn:8800/home")
if err != nil {
return "", err
}
return utils.ReadBody(resp), nil
}

func (d *DashboardHandler) fetchDashboardBillsBody(page int) (string, error) {
resp, err := d.client.Get(fmt.Sprintf("http://ipgw.neu.edu.cn:8800/log/check-out?page=%d&per-page=10", page))
resp, err := d.client.Get(fmt.Sprintf("https://ipgw.neu.edu.cn:8800/log/check-out?page=%d&per-page=10", page))
if err != nil {
return "", err
}
return utils.ReadBody(resp), nil
}

func (d *DashboardHandler) fetchDashboardRechargeBody(page int) (string, error) {
resp, err := d.client.Get(fmt.Sprintf("http://ipgw.neu.edu.cn:8800/log/pay?page=%d&per-page=10", page))
resp, err := d.client.Get(fmt.Sprintf("https://ipgw.neu.edu.cn:8800/log/pay?page=%d&per-page=10", page))
if err != nil {
return "", err
}
return utils.ReadBody(resp), nil
}

func (d *DashboardHandler) fetchDashboardUsageLogBody(page int) (string, error) {
resp, err := d.client.Get(fmt.Sprintf("http://ipgw.neu.edu.cn:8800/log/detail?page=%d&per-page=10", page))
resp, err := d.client.Get(fmt.Sprintf("https://ipgw.neu.edu.cn:8800/log/detail?page=%d&per-page=10", page))
if err != nil {
return "", err
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (d *DashboardHandler) GetDevice() ([]Device, error) {
if err != nil {
return []Device{}, err
}
ds, _ := utils.MatchMultiple(regexp.MustCompile(`<tr data-key="(\d+)"><td data-col-seq="0">\d+</td><td data-col-seq="1">(.+?)</td><td data-col-seq="3">(.+?)</td><td data-col-seq="9"></td>`), body)
ds, _ := utils.MatchMultiple(regexp.MustCompile(`<tr data-key="(\d+)"><td data-col-seq="0">\d+</td><td data-col-seq="1">(.+?)</td><td data-col-seq="3">(.+?)</td><td data-col-seq="9">.+?</td>`), body)
result := make([]Device, len(ds))
for i, device := range ds {
result[i] = Device{i, device[2], device[3], device[1]}
Expand Down
10 changes: 5 additions & 5 deletions pkg/handler/ipgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (h *IpgwHandler) ParseBasicInfo() error {

func (h *IpgwHandler) Logout() error {
req, _ := http.NewRequest("GET", "https://ipgw.neu.edu.cn/cgi-bin/srun_portal?action=logout&username="+h.info.Username, nil)
req.Header.Add("Referer", "http://ipgw.neu.edu.cn/srun_portal_success?ac_id=1")
req.Header.Add("Referer", "https://ipgw.neu.edu.cn/srun_portal_success?ac_id=1")
_, err := h.client.Do(req)
return err
}
Expand All @@ -160,19 +160,19 @@ func (h *IpgwHandler) IsConnectedAndLoggedIn() (connected bool, loggedIn bool) {

func (h *IpgwHandler) Kick(sid string) (bool, error) {
once.Do(func() {
h.client.Get("http://ipgw.neu.edu.cn:8800/sso/neusoft/index")
h.client.Get("https://ipgw.neu.edu.cn:8800/sso/neusoft/index")
})
// 请求主页
resp, err := h.client.Get("http://ipgw.neu.edu.cn:8800/home")
resp, err := h.client.Get("https://ipgw.neu.edu.cn:8800/home")
if err != nil {
return false, err
}
body := utils.ReadBody(resp)
// 获取csrf-token
token, _ := utils.MatchSingle(regexp.MustCompile(`<meta name="csrf-token" content="(.+?)">`), body)

req, _ := http.NewRequest("POST", "http://ipgw.neu.edu.cn:8800/home/delete?id="+sid, strings.NewReader("_csrf-8800="+token))
req.Header.Set("Referer", "http://ipgw.neu.edu.cn:8800/home/index")
req, _ := http.NewRequest("POST", "https://ipgw.neu.edu.cn:8800/home/delete?id="+sid, strings.NewReader("_csrf-8800="+token))
req.Header.Set("Referer", "https://ipgw.neu.edu.cn:8800/home/index")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

resp, err = h.client.Do(req)
Expand Down

0 comments on commit 632ca55

Please sign in to comment.