fix settings and xray page state leaks

This commit is contained in:
Sora39831 2026-04-06 21:02:58 +08:00
parent 3e1b6ed76f
commit 6564cf8202
2 changed files with 84 additions and 87 deletions

View file

@ -206,11 +206,11 @@
{ label: 'Google', value: 'geosite:google' }, { label: 'Google', value: 'geosite:google' },
], ],
get remarkModel() { get remarkModel() {
rm = this.allSetting.remarkModel; const rm = this.allSetting.remarkModel;
return rm.length > 1 ? rm.substring(1).split('') : []; return rm.length > 1 ? rm.substring(1).split('') : [];
}, },
set remarkModel(value) { set remarkModel(value) {
rs = this.allSetting.remarkModel[0]; const rs = this.allSetting.remarkModel[0];
this.allSetting.remarkModel = rs + value.join(''); this.allSetting.remarkModel = rs + value.join('');
this.changeRemarkSample(); this.changeRemarkSample();
}, },
@ -228,7 +228,7 @@
this.allSetting.datepicker = value; this.allSetting.datepicker = value;
}, },
changeRemarkSample() { changeRemarkSample() {
sample = [] const sample = [];
this.remarkModel.forEach(r => sample.push(this.remarkModels[r])); this.remarkModel.forEach(r => sample.push(this.remarkModels[r]));
this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator); this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator);
} }
@ -355,13 +355,9 @@
return; return;
} }
let finalHost = this.entryHost; const finalHost = webDomain && this._isIp(webDomain) ? webDomain : this.entryHost;
let finalPort = this.entryPort || ""; let finalPort = this.entryPort || "";
if (webDomain && this._isIp(webDomain)) {
finalHost = webDomain;
}
if (webPort && Number(webPort) !== Number(this.entryPort)) { if (webPort && Number(webPort) !== Number(this.entryPort)) {
finalPort = String(webPort); finalPort = String(webPort);
} }
@ -457,7 +453,7 @@
get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.packets : ""; }, get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.packets : ""; },
set: function (v) { set: function (v) {
if (v != "") { if (v != "") {
newFragment = JSON.parse(this.allSetting.subJsonFragment); const newFragment = JSON.parse(this.allSetting.subJsonFragment);
newFragment.settings.fragment.packets = v; newFragment.settings.fragment.packets = v;
this.allSetting.subJsonFragment = JSON.stringify(newFragment); this.allSetting.subJsonFragment = JSON.stringify(newFragment);
} }
@ -467,7 +463,7 @@
get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.length : ""; }, get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.length : ""; },
set: function (v) { set: function (v) {
if (v != "") { if (v != "") {
newFragment = JSON.parse(this.allSetting.subJsonFragment); const newFragment = JSON.parse(this.allSetting.subJsonFragment);
newFragment.settings.fragment.length = v; newFragment.settings.fragment.length = v;
this.allSetting.subJsonFragment = JSON.stringify(newFragment); this.allSetting.subJsonFragment = JSON.stringify(newFragment);
} }
@ -477,7 +473,7 @@
get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.interval : ""; }, get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.interval : ""; },
set: function (v) { set: function (v) {
if (v != "") { if (v != "") {
newFragment = JSON.parse(this.allSetting.subJsonFragment); const newFragment = JSON.parse(this.allSetting.subJsonFragment);
newFragment.settings.fragment.interval = v; newFragment.settings.fragment.interval = v;
this.allSetting.subJsonFragment = JSON.stringify(newFragment); this.allSetting.subJsonFragment = JSON.stringify(newFragment);
} }
@ -487,7 +483,7 @@
get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.maxSplit : ""; }, get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.maxSplit : ""; },
set: function (v) { set: function (v) {
if (v != "") { if (v != "") {
newFragment = JSON.parse(this.allSetting.subJsonFragment); const newFragment = JSON.parse(this.allSetting.subJsonFragment);
newFragment.settings.fragment.maxSplit = v; newFragment.settings.fragment.maxSplit = v;
this.allSetting.subJsonFragment = JSON.stringify(newFragment); this.allSetting.subJsonFragment = JSON.stringify(newFragment);
} }
@ -526,7 +522,7 @@
muxConcurrency: { muxConcurrency: {
get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1; }, get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1; },
set: function (v) { set: function (v) {
newMux = JSON.parse(this.allSetting.subJsonMux); const newMux = JSON.parse(this.allSetting.subJsonMux);
newMux.concurrency = v; newMux.concurrency = v;
this.allSetting.subJsonMux = JSON.stringify(newMux); this.allSetting.subJsonMux = JSON.stringify(newMux);
} }
@ -534,7 +530,7 @@
muxXudpConcurrency: { muxXudpConcurrency: {
get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1; }, get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1; },
set: function (v) { set: function (v) {
newMux = JSON.parse(this.allSetting.subJsonMux); const newMux = JSON.parse(this.allSetting.subJsonMux);
newMux.xudpConcurrency = v; newMux.xudpConcurrency = v;
this.allSetting.subJsonMux = JSON.stringify(newMux); this.allSetting.subJsonMux = JSON.stringify(newMux);
} }
@ -542,7 +538,7 @@
muxXudpProxyUDP443: { muxXudpProxyUDP443: {
get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject"; }, get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject"; },
set: function (v) { set: function (v) {
newMux = JSON.parse(this.allSetting.subJsonMux); const newMux = JSON.parse(this.allSetting.subJsonMux);
newMux.xudpProxyUDP443 = v; newMux.xudpProxyUDP443 = v;
this.allSetting.subJsonMux = JSON.stringify(newMux); this.allSetting.subJsonMux = JSON.stringify(newMux);
} }
@ -607,14 +603,14 @@
var alerts = [] var alerts = []
if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}'); if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}');
if (this.allSetting.webPort === 2053) alerts.push('{{ i18n "secAlertPanelPort" }}'); if (this.allSetting.webPort === 2053) alerts.push('{{ i18n "secAlertPanelPort" }}');
panelPath = window.location.pathname.split('/').length < 4 const panelPath = window.location.pathname.split('/').length < 4
if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}'); if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}');
if (this.allSetting.subEnable) { if (this.allSetting.subEnable) {
subPath = this.allSetting.subURI.length > 0 ? new URL(this.allSetting.subURI).pathname : this.allSetting.subPath; const subPath = this.allSetting.subURI.length > 0 ? new URL(this.allSetting.subURI).pathname : this.allSetting.subPath;
if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}'); if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}');
} }
if (this.allSetting.subJsonEnable) { if (this.allSetting.subJsonEnable) {
subJsonPath = this.allSetting.subJsonURI.length > 0 ? new URL(this.allSetting.subJsonURI).pathname : this.allSetting.subJsonPath; const subJsonPath = this.allSetting.subJsonURI.length > 0 ? new URL(this.allSetting.subJsonURI).pathname : this.allSetting.subJsonPath;
if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}'); if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}');
} }
return alerts return alerts

View file

@ -483,7 +483,7 @@
const { data, property, outboundTag } = routeSettings; const { data, property, outboundTag } = routeSettings;
const oldTemplateSettings = this.templateSettings; const oldTemplateSettings = this.templateSettings;
const newTemplateSettings = oldTemplateSettings; const newTemplateSettings = oldTemplateSettings;
currentProperty = this.templateRuleGetter({ outboundTag, property }) const currentProperty = this.templateRuleGetter({ outboundTag, property })
if (currentProperty.length == 0) { if (currentProperty.length == 0) {
const propertyRule = { const propertyRule = {
type: "field", type: "field",
@ -494,7 +494,7 @@
} }
else { else {
const newRules = []; const newRules = [];
insertedOnce = false; let insertedOnce = false;
newTemplateSettings.routing.rules.forEach( newTemplateSettings.routing.rules.forEach(
(routingRule) => { (routingRule) => {
if ( if (
@ -521,11 +521,11 @@
if (this.cm != null) { if (this.cm != null) {
this.cm.toTextArea(); this.cm.toTextArea();
} }
textAreaObj = document.getElementById('xraySetting'); const textAreaObj = document.getElementById('xraySetting');
textAreaObj.value = this[this.advSettings]; textAreaObj.value = this[this.advSettings];
this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions); this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
this.cm.on('change', editor => { this.cm.on('change', editor => {
value = editor.getValue(); const value = editor.getValue();
if (this.isJsonString(value)) { if (this.isJsonString(value)) {
this[this.advSettings] = value; this[this.advSettings] = value;
} }
@ -539,11 +539,11 @@
this.cm = null; this.cm = null;
return return
} }
textAreaObj = document.getElementById('obsSetting'); const textAreaObj = document.getElementById('obsSetting');
textAreaObj.value = this[this.obsSettings]; textAreaObj.value = this[this.obsSettings];
this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions); this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
this.cm.on('change', editor => { this.cm.on('change', editor => {
value = editor.getValue(); const value = editor.getValue();
if (this.isJsonString(value)) { if (this.isJsonString(value)) {
this[this.obsSettings] = value; this[this.obsSettings] = value;
} }
@ -566,7 +566,7 @@
return `${SizeFormatter.sizeFormat(0)} / ${SizeFormatter.sizeFormat(0)}` return `${SizeFormatter.sizeFormat(0)} / ${SizeFormatter.sizeFormat(0)}`
}, },
findOutboundAddress(o) { findOutboundAddress(o) {
serverObj = null; let serverObj = null;
switch (o.protocol) { switch (o.protocol) {
case Protocols.VMess: case Protocols.VMess:
serverObj = o.settings.vnext; serverObj = o.settings.vnext;
@ -619,12 +619,12 @@
}); });
}, },
deleteOutbound(index) { deleteOutbound(index) {
outbounds = this.templateSettings.outbounds; const outbounds = this.templateSettings.outbounds;
outbounds.splice(index, 1); outbounds.splice(index, 1);
this.outboundSettings = JSON.stringify(outbounds); this.outboundSettings = JSON.stringify(outbounds);
}, },
setFirstOutbound(index) { setFirstOutbound(index) {
outbounds = this.templateSettings.outbounds; const outbounds = this.templateSettings.outbounds;
outbounds.splice(0, 0, outbounds.splice(index, 1)[0]); outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
this.outboundSettings = JSON.stringify(outbounds); this.outboundSettings = JSON.stringify(outbounds);
}, },
@ -700,7 +700,7 @@
confirm: (reverse, rules) => { confirm: (reverse, rules) => {
reverseModal.loading(); reverseModal.loading();
if (reverse.tag.length > 0) { if (reverse.tag.length > 0) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {}; if (newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
if (newTemplateSettings.reverse[reverse.type + 's'] == undefined) newTemplateSettings.reverse[reverse.type + 's'] = []; if (newTemplateSettings.reverse[reverse.type + 's'] == undefined) newTemplateSettings.reverse[reverse.type + 's'] = [];
newTemplateSettings.reverse[reverse.type + 's'].push({ tag: reverse.tag, domain: reverse.domain }); newTemplateSettings.reverse[reverse.type + 's'].push({ tag: reverse.tag, domain: reverse.domain });
@ -716,6 +716,7 @@
}); });
}, },
editReverse(index) { editReverse(index) {
let oldRules;
if (this.reverseData[index].type == "bridge") { if (this.reverseData[index].type == "bridge") {
oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag); oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
} else { } else {
@ -728,11 +729,11 @@
confirm: (reverse, rules) => { confirm: (reverse, rules) => {
reverseModal.loading(); reverseModal.loading();
if (reverse.tag.length > 0) { if (reverse.tag.length > 0) {
oldData = this.reverseData[index]; const oldData = this.reverseData[index];
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
oldReverseIndex = newTemplateSettings.reverse[oldData.type + 's'].findIndex(rs => rs.tag == oldData.tag); const oldReverseIndex = newTemplateSettings.reverse[oldData.type + 's'].findIndex(rs => rs.tag == oldData.tag);
oldRuleIndex0 = oldRules.length > 0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1; const oldRuleIndex0 = oldRules.length > 0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
oldRuleIndex1 = oldRules.length == 2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1; const oldRuleIndex1 = oldRules.length == 2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
if (oldData.type == reverse.type) { if (oldData.type == reverse.type) {
newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain }; newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
} else { } else {
@ -746,7 +747,7 @@
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
// Adjust Rules // Adjust Rules
newRules = this.templateSettings.routing.rules; const newRules = this.templateSettings.routing.rules;
oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]); oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]); oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
this.routingRuleSettings = JSON.stringify(newRules); this.routingRuleSettings = JSON.stringify(newRules);
@ -757,10 +758,10 @@
}); });
}, },
deleteReverse(index) { deleteReverse(index) {
oldData = this.reverseData[index]; const oldData = this.reverseData[index];
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
reverseTypeObj = newTemplateSettings.reverse[oldData.type + 's']; const reverseTypeObj = newTemplateSettings.reverse[oldData.type + 's'];
realIndex = reverseTypeObj.findIndex(r => r.tag == oldData.tag && r.domain == oldData.domain); const realIndex = reverseTypeObj.findIndex(r => r.tag == oldData.tag && r.domain == oldData.domain);
newTemplateSettings.reverse[oldData.type + 's'].splice(realIndex, 1); newTemplateSettings.reverse[oldData.type + 's'].splice(realIndex, 1);
// delete empty objects // delete empty objects
@ -768,7 +769,7 @@
if (Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse'); if (Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
// delete related routing rules // delete related routing rules
newRules = newTemplateSettings.routing.rules; let newRules = newTemplateSettings.routing.rules;
if (oldData.type == "bridge") { if (oldData.type == "bridge") {
newRules = newTemplateSettings.routing.rules.filter(r => !(r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag)); newRules = newTemplateSettings.routing.rules.filter(r => !(r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
} else if (oldData.type == "portal") { } else if (oldData.type == "portal") {
@ -783,7 +784,7 @@
this.refreshing = true; this.refreshing = true;
await this.getOutboundsTraffic(); await this.getOutboundsTraffic();
data = [] const data = []
if (this.templateSettings != null) { if (this.templateSettings != null) {
this.templateSettings.outbounds.forEach((o, index) => { this.templateSettings.outbounds.forEach((o, index) => {
data.push({ 'key': index, ...o }); data.push({ 'key': index, ...o });
@ -817,11 +818,11 @@
}, },
confirm: (balancer) => { confirm: (balancer) => {
balancerModal.loading(); balancerModal.loading();
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newTemplateSettings.routing.balancers == undefined) { if (newTemplateSettings.routing.balancers == undefined) {
newTemplateSettings.routing.balancers = []; newTemplateSettings.routing.balancers = [];
} }
let tmpBalancer = { const tmpBalancer = {
'tag': balancer.tag, 'tag': balancer.tag,
'selector': balancer.selector, 'selector': balancer.selector,
'fallbackTag': balancer.fallbackTag 'fallbackTag': balancer.fallbackTag
@ -849,9 +850,9 @@
balancer: this.balancersData[index], balancer: this.balancersData[index],
confirm: (balancer) => { confirm: (balancer) => {
balancerModal.loading(); balancerModal.loading();
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
let tmpBalancer = { const tmpBalancer = {
'tag': balancer.tag, 'tag': balancer.tag,
'selector': balancer.selector, 'selector': balancer.selector,
'fallbackTag': balancer.fallbackTag 'fallbackTag': balancer.fallbackTag
@ -889,7 +890,7 @@
}); });
}, },
updateObservatorySelectors() { updateObservatorySelectors() {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing'); const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing');
const leastLoads = this.balancersData.filter((b) => const leastLoads = this.balancersData.filter((b) =>
b.strategy === 'leastLoad' || b.strategy === 'leastLoad' ||
@ -926,7 +927,7 @@
this.changeObsCode(); this.changeObsCode();
}, },
deleteBalancer(index) { deleteBalancer(index) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
// Remove from balancers // Remove from balancers
const removedBalancer = this.balancersData.splice(index, 1)[0]; const removedBalancer = this.balancersData.splice(index, 1)[0];
@ -958,7 +959,7 @@
dnsModal.show({ dnsModal.show({
title: '{{ i18n "pages.xray.dns.add" }}', title: '{{ i18n "pages.xray.dns.add" }}',
confirm: (dnsServer) => { confirm: (dnsServer) => {
dnsServers = this.dnsServers; const dnsServers = this.dnsServers;
dnsServers.push(dnsServer); dnsServers.push(dnsServer);
this.dnsServers = dnsServers; this.dnsServers = dnsServers;
dnsModal.close(); dnsModal.close();
@ -971,7 +972,7 @@
title: '{{ i18n "pages.xray.dns.edit" }} #' + (index + 1), title: '{{ i18n "pages.xray.dns.edit" }} #' + (index + 1),
dnsServer: this.dnsServers[index], dnsServer: this.dnsServers[index],
confirm: (dnsServer) => { confirm: (dnsServer) => {
dnsServers = this.dnsServers; const dnsServers = this.dnsServers;
dnsServers[index] = dnsServer; dnsServers[index] = dnsServer;
this.dnsServers = dnsServers; this.dnsServers = dnsServers;
dnsModal.close(); dnsModal.close();
@ -980,7 +981,7 @@
}); });
}, },
deleteDNSServer(index) { deleteDNSServer(index) {
newDnsServers = this.dnsServers; const newDnsServers = this.dnsServers;
newDnsServers.splice(index, 1); newDnsServers.splice(index, 1);
this.dnsServers = newDnsServers; this.dnsServers = newDnsServers;
}, },
@ -988,7 +989,7 @@
fakednsModal.show({ fakednsModal.show({
title: '{{ i18n "pages.xray.fakedns.add" }}', title: '{{ i18n "pages.xray.fakedns.add" }}',
confirm: (item) => { confirm: (item) => {
fakeDns = this.fakeDns ?? []; const fakeDns = this.fakeDns ?? [];
fakeDns.push(item); fakeDns.push(item);
this.fakeDns = fakeDns; this.fakeDns = fakeDns;
fakednsModal.close(); fakednsModal.close();
@ -1001,7 +1002,7 @@
title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index + 1), title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index + 1),
fakeDns: this.fakeDns[index], fakeDns: this.fakeDns[index],
confirm: (item) => { confirm: (item) => {
fakeDns = this.fakeDns; const fakeDns = this.fakeDns;
fakeDns[index] = item; fakeDns[index] = item;
this.fakeDns = fakeDns; this.fakeDns = fakeDns;
fakednsModal.close(); fakednsModal.close();
@ -1010,7 +1011,7 @@
}); });
}, },
deleteFakedns(index) { deleteFakedns(index) {
fakeDns = this.fakeDns; const fakeDns = this.fakeDns;
fakeDns.splice(index, 1); fakeDns.splice(index, 1);
this.fakeDns = fakeDns; this.fakeDns = fakeDns;
}, },
@ -1045,13 +1046,13 @@
}); });
}, },
replaceRule(old_index, new_index) { replaceRule(old_index, new_index) {
rules = this.templateSettings.routing.rules; const rules = this.templateSettings.routing.rules;
if (new_index >= rules.length) rules.push(undefined); if (new_index >= rules.length) rules.push(undefined);
rules.splice(new_index, 0, rules.splice(old_index, 1)[0]); rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
this.routingRuleSettings = JSON.stringify(rules); this.routingRuleSettings = JSON.stringify(rules);
}, },
deleteRule(index) { deleteRule(index) {
rules = this.templateSettings.routing.rules; const rules = this.templateSettings.routing.rules;
rules.splice(index, 1); rules.splice(index, 1);
this.routingRuleSettings = JSON.stringify(rules); this.routingRuleSettings = JSON.stringify(rules);
}, },
@ -1101,7 +1102,7 @@
inboundSettings: { inboundSettings: {
get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; }, get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.inbounds = JSON.parse(newValue); newTemplateSettings.inbounds = JSON.parse(newValue);
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
}, },
@ -1109,14 +1110,14 @@
outboundSettings: { outboundSettings: {
get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; }, get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.outbounds = JSON.parse(newValue); newTemplateSettings.outbounds = JSON.parse(newValue);
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
}, },
}, },
outboundData: { outboundData: {
get: function () { get: function () {
data = [] const data = [];
if (this.templateSettings != null) { if (this.templateSettings != null) {
this.templateSettings.outbounds.forEach((o, index) => { this.templateSettings.outbounds.forEach((o, index) => {
data.push({ 'key': index, ...o }); data.push({ 'key': index, ...o });
@ -1127,7 +1128,7 @@
}, },
reverseData: { reverseData: {
get: function () { get: function () {
data = [] const data = [];
if (this.templateSettings != null && this.templateSettings.reverse != null) { if (this.templateSettings != null && this.templateSettings.reverse != null) {
if (this.templateSettings.reverse.bridges) { if (this.templateSettings.reverse.bridges) {
this.templateSettings.reverse.bridges.forEach((o, index) => { this.templateSettings.reverse.bridges.forEach((o, index) => {
@ -1146,14 +1147,14 @@
routingRuleSettings: { routingRuleSettings: {
get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; }, get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.routing.rules = JSON.parse(newValue); newTemplateSettings.routing.rules = JSON.parse(newValue);
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
}, },
}, },
routingRuleData: { routingRuleData: {
get: function () { get: function () {
data = []; const data = [];
if (this.templateSettings != null) { if (this.templateSettings != null) {
this.templateSettings.routing.rules.forEach((r, index) => { this.templateSettings.routing.rules.forEach((r, index) => {
data.push({ 'key': index, ...r }); data.push({ 'key': index, ...r });
@ -1174,7 +1175,7 @@
}, },
balancersData: { balancersData: {
get: function () { get: function () {
data = [] const data = [];
if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) { if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
this.templateSettings.routing.balancers.forEach((o, index) => { this.templateSettings.routing.balancers.forEach((o, index) => {
data.push({ data.push({
@ -1194,7 +1195,7 @@
return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null; return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.observatory = JSON.parse(newValue); newTemplateSettings.observatory = JSON.parse(newValue);
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
}, },
@ -1204,7 +1205,7 @@
return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null; return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.burstObservatory = JSON.parse(newValue); newTemplateSettings.burstObservatory = JSON.parse(newValue);
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
}, },
@ -1214,14 +1215,14 @@
freedomStrategy: { freedomStrategy: {
get: function () { get: function () {
if (!this.templateSettings) return "AsIs"; if (!this.templateSettings) return "AsIs";
freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct"); const freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
if (!freedomOutbound) return "AsIs"; if (!freedomOutbound) return "AsIs";
if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs"; if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
return freedomOutbound.settings.domainStrategy; return freedomOutbound.settings.domainStrategy;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct"); const freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
if (freedomOutboundIndex == -1) { if (freedomOutboundIndex == -1) {
newTemplateSettings.outbounds.push({ protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue } }); newTemplateSettings.outbounds.push({ protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue } });
} else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) { } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
@ -1238,7 +1239,7 @@
return this.templateSettings.routing.domainStrategy; return this.templateSettings.routing.domainStrategy;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.routing.domainStrategy = newValue; newTemplateSettings.routing.domainStrategy = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1249,7 +1250,7 @@
return this.templateSettings.log.loglevel; return this.templateSettings.log.loglevel;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.log.loglevel = newValue; newTemplateSettings.log.loglevel = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1260,7 +1261,7 @@
return this.templateSettings.log.access; return this.templateSettings.log.access;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.log.access = newValue; newTemplateSettings.log.access = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1271,7 +1272,7 @@
return this.templateSettings.log.error; return this.templateSettings.log.error;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.log.error = newValue; newTemplateSettings.log.error = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1282,7 +1283,7 @@
return this.templateSettings.log.dnsLog; return this.templateSettings.log.dnsLog;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.log.dnsLog = newValue; newTemplateSettings.log.dnsLog = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1293,7 +1294,7 @@
return this.templateSettings.policy.system.statsInboundUplink; return this.templateSettings.policy.system.statsInboundUplink;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.policy.system.statsInboundUplink = newValue; newTemplateSettings.policy.system.statsInboundUplink = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1304,7 +1305,7 @@
return this.templateSettings.policy.system.statsInboundDownlink; return this.templateSettings.policy.system.statsInboundDownlink;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.policy.system.statsInboundDownlink = newValue; newTemplateSettings.policy.system.statsInboundDownlink = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1315,7 +1316,7 @@
return this.templateSettings.policy.system.statsOutboundUplink; return this.templateSettings.policy.system.statsOutboundUplink;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.policy.system.statsOutboundUplink = newValue; newTemplateSettings.policy.system.statsOutboundUplink = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1326,7 +1327,7 @@
return this.templateSettings.policy.system.statsOutboundDownlink; return this.templateSettings.policy.system.statsOutboundDownlink;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.policy.system.statsOutboundDownlink = newValue; newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1337,7 +1338,7 @@
return this.templateSettings.log.maskAddress; return this.templateSettings.log.maskAddress;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.log.maskAddress = newValue; newTemplateSettings.log.maskAddress = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1423,7 +1424,7 @@
return this.templateSettings ? this.templateSettings.dns != null : false; return this.templateSettings ? this.templateSettings.dns != null : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns = { newTemplateSettings.dns = {
servers: [], servers: [],
@ -1444,7 +1445,7 @@
return this.enableDNS ? this.templateSettings.dns.tag : ""; return this.enableDNS ? this.templateSettings.dns.tag : "";
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.dns.tag = newValue; newTemplateSettings.dns.tag = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1454,7 +1455,7 @@
return this.enableDNS ? this.templateSettings.dns.clientIp : null; return this.enableDNS ? this.templateSettings.dns.clientIp : null;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.clientIp = newValue; newTemplateSettings.dns.clientIp = newValue;
} else { } else {
@ -1468,7 +1469,7 @@
return this.enableDNS ? this.templateSettings.dns.disableCache : false; return this.enableDNS ? this.templateSettings.dns.disableCache : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.disableCache = newValue; newTemplateSettings.dns.disableCache = newValue;
} else { } else {
@ -1482,7 +1483,7 @@
return this.enableDNS ? this.templateSettings.dns.disableFallback : false; return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.disableFallback = newValue; newTemplateSettings.dns.disableFallback = newValue;
} else { } else {
@ -1496,7 +1497,7 @@
return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false; return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.disableFallbackIfMatch = newValue; newTemplateSettings.dns.disableFallbackIfMatch = newValue;
} else { } else {
@ -1510,7 +1511,7 @@
return this.enableDNS ? (this.templateSettings.dns.enableParallelQuery || false) : false; return this.enableDNS ? (this.templateSettings.dns.enableParallelQuery || false) : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.enableParallelQuery = newValue; newTemplateSettings.dns.enableParallelQuery = newValue;
} else { } else {
@ -1524,7 +1525,7 @@
return this.enableDNS ? this.templateSettings.dns.useSystemHosts : false; return this.enableDNS ? this.templateSettings.dns.useSystemHosts : false;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (newValue) { if (newValue) {
newTemplateSettings.dns.useSystemHosts = newValue; newTemplateSettings.dns.useSystemHosts = newValue;
} else { } else {
@ -1538,7 +1539,7 @@
return this.enableDNS ? this.templateSettings.dns.queryStrategy : null; return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
}, },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.dns.queryStrategy = newValue; newTemplateSettings.dns.queryStrategy = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1546,7 +1547,7 @@
dnsServers: { dnsServers: {
get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; }, get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
newTemplateSettings.dns.servers = newValue; newTemplateSettings.dns.servers = newValue;
this.templateSettings = newTemplateSettings; this.templateSettings = newTemplateSettings;
} }
@ -1554,7 +1555,7 @@
fakeDns: { fakeDns: {
get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; }, get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
set: function (newValue) { set: function (newValue) {
newTemplateSettings = this.templateSettings; const newTemplateSettings = this.templateSettings;
if (this.enableDNS) { if (this.enableDNS) {
newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null; newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
} else { } else {