Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/modules/sys.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ ruleset uses conntrack), so there is no cost before the firewall. The mon module
| `sys.restore` | POST | `{data (base64 tar.gz ≤ 2.9 MB), confirm: 60-600}` → starts the apply job; poll `job`, then `confirm` / `revert` as for any apply |
| `sys.fw` | GET | `{sysupgrade, factory_reset (scripts present), tmp_free, max_image, max_chunk, upload {total, received}, run {state: "" \| running \| failed \| done \| stale, rc, message}}` |
| `sys.fwupload` | POST | `{offset, total, data (base64 ≤ 2 MiB)}` → `{received}`; must continue exactly at the end of the file (409 + `received` otherwise, so a lost response can be resumed); `{cancel: true}` deletes it |
| `sys.fwupgrade` | POST | `{sha256}` — must match the uploaded file, then `/usr/libexec/mr/sysupgrade <image>` runs detached |
| `sys.factoryreset` | POST | `{confirm: "RESET"}` → `/usr/libexec/mr/factory-reset` runs detached |
| `sys.fwupgrade` | POST | `{sha256}` — must match the uploaded file, then `/usr/libexec/mr/sysupgrade -y <image>` runs detached |
| `sys.factoryreset` | POST | `{confirm: "RESET"}` → `/usr/libexec/mr/factory-reset -y` runs detached |

Mutations are POST only. `sys.backup` returns secrets only when asked for (the user's own download),
never the web UI password hash. The firmware image lives in `/tmp/mr-upgrade/` (created 0700 by root;
Expand Down Expand Up @@ -676,10 +676,10 @@ warn); issued and failed certificates are events of type `cert`.

## Platform interface

* `/usr/libexec/mr/sysupgrade IMAGE` — IMAGE is `/tmp/mr-upgrade/firmware.img`; exit ≠ 0 = refused,
* `/usr/libexec/mr/sysupgrade -y IMAGE` — IMAGE is `/tmp/mr-upgrade/firmware.img`; exit ≠ 0 = refused,
reason on stderr (shown in the web UI); on success it flashes and reboots. `/tmp` must be a tmpfs
with room for the image (+8 MiB).
* `/usr/libexec/mr/factory-reset` — wipes the configuration and reboots.
* `/usr/libexec/mr/factory-reset -y` — wipes the configuration and reboots.
* Boot runlevel must contain `modules` and `sysctl` (build/m2 does).

## Changes to the real home output (examples/router.yaml)
Expand Down
10 changes: 5 additions & 5 deletions mr/mod_sys_fw.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
// sys module: firmware upgrade and factory reset (web UI). The platform ships the scripts that do
// the real work:
//
// /usr/libexec/mr/sysupgrade IMAGE checks and flashes IMAGE (a file in /tmp) and reboots;
// exit code != 0 = refused, reason on stderr
// /usr/libexec/mr/factory-reset wipes the configuration and reboots
// /usr/libexec/mr/sysupgrade -y IMAGE checks and flashes IMAGE (a file in /tmp) and reboots;
// exit code != 0 = refused, reason on stderr
// /usr/libexec/mr/factory-reset -y wipes the configuration and reboots
//
// When a script is missing the web UI shows "当前构建不支持". The image is uploaded in chunks
// (the API body limit is 4 MiB): each POST carries {offset, total, data (base64)} and must continue
Expand Down Expand Up @@ -255,7 +255,7 @@ func apiSysFwUpgrade(r apiReq) apiResp {
}
appendChangeLog("webui: firmware upgrade started (sha256 " + sum[:16] + "…)")
logf("webui: firmware upgrade, image sha256 %s", sum)
if err := fwStart("sysupgrade", fwSysupgrade, fwImage()); err != nil {
if err := fwStart("sysupgrade", fwSysupgrade, "-y", fwImage()); err != nil {
return errResp(500, "%v", err)
}
return apiResp{body: map[string]any{"ok": true, "sha256": sum}}
Expand All @@ -281,7 +281,7 @@ func apiSysFactoryReset(r apiReq) apiResp {
}
appendChangeLog("webui: factory reset")
logf("webui: factory reset")
if err := fwStart("factory-reset", fwFactoryReset); err != nil {
if err := fwStart("factory-reset", fwFactoryReset, "-y"); err != nil {
return errResp(500, "%v", err)
}
return apiResp{body: map[string]any{"ok": true}}
Expand Down
16 changes: 15 additions & 1 deletion mr/mod_sys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func TestSysFirmwareUpload(t *testing.T) {
if st := apiSysFw(apiReq{method: "GET"}).body.(map[string]any); st["sysupgrade"] != false {
t.Error("sysupgrade reported without the script")
}
os.WriteFile(fwSysupgrade, []byte("#!/bin/sh\necho \"refused: $1 is not an AX6000 image\" >&2\nexit 3\n"), 0755)
os.WriteFile(fwSysupgrade, []byte("#!/bin/sh\n[ \"$1\" = -y ] || { echo \"missing -y\" >&2; exit 2; }\necho \"refused: $2 is not an AX6000 image\" >&2\nexit 3\n"), 0755)
if r := post(apiSysFwUpload, chunk(0, 4000)); r.status != 0 {
t.Fatalf("first chunk: %v", r.body)
}
Expand Down Expand Up @@ -685,6 +685,20 @@ func TestSysFirmwareUpload(t *testing.T) {
if r := post(apiSysFactoryReset, map[string]any{"confirm": "RESET"}); r.status != 501 {
t.Errorf("factory reset without the script: %d", r.status)
}
os.WriteFile(fwFactoryReset, []byte("#!/bin/sh\n[ \"$1\" = -y ] || { echo \"missing -y\" >&2; exit 2; }\necho \"ok\"\n"), 0755)
if r := post(apiSysFactoryReset, map[string]any{"confirm": "RESET"}); r.status != 0 {
t.Fatalf("factory reset: %v", r.body)
}
for i := 0; i < 50; i++ {
st = fwRunStatus()
if st["state"] != "running" {
break
}
time.Sleep(100 * time.Millisecond)
}
if st["state"] != "done" || st["rc"] != 0 {
t.Errorf("factory reset run status: %v", st)
}
if r := post(apiSysFwUpload, map[string]any{"cancel": true}); r.status != 0 {
t.Error("cancel")
}
Expand Down
Loading