update 2025-01-04 14:14:13

This commit is contained in:
kenzok8 2025-01-04 14:14:13 +08:00
parent 95f70728d5
commit 100e3a0aec
5 changed files with 116 additions and 8 deletions

View File

@ -174,9 +174,9 @@ return baseclass.extend({
],
rules_logical_payload_count: {
'AND': 2,
'OR': 2,
'NOT': 1,
'AND': { req: 2, opt: undefined },
'OR': { req: 2, opt: undefined },
'NOT': { req: 1, opt: 0 },
//'SUB-RULE': 0,
},

View File

@ -125,13 +125,20 @@ class RulesEntry {
return this.payload[n] || {};
}
setPayload(n, obj) {
getPayloads() {
return this.payload || [];
}
setPayload(n, obj, limit) {
this.payload[n] ||= {};
Object.keys(obj).forEach((key) => {
this.payload[n][key] = obj[key] || null;
});
if (limit)
this.payload.splice(limit);
return this
}
@ -152,7 +159,7 @@ class RulesEntry {
var logical = hm.rules_logical_type.map(e => e[0] || e).includes(this.type),
factor = '';
if (logical) {
let n = hm.rules_logical_payload_count[this.type] || 0;
let n = hm.rules_logical_payload_count[this.type] ? hm.rules_logical_payload_count[this.type].opt : 0;
factor = '(%s)'.format(this.payload.slice(0, n).map((payload) => {
return '(%s%s)'.format(payload.type || '', payload.factor || '');
}).join(''));
@ -215,8 +222,35 @@ function renderPayload(s, total, uciconfig) {
o.rmempty = false;
o.modalonly = true;
}
var initDynamicPayload = function(o, n, key, uciconfig) {
o.load = L.bind(function(n, key, uciconfig, section_id) {
return new RulesEntry(uci.get(uciconfig, section_id, 'entry')).getPayloads().slice(n).map(e => e[key]);
}, o, n, key, uciconfig);
o.validate = function(section_id, value) {
value = this.formvalue(section_id);
var UIEl = this.section.getUIElement(section_id, 'entry');
var rule = new RulesEntry(UIEl.getValue());
let n = this.option.match(/^payload(\d+)_/)[1];
let limit = rule.getPayloads().length;
value.forEach((val) => {
rule.setPayload(n, {factor: val}); n++;
});
rule.setPayload(limit, {factor: null}, limit);
var newvalue = rule.toString();
UIEl.node.previousSibling.innerText = newvalue;
UIEl.setValue(newvalue);
return true;
}
o.write = function() {};
o.rmempty = true;
o.modalonly = true;
}
var o, prefix;
// StaticList payload
for (var n=0; n<total; n++) {
prefix = `payload${n}_`;
@ -226,7 +260,7 @@ function renderPayload(s, total, uciconfig) {
o.value.apply(o, res);
})
Object.keys(hm.rules_logical_payload_count).forEach((key) => {
if (n < hm.rules_logical_payload_count[key])
if (n < hm.rules_logical_payload_count[key].req)
o.depends('type', key);
})
initPayload(o, n, 'type', uciconfig);
@ -297,6 +331,68 @@ function renderPayload(s, total, uciconfig) {
return new RulesEntry(uci.get(uciconfig, section_id, 'entry')).getPayload(n)[key];
}, o, n, 'factor', uciconfig)
}
// DynamicList payload
var extenbox = {};
Object.entries(hm.rules_logical_payload_count).filter(e => e[1].opt === undefined).forEach((e) => {
let n = e[1].req;
if (!Array.isArray(extenbox[n]))
extenbox[n] = [];
extenbox[n].push(e[0]);
})
Object.keys(extenbox).forEach((n) => {
prefix = `payload${n}_`;
o = s.option(form.DynamicList, prefix + 'type', _('Type') + ' ++');
o.default = hm.rules_type[0][0];
hm.rules_type.forEach((res) => {
o.value.apply(o, res);
})
extenbox[n].forEach((type) => {
o.depends('type', type);
})
initDynamicPayload(o, n, 'type', uciconfig);
o.validate = function(section_id, value) {
value = this.formvalue(section_id);
var UIEl = this.section.getUIElement(section_id, 'entry');
var rule = new RulesEntry(UIEl.getValue());
let n = this.option.match(/^payload(\d+)_/)[1];
value.forEach((val) => {
rule.setPayload(n, {type: val}); n++;
});
rule.setPayload(n, {factor: null}, n);
var newvalue = rule.toString();
UIEl.node.previousSibling.innerText = newvalue;
UIEl.setValue(newvalue);
return true;
}
o = s.option(form.DynamicList, prefix + 'fused', _('Factor') + ' ++',
_('Content will not be verified, Please make sure you enter it correctly.'));
o.value('', _('-- Please choose --'));
extenbox[n].forEach((type) => {
o.depends(Object.fromEntries([['type', type], [prefix + 'type', /.+/]]));
})
initDynamicPayload(o, n, 'factor', uciconfig);
o.load = L.bind(function(n, key, uciconfig, section_id) {
let fusedval = [
['', _('-- Please choose --')],
['NETWORK', '-- NETWORK --'],
['udp', _('UDP')],
['tcp', _('TCP')],
['RULESET', '-- RULE-SET --']
];
hm.loadRulesetLabel.call(this, null, section_id);
this.keylist = [...fusedval.map(e => e[0]), ...this.keylist];
this.vallist = [...fusedval.map(e => e[1]), ...this.vallist];
this.super('load', section_id);
return new RulesEntry(uci.get(uciconfig, section_id, 'entry')).getPayloads().slice(n).map(e => e[key]);
}, o, n, 'factor', uciconfig)
})
}
function renderRules(s, uciconfig) {
@ -356,7 +452,7 @@ function renderRules(s, uciconfig) {
o.rmempty = false;
o.modalonly = true;
renderPayload(s, Math.max(...Object.values(hm.rules_logical_payload_count)), uciconfig);
renderPayload(s, Math.max(...Object.values(hm.rules_logical_payload_count).map(e => e.req)), uciconfig);
o = s.option(form.ListValue, 'detour', _('Proxy group'));
o.renderWidget = function(/* ... */) {
@ -1018,7 +1114,7 @@ return view.extend({
so.rmempty = false;
so.editable = true;
so = ss.option(form.ListValue, 'proxy', _('Proxy group'),
so = ss.option(form.ListValue, 'proxy', _('Proxy group override'),
_('Override the Proxy group of DNS server.'));
so.renderWidget = function(/* ... */) {
var frameEl = form.ListValue.prototype.renderWidget.apply(this, arguments);

View File

@ -1667,6 +1667,10 @@ msgstr ""
msgid "Proxy group"
msgstr ""
#: htdocs/luci-static/resources/view/fchomo/client.js:1117
msgid "Proxy group override"
msgstr ""
#: htdocs/luci-static/resources/view/fchomo/global.js:450
msgid "Proxy mode"
msgstr ""

View File

@ -1690,6 +1690,10 @@ msgstr "代理链"
msgid "Proxy group"
msgstr "代理组"
#: htdocs/luci-static/resources/view/fchomo/client.js:1117
msgid "Proxy group override"
msgstr "代理组覆盖"
#: htdocs/luci-static/resources/view/fchomo/global.js:450
msgid "Proxy mode"
msgstr "代理模式"

View File

@ -1690,6 +1690,10 @@ msgstr "代理鏈"
msgid "Proxy group"
msgstr "代理組"
#: htdocs/luci-static/resources/view/fchomo/client.js:1117
msgid "Proxy group override"
msgstr "代理組覆蓋"
#: htdocs/luci-static/resources/view/fchomo/global.js:450
msgid "Proxy mode"
msgstr "代理模式"