ictlogin/README.md

96 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ICT 网关命令行登录工具
这是针对 `https://gw.ict.ac.cn`(SRun Portal)的服务器命令行客户端。它复刻网页端的挑战码、HMAC-MD5、XXTEA、定制 Base64 和 SHA-1 校验流程,不依赖第三方 Python 包,也不会保存密码。
## 安装
在服务器上进入本目录后执行:
```bash
python3 -m pip install --user --no-deps --no-build-isolation .
```
若 `ictlogin` 不在当前 shell 的 `PATH` 中,先执行 `export PATH="$HOME/.local/bin:$PATH"`,或直接使用 `~/.local/bin/ictlogin`。
如果不想安装,也可以直接运行 `python3 run_ictlogin.py ...`。
## 单文件安装
服务器上可直接从公开 Release 获取并安装单文件程序:
```bash
curl --fail --location https://gitx.roy1994.top/mancitrus/ictlogin/raw/branch/main/install.sh | sh
```
安装脚本默认下载 `v0.2.0` Release 中的 `ictlogin.pyz`,验证对应的 SHA-256 后写入 `~/.local/bin/ictlogin`。需要其他版本时设置 Release 标签:
```bash
ICTLOGIN_RELEASE_TAG=v0.2.0 ./install.sh
```
也可以先保存 `install.sh`,再从已有的本地文件或自定义 URL 安装:
```bash
./install.sh
./install.sh --source /path/to/ictlogin.pyz --prefix "$HOME/.local/bin"
ICTLOGIN_PYZ_URL="https://example.invalid/ictlogin.pyz" ./install.sh
ICTLOGIN_PYZ_URL="https://example.invalid/ictlogin.pyz" \
ICTLOGIN_PYZ_SHA256_URL="https://example.invalid/ictlogin.pyz.sha256" ./install.sh
```
## 使用
先检查当前 IP:
```bash
ictlogin status
```
交互式登录(账号和密码不会出现在 shell 历史或进程列表中):
```bash
ictlogin login
```
也可以只把账号放在参数中,密码仍会安全地提示输入:
```bash
ictlogin login --username YOUR_ACCOUNT
```
注销和 JSON 状态输出:
```bash
ictlogin logout
ictlogin status --json
```
保持服务器会话活跃:
```bash
ictlogin heartbeat --interval 60
```
该命令会周期性请求网关的在线接口并持续运行,按 `Ctrl-C` 停止;先用 `--once` 做单次检查。若希望掉线后自动重新认证,必须显式开启并提供账号密码:
```bash
ictlogin heartbeat --auto-login --username YOUR_ACCOUNT --password-env ICT_PASSWORD
```
每次连续掉线期间只尝试一次自动认证,恢复在线后才会重置,避免错误密码造成反复锁定。
脚本场景可以使用标准输入或显式环境变量读取密码,避免使用 `--password` 这种会暴露在进程列表中的参数:
```bash
printf '%s\n' "$ICT_PASSWORD" | ictlogin login --username YOUR_ACCOUNT --password-stdin
ictlogin login --username YOUR_ACCOUNT --password-env ICT_PASSWORD
```
若网关要求图片验证码,CLI 会将 PNG 保存到 `~/.cache/ictlogin/`(目录和文件权限为当前用户私有),然后提示输入验证码。可用 `--ip`、`--ac-id` 和 `--base-url` 覆盖自动探测的连接参数。
## 安全说明
- 密码只在内存中用于生成认证请求,程序不会写入配置文件、日志或命令行参数。
- 默认校验 HTTPS 证书;只有在明确确认网关证书问题时才使用 `--insecure`。
- 工具每次登录只发送一次认证请求,不会重试密码,避免触发账号锁定。