fh_tool-cli 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fh_tool_cli-0.2.0/PKG-INFO +319 -0
- fh_tool_cli-0.2.0/README.md +305 -0
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/pyproject.toml +1 -1
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/src/fh_tool_cli/__init__.py +1 -1
- fh_tool_cli-0.2.0/src/fh_tool_cli/account.py +89 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/argparse_utils.py +59 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/__init__.py +1 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/cfg_cmd.py +124 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/fh_tool.py +74 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/local_vm.py +62 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/telnet.py +66 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backends/web_ajax.py +381 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/backup.py +704 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/cli.py +845 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/client.py +45 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/commands/__init__.py +1 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/commands/web.py +863 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/config_decrypt.py +292 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/config_store.py +180 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/credentials.py +98 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/crypto.py +61 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/diagnostics.py +572 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/errors.py +9 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/parser.py +673 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/remote.py +279 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/risk.py +24 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/upload.py +252 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/web_discovery.py +666 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli/web_writes.py +388 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli.egg-info/PKG-INFO +319 -0
- fh_tool_cli-0.2.0/src/fh_tool_cli.egg-info/SOURCES.txt +50 -0
- fh_tool_cli-0.2.0/tests/test_account.py +76 -0
- fh_tool_cli-0.2.0/tests/test_backup.py +247 -0
- fh_tool_cli-0.2.0/tests/test_cfg_cmd.py +128 -0
- fh_tool_cli-0.2.0/tests/test_cli_risk.py +214 -0
- fh_tool_cli-0.2.0/tests/test_config_decrypt.py +87 -0
- fh_tool_cli-0.2.0/tests/test_credentials.py +137 -0
- fh_tool_cli-0.2.0/tests/test_diagnostics.py +202 -0
- fh_tool_cli-0.2.0/tests/test_extracted_helpers.py +66 -0
- fh_tool_cli-0.2.0/tests/test_local_vm_integration.py +79 -0
- fh_tool_cli-0.2.0/tests/test_parser_registration.py +95 -0
- fh_tool_cli-0.2.0/tests/test_remote.py +169 -0
- fh_tool_cli-0.2.0/tests/test_upload.py +155 -0
- fh_tool_cli-0.2.0/tests/test_web_ajax.py +321 -0
- fh_tool_cli-0.2.0/tests/test_web_ajax_post.py +145 -0
- fh_tool_cli-0.2.0/tests/test_web_discovery.py +148 -0
- fh_tool_cli-0.2.0/tests/test_web_write_payloads.py +375 -0
- fh_tool_cli-0.1.1/PKG-INFO +0 -178
- fh_tool_cli-0.1.1/README.md +0 -164
- fh_tool_cli-0.1.1/src/fh_tool_cli/cli.py +0 -927
- fh_tool_cli-0.1.1/src/fh_tool_cli.egg-info/PKG-INFO +0 -178
- fh_tool_cli-0.1.1/src/fh_tool_cli.egg-info/SOURCES.txt +0 -10
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/setup.cfg +0 -0
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/src/fh_tool_cli.egg-info/dependency_links.txt +0 -0
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/src/fh_tool_cli.egg-info/entry_points.txt +0 -0
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/src/fh_tool_cli.egg-info/requires.txt +0 -0
- {fh_tool_cli-0.1.1 → fh_tool_cli-0.2.0}/src/fh_tool_cli.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fh_tool-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: 用于本地管理 FiberHome fh_tool 接口的 Python CLI
|
|
5
|
+
Author: Gxxk
|
|
6
|
+
License-Expression: AGPL-3.0-or-later
|
|
7
|
+
Keywords: FiberHome,fh_tool,ONU,gateway,telecomadmin
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: System :: Networking
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: cryptography>=42.0.0
|
|
13
|
+
Requires-Dist: requests>=2.31.0
|
|
14
|
+
|
|
15
|
+
# fh_tool-cli
|
|
16
|
+
|
|
17
|
+
本项目是本地管理 FiberHome `/fh_tool` 接口的 Python CLI,目标是快速管理/调整你自己的设备。
|
|
18
|
+
|
|
19
|
+
默认推荐用 `uvx`:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uvx --from . fh-tool --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
如果已经发布到 PyPI,使用方式会变成:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uvx --from fh_tool-cli fh-tool --help
|
|
29
|
+
uvx fh_tool-cli --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
也可以在源码目录里运行:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
cd ~/fh_tool-cli
|
|
36
|
+
uv run fh-tool --help
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
下文示例中的 `fh-tool ...` 如果是在源码目录内运行,可以统一写成 `uv run fh-tool ...`。
|
|
40
|
+
|
|
41
|
+
## 快速配置
|
|
42
|
+
|
|
43
|
+
保存默认 IP/MAC:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
fh-tool config set --ip 192.168.1.1 --mac AABBCCDDEEFF
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
查看配置:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
fh-tool config show
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
配置文件默认在:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
~/.config/fh_tool-cli/config.json
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
所有命令也都可以临时传:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
fh-tool dev-info --ip 192.168.1.1 --mac AABBCCDDEEFF
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 常用命令
|
|
68
|
+
|
|
69
|
+
低风险 probe:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
fh-tool probe
|
|
73
|
+
fh-tool probe --json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
读取设备信息:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
fh-tool dev-info
|
|
80
|
+
fh-tool get-result
|
|
81
|
+
fh-tool get-port-mirror
|
|
82
|
+
fh-tool get-preconfig
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
读取账号类信息:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
fh-tool admin-account
|
|
89
|
+
fh-tool reg-account
|
|
90
|
+
fh-tool pppoe-account
|
|
91
|
+
fh-tool pwd-reg-password
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
只读派生 HG5143F 管理面凭据候选,默认脱敏:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
fh-tool credentials derive --mac AABBCCDDEEFF
|
|
98
|
+
fh-tool credentials derive --kind hg5143f-telnet --mac AABBCCDDEEFF
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
当前只实现本地验证过的 HG5143F 管理面规则:Telnet 登录候选和 runtime `su root` 候选。Web superadmin、LOID/registration、TR-069/ACS 是配置层存储值,工具通过 `/fh_tool/api`、`cfg_cmd` 或离线配置解密读取并默认脱敏,不把它们当成公式猜测。Wi-Fi SSID/PSK 不属于当前 `fh_tool-cli` 范围。
|
|
102
|
+
|
|
103
|
+
打开 runtime Telnet:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
fh-tool telnet enable --yes
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
检查端口:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
fh-tool ports --ports 23,80,443,8080
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 本地 VM 测试环境
|
|
116
|
+
|
|
117
|
+
如果已经在 `/mnt/dev-cold/HG5143F-ONU-vm` 启动本地 userspace VM,可直接用它测试 `cfg_cmd` 和 Web AJAX,不需要碰真实网关:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
/mnt/dev-cold/HG5143F-ONU-vm/bin/start-fhapi-proot
|
|
121
|
+
/mnt/dev-cold/HG5143F-ONU-vm/bin/start-http-stack-proot
|
|
122
|
+
|
|
123
|
+
fh-tool cfg get InternetGatewayDevice.DeviceInfo.Manufacturer --backend local-vm
|
|
124
|
+
fh-tool cfg snapshot --backend local-vm --path InternetGatewayDevice.DeviceInfo.Manufacturer --path InternetGatewayDevice.DeviceInfo.ModelName
|
|
125
|
+
fh-tool web login-check --ip 127.0.0.1 --web-port 8080
|
|
126
|
+
fh-tool web ajax get get_factory_mode --ip 127.0.0.1 --web-port 8080
|
|
127
|
+
fh-tool web wan list --ip 127.0.0.1 --web-port 8080
|
|
128
|
+
fh-tool web port-mapping list --ip 127.0.0.1 --web-port 8080
|
|
129
|
+
fh-tool web vlanbind show --ip 127.0.0.1 --web-port 8080
|
|
130
|
+
fh-tool web diagnostics show --ip 127.0.0.1 --web-port 8080
|
|
131
|
+
fh-tool pon status --backend local-vm
|
|
132
|
+
fh-tool wan list --backend local-vm
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`local-vm` 只是在本机 proot VM 内执行厂商 `cfg_cmd`。`--vm-root` 必须指向 VM 工作区目录,也就是包含 `bin/proot-shell` 和 `rootfs-vm/fhrom/bin/cfg_cmd` 的目录;默认是 `/mnt/dev-cold/HG5143F-ONU-vm`。不要把它指到里面的 `rootfs-vm/`。
|
|
136
|
+
|
|
137
|
+
Web AJAX 读取命令只读。需要复用已有 Web session 时加 `--sessionid`;需要登录时可显式传 `--password-stdin` 或 `--password`。未显式提供密码时默认 `--username useradmin --password-source auto`,会依次尝试 `GetAdminAccount` 和 cfg 路径读取 Web superadmin 密码;失败不会阻塞只读抓取。sessionid、密码、LOID、PPPoE 等敏感字段默认会脱敏;只有显式加 `--reveal-secrets` 才输出明文。
|
|
138
|
+
|
|
139
|
+
后台 AJAX 接口发现以 live discovery 为主路径,不需要 HAR,也不需要 rootfs:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
fh-tool web discover live --ip 192.168.1.1 --web-port 8080 --output web-ajax-catalog.json
|
|
143
|
+
fh-tool web discover static --root /mnt/dev-cold/HG5143F-ONU-vm/rootfs-vm --output static-web-ajax-catalog.json
|
|
144
|
+
fh-tool web discover merge --input web-ajax-catalog.json --input static-web-ajax-catalog.json --output merged-web-ajax-catalog.json
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`live` 只探测只读 `get_*/query_*/show_*` 候选;写候选只进入 catalog,不会自动 POST。`static` 是补充路径,用于从 rootfs/备份目录扫描 HTML/JS/CSS 里的 `ajaxmethod`、参数名和上下文。
|
|
148
|
+
|
|
149
|
+
Web AJAX 写接口默认只做 dry-run。执行 POST 需要先完成备份,并显式加 `--execute --backup-confirmed --yes --danger`:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
fh-tool web ajax post set_wan_info --param VLANID=100
|
|
153
|
+
fh-tool web ajax replay --catalog web-ajax-catalog.json --method set_wan_info --param VLANID=100
|
|
154
|
+
fh-tool web port-mapping set --operation add --wan-index 1 --wan-session-index 1 --wan-iporppp ppp --external-port 8080 --protocol tcp --internal-client 192.168.1.2 --internal-port 80
|
|
155
|
+
fh-tool web vlanbind set --operation add --if-name eth1 --user-vlan 100 --wan-vlan 100
|
|
156
|
+
fh-tool web firewall set --enable 1 --level medium --dos-enable 1 --ipv6-enable 1 --execute --backup-confirmed --yes --danger
|
|
157
|
+
fh-tool web services set --service telnet --enabled 0 --execute --backup-confirmed --yes --danger
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
常规 Web 写接口优先使用 typed 参数。`web ajax post` 和 `web ajax replay` 支持任意已知或未知 AJAX method,默认只输出计划,不发 POST;执行同样必须加 `--execute --backup-confirmed --yes --danger`,且默认拒绝空 payload。`--json-payload` 和可重复的 `--param k=v` 仍保留为固件差异逃生口,合并顺序是 typed 参数、JSON、最后 `--param` 覆盖。
|
|
161
|
+
|
|
162
|
+
Telnet/cfg/诊断命令默认不会自动套用派生凭据。如果设备仍是 HG5143F 默认 Telnet 规则,并且已提供或保存 MAC,可以显式加 `--use-derived-credentials` 作为 fallback:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
fh-tool cfg get InternetGatewayDevice.DeviceInfo.Manufacturer --use-derived-credentials
|
|
166
|
+
fh-tool wan list --use-derived-credentials
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
诊断命令保持只读;`ip status` 这类依赖 VM/userspace 工具的命令会分别标记每个 probe 的 `ok/output/error`,工具缺失时输出 `partial_failure=true`,不会吞掉其它已成功字段。
|
|
170
|
+
|
|
171
|
+
本地 VM 集成测试默认会跳过;需要显式指定 VM 目录才会运行:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
uv run python -m unittest discover -s tests
|
|
175
|
+
FH_TOOL_CLI_VM_ROOT=/mnt/dev-cold/HG5143F-ONU-vm uv run python -m unittest tests.test_local_vm_integration
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## 备份与安全回滚
|
|
179
|
+
|
|
180
|
+
创建和验证备份:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
fh-tool backup --source-root / --output backup.tgz
|
|
184
|
+
fh-tool backup verify backup.tgz
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`restore` 默认只做 dry-run:解析 backup、验证 manifest/sha256,并显示将恢复的文件、目标路径和风险等级,不写入任何文件。
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
fh-tool restore backup.tgz --dry-run
|
|
191
|
+
fh-tool restore backup.tgz --dry-run --path /fhconf/usrconfig_conf
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
执行恢复必须显式指定本地目标根目录,并通过 extreme 风险确认:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
fh-tool restore backup.tgz \
|
|
198
|
+
--target-root /tmp/fh-tool-restore-root \
|
|
199
|
+
--execute \
|
|
200
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
也可以选择真实设备目标。该模式会通过 Telnet 把 allowlist 文件先写入 `/tmp/fh-tool-restore` staging,远端 sha256 校验通过后才覆盖目标路径;仍然不会自动 reboot 或 factory reset:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
fh-tool restore backup.tgz \
|
|
207
|
+
--target device \
|
|
208
|
+
--path /fhconf/usrconfig_conf \
|
|
209
|
+
--execute \
|
|
210
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
当前 restore 只恢复 allowlist 内的配置文件,且会拒绝路径穿越、绝对路径逃逸和未知文件写入。`/proc/mtd`、runtime password 文件、restore/factory reset flag 等备份内容不会被恢复。恢复后会 read-back/hash verify;不会自动 reboot,也不会自动 factory reset。
|
|
214
|
+
|
|
215
|
+
## CloudPlat / SmartSwitch
|
|
216
|
+
|
|
217
|
+
CloudPlat 默认先做只读审计和计划:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
fh-tool cloud status
|
|
221
|
+
fh-tool cloud audit --output cloud-report.md
|
|
222
|
+
fh-tool cloud plan
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`cloud status/audit/plan` 会结构化显示 SmartSwitch 当前值、配置路径、禁用值、影响面和禁止改动项。禁用 SmartSwitch 只会写入 `InternetGatewayDevice.X_CT-COM_SmartSwitch.Enable=0`,需要先完成备份,并在写入后 read-back verify:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
fh-tool cloud disable-smartswitch \
|
|
229
|
+
--backup-confirmed \
|
|
230
|
+
--yes --danger
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
该命令不会修改 LOID、PON、WAN VLAN、ServiceList 或 TR-069 VLAN。
|
|
234
|
+
|
|
235
|
+
## 22 个 `/fh_tool/api` method 覆盖
|
|
236
|
+
|
|
237
|
+
已提供 typed command:
|
|
238
|
+
|
|
239
|
+
| func | command |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `GetResult` | `fh-tool get-result` |
|
|
242
|
+
| `SetResult` | `fh-tool set-result --result VALUE --yes` |
|
|
243
|
+
| `GetPortMirror` | `fh-tool get-port-mirror` |
|
|
244
|
+
| `SetPortMirror` | `fh-tool set-port-mirror --enable ... --direction ... --srcport ... --dstport ... --yes` |
|
|
245
|
+
| `LogDownload` | `fh-tool log-download [--output log.tar.gz]` |
|
|
246
|
+
| `GetDevInfo` | `fh-tool dev-info` |
|
|
247
|
+
| `GetAdminAccount` | `fh-tool admin-account` |
|
|
248
|
+
| `GetRegAccount` | `fh-tool reg-account` |
|
|
249
|
+
| `SetRegAccount` | `fh-tool set-reg-account --regname ... --regpwd ... --yes` |
|
|
250
|
+
| `GetPwdRegPassword` | `fh-tool pwd-reg-password` |
|
|
251
|
+
| `SetPwdRegPassword` | `fh-tool set-pwd-reg-password --password ... --yes` |
|
|
252
|
+
| `DownloadFile` | `fh-tool download-file --file-name /var/... --output out.tar.gz --yes` |
|
|
253
|
+
| `RestoreDefaultSettings` | `fh-tool restore-default-settings --yes --danger --i-know-this-can-break-my-device` |
|
|
254
|
+
| `UploadPrepare` | `fh-tool upload-prepare` |
|
|
255
|
+
| `DeviceReboot` | `fh-tool reboot --yes --danger --i-know-this-can-break-my-device` |
|
|
256
|
+
| `GetPreconfig` | `fh-tool get-preconfig` |
|
|
257
|
+
| `SetPreconfig` | `fh-tool set-preconfig --fullname ... --yes --danger` |
|
|
258
|
+
| `TelnetEnable` | `fh-tool telnet enable --yes` / `fh-tool telnet disable --yes --danger` |
|
|
259
|
+
| `GetPppoeAccount` | `fh-tool pppoe-account` |
|
|
260
|
+
| `SetFHDebugLog` | `fh-tool set-fh-debug-log --module tr069 --data ... --yes --danger` |
|
|
261
|
+
| `CloseFHDebugLog` | `fh-tool close-fh-debug-log --yes` |
|
|
262
|
+
| `OpenFHDebugLog` | `fh-tool open-fh-debug-log --yes` |
|
|
263
|
+
|
|
264
|
+
原始调用入口:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
fh-tool call --func GetDevInfo
|
|
268
|
+
fh-tool call --func TelnetEnable --param telnet=1 --allow-risky
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## upload / download endpoint
|
|
272
|
+
|
|
273
|
+
下载 `LogDownload` 或 `DownloadFile` 返回的文件:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
fh-tool download-url --url '/fh_tool/tool_download?file=xxx.tar.gz' --output xxx.tar.gz
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
上传前先获取 token:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
fh-tool upload-plan --action preconfig --file sysinfo_conf
|
|
283
|
+
fh-tool upload-prepare
|
|
284
|
+
fh-tool upload-prepare --reveal-secrets
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
上传 firmware/preconfig 前先 dry-run:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
fh-tool upload --action preconfig --file sysinfo_conf --sessionid TOKEN --dry-run
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
真正上传属于 extreme 风险,只上传文件到 staging path,不会自动 reboot、restore 或切换 preconfig:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
fh-tool upload \
|
|
297
|
+
--action preconfig \
|
|
298
|
+
--file sysinfo_conf \
|
|
299
|
+
--sessionid TOKEN \
|
|
300
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## 风险边界
|
|
304
|
+
|
|
305
|
+
这些命令默认不会执行,必须显式确认:
|
|
306
|
+
|
|
307
|
+
- `--yes`: 会写设备状态或创建下载文件。
|
|
308
|
+
- `--danger`: 高风险写入、关闭 Telnet、执行 debug script。
|
|
309
|
+
- `--i-know-this-can-break-my-device`: restore、firmware/preconfig upload、恢复出厂或重启。
|
|
310
|
+
|
|
311
|
+
当前设备如果需要保持 Telnet 打开,不要运行:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
fh-tool telnet disable --yes --danger
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## License
|
|
318
|
+
|
|
319
|
+
AGPL-3.0-or-later
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# fh_tool-cli
|
|
2
|
+
|
|
3
|
+
本项目是本地管理 FiberHome `/fh_tool` 接口的 Python CLI,目标是快速管理/调整你自己的设备。
|
|
4
|
+
|
|
5
|
+
默认推荐用 `uvx`:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uvx --from . fh-tool --help
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
如果已经发布到 PyPI,使用方式会变成:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uvx --from fh_tool-cli fh-tool --help
|
|
15
|
+
uvx fh_tool-cli --help
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
也可以在源码目录里运行:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
cd ~/fh_tool-cli
|
|
22
|
+
uv run fh-tool --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
下文示例中的 `fh-tool ...` 如果是在源码目录内运行,可以统一写成 `uv run fh-tool ...`。
|
|
26
|
+
|
|
27
|
+
## 快速配置
|
|
28
|
+
|
|
29
|
+
保存默认 IP/MAC:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
fh-tool config set --ip 192.168.1.1 --mac AABBCCDDEEFF
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
查看配置:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
fh-tool config show
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
配置文件默认在:
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
~/.config/fh_tool-cli/config.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
所有命令也都可以临时传:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
fh-tool dev-info --ip 192.168.1.1 --mac AABBCCDDEEFF
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 常用命令
|
|
54
|
+
|
|
55
|
+
低风险 probe:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
fh-tool probe
|
|
59
|
+
fh-tool probe --json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
读取设备信息:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
fh-tool dev-info
|
|
66
|
+
fh-tool get-result
|
|
67
|
+
fh-tool get-port-mirror
|
|
68
|
+
fh-tool get-preconfig
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
读取账号类信息:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
fh-tool admin-account
|
|
75
|
+
fh-tool reg-account
|
|
76
|
+
fh-tool pppoe-account
|
|
77
|
+
fh-tool pwd-reg-password
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
只读派生 HG5143F 管理面凭据候选,默认脱敏:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
fh-tool credentials derive --mac AABBCCDDEEFF
|
|
84
|
+
fh-tool credentials derive --kind hg5143f-telnet --mac AABBCCDDEEFF
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
当前只实现本地验证过的 HG5143F 管理面规则:Telnet 登录候选和 runtime `su root` 候选。Web superadmin、LOID/registration、TR-069/ACS 是配置层存储值,工具通过 `/fh_tool/api`、`cfg_cmd` 或离线配置解密读取并默认脱敏,不把它们当成公式猜测。Wi-Fi SSID/PSK 不属于当前 `fh_tool-cli` 范围。
|
|
88
|
+
|
|
89
|
+
打开 runtime Telnet:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
fh-tool telnet enable --yes
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
检查端口:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
fh-tool ports --ports 23,80,443,8080
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 本地 VM 测试环境
|
|
102
|
+
|
|
103
|
+
如果已经在 `/mnt/dev-cold/HG5143F-ONU-vm` 启动本地 userspace VM,可直接用它测试 `cfg_cmd` 和 Web AJAX,不需要碰真实网关:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
/mnt/dev-cold/HG5143F-ONU-vm/bin/start-fhapi-proot
|
|
107
|
+
/mnt/dev-cold/HG5143F-ONU-vm/bin/start-http-stack-proot
|
|
108
|
+
|
|
109
|
+
fh-tool cfg get InternetGatewayDevice.DeviceInfo.Manufacturer --backend local-vm
|
|
110
|
+
fh-tool cfg snapshot --backend local-vm --path InternetGatewayDevice.DeviceInfo.Manufacturer --path InternetGatewayDevice.DeviceInfo.ModelName
|
|
111
|
+
fh-tool web login-check --ip 127.0.0.1 --web-port 8080
|
|
112
|
+
fh-tool web ajax get get_factory_mode --ip 127.0.0.1 --web-port 8080
|
|
113
|
+
fh-tool web wan list --ip 127.0.0.1 --web-port 8080
|
|
114
|
+
fh-tool web port-mapping list --ip 127.0.0.1 --web-port 8080
|
|
115
|
+
fh-tool web vlanbind show --ip 127.0.0.1 --web-port 8080
|
|
116
|
+
fh-tool web diagnostics show --ip 127.0.0.1 --web-port 8080
|
|
117
|
+
fh-tool pon status --backend local-vm
|
|
118
|
+
fh-tool wan list --backend local-vm
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`local-vm` 只是在本机 proot VM 内执行厂商 `cfg_cmd`。`--vm-root` 必须指向 VM 工作区目录,也就是包含 `bin/proot-shell` 和 `rootfs-vm/fhrom/bin/cfg_cmd` 的目录;默认是 `/mnt/dev-cold/HG5143F-ONU-vm`。不要把它指到里面的 `rootfs-vm/`。
|
|
122
|
+
|
|
123
|
+
Web AJAX 读取命令只读。需要复用已有 Web session 时加 `--sessionid`;需要登录时可显式传 `--password-stdin` 或 `--password`。未显式提供密码时默认 `--username useradmin --password-source auto`,会依次尝试 `GetAdminAccount` 和 cfg 路径读取 Web superadmin 密码;失败不会阻塞只读抓取。sessionid、密码、LOID、PPPoE 等敏感字段默认会脱敏;只有显式加 `--reveal-secrets` 才输出明文。
|
|
124
|
+
|
|
125
|
+
后台 AJAX 接口发现以 live discovery 为主路径,不需要 HAR,也不需要 rootfs:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
fh-tool web discover live --ip 192.168.1.1 --web-port 8080 --output web-ajax-catalog.json
|
|
129
|
+
fh-tool web discover static --root /mnt/dev-cold/HG5143F-ONU-vm/rootfs-vm --output static-web-ajax-catalog.json
|
|
130
|
+
fh-tool web discover merge --input web-ajax-catalog.json --input static-web-ajax-catalog.json --output merged-web-ajax-catalog.json
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`live` 只探测只读 `get_*/query_*/show_*` 候选;写候选只进入 catalog,不会自动 POST。`static` 是补充路径,用于从 rootfs/备份目录扫描 HTML/JS/CSS 里的 `ajaxmethod`、参数名和上下文。
|
|
134
|
+
|
|
135
|
+
Web AJAX 写接口默认只做 dry-run。执行 POST 需要先完成备份,并显式加 `--execute --backup-confirmed --yes --danger`:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
fh-tool web ajax post set_wan_info --param VLANID=100
|
|
139
|
+
fh-tool web ajax replay --catalog web-ajax-catalog.json --method set_wan_info --param VLANID=100
|
|
140
|
+
fh-tool web port-mapping set --operation add --wan-index 1 --wan-session-index 1 --wan-iporppp ppp --external-port 8080 --protocol tcp --internal-client 192.168.1.2 --internal-port 80
|
|
141
|
+
fh-tool web vlanbind set --operation add --if-name eth1 --user-vlan 100 --wan-vlan 100
|
|
142
|
+
fh-tool web firewall set --enable 1 --level medium --dos-enable 1 --ipv6-enable 1 --execute --backup-confirmed --yes --danger
|
|
143
|
+
fh-tool web services set --service telnet --enabled 0 --execute --backup-confirmed --yes --danger
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
常规 Web 写接口优先使用 typed 参数。`web ajax post` 和 `web ajax replay` 支持任意已知或未知 AJAX method,默认只输出计划,不发 POST;执行同样必须加 `--execute --backup-confirmed --yes --danger`,且默认拒绝空 payload。`--json-payload` 和可重复的 `--param k=v` 仍保留为固件差异逃生口,合并顺序是 typed 参数、JSON、最后 `--param` 覆盖。
|
|
147
|
+
|
|
148
|
+
Telnet/cfg/诊断命令默认不会自动套用派生凭据。如果设备仍是 HG5143F 默认 Telnet 规则,并且已提供或保存 MAC,可以显式加 `--use-derived-credentials` 作为 fallback:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
fh-tool cfg get InternetGatewayDevice.DeviceInfo.Manufacturer --use-derived-credentials
|
|
152
|
+
fh-tool wan list --use-derived-credentials
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
诊断命令保持只读;`ip status` 这类依赖 VM/userspace 工具的命令会分别标记每个 probe 的 `ok/output/error`,工具缺失时输出 `partial_failure=true`,不会吞掉其它已成功字段。
|
|
156
|
+
|
|
157
|
+
本地 VM 集成测试默认会跳过;需要显式指定 VM 目录才会运行:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
uv run python -m unittest discover -s tests
|
|
161
|
+
FH_TOOL_CLI_VM_ROOT=/mnt/dev-cold/HG5143F-ONU-vm uv run python -m unittest tests.test_local_vm_integration
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 备份与安全回滚
|
|
165
|
+
|
|
166
|
+
创建和验证备份:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
fh-tool backup --source-root / --output backup.tgz
|
|
170
|
+
fh-tool backup verify backup.tgz
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`restore` 默认只做 dry-run:解析 backup、验证 manifest/sha256,并显示将恢复的文件、目标路径和风险等级,不写入任何文件。
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
fh-tool restore backup.tgz --dry-run
|
|
177
|
+
fh-tool restore backup.tgz --dry-run --path /fhconf/usrconfig_conf
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
执行恢复必须显式指定本地目标根目录,并通过 extreme 风险确认:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
fh-tool restore backup.tgz \
|
|
184
|
+
--target-root /tmp/fh-tool-restore-root \
|
|
185
|
+
--execute \
|
|
186
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
也可以选择真实设备目标。该模式会通过 Telnet 把 allowlist 文件先写入 `/tmp/fh-tool-restore` staging,远端 sha256 校验通过后才覆盖目标路径;仍然不会自动 reboot 或 factory reset:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
fh-tool restore backup.tgz \
|
|
193
|
+
--target device \
|
|
194
|
+
--path /fhconf/usrconfig_conf \
|
|
195
|
+
--execute \
|
|
196
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
当前 restore 只恢复 allowlist 内的配置文件,且会拒绝路径穿越、绝对路径逃逸和未知文件写入。`/proc/mtd`、runtime password 文件、restore/factory reset flag 等备份内容不会被恢复。恢复后会 read-back/hash verify;不会自动 reboot,也不会自动 factory reset。
|
|
200
|
+
|
|
201
|
+
## CloudPlat / SmartSwitch
|
|
202
|
+
|
|
203
|
+
CloudPlat 默认先做只读审计和计划:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
fh-tool cloud status
|
|
207
|
+
fh-tool cloud audit --output cloud-report.md
|
|
208
|
+
fh-tool cloud plan
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`cloud status/audit/plan` 会结构化显示 SmartSwitch 当前值、配置路径、禁用值、影响面和禁止改动项。禁用 SmartSwitch 只会写入 `InternetGatewayDevice.X_CT-COM_SmartSwitch.Enable=0`,需要先完成备份,并在写入后 read-back verify:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
fh-tool cloud disable-smartswitch \
|
|
215
|
+
--backup-confirmed \
|
|
216
|
+
--yes --danger
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
该命令不会修改 LOID、PON、WAN VLAN、ServiceList 或 TR-069 VLAN。
|
|
220
|
+
|
|
221
|
+
## 22 个 `/fh_tool/api` method 覆盖
|
|
222
|
+
|
|
223
|
+
已提供 typed command:
|
|
224
|
+
|
|
225
|
+
| func | command |
|
|
226
|
+
|---|---|
|
|
227
|
+
| `GetResult` | `fh-tool get-result` |
|
|
228
|
+
| `SetResult` | `fh-tool set-result --result VALUE --yes` |
|
|
229
|
+
| `GetPortMirror` | `fh-tool get-port-mirror` |
|
|
230
|
+
| `SetPortMirror` | `fh-tool set-port-mirror --enable ... --direction ... --srcport ... --dstport ... --yes` |
|
|
231
|
+
| `LogDownload` | `fh-tool log-download [--output log.tar.gz]` |
|
|
232
|
+
| `GetDevInfo` | `fh-tool dev-info` |
|
|
233
|
+
| `GetAdminAccount` | `fh-tool admin-account` |
|
|
234
|
+
| `GetRegAccount` | `fh-tool reg-account` |
|
|
235
|
+
| `SetRegAccount` | `fh-tool set-reg-account --regname ... --regpwd ... --yes` |
|
|
236
|
+
| `GetPwdRegPassword` | `fh-tool pwd-reg-password` |
|
|
237
|
+
| `SetPwdRegPassword` | `fh-tool set-pwd-reg-password --password ... --yes` |
|
|
238
|
+
| `DownloadFile` | `fh-tool download-file --file-name /var/... --output out.tar.gz --yes` |
|
|
239
|
+
| `RestoreDefaultSettings` | `fh-tool restore-default-settings --yes --danger --i-know-this-can-break-my-device` |
|
|
240
|
+
| `UploadPrepare` | `fh-tool upload-prepare` |
|
|
241
|
+
| `DeviceReboot` | `fh-tool reboot --yes --danger --i-know-this-can-break-my-device` |
|
|
242
|
+
| `GetPreconfig` | `fh-tool get-preconfig` |
|
|
243
|
+
| `SetPreconfig` | `fh-tool set-preconfig --fullname ... --yes --danger` |
|
|
244
|
+
| `TelnetEnable` | `fh-tool telnet enable --yes` / `fh-tool telnet disable --yes --danger` |
|
|
245
|
+
| `GetPppoeAccount` | `fh-tool pppoe-account` |
|
|
246
|
+
| `SetFHDebugLog` | `fh-tool set-fh-debug-log --module tr069 --data ... --yes --danger` |
|
|
247
|
+
| `CloseFHDebugLog` | `fh-tool close-fh-debug-log --yes` |
|
|
248
|
+
| `OpenFHDebugLog` | `fh-tool open-fh-debug-log --yes` |
|
|
249
|
+
|
|
250
|
+
原始调用入口:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
fh-tool call --func GetDevInfo
|
|
254
|
+
fh-tool call --func TelnetEnable --param telnet=1 --allow-risky
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## upload / download endpoint
|
|
258
|
+
|
|
259
|
+
下载 `LogDownload` 或 `DownloadFile` 返回的文件:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
fh-tool download-url --url '/fh_tool/tool_download?file=xxx.tar.gz' --output xxx.tar.gz
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
上传前先获取 token:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
fh-tool upload-plan --action preconfig --file sysinfo_conf
|
|
269
|
+
fh-tool upload-prepare
|
|
270
|
+
fh-tool upload-prepare --reveal-secrets
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
上传 firmware/preconfig 前先 dry-run:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
fh-tool upload --action preconfig --file sysinfo_conf --sessionid TOKEN --dry-run
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
真正上传属于 extreme 风险,只上传文件到 staging path,不会自动 reboot、restore 或切换 preconfig:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
fh-tool upload \
|
|
283
|
+
--action preconfig \
|
|
284
|
+
--file sysinfo_conf \
|
|
285
|
+
--sessionid TOKEN \
|
|
286
|
+
--yes --danger --i-know-this-can-break-my-device
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## 风险边界
|
|
290
|
+
|
|
291
|
+
这些命令默认不会执行,必须显式确认:
|
|
292
|
+
|
|
293
|
+
- `--yes`: 会写设备状态或创建下载文件。
|
|
294
|
+
- `--danger`: 高风险写入、关闭 Telnet、执行 debug script。
|
|
295
|
+
- `--i-know-this-can-break-my-device`: restore、firmware/preconfig upload、恢复出厂或重启。
|
|
296
|
+
|
|
297
|
+
当前设备如果需要保持 Telnet 打开,不要运行:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
fh-tool telnet disable --yes --danger
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
AGPL-3.0-or-later
|