mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
The port was frozen at 514 in the call that opens the connection, so a collector listening anywhere else was simply out of reach, and plenty do, because 514 is privileged and containerised collectors usually get a high port instead. Working around it meant putting a proxy in front, which then rewrites the source address and hides which device actually sent the line. Add `syslog port <n>`. The default stays 514, so nothing changes for an existing configuration. Setting it tears the connection down and builds a new one, the same dance the address already does, because uip_udp_new() freezes the port into the connection. The value is parsed here rather than through atoi_short(), which reports "no digits" but not overflow: 65540 would quietly wrap to 4 and we would open a connection to a port nobody asked for. Checking before each multiply keeps it in 16-bit arithmetic. Zero then covers all three ways to be wrong - no digits, past 65535, or an explicit "0", which is not a port either. Whitelist the new command in config.js as well, next to `syslog ip`, or the line is dropped without a word when the configuration is saved and the setting quietly fails to survive a reboot. The dedup entry has to precede the general `^syslog\b` one, otherwise it would deduplicate against `syslog on`. itoa_short() is new: itoa() only handles a byte and print_short() prints hex, so there was no way to show a port as a decimal number. Kept separate from itoa() rather than widening it, because every existing caller passes a byte and would start paying for 16-bit divisions it does not need. The scratch variables for the parser live in xdata. Locals there would take internal RAM, and this image has none left: data ends at 0x77, the overlay occupies 0x78-0x7f and the stack starts at 0x80. Measured: no module's DSEG grew.
114 lines
3.1 KiB
JavaScript
114 lines
3.1 KiB
JavaScript
var configInterval = Number();
|
|
var configuration = [];
|
|
const conf_cmds = [
|
|
/^ip\s+(\d{1,3}\.){3}\d{1,3}$/,
|
|
/^ip\s+dhcp$/,
|
|
/^gw\s+(\d{1,3}\.){3}\d{1,3}$/,
|
|
/^netmask\s+(\d{1,3}\.){3}\d{1,3}$/,
|
|
/^syslog\s+(on|off)$/,
|
|
/^syslog\s+ip\s+(\d{1,3}\.){3}\d{1,3}$/,
|
|
/^syslog\s+port\s+\d{1,5}$/,
|
|
/^passwd\s+\S+$/,
|
|
/^vlan\s+\d{1,4}\s+d$/,
|
|
/^vlan\s+\d{1,4}\s+mgmt$/,
|
|
/^vlan\s+\d{1,4}(\s+[a-zA-Z]\w*)?(\s+\d{1,2}[tu]?)+$/,
|
|
/^pvid\s+\d{1,2}\s+\d{1,4}$/,
|
|
/^ingress(\s+\d{1,2}[tua])+$/,
|
|
/^ingress\s+[tua]$/,
|
|
/^port\s+\d{1,2}\s+(10m|100m|1g|2g5|5g|10g|auto|on|off)(\s+(half|full))?$/,
|
|
/^port\s+\d{1,2}\s+name\s+\S+$/,
|
|
/^eee(\s+\d{1,2})?\s+(on|off)$/,
|
|
/^mirror(\s+\d{1,2})(\s+\d{1,2}[tr]?)+$/,
|
|
/^lag\s+\d(\s+\d{1,2})+$/,
|
|
/^laghash\s+\d(\s+\w+)+$/,
|
|
/^isolate\s+\d{1,2}(\s+(off|\d{1,2}))+$/,
|
|
/^stp\s+(on|off)$/,
|
|
/^igmp\s+(on|off)$/,
|
|
/^mtu\s+\d{1,2}\s+\d+$/,
|
|
/^bw\s+(in|out)\s+\d{1,2}\s+\S+$/,
|
|
/^hostname\s+.{1,23}$/,
|
|
];
|
|
const conf_overwrite = [
|
|
/^ip\b/,
|
|
/^gw\b/,
|
|
/^netmask\b/,
|
|
/^syslog\s+ip\b/,
|
|
/^syslog\s+port\b/,
|
|
/^syslog\b/,
|
|
/^passwd\b/,
|
|
/^vlan\s+\d{1,4}\s+mgmt$/,
|
|
/^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
|
|
/^pvid\s+\d{1,2}\b/,
|
|
/^ingress\b/,
|
|
/^port\s+\d{1,2}(?!\s+name\b)/,
|
|
/^port\s+\d{1,2}\s+name\b/,
|
|
/^eee\s+\d{1,2}\b/,
|
|
/^eee\b/,
|
|
/^mirror\b/,
|
|
/^lag\s+\d+\b/,
|
|
/^laghash\b/,
|
|
/^isolate\s+\d{1,2}\b/,
|
|
/^stp\b/,
|
|
/^igmp\b/,
|
|
/^mtu\s+\d{1,2}\b/,
|
|
/^bw\s+(in|out)\s+\d{1,2}\b/,
|
|
/^hostname\b/,
|
|
];
|
|
|
|
function parseConf(s){
|
|
var a = s.split(/\r\n|\n/);
|
|
for (var l = 0; l < a.length; l++) {
|
|
var line = a[l].trim().replace(/\s+/g, ' ');
|
|
if (!line.length) continue;
|
|
const deleteMatch = line.match(/^vlan\s+(\d{1,4})\s+d$/);
|
|
if (deleteMatch) {
|
|
const prefix = "vlan " + deleteMatch[1] + " ";
|
|
configuration = configuration.filter(c => !c.startsWith(prefix));
|
|
continue;
|
|
}
|
|
console.log(l + ' --> ' + line);
|
|
var ignore = true;
|
|
for (const x of conf_cmds)
|
|
if (x.test(line)) { ignore = false; break; }
|
|
if (ignore) continue;
|
|
for (const x of conf_overwrite) {
|
|
if (x.test(line)) {
|
|
let m = line.match(x);
|
|
let matchStr = m[0];
|
|
configuration = configuration.filter(item =>
|
|
!(item === matchStr || (item.startsWith(matchStr + " ") && !item.endsWith(" mgmt") && !item.startsWith(matchStr + " name "))));
|
|
break;
|
|
}
|
|
}
|
|
// Only one management VLAN can be active, so drop any previous mgmt entry
|
|
if (/^vlan\s+\d{1,4}\s+mgmt$/.test(line))
|
|
configuration = configuration.filter(item => !/^vlan\s+\d{1,4}\s+mgmt$/.test(item));
|
|
configuration.push(line);
|
|
}
|
|
console.log("Configuration now:");
|
|
for (const x of configuration) { console.log(x); }
|
|
}
|
|
|
|
async function fetchConfig() {
|
|
try {
|
|
const response = await fetch('/config');
|
|
console.log("CONFIG: ", response);
|
|
const t = await response.text();
|
|
return t;
|
|
} catch(err) {
|
|
console.error("Error: ", err);
|
|
}
|
|
}
|
|
|
|
async function fetchCmdLog() {
|
|
try {
|
|
const response = await fetch('/cmd_log');
|
|
console.log("CMD-Log: ", response);
|
|
const t = await response.text();
|
|
return t;
|
|
} catch(err) {
|
|
console.error("Error: ", err);
|
|
return "";
|
|
}
|
|
}
|