system: stop "syslog on" from wiping the server address

Saving the configuration drops the syslog server address whenever the log
of executed commands also contains "syslog on", which it almost always
does, since you have to enable the thing after pointing it somewhere.

parseConf() deduplicates by taking the matched text of a conf_overwrite
entry and removing every stored line that starts with it. For "syslog on"
the entry that matches is the catch-all ^syslog\b, so the matched text is
just "syslog" and the filter removes anything beginning with "syslog ",
including the "syslog ip ..." line saved a moment earlier. The address then
falls back to 0.0.0.0 on the next boot.

It fails quietly: nothing is reported, the running switch keeps logging
until it is restarted, and the loss looks like the firmware forgetting a
setting rather than the page dropping it.

Narrow the entry to the commands it is meant to collapse, so the address and
the port keep their own entries and are no longer collateral.

That alone would stop "syslog on" and "syslog off" from replacing each other,
because the list drops lines starting with the text it matched and "syslog off"
does not start with "syslog on". A separate list names the stem of such a pair
and collapses the two, which is what the catch-all used to do by accident.
This commit is contained in:
d00f committed 2026-08-30 22:38:31 +02:00
1 parent cb43b3cbd6
commit ccafa01c74
1 file changed
+16 -1
+16 -1
View File
@@ -28,13 +28,21 @@ const conf_cmds = [
/^bw\s+(in|out)\s+\d{1,2}\s+\S+$/,
/^hostname\s+.{1,23}$/,
];
/* Commands that come in an on/off pair replace each other, which the list
* below cannot express: it drops lines starting with the text it matched, and
* "syslog off" does not start with "syslog on". Naming the stem separately
* keeps the pair collapsed without widening the match to the whole family. */
const conf_toggle = [
/^(syslog)\s+(?:on|off)$/,
];
const conf_overwrite = [
/^ip\b/,
/^gw\b/,
/^netmask\b/,
/^syslog\s+ip\b/,
/^syslog\s+port\b/,
/^syslog\b/,
/^syslog\s+(on|off)$/,
/^passwd\b/,
/^vlan\s+\d{1,4}\s+mgmt$/,
/^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
@@ -71,6 +79,13 @@ function parseConf(s){
for (const x of conf_cmds)
if (x.test(line)) { ignore = false; break; }
if (ignore) continue;
for (const x of conf_toggle) {
const t = line.match(x);
if (t) {
configuration = configuration.filter(item => item !== t[1] + " on" && item !== t[1] + " off");
break;
}
}
for (const x of conf_overwrite) {
if (x.test(line)) {
let m = line.match(x);