CI / go-test (push) Waiting to run
CI / postgres-durable-first (push) Waiting to run
CI / codegen (push) Waiting to run
CI / govulncheck (push) Waiting to run
CI / race (push) Waiting to run
CI / fuzz-smoke (push) Waiting to run
CI / golangci (push) Waiting to run
CI / frontend (push) Waiting to run
Docs CI / build (push) Waiting to run
Docs Deploy (GitHub Pages) / build (push) Waiting to run
Docs Deploy (GitHub Pages) / deploy (push) Blocked by required conditions
Release 3X-UI / build (386) (push) Waiting to run
Release 3X-UI / build (amd64) (push) Waiting to run
Release 3X-UI / build (arm64) (push) Waiting to run
Release 3X-UI / build (armv5) (push) Waiting to run
Release 3X-UI / build (armv6) (push) Waiting to run
Release 3X-UI / build (armv7) (push) Waiting to run
Release 3X-UI / build (s390x) (push) Waiting to run
Release 3X-UI / Build for Windows (amd64) (push) Waiting to run
Release 3X-UI / Publish rolling dev release (push) Blocked by required conditions
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
- 0: sing-box gen overrides fragment listen/port from the inbound row (empty listen -> "::"), Update/Add recompute the stored fragment; non-loopback E2E against the real core binary. - 1: agent fetches the sing-box core from the Gitea release when missing, self-checks it, and only then latches the switch. - 2: node list shows the sing-box core version (heartbeat field, persisted on the node row), xray version as fallback. - 3: public-page fallback returns 404 to anonymous visitors when the page is disabled. - 4: settings restart hint bar removed, dead i18n keys cleaned. - 5: two PUT calls missing JSON headers fixed (audit: only those two), batch probe-task creation endpoint + UI. - 6: cf-probe retirement card and coverage pipeline removed. - 7: generated vless links no longer carry spx (panel export + sub); parser still accepts spx; golden fixtures updated. - probe batch: dedicated probe settings tab (public-page settings, tasks, per-node meta), retention_days editable, per-node traffic calibration + stat-interface pinning, runtime metrics split into a lightweight fast report (default 3s, 1-60s adjustable). - 8: sing-box core processes start with GOMEMLIMIT=32MiB, GOGC=50. - 9: dead /getTwoFactorEnable docs entries removed (frontend call and contract entry already gone at base; verified by grep).
433 lines
14 KiB
TypeScript
433 lines
14 KiB
TypeScript
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useNavigate } from 'react-router';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import {
|
|
Alert,
|
|
Button,
|
|
Card,
|
|
Checkbox,
|
|
Col,
|
|
ConfigProvider,
|
|
Input,
|
|
Layout,
|
|
Modal,
|
|
Result,
|
|
Row,
|
|
Spin,
|
|
Statistic,
|
|
Typography,
|
|
message,
|
|
} from 'antd';
|
|
import {
|
|
CheckCircleOutlined,
|
|
CloseCircleOutlined,
|
|
CloudServerOutlined,
|
|
ThunderboltOutlined,
|
|
} from '@ant-design/icons';
|
|
|
|
import { useTheme } from '@/hooks/useTheme';
|
|
import { useMediaQuery } from '@/hooks/useMediaQuery';
|
|
import { useNodesQuery } from '@/api/queries/useNodesQuery';
|
|
import type { NodeRecord } from '@/api/queries/useNodesQuery';
|
|
import { useNodeMutations } from '@/api/queries/useNodeMutations';
|
|
import AppSidebar from '@/layouts/AppSidebar';
|
|
import NodeList from './NodeList';
|
|
import NodeFormModal from './NodeFormModal';
|
|
import { setMessageInstance } from '@/utils/messageBus';
|
|
import { HttpUtil } from '@/utils';
|
|
import type { PanelUpdateInfo } from '../index/PanelUpdateModal';
|
|
|
|
// Confirm-dialog body that lets the operator pick the stable or dev channel for
|
|
// a node panel update. Reports changes via onChange so the imperative
|
|
// modal.confirm onOk can read the latest choice through a ref.
|
|
function UpdateChannelChoice({ onChange }: { onChange: (dev: boolean) => void }) {
|
|
const { t } = useTranslation();
|
|
const [dev, setDev] = useState(false);
|
|
return (
|
|
<div>
|
|
<p>{t('pages.nodes.updateConfirmContent')}</p>
|
|
<Checkbox
|
|
checked={dev}
|
|
onChange={(e) => {
|
|
setDev(e.target.checked);
|
|
onChange(e.target.checked);
|
|
}}
|
|
>
|
|
{t('pages.nodes.updateDevChannel')}
|
|
</Checkbox>
|
|
{dev && (
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
style={{ marginTop: 8 }}
|
|
title={t('pages.index.devChannelWarning')}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function NodesPage() {
|
|
const { t } = useTranslation();
|
|
const navigate = useNavigate();
|
|
const { isDark, isUltra, antdThemeConfig } = useTheme();
|
|
const { isMobile } = useMediaQuery();
|
|
const [modal, modalContextHolder] = Modal.useModal();
|
|
const [messageApi, messageContextHolder] = message.useMessage();
|
|
useEffect(() => {
|
|
setMessageInstance(messageApi);
|
|
}, [messageApi]);
|
|
|
|
const { nodes, loading, fetched, fetchError, refetch, totals } = useNodesQuery();
|
|
const {
|
|
create,
|
|
update,
|
|
remove,
|
|
setEnable,
|
|
testConnection,
|
|
fetchFingerprint,
|
|
fetchInbounds,
|
|
probe,
|
|
updatePanels,
|
|
} = useNodeMutations();
|
|
|
|
const { data: latestVersion = '' } = useQuery({
|
|
queryKey: ['server', 'panelUpdateInfo'],
|
|
queryFn: async () => {
|
|
const msg = await HttpUtil.get<PanelUpdateInfo>('/panel/api/server/getPanelUpdateInfo');
|
|
return msg?.obj?.latestVersion || '';
|
|
},
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
|
|
const [formOpen, setFormOpen] = useState(false);
|
|
const [formMode, setFormMode] = useState<'add' | 'edit'>('add');
|
|
const [formNode, setFormNode] = useState<NodeRecord | null>(null);
|
|
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
|
const [mtlsOpen, setMtlsOpen] = useState(false);
|
|
const [trustCa, setTrustCa] = useState('');
|
|
const [copyingCa, setCopyingCa] = useState(false);
|
|
const [savingTrustCa, setSavingTrustCa] = useState(false);
|
|
|
|
const onCopyNodeCa = useCallback(async () => {
|
|
setCopyingCa(true);
|
|
try {
|
|
const msg = await HttpUtil.post<{ caCert: string }>('/panel/api/nodes/mtls/ca');
|
|
const ca = msg?.obj?.caCert;
|
|
if (msg?.success && ca) {
|
|
await navigator.clipboard.writeText(ca);
|
|
messageApi.success(t('pages.nodes.mtls.caCopied'));
|
|
} else {
|
|
messageApi.error(msg?.msg || t('pages.nodes.mtls.caFailed'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('pages.nodes.mtls.caFailed'));
|
|
} finally {
|
|
setCopyingCa(false);
|
|
}
|
|
}, [messageApi, t]);
|
|
|
|
const onSaveTrustCa = useCallback(async () => {
|
|
setSavingTrustCa(true);
|
|
try {
|
|
const msg = await HttpUtil.post('/panel/api/nodes/mtls/trustCA', { caCert: trustCa });
|
|
if (msg?.success) {
|
|
messageApi.success(t('pages.nodes.mtls.saved'));
|
|
setMtlsOpen(false);
|
|
} else {
|
|
messageApi.error(msg?.msg || t('somethingWentWrong'));
|
|
}
|
|
} catch {
|
|
messageApi.error(t('somethingWentWrong'));
|
|
} finally {
|
|
setSavingTrustCa(false);
|
|
}
|
|
}, [trustCa, messageApi, t]);
|
|
|
|
const onAdd = useCallback(() => {
|
|
setFormMode('add');
|
|
setFormNode(null);
|
|
setFormOpen(true);
|
|
}, []);
|
|
|
|
const onEdit = useCallback((node: NodeRecord) => {
|
|
setFormMode('edit');
|
|
setFormNode({ ...node });
|
|
setFormOpen(true);
|
|
}, []);
|
|
|
|
const onSave = useCallback(
|
|
async (payload: Partial<NodeRecord>) => {
|
|
if (formMode === 'edit' && formNode?.id) {
|
|
return update(formNode.id, payload);
|
|
}
|
|
return create(payload);
|
|
},
|
|
[formMode, formNode, update, create],
|
|
);
|
|
|
|
const onDelete = useCallback(
|
|
(node: NodeRecord) => {
|
|
modal.confirm({
|
|
title: t('pages.nodes.deleteConfirmTitle', { name: node.name }),
|
|
content: t('pages.nodes.deleteConfirmContent'),
|
|
okText: t('delete'),
|
|
okType: 'danger',
|
|
cancelText: t('cancel'),
|
|
onOk: async () => {
|
|
const msg = await remove(node.id);
|
|
if (msg?.success) messageApi.success(t('pages.nodes.toasts.deleted'));
|
|
},
|
|
});
|
|
},
|
|
[modal, t, remove, messageApi],
|
|
);
|
|
|
|
const onProbe = useCallback(
|
|
async (node: NodeRecord) => {
|
|
const msg = await probe(node.id);
|
|
if (msg?.success && msg.obj) {
|
|
if (msg.obj.status === 'online') {
|
|
// Even if xray is in error/stop on the node we still reached its panel API.
|
|
messageApi.success(t('pages.nodes.connectionOk', { ms: msg.obj.latencyMs }));
|
|
} else {
|
|
messageApi.error(msg.obj.error || t('pages.nodes.toasts.probeFailed'));
|
|
}
|
|
}
|
|
// Refresh the list so the new xrayState / xrayError (if any) appears immediately in the row.
|
|
refetch();
|
|
},
|
|
[probe, t, messageApi, refetch],
|
|
);
|
|
|
|
const onToggleEnable = useCallback(
|
|
async (node: NodeRecord, next: boolean) => {
|
|
await setEnable(node.id, next);
|
|
},
|
|
[setEnable],
|
|
);
|
|
|
|
const devRef = useRef(false);
|
|
|
|
const runUpdate = useCallback(
|
|
async (ids: number[], dev: boolean) => {
|
|
const msg = await updatePanels(ids, dev);
|
|
if (!msg?.success) {
|
|
messageApi.error(msg?.msg || t('somethingWentWrong'));
|
|
return;
|
|
}
|
|
const results = msg.obj ?? [];
|
|
const ok = results.filter((r) => r.ok).length;
|
|
const failed = results.length - ok;
|
|
if (failed === 0) {
|
|
messageApi.success(t('pages.nodes.toasts.updateStarted'));
|
|
} else {
|
|
const firstError = results.find((r) => !r.ok)?.error ?? '';
|
|
const base = t('pages.nodes.toasts.updateResult', { ok, failed });
|
|
messageApi.warning(firstError ? `${base} — ${firstError}` : base);
|
|
}
|
|
setSelectedIds([]);
|
|
},
|
|
[updatePanels, messageApi, t],
|
|
);
|
|
|
|
const onUpdateNode = useCallback(
|
|
(node: NodeRecord) => {
|
|
// Agent nodes update through the master-recorded intent (item 20):
|
|
// there is no channel to pick, so the confirm is a plain message.
|
|
if (node.nodeType === 'agent') {
|
|
modal.confirm({
|
|
title: t('pages.nodes.updateConfirmTitle', { count: 1 }),
|
|
content: t('pages.nodes.updateAgentConfirmContent'),
|
|
okText: t('update'),
|
|
cancelText: t('cancel'),
|
|
onOk: () => runUpdate([node.id], false),
|
|
});
|
|
return;
|
|
}
|
|
devRef.current = false;
|
|
modal.confirm({
|
|
title: t('pages.nodes.updateConfirmTitle', { count: 1 }),
|
|
content: (
|
|
<UpdateChannelChoice
|
|
onChange={(v) => {
|
|
devRef.current = v;
|
|
}}
|
|
/>
|
|
),
|
|
okText: t('update'),
|
|
cancelText: t('cancel'),
|
|
onOk: () => runUpdate([node.id], devRef.current),
|
|
});
|
|
},
|
|
[modal, t, runUpdate],
|
|
);
|
|
|
|
const onUpdateSelected = useCallback(() => {
|
|
const eligible = nodes
|
|
.filter((n) => selectedIds.includes(n.id) && n.enable && n.status === 'online')
|
|
.map((n) => n.id);
|
|
if (eligible.length === 0) {
|
|
messageApi.warning(t('pages.nodes.toasts.updateNoneEligible'));
|
|
return;
|
|
}
|
|
devRef.current = false;
|
|
modal.confirm({
|
|
title: t('pages.nodes.updateConfirmTitle', { count: eligible.length }),
|
|
content: (
|
|
<UpdateChannelChoice
|
|
onChange={(v) => {
|
|
devRef.current = v;
|
|
}}
|
|
/>
|
|
),
|
|
okText: t('update'),
|
|
cancelText: t('cancel'),
|
|
onOk: () => runUpdate(eligible, devRef.current),
|
|
});
|
|
}, [modal, t, nodes, selectedIds, runUpdate, messageApi]);
|
|
|
|
const pageClass = useMemo(() => {
|
|
const classes = ['nodes-page'];
|
|
if (isDark) classes.push('is-dark');
|
|
if (isUltra) classes.push('is-ultra');
|
|
return classes.join(' ');
|
|
}, [isDark, isUltra]);
|
|
|
|
return (
|
|
<ConfigProvider theme={antdThemeConfig}>
|
|
{messageContextHolder}
|
|
{modalContextHolder}
|
|
<Layout className={pageClass}>
|
|
<AppSidebar />
|
|
|
|
<Layout className="content-shell">
|
|
<Layout.Content id="content-layout" className="content-area">
|
|
<Spin spinning={!fetched} delay={200} description={t('loading')} size="large">
|
|
{!fetched ? (
|
|
<div className="loading-spacer" />
|
|
) : fetchError ? (
|
|
<Result
|
|
status="error"
|
|
title={t('somethingWentWrong')}
|
|
subTitle={fetchError}
|
|
extra={
|
|
<Button type="primary" loading={loading} onClick={() => refetch()}>
|
|
{t('refresh')}
|
|
</Button>
|
|
}
|
|
/>
|
|
) : (
|
|
<Row gutter={[isMobile ? 8 : 16, isMobile ? 8 : 12]}>
|
|
<Col span={24}>
|
|
<Card size="small" hoverable className="summary-card">
|
|
<Row gutter={[16, isMobile ? 16 : 12]}>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.totalNodes')}
|
|
value={String(totals.total)}
|
|
prefix={<CloudServerOutlined />}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.onlineNodes')}
|
|
value={String(totals.online)}
|
|
prefix={
|
|
<CheckCircleOutlined style={{ color: 'var(--ant-color-success)' }} />
|
|
}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.offlineNodes')}
|
|
value={String(totals.offline)}
|
|
prefix={
|
|
<CloseCircleOutlined style={{ color: 'var(--ant-color-error)' }} />
|
|
}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.avgLatency')}
|
|
value={totals.avgLatency > 0 ? `${totals.avgLatency} ms` : '-'}
|
|
prefix={<ThunderboltOutlined />}
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
</Card>
|
|
</Col>
|
|
|
|
<Col span={24}>
|
|
<NodeList
|
|
nodes={nodes}
|
|
loading={loading}
|
|
isMobile={isMobile}
|
|
latestVersion={latestVersion}
|
|
selectedIds={selectedIds}
|
|
onSelectionChange={setSelectedIds}
|
|
onAdd={onAdd}
|
|
onMtls={() => setMtlsOpen(true)}
|
|
onProbeTasks={() => navigate('/settings#probe')}
|
|
onEdit={onEdit}
|
|
onDelete={onDelete}
|
|
onProbe={onProbe}
|
|
onToggleEnable={onToggleEnable}
|
|
onUpdateNode={onUpdateNode}
|
|
onUpdateSelected={onUpdateSelected}
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
)}
|
|
</Spin>
|
|
</Layout.Content>
|
|
</Layout>
|
|
|
|
<NodeFormModal
|
|
open={formOpen}
|
|
mode={formMode}
|
|
node={formNode}
|
|
testConnection={testConnection}
|
|
fetchFingerprint={fetchFingerprint}
|
|
fetchInbounds={fetchInbounds}
|
|
save={onSave}
|
|
onOpenChange={setFormOpen}
|
|
/>
|
|
|
|
<Modal
|
|
open={mtlsOpen}
|
|
title={t('pages.nodes.mtls.title')}
|
|
footer={null}
|
|
onCancel={() => setMtlsOpen(false)}
|
|
destroyOnHidden
|
|
>
|
|
<Typography.Paragraph type="secondary" style={{ marginTop: 0 }}>
|
|
{t('pages.nodes.mtls.intro')}
|
|
</Typography.Paragraph>
|
|
<Button onClick={onCopyNodeCa} loading={copyingCa} style={{ marginBottom: 4 }}>
|
|
{t('pages.nodes.mtls.copyCa')}
|
|
</Button>
|
|
<Typography.Paragraph type="secondary">
|
|
{t('pages.nodes.mtls.copyCaHint')}
|
|
</Typography.Paragraph>
|
|
<Typography.Text strong>{t('pages.nodes.mtls.trustLabel')}</Typography.Text>
|
|
<Input.TextArea
|
|
rows={5}
|
|
value={trustCa}
|
|
onChange={(e) => setTrustCa(e.target.value)}
|
|
placeholder={t('pages.nodes.mtls.trustPlaceholder')}
|
|
style={{ marginTop: 4, fontFamily: 'monospace' }}
|
|
/>
|
|
<Typography.Paragraph type="secondary" style={{ marginTop: 4 }}>
|
|
{t('pages.nodes.mtls.trustHint')}
|
|
</Typography.Paragraph>
|
|
<Button type="primary" onClick={onSaveTrustCa} loading={savingTrustCa} block>
|
|
{t('pages.nodes.mtls.save')}
|
|
</Button>
|
|
</Modal>
|
|
</Layout>
|
|
</ConfigProvider>
|
|
);
|
|
}
|