mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add filtering logic for configuration commands
This commit is contained in:
+42
-28
@@ -1,41 +1,55 @@
|
|||||||
var configInterval = Number();
|
var configInterval = Number();
|
||||||
var configuration = {};
|
var configuration = [];
|
||||||
|
const conf_cmds = [
|
||||||
|
/ip\s+(\d{1,3}\.){3}\d{1,3}/, /gw\s+(\d{1,3}\.){3}\d{1,3}/, /netmask\s+(\d{1,3}\.){3}\d{1,3}/,
|
||||||
|
/eee(\s+\d)?\s+(on|off)/, /mirror(\s+(\d|10))(\s+(\d|10)(t|r)?)+/, /vlan\s+(\d{1,4})(\s+(\d|10)(t|u)?)+/
|
||||||
|
];
|
||||||
|
const conf_overwrite = [
|
||||||
|
/ip/, /gw/, /netmask/, /eee\s+\w+/, /eee(\s+\w)/, /mirror/, /vlan\s+(\d{1,4})/
|
||||||
|
];
|
||||||
|
|
||||||
function parseConf(c){
|
function parseConf(s){
|
||||||
var a = s.split(/\r\n|\n/);
|
var a = s.split(/\r\n|\n/);
|
||||||
for (var l = 0; l < a.length; l++) {
|
for (var l = 0; l < a.length; l++) {
|
||||||
|
if (!a[l].length || a[l] == "\n" || a[l] == "\r\n")
|
||||||
|
continue;
|
||||||
console.log(l + ' --> ' + a[l]);
|
console.log(l + ' --> ' + a[l]);
|
||||||
|
var ignore = true;
|
||||||
|
for (const x of conf_cmds)
|
||||||
|
if (x.test(a[l])) ignore = false;
|
||||||
|
if (ignore) continue;
|
||||||
|
for (const x of conf_overwrite) {
|
||||||
|
if (x.test(a[l])) {
|
||||||
|
console.log("Match ", x, " to ", a[l]);
|
||||||
|
m = a[l].match(x);
|
||||||
|
console.log("Starts with ", m[0]);
|
||||||
|
configuration = configuration.filter(item => !(item.startsWith(m[0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configuration.push(a[l]);
|
||||||
}
|
}
|
||||||
|
console.log("Configuration now:");
|
||||||
|
for (const x of configuration) { console.log(x); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchConfig() {
|
async function fetchConfig() {
|
||||||
var xhttp = new XMLHttpRequest();
|
try {
|
||||||
xhttp.onreadystatechange = function() {
|
const response = await fetch('/config');
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
console.log("CONFIG: ", response);
|
||||||
s = xhttp.responseText;
|
const t = await response.text();
|
||||||
console.log("CONFIG: ", s);
|
return t;
|
||||||
parseConf(s);
|
} catch(err) {
|
||||||
clearInterval(configInterval);
|
console.error("Error: ", err);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xhttp.open("GET", `/config`, true);
|
|
||||||
xhttp.send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchCmdLog() {
|
async function fetchCmdLog() {
|
||||||
var xhttp = new XMLHttpRequest();
|
try {
|
||||||
xhttp.onreadystatechange = function() {
|
const response = await fetch('/cmd_log');
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
console.log("CMD-Log: ", response);
|
||||||
s = xhttp.responseText;
|
const t = await response.text();
|
||||||
console.log("CMD-Log: ", s);
|
return t;
|
||||||
parseConf(s);
|
} catch(error) {
|
||||||
clearInterval(configInterval);
|
console.error("Error: ", err);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xhttp.open("GET", `/cmd_log`, true);
|
|
||||||
xhttp.send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", function() {
|
|
||||||
configInterval = setInterval(fetchConfig, 1000);
|
|
||||||
});
|
|
||||||
|
|||||||
+2
-2
@@ -14,8 +14,8 @@
|
|||||||
<div class="rcol"> <input id="ip" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
|
<div class="rcol"> <input id="ip" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="lcol"> <label for="nm">Netmask:</label></div>
|
<div class="lcol"> <label for="netmask">Netmask:</label></div>
|
||||||
<div class="rcol"><input id="nm" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
|
<div class="rcol"><input id="netmask" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="lcol"> <label for="gw">Gateway:</label></div>
|
<div class="lcol"> <label for="gw">Gateway:</label></div>
|
||||||
|
|||||||
+21
-8
@@ -1,5 +1,5 @@
|
|||||||
var systemInterval = Number();
|
var systemInterval = Number();
|
||||||
const ips = ["ip", "nm", "gw"];
|
const ips = ["ip", "netmask", "gw"];
|
||||||
|
|
||||||
function checkIp(ip) {
|
function checkIp(ip) {
|
||||||
const ipv4 = /^(\d{1,3}\.){3}\d{1,3}$/;
|
const ipv4 = /^(\d{1,3}\.){3}\d{1,3}$/;
|
||||||
@@ -27,14 +27,14 @@ async function ipSub() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function flashSave() {
|
async function sendConfig(c) {
|
||||||
fetchConfig();
|
const form = new FormData();
|
||||||
fetchCmdLog();
|
form.append("MAX_FILE_SIZE", "4096");
|
||||||
return;
|
form.append("configuration", new Blob([c], {type: "application/octet-stream"}));
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/save', {
|
const response = await fetch('/config', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: cmd
|
body: form
|
||||||
});
|
});
|
||||||
console.log('Completed!', response);
|
console.log('Completed!', response);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@@ -42,6 +42,19 @@ async function flashSave() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function flashSave() {
|
||||||
|
fetchConfig().then((s) => {
|
||||||
|
parseConf(s);
|
||||||
|
fetchCmdLog().then((s) => {
|
||||||
|
parseConf(s);
|
||||||
|
var body = "";
|
||||||
|
for (const x of configuration) { body = body + x + "\n"; }
|
||||||
|
console.log("CONFIGURATION to save: ", body);
|
||||||
|
sendConfig(body);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function fetchIP() {
|
function fetchIP() {
|
||||||
var xhttp = new XMLHttpRequest();
|
var xhttp = new XMLHttpRequest();
|
||||||
xhttp.onreadystatechange = function() {
|
xhttp.onreadystatechange = function() {
|
||||||
@@ -49,7 +62,7 @@ function fetchIP() {
|
|||||||
const s = JSON.parse(xhttp.responseText);
|
const s = JSON.parse(xhttp.responseText);
|
||||||
console.log("IP: ", s);
|
console.log("IP: ", s);
|
||||||
document.getElementById("ip").value=s.ip_address;
|
document.getElementById("ip").value=s.ip_address;
|
||||||
document.getElementById("nm").value=s.ip_netmask;
|
document.getElementById("netmask").value=s.ip_netmask;
|
||||||
document.getElementById("gw").value=s.ip_gateway;
|
document.getElementById("gw").value=s.ip_gateway;
|
||||||
clearInterval(systemInterval);
|
clearInterval(systemInterval);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user