mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
Merge pull request #462 from DrDoof/fix/gui-save-merge
web: keep stored config lines and per-port ingress when saving
This commit is contained in:
3 files changed
+28
-12
No files matched your search
+26
-10
@@ -1741,7 +1741,7 @@ var CONF_OVERWRITE=[
|
|||||||
/^ip\b/,/^gw\b/,/^netmask\b/,/^hostname\b/,
|
/^ip\b/,/^gw\b/,/^netmask\b/,/^hostname\b/,
|
||||||
/^syslog\s+ip\b/,/^syslog\s+port\b/,/^passwd\b/,
|
/^syslog\s+ip\b/,/^syslog\s+port\b/,/^passwd\b/,
|
||||||
/^vlan\s+\d{1,4}\s+mgmt$/,/^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
|
/^vlan\s+\d{1,4}\s+mgmt$/,/^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
|
||||||
/^pvid\s+\d{1,2}\b/,/^ingress\b/,
|
/^pvid\s+\d{1,2}\b/,
|
||||||
/^port\s+\d{1,2}(?!\s+name\b)/,/^port\s+\d{1,2}\s+name\b/,
|
/^port\s+\d{1,2}(?!\s+name\b)/,/^port\s+\d{1,2}\s+name\b/,
|
||||||
/^mirror\b/,
|
/^mirror\b/,
|
||||||
/^lag\s+\d\b/,/^laghash\s+\d\b/,/^isolate\s+\d{1,2}\b/,
|
/^lag\s+\d\b/,/^laghash\s+\d\b/,/^isolate\s+\d{1,2}\b/,
|
||||||
@@ -1767,6 +1767,21 @@ function mergeConf(base,texts){
|
|||||||
}
|
}
|
||||||
if(line==="mirror off"){drop(/^mirror /);return;}
|
if(line==="mirror off"){drop(/^mirror /);return;}
|
||||||
if(!isConfCmd(line))return;
|
if(!isConfCmd(line))return;
|
||||||
|
if((m=line.match(/^ingress (.+)$/))){
|
||||||
|
if(/^[tua]$/.test(m[1])){drop(/^ingress /);conf.push(line);return;}
|
||||||
|
var ports={},order=[],last=-1;
|
||||||
|
conf.forEach(function(c,i){if(/^ingress [tua]$/.test(c))last=i;});
|
||||||
|
conf.forEach(function(c,i){
|
||||||
|
var cm=c.match(/^ingress (.+)$/);
|
||||||
|
if(!cm||/^[tua]$/.test(cm[1])||i<last)return;
|
||||||
|
cm[1].split(" ").forEach(function(tk){var n=tk.slice(0,-1);if(!(n in ports))order.push(n);ports[n]=tk;});
|
||||||
|
});
|
||||||
|
m[1].split(" ").forEach(function(tk){var n=tk.slice(0,-1);if(!(n in ports))order.push(n);ports[n]=tk;});
|
||||||
|
conf=conf.filter(function(c){var cm=c.match(/^ingress (.+)$/);return!cm||/^[tua]$/.test(cm[1])});
|
||||||
|
order.sort(function(a,b){return a-b});
|
||||||
|
conf.push("ingress "+order.map(function(n){return ports[n]}).join(" "));
|
||||||
|
return;
|
||||||
|
}
|
||||||
if((m=line.match(/^bw (in|out) (\d{1,2}) (\S+)$/))){
|
if((m=line.match(/^bw (in|out) (\d{1,2}) (\S+)$/))){
|
||||||
var pre="^bw "+m[1]+" "+m[2]+" ";
|
var pre="^bw "+m[1]+" "+m[2]+" ";
|
||||||
if(m[1]==="out"||m[3]==="off")drop(new RegExp(pre));
|
if(m[1]==="out"||m[3]==="off")drop(new RegExp(pre));
|
||||||
@@ -1794,11 +1809,11 @@ function mergeConf(base,texts){
|
|||||||
});
|
});
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
function writeConfig(txt,title){
|
function writeConfig(txt,title,fromLog){
|
||||||
var info=h("p",{class:"small mut"}),warn=h("p",{class:"small"});
|
var info=h("p",{class:"small mut"}),warn=h("p",{class:"small"});
|
||||||
var ed=h("textarea",{class:"cfg",spellcheck:"false",placeholder:t("cw_empty"),style:"min-height:45vh"});
|
var ed=h("textarea",{class:"cfg",spellcheck:"false",placeholder:t("cw_empty"),style:"min-height:45vh"});
|
||||||
ed.value=txt.replace(/\r\n/g,"\n");
|
ed.value=txt.replace(/\r\n/g,"\n");
|
||||||
var ok=h("button",{class:"ctl pri",text:t("sy_write"),onclick:function(){closeModal();doWriteConfig(cfgText(ed.value))}});
|
var ok=h("button",{class:"ctl pri",text:t("sy_write"),onclick:function(){closeModal();doWriteConfig(cfgText(ed.value),fromLog)}});
|
||||||
function refresh(){
|
function refresh(){
|
||||||
var v=cfgText(ed.value),bytes=new Blob([v]).size,long=cfgLongLine(v);
|
var v=cfgText(ed.value),bytes=new Blob([v]).size,long=cfgLongLine(v);
|
||||||
var unknown=v.split("\n").filter(function(l){return l.trim()&&!isConfCmd(l.trim().replace(/\s+/g," "))});
|
var unknown=v.split("\n").filter(function(l){return l.trim()&&!isConfCmd(l.trim().replace(/\s+/g," "))});
|
||||||
@@ -1814,7 +1829,7 @@ function cfgText(txt){
|
|||||||
txt=txt.replace(/\r\n/g,"\n");
|
txt=txt.replace(/\r\n/g,"\n");
|
||||||
return txt&&txt.slice(-1)!=="\n"?txt+"\n":txt;
|
return txt&&txt.slice(-1)!=="\n"?txt+"\n":txt;
|
||||||
}
|
}
|
||||||
function doWriteConfig(txt){
|
function doWriteConfig(txt,fromLog){
|
||||||
var form=new FormData();
|
var form=new FormData();
|
||||||
form.append("configuration",new Blob([txt],{type:"application/octet-stream"}),"config.txt");
|
form.append("configuration",new Blob([txt],{type:"application/octet-stream"}),"config.txt");
|
||||||
toast(t("cw_writing"));
|
toast(t("cw_writing"));
|
||||||
@@ -1824,9 +1839,10 @@ function doWriteConfig(txt){
|
|||||||
}).then(function(back){
|
}).then(function(back){
|
||||||
back=back.replace(/\0[\s\S]*$/,"").replace(/\r\n/g,"\n").trim();
|
back=back.replace(/\0[\s\S]*$/,"").replace(/\r\n/g,"\n").trim();
|
||||||
if(back!==txt.trim())throw new Error(t("cw_verify_fail"));
|
if(back!==txt.trim())throw new Error(t("cw_verify_fail"));
|
||||||
return api("/cmd_log_clear").catch(function(){});
|
if(!fromLog)return false;
|
||||||
}).then(function(){
|
return api("/cmd_log_clear").then(function(){return true},function(){return true});
|
||||||
setDirty(false);
|
}).then(function(cleared){
|
||||||
|
if(cleared)setDirty(false);
|
||||||
$("cfgedit").value=txt;cfgBytes();cfgParseKnown(txt);
|
$("cfgedit").value=txt;cfgBytes();cfgParseKnown(txt);
|
||||||
toast(t("cw_saved"),"ok");
|
toast(t("cw_saved"),"ok");
|
||||||
}).catch(function(e){toast(e.message||String(e),"err")});
|
}).catch(function(e){toast(e.message||String(e),"err")});
|
||||||
@@ -1837,9 +1853,9 @@ $("saveBtn").addEventListener("click",function(){
|
|||||||
getText("/config").catch(function(){return""}),
|
getText("/config").catch(function(){return""}),
|
||||||
getText("/cmd_log").catch(function(){return""}),
|
getText("/cmd_log").catch(function(){return""}),
|
||||||
]).then(function(r){
|
]).then(function(r){
|
||||||
var cur=r[0].replace(/\0[\s\S]*$/,"");
|
var cur=r[0].replace(/\0[\s\S]*$/,"").split(/\r?\n/).map(function(l){return l.trim().replace(/\s+/g," ")}).filter(Boolean);
|
||||||
var merged=mergeConf([],[cur,r[1].replace(/\0[\s\S]*$/,"")]);
|
var merged=mergeConf(cur,[r[1].replace(/\0[\s\S]*$/,"")]);
|
||||||
writeConfig(merged.join("\n"),t("cw_save_title"));
|
writeConfig(merged.join("\n"),t("cw_save_title"),true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1011,7 +1011,7 @@ void send_cmd_log(void)
|
|||||||
__xdata uint8_t found_begin = 0;
|
__xdata uint8_t found_begin = 0;
|
||||||
dbg_string("History ptr: ");
|
dbg_string("History ptr: ");
|
||||||
dbg_short(cmd_history_ptr); dbg_char('\n');
|
dbg_short(cmd_history_ptr); dbg_char('\n');
|
||||||
while (p != cmd_history_ptr) {
|
while (p != cmd_history_ptr && slen < TCP_OUTBUF_SIZE) {
|
||||||
if (!cmd_history[p] || cmd_history[p] == '\n')
|
if (!cmd_history[p] || cmd_history[p] == '\n')
|
||||||
found_begin = 1;
|
found_begin = 1;
|
||||||
if (found_begin && cmd_history[p])
|
if (found_begin && cmd_history[p])
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ struct vlan_tag {
|
|||||||
#define FIRMWARE_UPLOAD_START 0x80000
|
#define FIRMWARE_UPLOAD_START 0x80000
|
||||||
|
|
||||||
// Constants for the circular command buffer, the size must be 2^n
|
// Constants for the circular command buffer, the size must be 2^n
|
||||||
#define CMD_HISTORY_SIZE 0x400
|
#define CMD_HISTORY_SIZE 0x800
|
||||||
#define CMD_HISTORY_MASK (CMD_HISTORY_SIZE - 1)
|
#define CMD_HISTORY_MASK (CMD_HISTORY_SIZE - 1)
|
||||||
|
|
||||||
enum sfp_speeds {
|
enum sfp_speeds {
|
||||||
|
|||||||
Reference in new issue
Block a user