Git Product home page Git Product logo

goauthing's Introduction

Hi there 👋

goauthing's People

Contributors

baksili avatar berrysoft avatar dependabot[bot] avatar duskmoon314 avatar jiegec avatar liblaf avatar oceans2000 avatar ritou11 avatar sharzyl avatar wrvsrx avatar z4yx avatar zenithalhourlyrate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goauthing's Issues

[Feature Request] `keepAliveLoop` 失败后,自动重新尝试认证

背景

keepOnline 选项开启时,本工具会在 keepAliveLoop 中定期发送 HTTP 请求至 https://www.tsinghua.edu.cn/ / https://www.baidu.com/,在正常情况可以持续保持在线状态。

GoAuthing/cli/main.go

Lines 207 to 267 in e42c2fd

func keepAliveLoop(c *cli.Context, campusOnly bool) (ret error) {
logger.Infof("Accessing websites periodically to keep you online")
accessTarget := func(url string, ipv6 bool) (ret error) {
network := "tcp4"
if ipv6 {
network = "tcp6"
}
netClient := &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
DialContext: func(ctx context.Context, _network, addr string) (net.Conn, error) {
logger.Debugf("DialContext %s (%s)\n", addr, network)
myDial := &net.Dialer{
Timeout: 6 * time.Second,
KeepAlive: 0,
FallbackDelay: -1, // disable RFC 6555 Fast Fallback
}
return myDial.DialContext(ctx, network, addr)
},
},
}
resp, ret := netClient.Head(url)
if ret != nil {
return
}
defer resp.Body.Close()
logger.Debugf("HTTP status code %d\n", resp.StatusCode)
return
}
targetInside := "https://www.tsinghua.edu.cn/"
targetOutside := "https://www.baidu.com/"
stop := make(chan int, 1)
defer func() { stop <- 1 }()
go func() {
// Keep IPv6 online, ignore any errors
for {
select {
case <-stop:
break
case <-time.After(13 * time.Minute):
_ = accessTarget(targetInside, true)
}
}
}()
for {
target := targetOutside
if campusOnly || settings.V6 {
target = targetInside
}
if ret = accessTarget(target, settings.V6); ret != nil {
ret = fmt.Errorf("accessing %s failed (re-login might be required): %w", target, ret)
break
}
// Consumes ~5MB per day
time.Sleep(3 * time.Second)
}
return
}

然而,在某些特殊情况下(如:校园网因某种特殊原因被暂停使用,然后被恢复使用,且在外地出差无法手动重新认证),目前的实现似乎未能实现自动重新认证

潜在解决方案

选项一:添加新的命令行参数(如:--auto-reauth

该参数与 --keepOnline 同时使用,当用户添加该参数时,可支持断线重连功能,即:当 keepAliveLoop 遇到错误后,重新进行认证操作。另外,可以添加指数退避策略防止过多的认证请求。

选项二:直接为 keepAliveLoop 添加断线重连功能

同上,当原始的 keepAliveLoop 失败时,说明校园网已掉线(可能是欠费或其他特殊原因),则重新认证。选项二的副作用是:改变了 keepAliveLoop 函数的语义(由 仅保持在线状态 变为 保持在线状态且断线重连

其他

如果作者觉得合适的话,我可以协助实现该功能。

相关讨论

有IP地址但是无法连接认证界面

在树莓派上之前还是可以连通的,这两天突然就上不了网了。使用命令 ip addr发现有地址166.111.132.231,但是上不去认证界面,求救。

  1. 事故现场:FIT楼。
  2. 别的机器连接校园网可以 ping 通我的地址,我不可以 ping 通别人
  3. 可以 ping 通 166.111.8.28 和 166.111.8.29
  4. ping https://auth4.tsinghua.edu.cn 发生错误
ping: https://auth4.tsinghua.edu.cn: Temporary failure in name resolution
  1. 使用命令 curl -L https://auth4.tsinghua.edu.cn 发生错误
Could not resolve host: auth4.tsinghua.edu.cn
  1. 使用命令 auth-thu --debug 显示下面几行错误
DEBUG libauth requests.go:223 GET "https://net.tsinghua.edu.cn"
DEBUG auth-thu main.go:282 Failed to get ac_id: GET "http://net.tsinghua.edu.cn": dial tcp: lookup net.tsinghua.edu.cn on [::1]:53: read udp [::1]:33399->[::1]:53: read: connection refused
DEBUG auth-thu main.go:283 Login may fail with 'IP 地址异常'.
DEBUG libauth requests.go:134 GET "https://auth4.tsinghua.edu.cn/srun_portal_pc.php?ac_id="
...(输入用户名和密码)
ERROR auth-thu main.go:340 Login Failed: Get "https://auth4.tsinghua.edu.cn/cgi-bin/get_challenge?callback=C_a_l_l_b_a_c_k&double_stack=1&ip=&username=hongal20": dial tcp: lookup auth4.tsinghua.edu.cn on [::1]:53: read udp [::1]:60574->[::1]:53: read: connectoin refused

Could not auth under ipv6 in OpenWrt

I tried to use GoAuthing on my OpenWrt system using ./auth-thu -u <MY_USERNAME> -p <MY_PASSWORD> auth --ipv6 and got the following error:

2023-08-25 15:24:14 ERROR auth-thu main.go:362 Auth error: Login Failed: Get "https://auth6.tsinghua.edu.cn/cgi-bin/get_challenge?callback=C_a_l_l_b_a_c_k&double_stack=1&ip=&username=<MY_USERNAME>": dial tcp: lookup auth6.tsinghua.edu.cn on 127.0.0.1:53: no such host

Directly authing ipv4 is OK in my environment. I wonder if there are any suggestions on how to successfully auth6? Thanks!

Questions on contribution

前辈们好!

我最近在 OpenWRT (mips) 上用 GoAuthing,由于 boot 仅支持 /etc/init.d 的 init script(参考),所以自己写了一份,用一阵子了。考虑到身边用路由器的朋友不少,是否有可以提交到 GoAuthing/docs 中?可以的话我就 PR 了。

Support auto auth

Set an interval for authing. It could be useful for some servers in the campus without static IP.

使用systemd运行auth-thu服务失败

我使用的系统是Arch Linux,安装了aur中auth-thu-bin这一软件包,包里含有systemd的配置文件/usr/lib/systemd/user/[email protected],我用这一命令启动服务systemctl --user start goauthing@<用户名>.service,之后查看运行状态systemctl --user staus goauthing@<用户名>.service显示如下错误

● goauthing@***.service - Authenticating utility for auth.tsinghua.edu.cn
Loaded: loaded (/usr/lib/systemd/user/[email protected]; disabled; preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2022-09-02 18:03:17 CST; 1s ago
Process: 1808 ExecStartPre=/usr/bin/auth-thu --debug -D deauth (code=exited, status=216/GROUP)
Process: 1809 ExecStartPre=/usr/bin/auth-thu --debug -D auth (code=exited, status=216/GROUP)
Process: 1810 ExecStartPre=/usr/bin/auth-thu --debug -D login (code=exited, status=216/GROUP)
Process: 1811 ExecStart=/usr/bin/auth-thu --debug -D online (code=exited, status=216/GROUP)
Main PID: 1811 (code=exited, status=216/GROUP)
CPU: 7ms

用journalctl查看日志如下

Sep 02 17:51:05 ****** systemd[623]: Stopped Authenticating utility for auth.tsinghua.edu.cn.
Sep 02 17:51:05 ****** systemd[623]: Starting Authenticating utility for auth.tsinghua.edu.cn...
Sep 02 17:51:05 ****** systemd[3085]: goauthing.service: Failed to determine supplementary groups: Operation not permitted
Sep 02 17:51:05 ****** systemd[3085]: goauthing.service: Failed at step GROUP spawning /usr/bin/auth-thu: Operation not permitted
Sep 02 17:51:05 ****** systemd[3086]: goauthing.service: Failed to determine supplementary groups: Operation not permitted
Sep 02 17:51:05 ****** systemd[3086]: goauthing.service: Failed at step GROUP spawning /usr/bin/auth-thu: Operation not permitted
Sep 02 17:51:05 ****** systemd[3087]: goauthing.service: Failed to determine supplementary groups: Operation not permitted
Sep 02 17:51:05 ****** systemd[3087]: goauthing.service: Failed at step GROUP spawning /usr/bin/auth-thu: Operation not permitted
Sep 02 17:51:05 ****** systemd[623]: Started Authenticating utility for auth.tsinghua.edu.cn.
Sep 02 17:51:05 ****** systemd[3088]: goauthing.service: Failed to determine supplementary groups: Operation not permitted
Sep 02 17:51:05 ****** systemd[3088]: goauthing.service: Failed at step GROUP spawning /usr/bin/auth-thu: Operation not permitted
Sep 02 17:51:05 ****** systemd[623]: goauthing.service: Main process exited, code=exited, status=216/GROUP
Sep 02 17:51:05 ****** systemd[623]: goauthing.service: Failed with result 'exit-code'.
Sep 02 17:51:10 ****** systemd[623]: goauthing.service: Scheduled restart job, restart counter is at 110.

我的.auth-thu文件是没问题的,因为我直接在命令行运行auth-thu是可以登录的
请问是怎么回事?谢谢

使用 UCI 的 init.d 脚本在 OpenWRT 21.02 无法运行

在 OpenWRT 21.02 版本上,文档中提供的 uci set goauthing.config.username='<YOUR-TUNET-ACCOUNT-NAME>' 运行报错,提示 uci: Invalid argument ;尝试手写配置文件后,goauthing@ init.d 脚本中所用的 config_get 函数也无法获取到相应的配置值。

经测试,一种可能正常工作的组合如下:

命令行:

touch /etc/config/goauthing
uci add goauthing goauthing
uci set goauthing.@goauthing[0].username='<YOUR-TUNET-ACCOUNT-NAME>'
uci set goauthing.@goauthing[0].password='<YOUR-TUNET-PASSWORD>'
uci commit

对应的 /etc/config/goauthing 配置文件格式:

config goauthing
        option username '<YOUR-TUNET-ACCOUNT-NAME>'
        option password '<YOUR-TUNET-PASSWORD>'

在 init.d 脚本中,需要修改获取配置的命令如下:

start_instance() {
  local config=$1
  local username password
  config_get username $config username
  config_get password $config password
  ...
}

logout() {
  local config=$1
  local username password
  config_get username $config username
  config_get password $config password
  ...
}

`auth -o` would deauthenticate all clients

Reproduced on v1.6.1, v.1.7, v1.9.2

Both auth -o and auth -6 -o suffer from this issue.

Several days ago when developing v1.7, this wasn't happening. It is suspected that usereg changed somehow in the meantime, which broke auth -o.

Also reported by @NickCao

[BUG] subcommand `login` got stuck when some HTTP request headers are not provided

Summary

Thank you so much for maintaining such a brilliant tool.

Currently, the Go-Authing tool does not include the User-Agent header in its HTTP requests, which could result in these requests being filtered by firewalls.

By adding a User-Agent header, this issue can be resolved. I am eager to address this and submit a pull request to implement the solution.

Expected Behavior

$ go run cli/main.go -c config.json --debug login 
2023-08-27 09:58:12 DEBUG auth-thu main.go:55 Read config file "config.json" succeeded
2023-08-27 09:58:12 DEBUG auth-thu main.go:93 Settings Username: "******"
2023-08-27 09:58:12 DEBUG auth-thu main.go:94 Settings Ip: ""
2023-08-27 09:58:12 DEBUG auth-thu main.go:95 Settings Host: ""
2023-08-27 09:58:12 DEBUG auth-thu main.go:96 Settings HookSucc: ""
2023-08-27 09:58:12 DEBUG auth-thu main.go:97 Settings NoCheck: false
2023-08-27 09:58:12 DEBUG auth-thu main.go:98 Settings V6: true
2023-08-27 09:58:12 DEBUG auth-thu main.go:99 Settings KeepOn: false
2023-08-27 09:58:12 DEBUG auth-thu main.go:100 Settings Insecure: false
2023-08-27 09:58:12 DEBUG auth-thu main.go:101 Settings Daemon: true
2023-08-27 09:58:12 DEBUG auth-thu main.go:102 Settings Debug: true
2023-08-27 09:58:12 DEBUG auth-thu main.go:103 Settings AcID: ""
2023-08-27 09:58:12 DEBUG auth-thu main.go:104 Settings Campus: false
2023-08-27 09:58:12 ERROR auth-thu main.go:399 Login error: IP has been online, please logout.
exit status 1

Current Behavior

$ go run cli/main.go -c config.json --debug login
2023-08-27 09:56:21 DEBUG auth-thu main.go:55 Read config file "config.json" succeeded
2023-08-27 09:56:21 DEBUG auth-thu main.go:93 Settings Username: "*****"
2023-08-27 09:56:21 DEBUG auth-thu main.go:94 Settings Ip: ""
2023-08-27 09:56:21 DEBUG auth-thu main.go:95 Settings Host: ""
2023-08-27 09:56:21 DEBUG auth-thu main.go:96 Settings HookSucc: ""
2023-08-27 09:56:21 DEBUG auth-thu main.go:97 Settings NoCheck: false
2023-08-27 09:56:21 DEBUG auth-thu main.go:98 Settings V6: true
2023-08-27 09:56:21 DEBUG auth-thu main.go:99 Settings KeepOn: false
2023-08-27 09:56:21 DEBUG auth-thu main.go:100 Settings Insecure: false
2023-08-27 09:56:21 DEBUG auth-thu main.go:101 Settings Daemon: true
2023-08-27 09:56:21 DEBUG auth-thu main.go:102 Settings Debug: true
2023-08-27 09:56:21 DEBUG auth-thu main.go:103 Settings AcID: ""
2023-08-27 09:56:21 DEBUG auth-thu main.go:104 Settings Campus: false
2023-08-27 09:56:23 ERROR auth-thu main.go:399 Login error: Get "http://net.tsinghua.edu.cn/do_login.php?ac_id=1&action=login&password=%7BMD5_HEX%7D********************************&username=******": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
exit status 1

How to run the prebuilt binary on macOS

Device: MacBook Air M2
macOS version: 13.0 (22A380)

I downloaded the prebuilt binary for macOS arm64. Running ./auth-thu.macos.arm64 from terminal leads to the warning in this picture.
Screenshot 2022-11-11 at 09 26 44

Then I tried open it from Finder. Another warning shows up and still I cannot open it.
Screenshot 2022-11-11 at 09 27 54

So I wanna ask how I can run this on my MacBook. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.