feat(xray): edit Lua DNS and routing scripts

xray-core 26.10.10 can hand DNS and routing to Lua: dns.script and
routing.script name a .lua file (absolute, or found next to the Xray
binary) that defines HandleDNSQuery / HandleRoute, and a DNS server's id
is how a DNS script picks it. The keys round-tripped through the JSON
template but had no field.

- DNS: a Lua Script field, and an ID field in the server modal;
- Basics: a Routing Script field beside the routing strategy;
- Routing: a warning above the rules while a script is set, since the
  core then routes only through the script and skips every rule, the
  panel's api rule included.

The descriptions say the script must still send the api inbound to the
api outbound, and that Xray will not start if the file is missing. An
empty field drops the key, because the core rejects an empty path.
This commit is contained in:
MHSanaei
2026-10-11 15:37:20 +02:00
parent 1c050f872a
commit b6c859f5b9
25 changed files with 338 additions and 30 deletions
@@ -160,6 +160,7 @@ export default function BasicsTab({
);
const routingStrategy = templateSettings?.routing?.domainStrategy ?? 'AsIs';
const routingScript = templateSettings?.routing?.script ?? '';
const log = (templateSettings?.log || {}) as Record<string, unknown>;
const policy = (templateSettings?.policy?.system || {}) as Record<string, boolean>;
const level0 = (templateSettings?.policy?.levels?.['0'] || {}) as Record<string, unknown>;
@@ -259,6 +260,25 @@ export default function BasicsTab({
/>
}
/>
<SettingListItem
title={t('pages.xray.routingScript')}
description={t('pages.xray.routingScriptDesc')}
paddings="small"
control={
<Input
value={routingScript}
placeholder="routing.lua"
onChange={(e) => {
const next = e.target.value;
mutate((tt) => {
if (!tt.routing) return;
if (next.trim() === '') delete tt.routing.script;
else tt.routing.script = next;
});
}}
/>
}
/>
<SettingListItem
title={t('pages.xray.outboundTestUrl')}
description={t('pages.xray.outboundTestUrlDesc')}
@@ -188,6 +188,13 @@ export default function DnsServerModal({
<InputNumber min={1} max={65535} />
</FormField>
)}
<FormField
label={t('pages.xray.dns.serverId')}
tooltip={t('pages.xray.dns.serverIdDesc')}
name="id"
>
<Input />
</FormField>
<FormField label={t('pages.xray.dns.tag')} name="tag">
<Input />
</FormField>
+12
View File
@@ -297,6 +297,18 @@ export default function DnsTab({ templateSettings, setTemplateSettings }: DnsTab
/>
}
/>
<SettingListItem
paddings="small"
title={t('pages.xray.dns.script')}
description={t('pages.xray.dns.scriptDesc')}
control={
<Input
value={dns?.script ?? ''}
placeholder="dns.lua"
onChange={(e) => setDnsField('script', e.target.value, true)}
/>
}
/>
{(
[
[
+10 -1
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Dropdown, Modal, Space, Table, Tabs, message } from 'antd';
import { Alert, Button, Dropdown, Modal, Space, Table, Tabs, message } from 'antd';
import {
AimOutlined,
ControlOutlined,
@@ -64,6 +64,7 @@ export default function RoutingTab({
moved: false,
});
const routingScript = templateSettings?.routing?.script ?? '';
const rules = useMemo(
() => (templateSettings?.routing?.rules || []) as RoutingRule[],
[templateSettings?.routing?.rules],
@@ -349,6 +350,14 @@ export default function RoutingTab({
<>
{modalContextHolder}
{messageContextHolder}
{routingScript.trim() !== '' && (
<Alert
type="warning"
showIcon
style={{ marginBottom: 12 }}
title={t('pages.xray.routingScriptActive', { section: t('pages.xray.basicTemplate') })}
/>
)}
<Tabs
defaultActiveKey="basic"
items={[