manage balancer in rules table

This commit is contained in:
Surbiks 2024-02-06 01:23:50 +03:30
parent 342d2e5a34
commit 8ffd59df10
3 changed files with 37 additions and 5 deletions

View file

@ -327,6 +327,14 @@
[[ rule.outboundTag ]] [[ rule.outboundTag ]]
</a-popover> </a-popover>
</template> </template>
<template slot="balancer" slot-scope="text, rule, index">
<a-popover :overlay-class-name="themeSwitcher.currentTheme">
<template slot="content">
<p v-if="rule.balancerTag">Balancer Tag: [[ rule.balancerTag ]]</p>
</template>
[[ rule.balancerTag ]]
</a-popover>
</template>
<template slot="info" slot-scope="text, rule, index"> <template slot="info" slot-scope="text, rule, index">
<a-popover placement="bottomRight" <a-popover placement="bottomRight"
v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0" v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
@ -526,9 +534,10 @@
{ title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true }, { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
{ title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]}, { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
{ title: '{{ i18n "pages.xray.rules.inbound"}}', children: [ { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
{ title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 20, ellipsis: true }, { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
{ title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]}, { title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
{ title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 20 }, { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 15 },
{ title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
]; ];
const rulesMobileColumns = [ const rulesMobileColumns = [
@ -971,6 +980,7 @@
}); });
}, },
editBalancer(index) { editBalancer(index) {
const oldTag = this.balancersData[index].tag;
balancerModal.show({ balancerModal.show({
title: '{{ i18n "pages.xray.balancer.editBalancer"}}', title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
okText: '{{ i18n "pages.xray.balancer.editBalancer"}}', okText: '{{ i18n "pages.xray.balancer.editBalancer"}}',
@ -979,7 +989,6 @@
confirm: (balancer) => { confirm: (balancer) => {
balancerModal.loading(); balancerModal.loading();
newTemplateSettings = this.templateSettings; newTemplateSettings = this.templateSettings;
let oldTag = this.balancersData[index].tag;
let tmpBalancer = { let tmpBalancer = {
'tag': balancer.tag, 'tag': balancer.tag,
@ -1010,7 +1019,7 @@
newTemplateSettings = this.templateSettings; newTemplateSettings = this.templateSettings;
//remove from balancers //remove from balancers
let oldTag = this.balancersData[index].tag; const oldTag = this.balancersData[index].tag;
this.balancersData.splice(index, 1); this.balancersData.splice(index, 1);
// remove from settings // remove from settings

View file

@ -107,6 +107,19 @@
<a-select-option v-for="tag in ruleModal.outboundTags" :value="tag">[[ tag ]]</a-select-option> <a-select-option v-for="tag in ruleModal.outboundTags" :value="tag">[[ tag ]]</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item>
<template slot="label">
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.xray.balancer.balancerDesc" }}</span>
</template>
Balancer Tag <a-icon type="question-circle"></a-icon>
</a-tooltip>
</template>
<a-select v-model="ruleModal.rule.balancerTag" :dropdown-class-name="themeSwitcher.currentTheme">
<a-select-option v-for="tag in ruleModal.balancerTags" :value="tag">[[ tag ]]</a-select-option>
</a-select>
</a-form-item>
</table> </table>
</a-form> </a-form>
</a-modal> </a-modal>
@ -133,11 +146,12 @@
protocol: [], protocol: [],
attrs: [], attrs: [],
outboundTag: "", outboundTag: "",
balancerTag: "",
}, },
inboundTags: [], inboundTags: [],
outboundTags: [], outboundTags: [],
users: [], users: [],
balancerTag: [], balancerTags: [],
ok() { ok() {
newRule = ruleModal.getResult(); newRule = ruleModal.getResult();
ObjectUtil.execute(ruleModal.confirm, newRule); ObjectUtil.execute(ruleModal.confirm, newRule);
@ -160,6 +174,7 @@
this.rule.protocol = rule.protocol; this.rule.protocol = rule.protocol;
this.rule.attrs = rule.attrs ? Object.entries(rule.attrs) : []; this.rule.attrs = rule.attrs ? Object.entries(rule.attrs) : [];
this.rule.outboundTag = rule.outboundTag; this.rule.outboundTag = rule.outboundTag;
this.rule.balancerTag = rule.balancerTag ? rule.balancerTag : ""
} else { } else {
this.rule = { this.rule = {
domainMatcher: "", domainMatcher: "",
@ -174,6 +189,7 @@
protocol: [], protocol: [],
attrs: [], attrs: [],
outboundTag: "", outboundTag: "",
balancerTag: "",
} }
} }
this.isEdit = isEdit; this.isEdit = isEdit;
@ -186,6 +202,10 @@
} }
if(app.templateSettings.reverse.portals) this.outboundTags.push(...app.templateSettings.reverse.portals.map(b => b.tag)); if(app.templateSettings.reverse.portals) this.outboundTags.push(...app.templateSettings.reverse.portals.map(b => b.tag));
} }
if (app.templateSettings.routing && app.templateSettings.routing.balancers) {
this.balancerTags = app.templateSettings.routing.balancers.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag)
}
}, },
close() { close() {
ruleModal.visible = false; ruleModal.visible = false;
@ -211,6 +231,7 @@
rule.protocol = value.protocol; rule.protocol = value.protocol;
rule.attrs = Object.fromEntries(value.attrs); rule.attrs = Object.fromEntries(value.attrs);
rule.outboundTag = value.outboundTag; rule.outboundTag = value.outboundTag;
rule.balancerTag = value.balancerTag;
for (const [key, value] of Object.entries(rule)) { for (const [key, value] of Object.entries(rule)) {
if ( if (

View file

@ -407,6 +407,7 @@
"dest" = "Destination" "dest" = "Destination"
"inbound" = "Inbound" "inbound" = "Inbound"
"outbound" = "Outbound" "outbound" = "Outbound"
"balancer" = "Balancer"
"info" = "Info" "info" = "Info"
"add" = "Add Rule" "add" = "Add Rule"
"edit" = "Edit Rule" "edit" = "Edit Rule"
@ -433,6 +434,7 @@
"balancerStrategy" = "Strategy" "balancerStrategy" = "Strategy"
"balancerSelectors" = "Selectors" "balancerSelectors" = "Selectors"
"tag" = "Tag" "tag" = "Tag"
"balancerDesc" = "balancerTag and outboundTag must choose one of the two. outboundTag Effective when specified at the same time."
[pages.xray.wireguard] [pages.xray.wireguard]
"secretKey" = "Secret Key" "secretKey" = "Secret Key"