fix(webconfig): tighten CLI failure detection, reboot deferral and refusals
Five findings from review, all confirmed against the source.
Failure classification (P2). Testing replies for an "Err" prefix passed five
other shapes off as success: "Unknown command", "unknown config: x", "??: x",
"Can't find GPS", "(ERR: clock cannot go backwards)" and "File system erase:
Err". They rendered green, and worse, left _batch_all_ok true — so a queued
reboot went ahead after commands that had failed, defeating the gate entirely.
Rather than lengthen one guess, the two questions are now asked separately,
each erring safe:
- colour asks "does this look like a failure", against every shape CommonCLI
actually emits, enumerated in WebConfigBatch.h and pinned by a host test
that uses the literal strings. Getting this wrong is cosmetic.
- the reboot gate asks something narrower and answerable: "did every setting
I asked for take". Only `set`/`password` gate it, and only on the "OK"
prefix every setter keeps. Diagnostics no longer gate a reboot at all, so a
harmless `memory` cannot strand one and no guess is made about "> value".
Reboot deferral (P2). CommonCLI dispatches on a six-byte prefix, so `reboot
now` and `rebooted` reach Board::reboot() too. Matching exactly meant those
variants skipped both the confirmation and the deferral and took the node down
mid-drain — the precise failure deferral exists to prevent. Both sides now
anchor the way the firmware dispatches, and the UI's risk matcher with them.
Three commands the portal cannot honestly serve are refused at POST with a
reason, and dropped from autocomplete, instead of running and lying:
- `start ota` builds a second AsyncWebServer on port 80 with no bind check
and answers "Started" regardless; the portal already holds that port, so it
could only leak the allocation and inhibit sleep.
- `clock sync` takes its time from the caller's timestamp, which a web
request has none of, so CommonCLI always rejected it. `time <epoch>` works
and remains offered.
- bare `log` and `get acl` write their real output to Serial and hand back a
stub the terminal showed as success; `log` also streams a whole file from
the loop task, stalling the mesh and radio while it does.
The mock now emits the same failure shapes it used to fake as successes, so
these are reproducible off-hardware. 24 batch + 14 keys tests pass; audit
reports 119/119 answered, 0 missing, 4/4 refused with a reason.
This commit is contained in:
1 parent
0f4c87118a
commit
944caebed7
6 files changed
+284
-47
No files matched your search
+22
-16
@@ -1440,7 +1440,8 @@ var CLI_VERBS=[
|
||||
["ver","Firmware version"],
|
||||
["board","Board and hardware info"],
|
||||
["clock","Show the device clock (UTC)"],
|
||||
["clock sync","Set the device clock from this browser"],
|
||||
// `clock sync` is absent on purpose: it takes its time from the caller's
|
||||
// timestamp, which a web request has none of, so it can only ever fail here.
|
||||
["time ","Set the clock {epoch-seconds}"],
|
||||
["region","Show the configured region"],
|
||||
["memory","Heap and PSRAM free/min/largest block"],
|
||||
@@ -1459,7 +1460,8 @@ var CLI_VERBS=[
|
||||
["stats-packets","Per-packet-type counters"],
|
||||
["stats-radio","Radio counters (RSSI, SNR, noise)"],
|
||||
["stats-radio-diag","Extended radio diagnostics"],
|
||||
["log","Show the packet log summary"],
|
||||
// Bare `log` is absent: it streams the file to the serial console and stalls
|
||||
// the radio doing it, and hands back only "EOF".
|
||||
["log start","Start packet logging to the filesystem"],
|
||||
["log stop","Stop packet logging"],
|
||||
["log erase","Delete the stored packet logs"],
|
||||
@@ -1480,7 +1482,7 @@ var CLI_VERBS=[
|
||||
["alert test","Send a test alert on the configured channel"],
|
||||
["ota check","Check for a newer build (does not flash)"],
|
||||
["ota update","Download and flash the newer build, then reboot"],
|
||||
["start ota","Raise the manual firmware-upload AP"],
|
||||
// `start ota` is absent: it binds port 80, which this portal is already using.
|
||||
["start webconfig","Start this portal on the LAN"],
|
||||
["start webconfig ap","Start this portal on its own setup AP"],
|
||||
["stop webconfig","Stop this portal"],
|
||||
@@ -1498,7 +1500,7 @@ var CLI_KEYS=[
|
||||
["lat","Advert latitude",0],
|
||||
["lon","Advert longitude",0],
|
||||
["public.key","This node's public key",1],
|
||||
["acl","Access control list (per-node permissions)",1],
|
||||
// `get acl` is absent: it prints to the serial console and returns nothing.
|
||||
["prv.key","Restore an identity {64-hex-char-key}",2],
|
||||
["role","Node role",1],
|
||||
["radio","Radio parameters {freq,bw,sf,cr}",0],
|
||||
@@ -1852,18 +1854,21 @@ function cliParse(text){
|
||||
/* ---------- CLI: confirmation ----------
|
||||
Rendered into the scrollback rather than as a modal: it reads as part of the
|
||||
session, and on a phone it can't end up behind the keyboard. */
|
||||
// Anchored the way CommonCLI dispatches, which is mostly on a PREFIX: `reboot`
|
||||
// matches the first six bytes, so `reboot now` reboots too. Matching these
|
||||
// exactly (/^reboot$/) let those variants skip the confirmation entirely.
|
||||
var CLI_RISK=[
|
||||
[/^erase$/,"erases the filesystem — stored settings and this node's identity"],
|
||||
[/^(reboot|clkreboot)$/,"restarts the node"],
|
||||
[/^(poweroff|shutdown)$/,"powers the node off"],
|
||||
[/^ota update$/,"downloads and flashes new firmware, then reboots"],
|
||||
[/^start ota$/,"drops this portal and raises the firmware-upload AP"],
|
||||
[/^clkreboot/,"resets the clock and restarts the node"],
|
||||
[/^reboot/,"restarts the node"],
|
||||
[/^(poweroff|shutdown)/,"powers the node off"],
|
||||
[/^ota update/,"downloads and flashes new firmware, then reboots"],
|
||||
[/^stop webconfig$/,"stops this portal"],
|
||||
[/^set wifi\.(ssid|pwd)\b/,"changes WiFi — this page will drop"],
|
||||
[/^set radio\b/,"changes radio parameters — a wrong value takes this node off the air"],
|
||||
[/^set freq\b/,"changes the frequency — a wrong value takes this node off the air"],
|
||||
[/^password\b/,"changes the admin password"],
|
||||
[/^set prv\.key\b/,"replaces this node's identity"]
|
||||
[/^set wifi\.(ssid|pwd)\s/,"changes WiFi — this page will drop"],
|
||||
[/^set radio\s/,"changes radio parameters — a wrong value takes this node off the air"],
|
||||
[/^set freq\s/,"changes the frequency — a wrong value takes this node off the air"],
|
||||
[/^password\s/,"changes the admin password"],
|
||||
[/^set prv\.key\s/,"replaces this node's identity"]
|
||||
];
|
||||
function cliRisks(cmds){
|
||||
var seen={},out=[];
|
||||
@@ -2019,13 +2024,14 @@ function cliAfter(cmds,r){
|
||||
if(/^password\s/.test(c))cli.pwd=true;
|
||||
if(/^(set|password)\s/.test(c))touched=true;
|
||||
});
|
||||
// Same prefix dispatch as the risk list: `poweroff now` powers off too.
|
||||
if(touched)loadConfigSoft();
|
||||
// A `reboot` in the sequence is not run by the CLI — Board::reboot() never
|
||||
// returns, so the node answers it and schedules the restart for after this
|
||||
// read. It withholds it when any command failed, exactly as a config save
|
||||
// does; say which happened rather than leaving the operator to guess.
|
||||
if(r&&r.reboot_withheld){
|
||||
cliEcho("err","Not rebooting — some commands failed. Fix them and run \"reboot\" again.");
|
||||
cliEcho("err","Not rebooting — a setting was rejected. Fix it and run \"reboot\" again.");
|
||||
return;
|
||||
}
|
||||
if(r&&r.reboot){
|
||||
@@ -2035,8 +2041,8 @@ function cliAfter(cmds,r){
|
||||
// clkreboot / poweroff / erase-and-flash take the node down themselves, so
|
||||
// there is no result to wait for.
|
||||
cmds.forEach(function(c){
|
||||
if(/^(poweroff|shutdown)$/.test(c))showReboot("The node is powering off. Reconnect power to bring it back.",false,"Powering off…");
|
||||
else if(/^clkreboot$/.test(c))showReboot("The node is restarting. This page will try to reconnect automatically.",true);
|
||||
if(/^(poweroff|shutdown)/.test(c))showReboot("The node is powering off. Reconnect power to bring it back.",false,"Powering off…");
|
||||
else if(/^clkreboot/.test(c))showReboot("The node is restarting. This page will try to reconnect automatically.",true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user