mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-13 09:36:05 +00:00
add loopback and dns servers tag to inbound lists in RuleFormModal (#4244)
* add loopback and dns servers tag to inbound lists in RuleFormModal * fix: remove clientIp from dns section when its empty
This commit is contained in:
parent
8834e5fbbe
commit
e20d73ba7e
4 changed files with 50 additions and 27 deletions
|
|
@ -22,6 +22,14 @@ const props = defineProps({
|
||||||
|
|
||||||
const STRATEGIES = ['UseSystem', 'UseIP', 'UseIPv4', 'UseIPv6'];
|
const STRATEGIES = ['UseSystem', 'UseIP', 'UseIPv4', 'UseIPv6'];
|
||||||
|
|
||||||
|
const dnsFieldOmit = Object.freeze(Object.create(null));
|
||||||
|
|
||||||
|
function dnsValueEmptyForOmit(v) {
|
||||||
|
if (v === undefined || v === null) return true;
|
||||||
|
if (typeof v === 'string') return v.trim() === '';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const enableDNS = computed({
|
const enableDNS = computed({
|
||||||
get: () => !!props.templateSettings?.dns,
|
get: () => !!props.templateSettings?.dns,
|
||||||
set: (next) => {
|
set: (next) => {
|
||||||
|
|
@ -29,7 +37,6 @@ const enableDNS = computed({
|
||||||
if (next) {
|
if (next) {
|
||||||
props.templateSettings.dns = {
|
props.templateSettings.dns = {
|
||||||
tag: 'dns_inbound',
|
tag: 'dns_inbound',
|
||||||
clientIp: '',
|
|
||||||
queryStrategy: 'UseIP',
|
queryStrategy: 'UseIP',
|
||||||
disableCache: false,
|
disableCache: false,
|
||||||
disableFallback: false,
|
disableFallback: false,
|
||||||
|
|
@ -50,16 +57,30 @@ const enableDNS = computed({
|
||||||
});
|
});
|
||||||
|
|
||||||
function dnsField(field, fallback) {
|
function dnsField(field, fallback) {
|
||||||
|
const omitWhenUnset = fallback === dnsFieldOmit;
|
||||||
return computed({
|
return computed({
|
||||||
get: () => props.templateSettings?.dns?.[field] ?? fallback,
|
get: () => {
|
||||||
|
const raw = props.templateSettings?.dns?.[field];
|
||||||
|
if (fallback === dnsFieldOmit) return raw ?? '';
|
||||||
|
return raw ?? fallback;
|
||||||
|
},
|
||||||
set: (v) => {
|
set: (v) => {
|
||||||
if (props.templateSettings?.dns) props.templateSettings.dns[field] = v;
|
if (!props.templateSettings?.dns) return;
|
||||||
|
if (omitWhenUnset) {
|
||||||
|
if (dnsValueEmptyForOmit(v)) {
|
||||||
|
if (field in props.templateSettings.dns) delete props.templateSettings.dns[field];
|
||||||
|
} else {
|
||||||
|
props.templateSettings.dns[field] = v;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
props.templateSettings.dns[field] = v;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const dnsTag = dnsField('tag', 'dns_inbound');
|
const dnsTag = dnsField('tag', 'dns_inbound');
|
||||||
const dnsClientIp = dnsField('clientIp', '');
|
const dnsClientIp = dnsField('clientIp', dnsFieldOmit);
|
||||||
const dnsStrategy = dnsField('queryStrategy', 'UseIP');
|
const dnsStrategy = dnsField('queryStrategy', 'UseIP');
|
||||||
const dnsDisableCache = dnsField('disableCache', false);
|
const dnsDisableCache = dnsField('disableCache', false);
|
||||||
const dnsDisableFallback = dnsField('disableFallback', false);
|
const dnsDisableFallback = dnsField('disableFallback', false);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ const props = defineProps({
|
||||||
open: { type: Boolean, default: false },
|
open: { type: Boolean, default: false },
|
||||||
outbound: { type: Object, default: null },
|
outbound: { type: Object, default: null },
|
||||||
existingTags: { type: Array, default: () => [] },
|
existingTags: { type: Array, default: () => [] },
|
||||||
inboundTags: { type: Array, default: () => [] },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['update:open', 'confirm']);
|
const emit = defineEmits(['update:open', 'confirm']);
|
||||||
|
|
@ -318,10 +317,8 @@ function regenerateWgKeys() {
|
||||||
<!-- ============== Loopback ============== -->
|
<!-- ============== Loopback ============== -->
|
||||||
<template v-if="isLoopback">
|
<template v-if="isLoopback">
|
||||||
<a-form-item label="Inbound tag">
|
<a-form-item label="Inbound tag">
|
||||||
<a-auto-complete v-model:value="outbound.settings.inboundTag"
|
<a-input v-model:value="outbound.settings.inboundTag"
|
||||||
:options="inboundTags.map((tag) => ({ value: tag }))"
|
placeholder="inbound tag using in routing rules" />
|
||||||
:filter-option="(input, option) => option.value.toLowerCase().includes(input.toLowerCase())"
|
|
||||||
placeholder="tag of an existing inbound to re-route into" />
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,6 @@ const props = defineProps({
|
||||||
isMobile: { type: Boolean, default: false },
|
isMobile: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const inboundTagOptions = computed(() => {
|
|
||||||
const out = new Set();
|
|
||||||
for (const ib of props.templateSettings?.inbounds || []) {
|
|
||||||
if (ib.tag) out.add(ib.tag);
|
|
||||||
}
|
|
||||||
for (const t of props.inboundTags || []) out.add(t);
|
|
||||||
return [...out];
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits(['reset-traffic', 'test', 'test-all', 'show-warp', 'show-nord', 'delete']);
|
const emit = defineEmits(['reset-traffic', 'test', 'test-all', 'show-warp', 'show-nord', 'delete']);
|
||||||
|
|
||||||
const testMode = ref('tcp');
|
const testMode = ref('tcp');
|
||||||
|
|
@ -443,7 +434,7 @@ const rows = computed(() => {
|
||||||
</a-table>
|
</a-table>
|
||||||
|
|
||||||
<OutboundFormModal v-model:open="modalOpen" :outbound="editingOutbound" :existing-tags="existingTags"
|
<OutboundFormModal v-model:open="modalOpen" :outbound="editingOutbound" :existing-tags="existingTags"
|
||||||
:inbound-tags="inboundTagOptions" @confirm="onConfirm" />
|
@confirm="onConfirm" />
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,18 +65,32 @@ const editingRule = ref(null);
|
||||||
const editingIndex = ref(null);
|
const editingIndex = ref(null);
|
||||||
|
|
||||||
const inboundTagOptions = computed(() => {
|
const inboundTagOptions = computed(() => {
|
||||||
const out = new Set();
|
const seen = new Set();
|
||||||
|
const out = [];
|
||||||
|
|
||||||
|
function pushUnique(tag) {
|
||||||
|
if (!tag) return;
|
||||||
|
if (seen.has(tag)) return;
|
||||||
|
seen.add(tag);
|
||||||
|
out.push(tag);
|
||||||
|
}
|
||||||
|
|
||||||
for (const ib of props.templateSettings?.inbounds || []) {
|
for (const ib of props.templateSettings?.inbounds || []) {
|
||||||
if (ib.tag) out.add(ib.tag);
|
pushUnique(ib.tag);
|
||||||
|
}
|
||||||
|
for (const t of props.inboundTags || []) {
|
||||||
|
pushUnique(t);
|
||||||
}
|
}
|
||||||
for (const t of props.inboundTags || []) out.add(t);
|
|
||||||
for (const ob of props.templateSettings?.outbounds || []) {
|
for (const ob of props.templateSettings?.outbounds || []) {
|
||||||
const rt = ob?.reverse?.tag || ob?.settings?.reverse?.tag;
|
const rt = ob?.reverse?.tag || ob?.settings?.reverse?.tag || ob?.settings?.inboundTag;
|
||||||
if (rt) out.add(rt);
|
pushUnique(rt);
|
||||||
}
|
}
|
||||||
// dnsTag if DNS is configured.
|
pushUnique(props.templateSettings?.dns?.tag);
|
||||||
const dt = props.templateSettings?.dns?.tag;
|
|
||||||
if (dt) out.add(dt);
|
for (const s of props.templateSettings?.dns?.servers || []) {
|
||||||
|
if (typeof s === 'object' && s?.tag) pushUnique(s.tag);
|
||||||
|
}
|
||||||
|
|
||||||
return [...out];
|
return [...out];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue