mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-14 17:15:24 +03:00
71aca2018a
* feat(a11y): label list, toolbar & dashboard actions for screen readers Phase 1 of #5486 (Android TalkBack support). Icon-only controls across the management surfaces previously announced only their untranslated icon name (e.g. "edit", "ellipsis") or nothing at all. - Add aria-label to icon-only row-action and toolbar buttons across inbounds, clients, groups, hosts, nodes and xray (outbounds/routing/dns/balancers) lists, plus the dashboard cards. - Make clickable bare icons and AntD Card actions keyboard-operable via role/tabIndex + Enter/Space (new activateOnKey helper); convert mobile dropdown triggers to buttons so they open from the keyboard. - Fix the sidebar hamburger's mislabeled aria-label (was the dashboard label) and translate previously-hardcoded outbound menu labels. New i18n keys in all 13 locales: sort, menu.openMenu, pages.xray.outbound.moveToTop. * feat(a11y): label modal, QR and copy/download controls for screen readers Phase 2 of #5486. Modal and overlay controls relied on tooltips (not a reliable accessible name) or were bare clickable icons with no keyboard or screen-reader support. - Add aria-label to copy/QR/download/info icon buttons in the inbound and client info modals, sub-links modal, QR panel, backup/log modals, and to the bare search/select inputs of the attach/detach client modals. - Make click-to-copy QR codes and the IP-log refresh/clear, geofile reload and log refresh icons keyboard-operable (role/tabIndex + Enter/Space) with translated labels. - Label the 2FA code input; drop the QrPanel download-image string fallback now that the key exists. New i18n key in all 13 locales: downloadImage. * feat(a11y): label form fields and shared form components for screen readers Phase 3 of #5486. Form controls and shared form widgets were largely unlabelled, and several remove controls were not keyboard-operable. - SettingListItem now ties its title to the control via aria-labelledby, giving accessible names to the ~90 settings-tab inputs at once. - InputAddon gains button semantics (role/tabIndex/Enter+Space) and an ariaLabel prop when used as an interactive remove control. - Sparkline charts expose a role="img" summary of their latest values. - Add aria-label to add/remove/regenerate icon buttons and bare inputs/selects across inbound, client and xray (dns/routing/balancer/ outbound) forms; make clickable remove icons keyboard-operable; mark decorative help/target icons aria-hidden; label the JSON editor, date-time clear button, header-map remove, notification select-all and remark token chips. New i18n keys in all 13 locales: regenerate, jsonEditor, pages.xray.balancer.{costMatch,costValue,costRegexp}. * chore(a11y): add eslint-plugin-jsx-a11y harness and fix flagged interactions Phase 4 of #5486. Adds eslint-plugin-jsx-a11y (recommended ruleset, scoped to .tsx) so screen-reader/keyboard regressions fail lint. - Make the mobile node-card header a proper keyboard disclosure (role=button, aria-expanded, Enter/Space activation that ignores clicks on the nested action buttons) and drop the now-redundant stop-propagation click handlers the linter flagged on card-action wrappers in the node, client and inbound mobile cards. - Disable jsx-a11y/no-autofocus: the autofocus on the login field and modal primary inputs is intentional focus management that helps screen-reader and keyboard users land on the right control. make lint passes with the a11y ruleset enforced. * feat(a11y): cover remaining deferred spots (settings tabs, sockopt, API docs) Completes the panel sweep for #5486 by labelling the spots previously left out of phases 1-4: - NotifyTimeField (Telegram notifications): the mode, interval, unit and custom-cron inputs now carry aria-labels. - The Sockopt toggle in transport options. - Settings category tabs in icons-only (mobile) mode now expose the tab name as the icon's aria-label instead of the raw icon name. - The Swagger API-docs view is wrapped in a labelled region landmark. New i18n keys in all 13 locales: pages.settings.notifyTime.{interval,unit}. * feat(a11y): label shared xray form components and remark field Code review surfaced frontend/src/lib/xray/forms/ — shared form components used by the host and inbound JSON forms — which the initial audit missed. - FinalMaskForm (TCP/UDP final-mask editor): label the icon-only add and regenerate buttons and make all six remove icons keyboard-operable (role/tabIndex/Enter+Space); adds useTranslation to its sub-components. - CustomSockoptList: the remove icon is now keyboard-operable. - SniffingFields: aria-label on the otherwise label-less destOverride select. - RemarkTemplateField: aria-label on the remark-variable picker button. New i18n key in all 13 locales: pages.inbounds.sniffingDestOverride. * feat(a11y): label client info modal and WireGuard config block After rebasing onto the WireGuard client-config feature, re-apply the ClientInfoModal copy/QR/IP-log aria-labels (the modal was restructured upstream, so the original labels did not carry over) and label the new ConfigBlock component's copy/download/QR actions. ConfigBlock's action wrapper keeps its stop-propagation handler (a non-interactive guard for the Collapse header) under a scoped jsx-a11y exception. * fix(frontend): let npm install jsx-a11y under ESLint 10 eslint-plugin-jsx-a11y@6.10.2 declares a peer range that stops at ESLint 9, but the panel is on ESLint 10, so `npm ci` aborts with ERESOLVE even though the plugin runs fine on ESLint 10 with flat config. Add an npm override so jsx-a11y accepts the project's ESLint version. This keeps normal peer resolution (recharts' react-is peer still auto-installs) — no global legacy-peer-deps and no manual react-is pin needed. * fix(a11y): size mobile row triggers and move node expand role to chevron Address automated review on #5652: - add size="small" to the inbound/client/node mobile-card "more" dropdown triggers so they match the adjacent small Switch and the established desktop RowActions pattern. - move the node card-head disclosure semantics (role/tabIndex/aria-expanded/ keyboard) onto the chevron affordance so the expand control is no longer a role="button" wrapping the Switch, info button and dropdown. Mouse click-anywhere-to-expand is preserved on the header div.
258 lines
8.7 KiB
TypeScript
258 lines
8.7 KiB
TypeScript
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button, Checkbox, Form, Input, Modal, Select, Tag } from 'antd';
|
|
import { DownloadOutlined, SyncOutlined } from '@ant-design/icons';
|
|
|
|
import { HttpUtil, FileManager, IntlUtil, PromiseUtil } from '@/utils';
|
|
import { activateOnKey } from '@/utils/a11y';
|
|
import { useDatepicker } from '@/hooks/useDatepicker';
|
|
import { useMediaQuery } from '@/hooks/useMediaQuery';
|
|
import './XrayLogModal.css';
|
|
|
|
interface XrayLogModalProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
interface XrayLogEntry {
|
|
DateTime?: string | number;
|
|
FromAddress?: string;
|
|
ToAddress?: string;
|
|
Inbound?: string;
|
|
Outbound?: string;
|
|
Email?: string;
|
|
Event?: number;
|
|
}
|
|
|
|
const EVENT_LABELS: Record<number, string> = { 0: 'DIRECT', 1: 'BLOCKED', 2: 'PROXY' };
|
|
const EVENT_COLORS: Record<number, string> = { 0: 'green', 1: 'red', 2: 'blue' };
|
|
|
|
function eventLabel(ev?: number): string {
|
|
return EVENT_LABELS[ev ?? -1] ?? String(ev ?? '');
|
|
}
|
|
|
|
function eventColor(ev?: number): string {
|
|
return EVENT_COLORS[ev ?? -1] ?? 'default';
|
|
}
|
|
|
|
function shortTime(value?: string | number): string {
|
|
if (!value) return '';
|
|
const d = new Date(value);
|
|
if (isNaN(d.getTime())) return '';
|
|
const hh = String(d.getHours()).padStart(2, '0');
|
|
const mm = String(d.getMinutes()).padStart(2, '0');
|
|
const ss = String(d.getSeconds()).padStart(2, '0');
|
|
return `${hh}:${mm}:${ss}`;
|
|
}
|
|
|
|
const AUTO_UPDATE_INTERVAL = 5000;
|
|
|
|
export default function XrayLogModal({ open, onClose }: XrayLogModalProps) {
|
|
const { t } = useTranslation();
|
|
const { datepicker } = useDatepicker();
|
|
const { isMobile } = useMediaQuery();
|
|
const [rows, setRows] = useState('20');
|
|
const [filter, setFilter] = useState('');
|
|
const [showDirect, setShowDirect] = useState(true);
|
|
const [showBlocked, setShowBlocked] = useState(true);
|
|
const [showProxy, setShowProxy] = useState(true);
|
|
const [autoUpdate, setAutoUpdate] = useState(false);
|
|
const [loading, setLoading] = useState(false);
|
|
const [logs, setLogs] = useState<XrayLogEntry[]>([]);
|
|
const openRef = useRef(open);
|
|
|
|
const orderedLogs = useMemo(() => [...logs].reverse(), [logs]);
|
|
|
|
const refresh = useCallback(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const msg = await HttpUtil.post<XrayLogEntry[]>(`/panel/api/server/xraylogs/${rows}`, {
|
|
filter,
|
|
showDirect,
|
|
showBlocked,
|
|
showProxy,
|
|
});
|
|
if (msg?.success) setLogs(msg.obj || []);
|
|
await PromiseUtil.sleep(300);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, [rows, filter, showDirect, showBlocked, showProxy]);
|
|
|
|
const refreshRef = useRef(refresh);
|
|
useEffect(() => {
|
|
refreshRef.current = refresh;
|
|
}, [refresh]);
|
|
|
|
useEffect(() => {
|
|
openRef.current = open;
|
|
if (open) refresh();
|
|
}, [open, refresh]);
|
|
|
|
useEffect(() => {
|
|
if (openRef.current) refresh();
|
|
}, [rows, showDirect, showBlocked, showProxy, refresh]);
|
|
|
|
useEffect(() => {
|
|
if (!open || !autoUpdate) return;
|
|
const id = setInterval(() => refreshRef.current(), AUTO_UPDATE_INTERVAL);
|
|
return () => clearInterval(id);
|
|
}, [open, autoUpdate]);
|
|
|
|
function fullDate(value?: string | number): string {
|
|
return IntlUtil.formatDate(value, datepicker);
|
|
}
|
|
|
|
function download() {
|
|
if (!Array.isArray(logs) || logs.length === 0) {
|
|
FileManager.downloadTextFile('', 'x-ui.log');
|
|
return;
|
|
}
|
|
const lines = logs.map((l) => {
|
|
try {
|
|
const dt = l.DateTime ? new Date(l.DateTime) : null;
|
|
const dateStr = dt && !isNaN(dt.getTime()) ? dt.toISOString() : '';
|
|
const eventText = eventLabel(l.Event);
|
|
const emailPart = l.Email ? ` Email=${l.Email}` : '';
|
|
return `${dateStr} FROM=${l.FromAddress || ''} TO=${l.ToAddress || ''} INBOUND=${l.Inbound || ''} OUTBOUND=${l.Outbound || ''}${emailPart} EVENT=${eventText}`.trim();
|
|
} catch {
|
|
return JSON.stringify(l);
|
|
}
|
|
}).join('\n');
|
|
FileManager.downloadTextFile(lines, 'x-ui.log');
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
footer={null}
|
|
width={isMobile ? '100vw' : '80vw'}
|
|
style={isMobile ? { top: 0, paddingBottom: 0, maxWidth: '100vw' } : undefined}
|
|
className={isMobile ? 'xraylog-modal-mobile' : undefined}
|
|
onCancel={onClose}
|
|
title={
|
|
<>
|
|
{t('pages.index.accessLogs')}
|
|
<SyncOutlined spin={loading} className="reload-icon" role="button" tabIndex={0} aria-label={t('refresh')} onClick={refresh} onKeyDown={activateOnKey(refresh)} />
|
|
</>
|
|
}
|
|
>
|
|
<Form layout="inline" className="log-toolbar">
|
|
<Form.Item>
|
|
<Select
|
|
value={rows}
|
|
size="small"
|
|
style={{ width: 70 }}
|
|
onChange={setRows}
|
|
options={[
|
|
{ value: '20', label: '20' },
|
|
{ value: '50', label: '50' },
|
|
{ value: '100', label: '100' },
|
|
{ value: '500', label: '500' },
|
|
{ value: '1000', label: '1000' },
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item label={t('filter')} className="filter-item">
|
|
<Input
|
|
value={filter}
|
|
size="small"
|
|
onChange={(e) => setFilter(e.target.value)}
|
|
onKeyUp={(e) => {
|
|
if (e.key === 'Enter') refresh();
|
|
}}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item>
|
|
<Checkbox checked={showDirect} onChange={(e) => setShowDirect(e.target.checked)}>
|
|
Direct
|
|
</Checkbox>
|
|
<Checkbox checked={showBlocked} onChange={(e) => setShowBlocked(e.target.checked)}>
|
|
Blocked
|
|
</Checkbox>
|
|
<Checkbox checked={showProxy} onChange={(e) => setShowProxy(e.target.checked)}>
|
|
Proxy
|
|
</Checkbox>
|
|
<Checkbox checked={autoUpdate} onChange={(e) => setAutoUpdate(e.target.checked)}>
|
|
{t('pages.index.autoUpdate')}
|
|
</Checkbox>
|
|
</Form.Item>
|
|
<Form.Item className="download-item">
|
|
<Button type="primary" onClick={download} icon={<DownloadOutlined />} aria-label={t('download')} />
|
|
</Form.Item>
|
|
</Form>
|
|
|
|
<div className={`log-container ${isMobile ? 'log-container-mobile' : ''}`}>
|
|
{orderedLogs.length === 0 ? (
|
|
<div className="log-empty">No Record...</div>
|
|
) : isMobile ? (
|
|
orderedLogs.map((log, idx) => (
|
|
<div key={idx} className="log-card">
|
|
<div className="log-card-head">
|
|
<span className="log-time" title={fullDate(log.DateTime)}>
|
|
{shortTime(log.DateTime)}
|
|
</span>
|
|
<Tag color={eventColor(log.Event)} className="log-event-tag">
|
|
{eventLabel(log.Event)}
|
|
</Tag>
|
|
</div>
|
|
<div className="log-route">
|
|
<span className="log-addr">{log.FromAddress}</span>
|
|
<span className="log-arrow">→</span>
|
|
<span className="log-addr">{log.ToAddress}</span>
|
|
</div>
|
|
<div className="log-meta">
|
|
{log.Inbound && (
|
|
<span className="log-meta-pair">
|
|
<span className="log-meta-key">in</span>
|
|
<span className="log-meta-val">{log.Inbound}</span>
|
|
</span>
|
|
)}
|
|
{log.Outbound && (
|
|
<span className="log-meta-pair">
|
|
<span className="log-meta-key">out</span>
|
|
<span className="log-meta-val">{log.Outbound}</span>
|
|
</span>
|
|
)}
|
|
{log.Email && (
|
|
<span className="log-meta-pair">
|
|
<span className="log-meta-key">email</span>
|
|
<span className="log-meta-val">{log.Email}</span>
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))
|
|
) : (
|
|
<table className="xraylog-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>From</th>
|
|
<th>To</th>
|
|
<th>Inbound</th>
|
|
<th>Outbound</th>
|
|
<th>Email</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{orderedLogs.map((log, idx) => (
|
|
<tr key={idx} className={`log-row-${log.Event}`}>
|
|
<td>
|
|
<b>{fullDate(log.DateTime)}</b>
|
|
</td>
|
|
<td>{log.FromAddress}</td>
|
|
<td>{log.ToAddress}</td>
|
|
<td>{log.Inbound}</td>
|
|
<td>{log.Outbound}</td>
|
|
<td>{log.Email}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|