mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-29 14:37:13 +00:00
0daedd3db9
* feat: add support for subscription-based outbounds with auto-update
- New OutboundSubscription model (full support on both SQLite and PostgreSQL)
- Go subscription link parser (vmess/vless/trojan/ss/hysteria2/wireguard) matching frontend behavior
- Stable tag assignment across refreshes (designed for balancer + routing use)
- Runtime merge of subscription outbounds into Xray config (additive only)
- Full CRUD + manual refresh + preview API
- Background auto-update job (per-subscription interval)
- Frontend management UI in Outbounds tab (Subscriptions drawer) + tag integration in balancers/routing rules
- Proper dual-database support including CLI migration path
Review & hardening notes:
- Fixed merge logic bug that could drop manual outbounds
- Added SSRF/private-IP protection on subscription URLs using SanitizePublicHTTPURL
- Improved update interval UX (hours + minutes)
- Auto-fetch on first subscription creation
- Added detailed comments on tag stability strategy and balancer implications when servers are added/removed/rotated
- Updated migrationModels() for CLI migrate-db support
* fix: resolve frontend lint/type errors and Go build break
Frontend (eslint + tsc clean):
- Destructure subscriptionOutboundTags prop in RoutingTab and
BalancersTab. It was declared in the interface and used in useMemo
but never destructured, so it resolved as an unresolved global
(react-hooks warning + tsc "Cannot find name"). The prop is passed
by XrayPage, so the feature was silently inert.
- OutboundsTab: remove unused useEffect import, add an OutboundSub
type to replace any[] state and the any/any table render signature,
type the subscriptionOutbounds cast, and replace unused catch (e)
bindings with parameter-less catch. Also type HttpUtil.post as
OutboundSub so r.obj?.id type-checks.
Backend (go build clean):
- outbound_subscription_job: websocket.MessageTypeXray is undefined;
use the existing MessageTypeOutbounds since the job refreshes
outbound subscriptions.
* fix(xray): make outbound subscription creation work end-to-end
- Correct API paths from /panel/xray/outbound-subs to
/panel/api/xray/outbound-subs. The controller is mounted under
/panel/api, so the old paths hit the SPA page route (GET-only)
and 404'd on POST.
- Send the create-subscription body as a plain object instead of
URLSearchParams. The axios request interceptor serializes bodies
with qs.stringify, which can't read URLSearchParams' internal
storage and produced an empty body, so the backend rejected it
with "subscription URL is required".
- Use message.useMessage() + context holder instead of the static
antd message API (resolves the "Static function can not consume
context" warning), matching XrayPage's pattern.
- Migrate the subscriptions Drawer to antd v6 props: width -> size,
destroyOnClose -> destroyOnHidden, and Space direction -> orientation.
* feat(xray): show traffic/test for subscription outbounds; harden + test the feature
Display (the reported issue):
- Replace the flat read-only pills with a proper read-only table (desktop)
and cards (mobile) in a new SubscriptionOutbounds component, showing
Address, Protocol, Traffic (matched by tag — already collected by Xray),
and a Test button with Latency. No edit/delete/move (read-only).
- Test subscription outbounds via the existing /testOutbound endpoint, with
results keyed by tag (subscriptionTestStates + testSubscriptionOutbound in
useXraySetting, wired through XrayPage). Generalize isTesting/testResult to
a string|number key so the same helpers serve index- and tag-keyed states.
i18n:
- Replace all hardcoded English subscription strings with t() calls and add
pages.xray.outboundSub.* keys to en-US.json (other locales fall back).
Backend hardening + tests:
- xray.go: drop the tautological `subSvc != nil` check.
- outbound_subscription: re-validate every redirect hop against private/
internal addresses (CheckRedirect) and cap the redirect chain, closing an
SSRF gap where only the initial host was checked.
- Extract assignStableTags as a pure function and add unit tests for tag
stability and SSRF rejection (the feature previously had no tests).
Misc:
- gofmt util/link/outbound.go (it was not gofmt-clean).
* fix(xray): make outbound-subs feature pass CI (test compile, route docs, openapi)
- outbound_test.go: remove unused `inner`/`lines` variables that broke the
`util/link` test build (declared and not used).
- Document the 7 outbound-subscription routes in endpoints.ts (list, create,
update, delete, del alias, refresh, parse) so TestAPIRoutesDocumented passes.
- Regenerate frontend/public/openapi.json (npm run gen) to include the new
endpoints, satisfying the codegen freshness check.
* feat(xray): per-subscription allow-private, gap-filled tags, UI tweaks, delete refresh
Backend:
- Add a per-subscription AllowPrivate flag (default off). Create/Update/refresh
and the redirect check sanitize the URL with it, so localhost/LAN sources work
only when explicitly opted in; the SSRF guard still blocks private targets by
default. Controller reads the allowPrivate form field on create/update/parse.
- Default outbound tag prefix now uses the smallest free "subN-" number instead
of the auto-increment id, so deleting a subscription frees its number for reuse
(a fresh start gives sub1) while staying stable per subscription. Extracted a
pure defaultPrefixNumber() with unit tests.
- deleteOutboundSub now signals SetToNeedRestart so xray drops the outbounds.
Frontend:
- "Allow private address" toggle in the add form (sends allowPrivate).
- Delete now refreshes the xray view immediately (no manual page reload).
- Subscriptions manager opens as a centered Modal instead of a right-side Drawer.
- Move Outbounds to a top-level sidebar item under Nodes (out of Xray Configs).
- Collapse WARP/NordVPN into a "more" dropdown.
- Document the allowPrivate param in endpoints.ts.
* i18n(xray): translate outbound-subscription UI into all locales
- Translate the pages.xray.outboundSub.* strings (and allowPrivate label/hint)
into all 12 non-English locales, matching each file's existing terminology.
- Remove the unused outboundSub.add ("Add subscription") key from every locale.
* feat(xray): subscription manager — edit, reorder/priority, status, preview, refresh-all
Backend:
- Per-subscription Priority + Prepend: subscriptions are ordered by Priority and
placed before (Prepend) or after the manual template outbounds in the merge, so
a subscription server can become the default. New Move(up/down) endpoint
re-normalizes priorities; merge split into prepend/template/append.
- List now returns a derived OutboundCount and orders by priority, and strips the
heavy LastFetchedOutbounds/LinkIdentities blobs from the list payload.
- Create/Update accept the prepend flag; new subs append at the end of priority.
Frontend (Outbound Subscriptions modal):
- Edit existing subscriptions (reuses the form + Update endpoint).
- Inline enable/disable Switch, Status column (OK / error tooltip), Outbounds
count column, per-row refresh spinner, "Refresh all" button.
- Reorder (move up/down) controls + a "Before manual outbounds" toggle.
- Preview button: fetch+parse a URL via /parse without saving.
- Document the move route + prepend param in endpoints.ts; regenerate openapi.json.
* i18n(xray): translate new subscription-manager strings into all locales
Add the prepend/prependHint, preview/previewEmpty, refreshAll, statusOk and
toastUpdated keys to all 12 non-English locales, matching each file's terminology.
---------
Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
655 lines
24 KiB
TypeScript
655 lines
24 KiB
TypeScript
import { useCallback, useMemo, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import {
|
|
Button,
|
|
Col,
|
|
Dropdown,
|
|
Form,
|
|
Input,
|
|
InputNumber,
|
|
Modal,
|
|
Popconfirm,
|
|
Radio,
|
|
Row,
|
|
Space,
|
|
Switch,
|
|
Table,
|
|
Tag,
|
|
Tooltip,
|
|
message,
|
|
} from 'antd';
|
|
import {
|
|
PlusOutlined,
|
|
CloudOutlined,
|
|
ApiOutlined,
|
|
MoreOutlined,
|
|
RetweetOutlined,
|
|
PlayCircleOutlined,
|
|
ReloadOutlined,
|
|
DeleteOutlined,
|
|
EditOutlined,
|
|
EyeOutlined,
|
|
ArrowUpOutlined,
|
|
ArrowDownOutlined,
|
|
CheckCircleOutlined,
|
|
WarningOutlined,
|
|
} from '@ant-design/icons';
|
|
|
|
import { HttpUtil } from '@/utils';
|
|
|
|
import OutboundFormModal from './OutboundFormModal';
|
|
import type { XraySettingsValue, SetTemplate, OutboundTestState, OutboundTrafficRow } from '@/hooks/useXraySetting';
|
|
import './OutboundsTab.css';
|
|
|
|
import type { OutboundRow } from './outbounds-tab-types';
|
|
import { useOutboundColumns } from './useOutboundColumns';
|
|
import OutboundCardList from './OutboundCardList';
|
|
import SubscriptionOutbounds from './SubscriptionOutbounds';
|
|
|
|
interface OutboundSub {
|
|
id: number;
|
|
remark?: string;
|
|
url?: string;
|
|
enabled?: boolean;
|
|
allowPrivate?: boolean;
|
|
prepend?: boolean;
|
|
priority?: number;
|
|
tagPrefix?: string;
|
|
updateInterval?: number;
|
|
lastUpdated?: number;
|
|
lastError?: string;
|
|
outboundCount?: number;
|
|
}
|
|
|
|
interface OutboundsTabProps {
|
|
templateSettings: XraySettingsValue | null;
|
|
setTemplateSettings: SetTemplate;
|
|
outboundsTraffic: OutboundTrafficRow[];
|
|
outboundTestStates: Record<number, OutboundTestState>;
|
|
subscriptionTestStates: Record<string, OutboundTestState>;
|
|
testingAll: boolean;
|
|
inboundTags: string[];
|
|
subscriptionOutbounds?: unknown[];
|
|
isMobile: boolean;
|
|
onResetTraffic: (tag: string) => void;
|
|
onTest: (index: number, mode: string) => void;
|
|
onTestSubscription: (outbound: Record<string, unknown>, mode: string) => void;
|
|
onTestAll: (mode: string) => void;
|
|
onShowWarp: () => void;
|
|
onShowNord: () => void;
|
|
onRefreshXrayData?: () => void;
|
|
}
|
|
|
|
export default function OutboundsTab({
|
|
templateSettings,
|
|
setTemplateSettings,
|
|
outboundsTraffic,
|
|
outboundTestStates,
|
|
subscriptionTestStates,
|
|
testingAll,
|
|
inboundTags: _inboundTags,
|
|
subscriptionOutbounds,
|
|
isMobile,
|
|
onResetTraffic,
|
|
onTest,
|
|
onTestSubscription,
|
|
onTestAll,
|
|
onShowWarp,
|
|
onShowNord,
|
|
onRefreshXrayData,
|
|
}: OutboundsTabProps) {
|
|
const { t } = useTranslation();
|
|
const [modal, modalContextHolder] = Modal.useModal();
|
|
const [messageApi, messageContextHolder] = message.useMessage();
|
|
const [testMode, setTestMode] = useState<'tcp' | 'http'>('tcp');
|
|
const [modalOpen, setModalOpen] = useState(false);
|
|
const [editingOutbound, setEditingOutbound] = useState<Record<string, unknown> | null>(null);
|
|
const [editingIndex, setEditingIndex] = useState<number | null>(null);
|
|
const [existingTags, setExistingTags] = useState<string[]>([]);
|
|
|
|
// Subscription manager (CRUD + reorder + refresh + preview)
|
|
const [subDrawerOpen, setSubDrawerOpen] = useState(false);
|
|
const [subs, setSubs] = useState<OutboundSub[]>([]);
|
|
const [subsLoading, setSubsLoading] = useState(false);
|
|
const [newSub, setNewSub] = useState({ remark: '', url: '', tagPrefix: '', updateInterval: 600, enabled: true, allowPrivate: false, prepend: false });
|
|
const [editingSubId, setEditingSubId] = useState<number | null>(null);
|
|
const [savingSub, setSavingSub] = useState(false);
|
|
const [refreshingId, setRefreshingId] = useState<number | null>(null);
|
|
const [refreshingAll, setRefreshingAll] = useState(false);
|
|
const [busyId, setBusyId] = useState<number | null>(null);
|
|
const [previewing, setPreviewing] = useState(false);
|
|
const [previewData, setPreviewData] = useState<{ tag?: string; protocol?: string }[] | null>(null);
|
|
|
|
// Convenience: expose hours/minutes for the interval input
|
|
const intervalHours = Math.floor((newSub.updateInterval || 600) / 3600);
|
|
const intervalMinutes = Math.floor(((newSub.updateInterval || 600) % 3600) / 60);
|
|
function setIntervalHM(h: number, m: number) {
|
|
const secs = Math.max(60, (h || 0) * 3600 + (m || 0) * 60);
|
|
setNewSub((prev) => ({ ...prev, updateInterval: secs }));
|
|
}
|
|
|
|
const outbounds = useMemo(
|
|
() => (templateSettings?.outbounds || []) as unknown as OutboundRow[],
|
|
[templateSettings?.outbounds],
|
|
);
|
|
|
|
const rows = useMemo(() => outbounds.map((o, i) => ({ ...o, key: i })), [outbounds]);
|
|
|
|
const mutate = useCallback(
|
|
(mutator: (next: XraySettingsValue) => void) => {
|
|
setTemplateSettings((prev) => {
|
|
if (!prev) return prev;
|
|
const clone = JSON.parse(JSON.stringify(prev)) as XraySettingsValue;
|
|
mutator(clone);
|
|
return clone;
|
|
});
|
|
},
|
|
[setTemplateSettings],
|
|
);
|
|
|
|
function openAdd() {
|
|
setEditingOutbound(null);
|
|
setEditingIndex(null);
|
|
setExistingTags((templateSettings?.outbounds || []).map((o) => o?.tag).filter((tg): tg is string => !!tg));
|
|
setModalOpen(true);
|
|
}
|
|
|
|
function openSubManager() {
|
|
setSubDrawerOpen(true);
|
|
loadSubs();
|
|
}
|
|
function openEdit(idx: number) {
|
|
setEditingOutbound((templateSettings?.outbounds || [])[idx] as Record<string, unknown>);
|
|
setEditingIndex(idx);
|
|
setExistingTags(
|
|
(templateSettings?.outbounds || [])
|
|
.filter((_, i) => i !== idx)
|
|
.map((o) => o?.tag)
|
|
.filter((tg): tg is string => !!tg),
|
|
);
|
|
setModalOpen(true);
|
|
}
|
|
function onConfirm(outbound: Record<string, unknown>) {
|
|
mutate((tt) => {
|
|
if (!Array.isArray(tt.outbounds)) tt.outbounds = [];
|
|
if (editingIndex == null) {
|
|
if (!outbound.tag) return;
|
|
tt.outbounds.push(outbound as never);
|
|
} else {
|
|
tt.outbounds[editingIndex] = outbound as never;
|
|
}
|
|
});
|
|
setModalOpen(false);
|
|
}
|
|
|
|
function confirmDelete(idx: number) {
|
|
modal.confirm({
|
|
title: `${t('delete')} ${t('pages.xray.Outbounds')} #${idx + 1}?`,
|
|
okText: t('delete'),
|
|
okType: 'danger',
|
|
cancelText: t('cancel'),
|
|
onOk: () => {
|
|
mutate((tt) => {
|
|
tt.outbounds?.splice(idx, 1);
|
|
});
|
|
},
|
|
});
|
|
}
|
|
function setFirst(idx: number) {
|
|
mutate((tt) => {
|
|
if (!tt.outbounds) return;
|
|
const [moved] = tt.outbounds.splice(idx, 1);
|
|
tt.outbounds.unshift(moved);
|
|
});
|
|
}
|
|
function moveUp(idx: number) {
|
|
if (idx <= 0) return;
|
|
mutate((tt) => {
|
|
if (!tt.outbounds) return;
|
|
[tt.outbounds[idx - 1], tt.outbounds[idx]] = [tt.outbounds[idx], tt.outbounds[idx - 1]];
|
|
});
|
|
}
|
|
function moveDown(idx: number) {
|
|
mutate((tt) => {
|
|
if (!tt.outbounds || idx >= tt.outbounds.length - 1) return;
|
|
[tt.outbounds[idx + 1], tt.outbounds[idx]] = [tt.outbounds[idx], tt.outbounds[idx + 1]];
|
|
});
|
|
}
|
|
|
|
// --- Subscription management (minimal inline UI) ---
|
|
async function loadSubs() {
|
|
setSubsLoading(true);
|
|
try {
|
|
const r = await HttpUtil.get('/panel/api/xray/outbound-subs');
|
|
if (r?.success) setSubs(Array.isArray(r.obj) ? r.obj : []);
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.toastLoadFailed'));
|
|
} finally {
|
|
setSubsLoading(false);
|
|
}
|
|
}
|
|
function subBody(src: { remark?: string; url?: string; tagPrefix?: string; updateInterval?: number; enabled?: boolean; allowPrivate?: boolean; prepend?: boolean }) {
|
|
return {
|
|
remark: src.remark ?? '',
|
|
url: src.url ?? '',
|
|
tagPrefix: src.tagPrefix ?? '',
|
|
updateInterval: src.updateInterval ?? 600,
|
|
enabled: src.enabled ?? true,
|
|
allowPrivate: src.allowPrivate ?? false,
|
|
prepend: src.prepend ?? false,
|
|
};
|
|
}
|
|
function resetSubForm() {
|
|
setNewSub({ remark: '', url: '', tagPrefix: '', updateInterval: 600, enabled: true, allowPrivate: false, prepend: false });
|
|
setEditingSubId(null);
|
|
setPreviewData(null);
|
|
}
|
|
function openEditSub(sub: OutboundSub) {
|
|
setNewSub({
|
|
remark: sub.remark ?? '',
|
|
url: sub.url ?? '',
|
|
tagPrefix: sub.tagPrefix ?? '',
|
|
updateInterval: sub.updateInterval ?? 600,
|
|
enabled: sub.enabled ?? true,
|
|
allowPrivate: sub.allowPrivate ?? false,
|
|
prepend: sub.prepend ?? false,
|
|
});
|
|
setEditingSubId(sub.id);
|
|
setPreviewData(null);
|
|
}
|
|
async function saveSub() {
|
|
if (!newSub.url.trim()) {
|
|
messageApi.warning(t('pages.xray.outboundSub.toastUrlRequired'));
|
|
return;
|
|
}
|
|
setSavingSub(true);
|
|
try {
|
|
const url = editingSubId != null
|
|
? `/panel/api/xray/outbound-subs/${editingSubId}`
|
|
: '/panel/api/xray/outbound-subs';
|
|
const r = await HttpUtil.post<OutboundSub>(url, subBody(newSub));
|
|
if (r?.success) {
|
|
messageApi.success(t(editingSubId != null ? 'pages.xray.outboundSub.toastUpdated' : 'pages.xray.outboundSub.toastAdded'));
|
|
const createdId = editingSubId == null ? r.obj?.id : undefined;
|
|
resetSubForm();
|
|
await loadSubs();
|
|
if (createdId) await refreshOne(createdId);
|
|
onRefreshXrayData?.();
|
|
} else {
|
|
messageApi.error(r?.msg || t('pages.xray.outboundSub.toastAddFailed'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.toastAddFailed'));
|
|
} finally {
|
|
setSavingSub(false);
|
|
}
|
|
}
|
|
async function previewSub() {
|
|
if (!newSub.url.trim()) {
|
|
messageApi.warning(t('pages.xray.outboundSub.toastUrlRequired'));
|
|
return;
|
|
}
|
|
setPreviewing(true);
|
|
setPreviewData(null);
|
|
try {
|
|
const r = await HttpUtil.post<{ tag?: string; protocol?: string }[]>('/panel/api/xray/outbound-subs/parse', { url: newSub.url, allowPrivate: newSub.allowPrivate });
|
|
if (r?.success && Array.isArray(r.obj)) {
|
|
setPreviewData(r.obj);
|
|
if (r.obj.length === 0) messageApi.info(t('pages.xray.outboundSub.previewEmpty'));
|
|
} else {
|
|
messageApi.error(r?.msg || t('pages.xray.outboundSub.previewEmpty'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.previewEmpty'));
|
|
} finally {
|
|
setPreviewing(false);
|
|
}
|
|
}
|
|
async function toggleEnabled(sub: OutboundSub) {
|
|
setBusyId(sub.id);
|
|
try {
|
|
const r = await HttpUtil.post(`/panel/api/xray/outbound-subs/${sub.id}`, subBody({ ...sub, enabled: !sub.enabled }));
|
|
if (r?.success) {
|
|
await loadSubs();
|
|
onRefreshXrayData?.();
|
|
} else {
|
|
messageApi.error(r?.msg || t('pages.xray.outboundSub.toastAddFailed'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.toastAddFailed'));
|
|
} finally {
|
|
setBusyId(null);
|
|
}
|
|
}
|
|
async function moveSub(id: number, dir: 'up' | 'down') {
|
|
setBusyId(id);
|
|
try {
|
|
const r = await HttpUtil.post(`/panel/api/xray/outbound-subs/${id}/move`, { dir });
|
|
if (r?.success) {
|
|
await loadSubs();
|
|
onRefreshXrayData?.();
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
} finally {
|
|
setBusyId(null);
|
|
}
|
|
}
|
|
async function refreshOne(id: number) {
|
|
setRefreshingId(id);
|
|
try {
|
|
const r = await HttpUtil.post(`/panel/api/xray/outbound-subs/${id}/refresh`);
|
|
if (r?.success) {
|
|
messageApi.success(t('pages.xray.outboundSub.toastRefreshed'));
|
|
await loadSubs();
|
|
onRefreshXrayData?.();
|
|
} else {
|
|
messageApi.error(r?.msg || t('pages.xray.outboundSub.toastRefreshFailed'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.toastRefreshFailed'));
|
|
} finally {
|
|
setRefreshingId(null);
|
|
}
|
|
}
|
|
async function refreshAllSubs() {
|
|
if (subs.length === 0) return;
|
|
setRefreshingAll(true);
|
|
try {
|
|
for (const s of subs) {
|
|
try { await HttpUtil.post(`/panel/api/xray/outbound-subs/${s.id}/refresh`); } catch { /* continue */ }
|
|
}
|
|
messageApi.success(t('pages.xray.outboundSub.toastRefreshed'));
|
|
await loadSubs();
|
|
onRefreshXrayData?.();
|
|
} finally {
|
|
setRefreshingAll(false);
|
|
}
|
|
}
|
|
async function deleteOne(id: number) {
|
|
try {
|
|
const r = await HttpUtil.post(`/panel/api/xray/outbound-subs/${id}/del`);
|
|
if (r?.success) {
|
|
messageApi.success(t('pages.xray.outboundSub.toastDeleted'));
|
|
await loadSubs();
|
|
onRefreshXrayData?.();
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.xray.outboundSub.toastDeleteFailed'));
|
|
}
|
|
}
|
|
|
|
const columns = useOutboundColumns({
|
|
testMode,
|
|
rows,
|
|
outboundsTraffic,
|
|
outboundTestStates,
|
|
openEdit,
|
|
setFirst,
|
|
moveUp,
|
|
moveDown,
|
|
confirmDelete,
|
|
onResetTraffic,
|
|
onTest,
|
|
});
|
|
|
|
return (
|
|
<>
|
|
{modalContextHolder}
|
|
{messageContextHolder}
|
|
<Space orientation="vertical" size="middle" style={{ width: '100%' }}>
|
|
<Row gutter={[12, 12]} align="middle" justify="space-between">
|
|
<Col xs={24} sm={12}>
|
|
<Space size="small" wrap>
|
|
<Button type="primary" icon={<PlusOutlined />} onClick={openAdd}>
|
|
{!isMobile && t('pages.xray.Outbounds')}
|
|
</Button>
|
|
<Button icon={<CloudOutlined />} onClick={openSubManager}>
|
|
{t('pages.xray.outboundSub.manage')}
|
|
</Button>
|
|
<Dropdown
|
|
trigger={['click']}
|
|
menu={{
|
|
items: [
|
|
{ key: 'warp', icon: <CloudOutlined />, label: 'WARP', onClick: onShowWarp },
|
|
{ key: 'nord', icon: <ApiOutlined />, label: 'NordVPN', onClick: onShowNord },
|
|
],
|
|
}}
|
|
>
|
|
<Button icon={<MoreOutlined />}>{t('more')}</Button>
|
|
</Dropdown>
|
|
</Space>
|
|
</Col>
|
|
<Col xs={24} sm={12} className="toolbar-right">
|
|
<Space size="small" wrap>
|
|
<Tooltip title={t('pages.xray.outbound.testModeTooltip')}>
|
|
<Radio.Group value={testMode} onChange={(e) => setTestMode(e.target.value)} buttonStyle="solid" size="small">
|
|
<Radio.Button value="tcp">TCP</Radio.Button>
|
|
<Radio.Button value="http">HTTP</Radio.Button>
|
|
</Radio.Group>
|
|
</Tooltip>
|
|
<Button type="primary" loading={testingAll} icon={<PlayCircleOutlined />} onClick={() => onTestAll(testMode)}>
|
|
{!isMobile && t('pages.xray.outbound.testAll')}
|
|
</Button>
|
|
<Popconfirm
|
|
placement="topRight"
|
|
okText={t('reset')}
|
|
cancelText={t('cancel')}
|
|
title={t('pages.inbounds.resetAllTrafficContent')}
|
|
onConfirm={() => onResetTraffic('-alltags-')}
|
|
>
|
|
<Button icon={<RetweetOutlined />} />
|
|
</Popconfirm>
|
|
</Space>
|
|
</Col>
|
|
</Row>
|
|
|
|
{isMobile ? (
|
|
<OutboundCardList
|
|
rows={rows}
|
|
testMode={testMode}
|
|
outboundsTraffic={outboundsTraffic}
|
|
outboundTestStates={outboundTestStates}
|
|
setFirst={setFirst}
|
|
openEdit={openEdit}
|
|
onResetTraffic={onResetTraffic}
|
|
confirmDelete={confirmDelete}
|
|
onTest={onTest}
|
|
/>
|
|
) : (
|
|
<Table
|
|
columns={columns}
|
|
dataSource={rows}
|
|
rowKey={(r) => r.key}
|
|
pagination={false}
|
|
size="small"
|
|
/>
|
|
)}
|
|
|
|
<OutboundFormModal
|
|
open={modalOpen}
|
|
outbound={editingOutbound}
|
|
existingTags={existingTags}
|
|
onClose={() => setModalOpen(false)}
|
|
onConfirm={onConfirm}
|
|
/>
|
|
|
|
{/* Subscription outbounds (read-only, merged at runtime) */}
|
|
{Array.isArray(subscriptionOutbounds) && subscriptionOutbounds.length > 0 && (
|
|
<SubscriptionOutbounds
|
|
subscriptionOutbounds={subscriptionOutbounds}
|
|
outboundsTraffic={outboundsTraffic}
|
|
subscriptionTestStates={subscriptionTestStates}
|
|
testMode={testMode}
|
|
isMobile={isMobile}
|
|
onTestSubscription={onTestSubscription}
|
|
/>
|
|
)}
|
|
</Space>
|
|
|
|
<Modal
|
|
title={t('pages.xray.outboundSub.title')}
|
|
open={subDrawerOpen}
|
|
onCancel={() => setSubDrawerOpen(false)}
|
|
footer={null}
|
|
width={isMobile ? '100%' : 640}
|
|
destroyOnHidden
|
|
>
|
|
<Space orientation="vertical" style={{ width: '100%' }} size="large">
|
|
<div>
|
|
{editingSubId != null && (
|
|
<div style={{ marginBottom: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
<Tag color="blue">{t('edit')}</Tag>
|
|
<span style={{ fontWeight: 600 }}>{newSub.remark || newSub.url}</span>
|
|
</div>
|
|
)}
|
|
<Form layout="vertical" size="small">
|
|
<Form.Item label={t('pages.xray.outboundSub.remark')}>
|
|
<Input value={newSub.remark} onChange={(e) => setNewSub({ ...newSub, remark: e.target.value })} placeholder={t('pages.xray.outboundSub.remarkPlaceholder')} />
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.url')} required>
|
|
<Input value={newSub.url} onChange={(e) => setNewSub({ ...newSub, url: e.target.value })} placeholder={t('pages.xray.outboundSub.urlPlaceholder')} />
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.tagPrefix')}>
|
|
<Input value={newSub.tagPrefix} onChange={(e) => setNewSub({ ...newSub, tagPrefix: e.target.value })} placeholder={t('pages.xray.outboundSub.tagPrefixPlaceholder')} />
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.interval')}>
|
|
<Space>
|
|
<InputNumber
|
|
min={0}
|
|
value={intervalHours}
|
|
onChange={(v) => setIntervalHM(Number(v) || 0, intervalMinutes)}
|
|
style={{ width: 80 }}
|
|
/> {t('pages.xray.outboundSub.hours')}
|
|
<InputNumber
|
|
min={0}
|
|
max={59}
|
|
value={intervalMinutes}
|
|
onChange={(v) => setIntervalHM(intervalHours, Number(v) || 0)}
|
|
style={{ width: 80 }}
|
|
/> {t('pages.xray.outboundSub.minutes')}
|
|
</Space>
|
|
<div style={{ fontSize: 12, color: '#888', marginTop: 4 }}>
|
|
{t('pages.xray.outboundSub.intervalHint')}
|
|
</div>
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.enabled')}>
|
|
<Switch checked={newSub.enabled} onChange={(v) => setNewSub({ ...newSub, enabled: v })} />
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.allowPrivate')}>
|
|
<Switch checked={newSub.allowPrivate} onChange={(v) => setNewSub({ ...newSub, allowPrivate: v })} />
|
|
<div style={{ fontSize: 12, color: '#888', marginTop: 4 }}>
|
|
{t('pages.xray.outboundSub.allowPrivateHint')}
|
|
</div>
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.xray.outboundSub.prepend')}>
|
|
<Switch checked={newSub.prepend} onChange={(v) => setNewSub({ ...newSub, prepend: v })} />
|
|
<div style={{ fontSize: 12, color: '#888', marginTop: 4 }}>
|
|
{t('pages.xray.outboundSub.prependHint')}
|
|
</div>
|
|
</Form.Item>
|
|
<Space wrap>
|
|
<Button type="primary" onClick={saveSub} loading={savingSub} icon={editingSubId != null ? <EditOutlined /> : <PlusOutlined />}>
|
|
{editingSubId != null ? t('save') : t('pages.xray.outboundSub.addButton')}
|
|
</Button>
|
|
<Button onClick={previewSub} loading={previewing} icon={<EyeOutlined />}>
|
|
{t('pages.xray.outboundSub.preview')}
|
|
</Button>
|
|
{editingSubId != null && <Button onClick={resetSubForm}>{t('cancel')}</Button>}
|
|
</Space>
|
|
{previewData && previewData.length > 0 && (
|
|
<div style={{ marginTop: 8 }}>
|
|
<div style={{ fontSize: 12, color: '#888', marginBottom: 4 }}>{previewData.length} · {t('pages.xray.Outbounds')}</div>
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4, maxHeight: 120, overflow: 'auto' }}>
|
|
{previewData.map((o, i) => (
|
|
<Tag key={i}>{o?.tag || '—'}{o?.protocol ? ` · ${o.protocol}` : ''}</Tag>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</Form>
|
|
</div>
|
|
|
|
<div>
|
|
<div style={{ fontWeight: 600, marginBottom: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
{t('pages.xray.outboundSub.active')}
|
|
<Button size="small" icon={<ReloadOutlined />} onClick={loadSubs} loading={subsLoading} />
|
|
{subs.length > 0 && (
|
|
<Button size="small" type="primary" icon={<ReloadOutlined />} onClick={refreshAllSubs} loading={refreshingAll}>
|
|
{t('pages.xray.outboundSub.refreshAll')}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
{subs.length === 0 ? (
|
|
<div style={{ color: '#888' }}>{t('pages.xray.outboundSub.empty')}</div>
|
|
) : (
|
|
<Table
|
|
size="small"
|
|
dataSource={subs}
|
|
rowKey={(r) => r.id}
|
|
pagination={false}
|
|
scroll={{ x: true }}
|
|
columns={[
|
|
{
|
|
title: '',
|
|
key: 'order',
|
|
width: 56,
|
|
render: (_: unknown, r: OutboundSub, index: number) => (
|
|
<Space size={0}>
|
|
<Button type="text" size="small" icon={<ArrowUpOutlined />} disabled={index === 0 || busyId === r.id} onClick={() => moveSub(r.id, 'up')} />
|
|
<Button type="text" size="small" icon={<ArrowDownOutlined />} disabled={index === subs.length - 1 || busyId === r.id} onClick={() => moveSub(r.id, 'down')} />
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: t('pages.xray.outboundSub.colRemark'),
|
|
key: 'remark',
|
|
render: (_: unknown, r: OutboundSub) => (
|
|
<div>
|
|
<div>{r.remark || <em>{t('pages.xray.outboundSub.auto')}</em>}</div>
|
|
{r.tagPrefix && <div style={{ fontSize: 11, color: '#888' }}>{r.tagPrefix}</div>}
|
|
</div>
|
|
),
|
|
},
|
|
{ title: t('pages.xray.Outbounds'), dataIndex: 'outboundCount', key: 'outboundCount', align: 'center', render: (v) => v ?? 0 },
|
|
{
|
|
title: t('status'),
|
|
key: 'status',
|
|
align: 'center',
|
|
render: (_: unknown, r: OutboundSub) => (r.lastError
|
|
? <Tooltip title={r.lastError}><WarningOutlined style={{ color: '#e04141' }} /></Tooltip>
|
|
: <Tooltip title={t('pages.xray.outboundSub.statusOk')}><CheckCircleOutlined style={{ color: '#008771' }} /></Tooltip>),
|
|
},
|
|
{ title: t('pages.xray.outboundSub.colLastFetch'), dataIndex: 'lastUpdated', key: 'lastUpdated', render: (v: number) => v ? new Date(v * 1000).toLocaleString() : t('pages.xray.outboundSub.never') },
|
|
{
|
|
title: t('pages.xray.outboundSub.colEnabled'),
|
|
key: 'enabled',
|
|
align: 'center',
|
|
render: (_: unknown, r: OutboundSub) => <Switch size="small" checked={!!r.enabled} loading={busyId === r.id} onChange={() => toggleEnabled(r)} />,
|
|
},
|
|
{
|
|
title: '',
|
|
key: 'actions',
|
|
render: (_: unknown, r: OutboundSub) => (
|
|
<Space>
|
|
<Button size="small" icon={<EditOutlined />} onClick={() => openEditSub(r)} title={t('edit')} />
|
|
<Button size="small" icon={<ReloadOutlined />} loading={refreshingId === r.id} onClick={() => refreshOne(r.id)} title={t('pages.xray.outboundSub.refreshNow')} />
|
|
<Popconfirm title={t('pages.xray.outboundSub.deleteConfirm')} okText={t('delete')} cancelText={t('cancel')} onConfirm={() => deleteOne(r.id)}>
|
|
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
</Popconfirm>
|
|
</Space>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
)}
|
|
<div style={{ marginTop: 8, fontSize: 12, color: '#666' }}>
|
|
{t('pages.xray.outboundSub.restartHint')}
|
|
</div>
|
|
</div>
|
|
</Space>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|