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