Compare commits

..

70 Commits

Author SHA1 Message Date
claude[bot] fbad71d620 fix: close panics and races the audit's own fixes left nearby
Second-pass review of the 54-commit self-correcting audit. Each item below
was confirmed by reading the surrounding source (and, where practical, the
pre-fix code) before being changed; regression tests are included for every
behavioral fix.

Concurrency:
- eventbus: Bus.Subscribe called wg.Add with no synchronization against a
  concurrent Bus.Stop's wg.Wait, a real "WaitGroup misuse" panic risk (e.g. a
  Telegram-bot settings save racing panel shutdown/restart). Stop now flips a
  mu-guarded `stopped` flag before waiting, and Subscribe checks it under the
  same lock, so Add and Wait can no longer race.

Security:
- login_limiter: evictForRoom's fallback eviction picked an arbitrary map
  key, including ones still under an active cooldown - an attacker flooding
  /login with fresh usernames could evict their own (or anyone's) blocked
  record and reset the lockout. The fallback now skips actively-blocked
  records, only falling back to an unconditional evict if the map is
  somehow entirely full of active blocks (preserves the hard memory cap).

Subscription-endpoint panics (reachable by any client hitting /sub):
- internal/sub/service.go: applyPathAndHostParams/Obj (ws/httpupgrade/xhttp
  with no path settings object) and the TLS alpn readers in three places
  used unchecked type assertions - exactly the bug class abab7cd0 patched
  elsewhere in the same switch statements, just not these call sites.
- internal/sub/json_service.go, clash_service.go: the externalProxy loops
  in the JSON and Clash generators used unchecked assertions on a
  legacy/admin-supplied field (missing "port", non-object entry, etc.).
- internal/sub/json_service.go: realityData's shortId/serverName selection
  could assert a non-string array element.

Other correctness:
- client_traffic.go: ResetAllTraffics (touched by 3eb214d0) still skipped
  clearing NodeClientTraffic node-sync baselines, unlike its sibling reset
  paths in the same file - a node's next sync would re-add pre-reset delta
  on top of the freshly-zeroed counter.
- inbound_traffic.go: the traffic-tick tx's Commit/Rollback errors were
  silently discarded; now logged so a backend-level commit failure (e.g. an
  aborted Postgres tx from a best-effort helper) doesn't masquerade as a
  successful tick.
- outbound_subscription.go: the new subscriptionFetchClient doc comment was
  wedged between fetchAndStore's existing comment and fetchAndStore itself,
  leaving fetchAndStore undocumented and the comment describing the wrong
  function.

Convention cleanup:
- Removed narrative // comments added by the audit that violate this repo's
  no-inline-comment rule (mostly narrating the specific bug/fix rather than
  a lasting contract, and mostly on new Test functions, which this repo's
  existing tests never comment) - calibrated against this exact codebase's
  own pre-existing comment style so legitimate godoc-style doc comments
  were left alone.
2026-07-15 12:00:09 +00:00
MHSanaei a862680645 style(sub): simplify a negated conjunction to satisfy staticcheck QF1001
golangci-lint (staticcheck QF1001) flagged the `!(a && b)` guard in
expandSegment. Rewrite it via De Morgan's law to the equivalent
`!a || !b` form so the linter passes; behavior is unchanged.
2026-07-15 13:34:14 +02:00
MHSanaei 325550e57f fix(frontend): meet WCAG AA contrast on the config-block link text
The Storybook accessibility test flagged the share-link <code> block: with no
explicit color it inherited a muted grey that renders as #888888 on the
#f8f8f8 tertiary-fill background in CI's Chromium — a 3.33:1 contrast, below
the 4.5:1 AA threshold. Set the text to the theme's primary text token so the
colour is explicit and high-contrast in both light and dark themes instead of
depending on an inherited value that varies by browser.
2026-07-15 13:23:41 +02:00
MHSanaei eb769e3f1f fix(frontend): map outbound mobile-card actions through the real index too
The desktop outbounds table was keyed by the outbound's real index, but the
mobile card list was left keying the probe trigger and every test-state
lookup by the positional row index. With a hidden balancer-loopback outbound
present, tapping Check on a mobile card probed the wrong outbound and the
Test-All results landed on the wrong card. Key onTest and the
testResult/isTesting reads by record.key, matching the desktop columns.
2026-07-15 06:29:49 +02:00
MHSanaei 0061892d87 fix(eventbus): deliver events on a bounded per-subscriber worker
The previous fix dispatched each event to every subscriber with a bare
`go safeCall`. That unblocked the dispatch loop, but removed the bus's
backpressure: under a login-attempt flood (which both notifier subscribers
process without rate-limiting) with email/Telegram enabled, every attempt
spawned handler goroutines that each block on network I/O for up to ~30s,
with no bound — a goroutine and outbound-connection storm. It also let a
subscriber's handler run concurrently with itself, racing the Telegram
notifier's lazily-cached hostname.

Give each subscriber its own bounded queue drained by a single worker
goroutine. Dispatch does a non-blocking send per subscriber (dropping only
that subscriber's event when its queue is full), so a slow subscriber still
can't stall the others, concurrency is bounded to one in-flight handler per
subscriber, per-subscriber event order is preserved, and Stop again waits
for in-flight handlers to finish.
2026-07-15 06:27:26 +02:00
MHSanaei eb669e1d83 fix(frontend): don't drift a client's byte quota on a no-op save
The quota field shows the total in GB rounded to two decimals; editing a
client and saving converted that display value straight back to bytes. A
byte total not aligned to 0.01 GB — one set via the API or an import — was
therefore rewritten to the rounded value on any save that never touched the
field, losing a few MB each time.

Add resolveTotalBytes: keep the original byte total when the displayed GB
still matches it, and only re-derive from GB when the user actually changed
the field.
2026-07-15 06:05:37 +02:00
MHSanaei 48b60fec54 fix(frontend): re-sync the sniffing island when its value changes externally
The sniffing config editor froze its seed value at mount and only watched
its own inner AntD form, never reflecting a later change to the shared RHF
`sniffing` path. Because the inbound form mounts every tab with
forceRender, the friendly Sniffing tab and the Advanced JSON editor are live
at once: editing sniffing in the JSON editor updated the RHF value but not
the frozen island, so the next interaction with the friendly tab emitted the
stale value and silently discarded the JSON edit.

Add an effect that pushes an external value change into the inner form,
guarded by the same lastEmitted marker the emit path uses so the island
never re-seeds from its own echo and no update loop forms.
2026-07-15 06:01:33 +02:00
MHSanaei 5f7c2424ef fix(frontend): preserve routing-rule fields the form does not surface
The rule form rebuilt the rule from a fixed literal of only the fields it
edits, and RoutingTab replaces the rule wholesale on confirm. Fields the
form never exposes — localPort, localIP, process, ruleTag, webhook — are in
the rule schema and can arrive via the advanced JSON editor or Import Rules;
opening such a rule in the form and saving silently dropped them.

Carry over every key of the original rule the form does not manage before
applying the form-derived fields, so an edit only touches what it surfaces.
2026-07-15 05:56:58 +02:00
MHSanaei 980c023287 fix(frontend): tolerate a malformed happyEyeballs value in the Xray Basics tab
BasicsTab derived directHappyEyeballs by calling HappyEyeballsSchema.parse
during render, guarding only against null/non-object. A wrong-typed field
(e.g. happyEyeballs.tryDelayMs as a string) or any other shape mismatch —
reachable via the Complete Template JSON editor or an imported config — threw
straight out of render, white-screening the default Xray landing tab.

Use safeParse and fall back to null so a bad value degrades to "no override"
instead of crashing the page.
2026-07-15 05:54:01 +02:00
MHSanaei ebfaad1499 fix(frontend): map outbound row actions through the outbound's real index
The outbounds table hides balancer-loopback outbounds (`_bl_*`) but keeps
each visible row's original index in `key`, then passed antd's positional
row index to edit/delete/move and to the per-row probe (onTest) and its
result lookup — all of which address the full, unfiltered outbounds array.
Once a hidden loopback outbound precedes a visible one, the positional index
diverges from the array index, so deleting or editing an outbound hit the
wrong one (its deletion-impact plan and removal targeting the wrong entry),
and the test button probed / showed results against the wrong outbound.

Add originalOutboundIndex and route the mutating handlers through it; key
the probe trigger and test-result columns by record.key. With no loopback
rows hidden the mapping is the identity, so ordinary configs are unaffected.
2026-07-15 05:51:13 +02:00
MHSanaei 982ab276e8 fix(frontend): map routing row actions through the rule's real index
The routing table hides balancer-loopback rules (`_bl_*`) but keeps each
visible row's original index in `key`, then handed antd's positional row
index straight to edit/delete/toggle/move/drag — all of which mutate the
full, unfiltered routing.rules array. Once a hidden loopback rule precedes a
visible one (e.g. a balancer whose fallback is another balancer, plus any
rule added afterwards), the positional index no longer matches the array
index, so deleting or editing a rule silently hit the wrong one — including
destroying the loopback rule that keeps the balancer alive.

Add originalRuleIndex to translate a positional row index back through the
row's `key`, and route every mutating handler (openEdit, confirmDelete,
toggleRule, moveUp/moveDown, drag) through it. When no loopback rows are
hidden the mapping is the identity, so ordinary configs are unaffected.
2026-07-15 05:42:16 +02:00
MHSanaei 8662c31296 fix(frontend): key the node table by the computed row key, not id
The desktop node table used rowKey="id", but transitive sub-nodes (the
read-only rows surfaced from downstream nodes) all carry id 0, so a topology
with two or more transitive rows gave React duplicate keys. antd's rowKey
prop overrides the row object's own computed `key` (`t-${guid}` for
transitive rows, the numeric id otherwise), so the unique key the code
already builds was ignored — causing row-state/DOM mis-association on any
re-render (heartbeat refetch, address-eye toggle). The mobile card path
already keyed by record.key.

Key the table by "key" so transitive rows get their distinct t-${guid}
identity; direct nodes keep key === id, so row selection (filtered to numeric
keys) is unchanged.
2026-07-15 05:31:42 +02:00
MHSanaei d2ba6c9fc2 fix(frontend): guard the outbounds WebSocket handler against non-array payloads
onOutbounds wrote the raw WebSocket payload straight into the
outboundsTraffic cache, unlike the sibling onNodes/onInbounds handlers which
first check Array.isArray. A malformed non-array push (for example an object)
would land in the cache with staleTime Infinity; consumers that call
.find()/.map() on the outbounds list would then throw and crash the Outbounds
tab. Add the same Array.isArray guard so a bad push is ignored.
2026-07-15 05:17:31 +02:00
MHSanaei 58b88800b4 fix(frontend): share one WebSocket connection across bridge and hooks
websocketBridge.ts and useWebSocket.ts each declared their own
module-scoped sharedClient plus an identical getSharedClient, so the
"shared" client was not shared between them: whenever a page using
useWebSocket (Clients/Inbounds) mounted alongside the always-mounted
bridge, the panel opened two sockets to /ws. The server then pushed every
traffic/stats/nodes/inbounds snapshot to both, doubling WebSocket bandwidth
and running two independent reconnect loops, and the hook's socket was never
disconnected on unmount.

Hoist a single getSharedWebSocketClient into api/websocket.ts and route both
the bridge and the hook through it, so exactly one connection is opened.
2026-07-15 05:15:56 +02:00
MHSanaei ab418a47be fix(frontend): surface backend error text from failed requests
HttpUtil.get/post read the thrown HttpError body as response.data.message,
but the backend error envelope (entity.Msg) serializes its text as msg. On
any non-2xx JSON response the real reason was therefore dropped and the
operator saw only the generic "Request failed with status N" toast.

Read response.data.msg first (keeping message and the native error text as
fallbacks). The sibling test had pinned the wrong body shape ({ message });
correct it to the real backend shape ({ success:false, msg }) so it exercises
the actual envelope.
2026-07-15 05:10:00 +02:00
MHSanaei 46cac582ab fix(frontend): refetch a fresh CSRF token on 403 instead of reusing the stale meta tag
On a 403 to an unsafe method the client cleared its cached CSRF token and
called ensureCsrfToken to retry. But ensureCsrfToken prefers the
<meta name="csrf-token"> tag baked into the page, which the production
panel always injects, so the "refresh" re-read the same stale token and the
/csrf-token refetch was never reached — the retry re-sent the token that had
just been rejected and the save failed with an error toast.

The token lives in the session and rotates when the session is regenerated
(for example re-login in another tab), leaving the tab's baked-in meta token
stale. Fetch the current token straight from /csrf-token in the 403 branch so
the retry uses the authoritative server value. The existing tests only passed
because they strip the meta tag; the new test keeps a stale tag present.
2026-07-15 05:08:00 +02:00
MHSanaei 588a524fa5 fix(tgbot): stop auto-deleted messages from resetting wizard state
SendMsgToTgbotDeleteAfter spawns a goroutine that, after the display delay,
deleted the transient message and then unconditionally cleared the chat's
conversation state. Every caller that ends a wizard step already clears the
state synchronously, so that call was redundant — and harmful: if within
the delay the user advanced to the next step (a callback sets a fresh
awaiting_* state), the late goroutine wiped it, and the user's next message
fell through unrecognized, silently dropping their input.

Move the delayed deletion into deleteMessageAfterDelay, which only removes
the message and no longer touches the conversation state. Guard
deleteMessageTgBot against a nil bot so the deletion path is unit-testable.
2026-07-15 04:54:41 +02:00
MHSanaei 3f7e141d2e fix(server): guard xray key-generator output parsing
GetNewX25519Cert, GetNewmldsa65 and GetNewmlkem768 parsed xray's stdout by
reading lines[0], lines[1] and each line's second colon-separated field
without any length check — unlike GetNewEchCert, which already guards its
line count. If the xray binary printed fewer than two lines or reformatted
its labels (a version change, or a silent failure that emitted nothing),
the fixed slice index panicked and the handler 500'd.

Extract the shared parsing into parseXrayKeyPairOutput, which length guards
the line count and each label split and returns an error instead of
panicking, then route all three generators through it.
2026-07-15 04:47:38 +02:00
MHSanaei 68a981c0c3 fix(server): guard access-log parser against malformed lines
GetXrayLogs split each Xray access-log line on whitespace and then read
fixed offsets — parts[1] for the timestamp and parts[i+1] after the "from",
"accepted" and "email:" markers — without checking the line had that many
fields. A truncated or malformed line (the logged destination is
attacker-influenced) indexed past the slice and panicked; the panel handler
returned a 500 via Gin's recovery.

Extract the per-line field parsing into parseAccessLogFields and length
guard every positional lookup so a short line yields a partial entry
instead of panicking.
2026-07-15 04:44:53 +02:00
MHSanaei a061a0ca87 fix(email): bound every SMTP step with a connection deadline
The "starttls"/"none" transport delivered through net/smtp.SendMail, which
dials with an untimed net.Dial and never sets a socket deadline. When an
SMTP server accepted the TCP connection but then stalled (or was a
blackhole), the caller was released by Send's 30s select, but the sender
goroutine and its socket stayed blocked until the OS TCP timeout — minutes
per notification, leaking a goroutine and a connection each time.
sendWithTLS dialed with a timeout but likewise armed no deadline on the
protocol phase, and TestConnection (called synchronously from the settings
handler, with no select guard) could hang the request indefinitely.

Replace SendMail with sendPlain, which dials with smtpConnectTimeout and
arms conn.SetDeadline(smtpDeadline) before the greeting read, preserving
SendMail's opportunistic STARTTLS upgrade. Arm the same deadline in
sendWithTLS and TestConnection so every SMTP step is bounded.
2026-07-15 04:41:22 +02:00
MHSanaei 61b59bb868 fix(integration): cap WARP API response body size
doWarpRequest read the response with an unbounded io.ReadAll, unlike the
sibling NordVPN client which already caps every read at maxResponseSize.
A hostile panel egress proxy or a MITM on the Cloudflare WARP endpoint
could stream an arbitrarily large body and force the panel into an
unbounded allocation. Wrap the body in an io.LimitReader(maxResponseSize)
to match the NordVPN client.
2026-07-15 04:36:30 +02:00
MHSanaei 66b239da7d fix(eventbus): dispatch each subscriber in its own goroutine
The fan-out loop called every subscriber's handler sequentially on the
single dispatch goroutine. The email and Telegram notifiers block on
network I/O for tens of seconds (or minutes when the remote is slow), so
one slow subscriber stalled the whole loop: the 256-slot channel then
filled and Publish silently dropped later events — including high-value
xray.crash and node.down notifications unrelated to the slow handler.

Hand each delivered event to every handler in its own goroutine so a
blocking subscriber can no longer stall delivery to the others. safeCall
already recovers panics, so a detached handler cannot take down the bus.
2026-07-15 04:34:06 +02:00
MHSanaei 18349c36ac fix(tgbot): require admin for privileged callbacks, not just the first switch
answerCallback wraps only its first callback switch in an isAdmin guard; the
second switch (server usage, inbound/online enumeration, database backup export,
ban logs, mass traffic reset, client creation) ran for every caller. Telegram
delivers a callback with the tapping user's id, so a non-admin who can see an
admin's inline keyboard — as when the bot runs in a group — could tap Backup and
receive the full database and config, or reset all traffic. Default-deny before
the second switch: a non-admin may only run the per-user client_* callbacks that
resolve their own data from their Telegram id.
2026-07-15 04:27:38 +02:00
MHSanaei 0f9099149e fix(security): bound the login-limiter attempts map
The login rate limiter keys its records on the caller-supplied username and only
evicted a record when that exact key was revisited or the login succeeded. An
unauthenticated attacker replaying one CSRF token while rotating a fresh username
per request seeded a record that was never revisited, growing the map without
bound until the panel OOMs. Cap the map: before inserting a new record, reclaim
records whose block has lapsed and whose failures aged out, and if the map is
still at the ceiling under a broad flood, drop one so memory can never grow past
the cap.
2026-07-15 04:11:22 +02:00
MHSanaei 6b89613ad7 fix(security): dial outbound subscriptions through the SSRF guard
The outbound-subscription fetch validated the URL host once (resolving DNS and
rejecting private targets) but then fetched with a plain HTTP client that
re-resolves the host at dial time, so a subscription domain the attacker controls
could pass validation as a public IP and rebind to 127.0.0.1 / a cloud metadata
endpoint / an internal host for the actual dial — a blind SSRF into the panel's
network. Route the direct fetch (and its redirects) through
netsafe.SSRFGuardedDialContext, which resolves, checks and dials the same IP
atomically, carrying the subscription's AllowPrivate flag on the request context;
a configured egress proxy still dials its loopback bridge unguarded.
2026-07-15 04:07:04 +02:00
MHSanaei 9b258becd0 fix(db): mark the IP-limit cleanup seeder done on a fresh install
ResetIpLimitNoFail2ban is a one-time migration that, on a host without fail2ban,
zeroes every existing client's limitIp because the limit can't be enforced. It
was missing from the fresh-install fast-path seeder list, so on a brand-new DB it
did not run on the first boot but fired on the second — wiping any IP limits the
admin had set in between. Add it to the fast-path so a truly fresh install marks
it done up front (there is nothing to clean), leaving later admin-set limits
intact.
2026-07-15 03:52:15 +02:00
MHSanaei 06cd75abe0 fix(settings): detect a wildcard listen collision between the web and sub ports
The web/sub same-port check compared the two listen addresses as raw strings, so
binding both on all interfaces with different spellings (webListen 0.0.0.0 vs an
empty subListen) slipped past validation and only failed at startup with an
opaque bind error. Treat any wildcard listen ('', 0.0.0.0, ::) as overlapping so
the clash is reported up front, while still allowing two distinct specific
addresses to share a port.
2026-07-15 03:48:05 +02:00
MHSanaei f2f11bc042 fix(xray): synchronize the process version and apiPort fields
Start writes p.version and p.apiPort (via refreshVersion/refreshAPIPort) after
flipping the process to running, while GetXrayVersion and GetAPIPort read them
lock-free from the status and traffic poll goroutines. The struct mutex
deliberately excluded these fields, so a restart racing a poll was a real data
race — a torn read of the version string header can crash. Extend the mutex to
cover version and apiPort, doing the blocking version probe before taking the
lock.
2026-07-15 03:33:38 +02:00
MHSanaei 40da7fdb76 fix(xray): retry a failed pending-restart instead of dropping the config change
The 30s cron consumed the need-restart flag with IsNeedRestartAndSetFalse before
calling RestartXray and only logged a failure. If RestartXray failed early (a
transient GetXrayConfig DB error) the old process kept running the old config,
the crash detector saw a running process and never retried, and the flag stayed
cleared — so an admin's saved change silently never reached the core. Move the
consume/restart/retry into ApplyPendingRestart, which re-arms the flag on
failure so the next tick retries.
2026-07-15 03:27:40 +02:00
MHSanaei 116ef900d5 fix(xray): do not revive a manually stopped Xray on a background restart
RestartXray cleared isManuallyStopped unconditionally at its top, so the @30s
pending-config cron (and warp/ldap/outbound reconcile jobs) that call
RestartXray(false) resurrected an Xray the admin had deliberately stopped —
unlike the crash-detector, which honors the manual-stop flag. Skip a non-forced
restart while the stop flag is set; only an explicit forced restart clears it.
2026-07-15 03:24:43 +02:00
MHSanaei 89c27c5835 fix(xray): guard RemoveUser against an uninitialized handler client
Every XrayAPI handler method returns an error when HandlerServiceClient is nil,
except RemoveUser, which dereferenced it directly. A depletion sweep runs Init
with the port ignored and, during a restart window where the fresh process's
api port is still 0, Init fails and leaves the client nil — so RemoveUser
panicked (recovered by the traffic writer, but re-thrown every poll) instead of
returning an error. Add the same nil guard the siblings have.
2026-07-15 03:21:11 +02:00
MHSanaei 8c63f7cc81 fix(xray): keep source- and domains-scoped routing rules when an inbound is deleted
removeInboundTagFromRules drops a routing rule whose inboundTag list becomes
empty only if the rule has no other matcher, but routingMatcherKeys omitted
xray-core's canonical source and domains keys. A rule scoped by source or domains
(common in hand-authored or imported configs) therefore lost its whole body —
including a security-relevant block — when its single listed inbound was deleted,
instead of just having the tag trimmed. Recognize source and domains as live
matchers.
2026-07-15 03:17:33 +02:00
MHSanaei aaf17bcfdc fix(sub): drop empty remark segments instead of leaving a stray separator
expandSegment dropped a "|" segment only when its tokens rendered the unlimited
mark, so a segment whose only token resolved to the empty string (a client with
no comment, an unlimited client's expiry date) was kept as bare decoration,
leaving a trailing "|" or a dangling emoji on every share link's remark. Drop a
token-bearing segment whenever none of its tokens produce a real value, while
still keeping pure-literal segments.
2026-07-15 02:56:42 +02:00
MHSanaei 0a1231d70c fix(ui): stop the sniffing form island from clobbering unrendered fields
antd's Form.useWatch only reports registered fields, so while the
sniffing toggle was off the island emitted { enabled: false } upward and
replaced the full Sniffing object in form state. Saving a VLESS reverse
outbound then crashed in sniffingToWire on the missing ipsExcluded
array; the loopback outbound and the inbound sniffing tab shared the
same hole. Watch the store with preserve: true so unrendered fields
keep their values, and seed a missing value from the schema defaults
instead of an empty cast.
2026-07-15 02:55:52 +02:00
MHSanaei 83de6e75e0 fix(link): honor the vmess ws path and hysteria2 vcn params on import
Two Go/TS parser parity gaps in the outbound share-link import path: parseVmess
only applied a ws link's path when the inner JSON also carried a host key, so a
generator that omits host dropped the path back to the default; and parseHysteria2
hardcoded verifyPeerCertByName to empty, ignoring the vcn param the panel emits,
so a hysteria2 outbound with a decoy SNI and a distinct cert name failed TLS
verification after import. The TS parser handles both; make the Go parser match.
2026-07-15 02:52:09 +02:00
MHSanaei babcf44891 fix(frontend): decode URL-safe base64 when parsing an imported share link
Base64.decode called window.atob directly, which rejects the base64url
alphabet (- and _) and unpadded input. But the panel's own share-link emitter
uses Base64.encode(x, true) (URL-safe, unpadded), and real SIP002 links do too,
so importing a Shadowsocks link whose method:password encodes with a - or _ threw,
fell back to the raw undecoded string, and produced a wrong method and garbage
password (the vmess parser shared the same limitation). Normalize base64url and
re-pad before atob so decode round-trips every emitted link.
2026-07-15 02:49:34 +02:00
MHSanaei e8cf7242a0 fix(link): parse the snake_case and extra-blob xhttp fields when importing a share link
The panel's share-link emitters (Go and TS) carry advanced xhttp knobs as a
snake_case x_padding_bytes plus an extra=<json> payload, but the Go parser's
xhttp branch read only top-level camelCase params, so importing an xhttp link
via the outbound-subscription feature dropped xPaddingBytes, scMaxEachPostBytes
and the rest, silently reverting them to the stream defaults and producing a
non-working outbound. Mirror the TS parser: read the snake_case alias, merge the
extra JSON blob, then let explicit camelCase params win.
2026-07-15 02:45:07 +02:00
MHSanaei 82073c10c9 fix(sub): emit the pinned peer cert sha256 in Clash subscriptions
The Clash stream builder computed tlsSettings["pin-sha256"] from the inbound's
pinnedPeerCertSha256, but applySecurity's tls case never copied it onto the
proxy, so it was written with no reader and silently dropped. Clash subscribers
lost certificate pinning while JSON subscribers kept it. Surface pin-sha256 on
the proxy in the tls case, matching the JSON emitter.
2026-07-15 02:41:49 +02:00
MHSanaei fa4ac3100d fix(sub): tolerate a hysteria inbound without hysteriaSettings in the JSON subscription
genHy asserted stream["hysteriaSettings"].(map[string]any) without the comma-ok
form, so a hysteria inbound whose StreamSettings omit the hysteriaSettings key
(a valid, representable shape the raw generator renders fine) panicked and 500ed
the entire JSON subscription. Use comma-ok; the downstream reads already guard
each key, so a nil map degrades gracefully.
2026-07-15 02:39:40 +02:00
MHSanaei abab7cd000 fix(sub): stop the subscription from 500ing on valid-but-unusual stream settings
The raw share-link generators used unchecked type assertions and unguarded
array indexing: an empty Reality shortIds/serverNames array (random.Num(0)
panics), a tcp-http header with no request block or an empty request.path, a
grpc block missing its keys, empty stream settings, and a non-string Host
header all panicked mid-generation. Because getSubs loops every client's link
with no recover, one such client 500s the entire subscription for everyone. The
sibling JSON, Clash and frontend generators already guard these; make the raw
generators match with comma-ok assertions and length checks.
2026-07-15 02:36:15 +02:00
MHSanaei e4d4ab3a63 fix(traffic): keep node reset propagation out of the serial traffic writer
ResetAllTraffics and ResetInboundTraffic performed their remote-node reset HTTP
calls inside submitTrafficWrite. Each call can block up to the remote timeout,
and Reset All Traffics loops every node serially, so the single traffic-writer
goroutine was held for seconds — long enough that the concurrent 5s traffic poll
timed out submitting its own write and dropped the deltas it had already drained
from xray. Do the DB reset inside the writer, then propagate to the nodes after
it returns, matching how the mtproto quota reset is already sequenced.
2026-07-15 02:13:23 +02:00
MHSanaei 3eb214d022 fix(traffic): re-enable clients and serialize the write in Reset All Client Traffic
ClientService.ResetAllTraffics zeroed up/down but, unlike every sibling reset
path, never restored enable=true, so clients that had been auto-disabled for
exceeding their quota stayed cut with zero usage after a reset. It also wrote
client_traffics directly on the shared DB handle instead of through the serial
traffic writer, reintroducing the cross-transaction lock-order deadlock the
writer exists to prevent. Restore enable and run the reset inside
submitTrafficWrite within one transaction.
2026-07-15 02:08:06 +02:00
MHSanaei b6928f4939 fix(traffic): commit a traffic tick even when a best-effort maintenance helper fails
addTrafficLocked stages the inbound and client deltas, then runs three helpers
(auto-renew, disable depleted clients, disable depleted inbounds) that are meant
to log and continue. All three reused the function-scope err that the deferred
commit/rollback inspects, so the last helper's error decided the whole tick: a
failure in disableInvalidInbounds rolled back the already-staged traffic while
AddTraffic reported success, and because xray had already advanced its counter
baseline that traffic was lost for good. Give each best-effort helper its own
error variable so only a genuine staging failure rolls the tick back.
2026-07-15 02:04:48 +02:00
MHSanaei f7cae8d1cf fix(client): apply enable-by-email to every inbound a client is attached to
ToggleClientEnableByEmail (Telegram bot) and SetClientEnableByEmail (LDAP sync)
resolved a single inbound via the legacy client_traffics pointer and flipped
enable only there. A client attached to several inbounds kept connecting through
the siblings' running Xray after being disabled, and the next edit could
re-enable it everywhere from a stale sibling. Route both through the
applyClientFieldByEmail fan-out (the #5039 fix path) so the whole multi-inbound
identity is toggled at once, dropping the circular Set/Toggle dependency.
2026-07-15 01:46:03 +02:00
MHSanaei c3f0378e68 fix(inbound): request an xray restart when toggling a routed MTProto inbound
AddInbound, DelInbound and UpdateInbound all flag needRestart when an inbound
routes MTProto through xray, so the egress SOCKS bridge is regenerated. Only
SetInboundEnable's local path omitted it, so toggling a routed MTProto inbound
off then on left the bridge out of the running config while the sidecar dialed
its loopback port, blackholing that inbound until an unrelated restart. Flag the
restart on the local enable path too.
2026-07-15 00:14:00 +02:00
MHSanaei 91e1e5eeff fix(client): delete external-link rows when bulk-deleting clients
The single-client Delete path removes a client's client_external_links rows,
but BulkDelete (and the DelDepleted reaper that routes through it) deleted the
record, mappings and traffic while leaving the external-link rows keyed by the
now-dead client id, so they accumulated as orphans. Delete them in the same
cleanup transaction, keyed by client id like the single path.
2026-07-15 00:09:41 +02:00
MHSanaei 781458d878 fix(inbound): defer a local MTProto inbound edit's sidecar push until after commit
UpdateInbound applied a local MTProto inbound change by calling the runtime
UpdateInbound (which stops/starts the mtg sidecar or talks to it) from inside
runSerializedTx. That runs process and network I/O on the single traffic-writer
goroutine while a DB transaction is open, so a slow sidecar stalls traffic
accounting and every concurrent client mutation, and a later step failing the
transaction leaves the sidecar ahead of the rolled-back row. Move the push into
the post-commit hook, matching the xray branch. Adds a SetLocalRuntimeOverride
test seam mirroring the existing node override so the deferral is regression
tested.
2026-07-15 00:06:53 +02:00
MHSanaei 0bbcd2a8f2 fix(client): honor keepTraffic when deleting a client that is attached to inbounds
Delete, DeleteByEmail and BulkDelete all pass keepTraffic to their final
cleanup transaction, but each called the per-inbound delete helper with a
hardcoded false. That helper purges the client's traffic, IP and stat rows
before the gated cleanup runs, so keepTraffic=true still destroyed all
traffic history for any client actually attached to an inbound (the pinned
test only covered a record with no inbound mappings). Thread the caller's
keepTraffic through to the per-inbound helper at all three call sites.
2026-07-14 23:54:48 +02:00
MHSanaei ade3a8f870 fix(client): stop holding the inbound-lock registry mutex while waiting on one inbound
lockInbound acquired the global registry mutex and then blocked on the
per-inbound mutex without releasing the registry first. A slow client
operation holding one inbound's mutex (for example a bulk delete pushing to
an unreachable node) made the next waiter park on that inbound while still
holding the registry mutex, which in turn blocked lockInbound for every
other inbound — freezing client mutations panel-wide. Release the registry
mutex before taking the per-inbound lock.
2026-07-14 23:50:34 +02:00
MHSanaei a77c365fe4 fix(inbound): accept WireGuard clients when creating an inbound
AddInbound's per-client validation switch had cases for every protocol
except WireGuard, so a WireGuard client fell through to the default branch
that requires a non-empty id. WireGuard clients are keyed by their public
key and carry no id, so importing a WireGuard inbound or re-adding one to a
reconciling node was rejected with "empty client ID". Add a wireguard case
that validates the client key, mirroring addInboundClient.
2026-07-14 23:47:43 +02:00
MHSanaei 091dbc0c6e fix(inbound): always create in AddInbound instead of overwriting a row whose id was posted
The add controller binds the inbound model's id form field and never clears
it, and AddInbound persisted with GORM Save, which updates in place when the
primary key is non-zero. A client that reused an existing id (for instance by
duplicating an inbound fetched from /get and changing the port) silently
overwrote that stored row instead of creating a new inbound. Zero the id at
the top of AddInbound, matching how it already zeroes the client-stat ids.
2026-07-14 23:42:44 +02:00
MHSanaei e4ef8a54d4 fix(client): persist a bulk adjustment's applied field even when the sibling field is skipped
In a mixed BulkAdjust (both a days delta and a bytes delta), a per-field
planning skip such as "unlimited expiry" or "unlimited traffic" was recorded
in the same map that gated the client_traffics write. The applied field was
already written to the inbound JSON and the clients table, but the enforcement
row was left untouched, so the depletion job cut the client on the old limit
while the panel showed the new one. Gate the traffic-row write on an actual
inbound-processing failure rather than on any planning-phase skip note.
2026-07-14 23:39:51 +02:00
MHSanaei 7b266a9001 fix(client): refuse a bulk quota reduction that would fall to or below zero
BulkAdjust clamped a client's new traffic limit with max(total+addBytes, 0).
Because 0 is the unlimited sentinel, reducing a client's quota by more than
it had left silently granted that client unlimited traffic. The sibling
expiry branch already refuses an over-reduction; mirror it for quota so the
adjustment is skipped with a clear reason instead of crossing the sentinel.
2026-07-14 23:36:30 +02:00
MHSanaei 448e8c97c2 fix(node): match prefixed central tags when filtering a selected-mode node snapshot
FilterNodeSnapshot compared a node snapshot's inbound tags against the
raw selected-tag list with an exact match, while its two siblings
(SnapshotHasUnadoptedInbounds and the reconcile tagToCentral map) expand
each selected tag to both its bare node-side form and its n<id>- prefixed
central form. A panel-created node inbound is recorded in the selected
list under the central prefixed tag but reported by the node under the
bare tag, so the exact match dropped it from every snapshot and the
orphan sweep then deleted its central row one tick after creation. Expand
the allowed set with the same prefix flip the siblings use.
2026-07-14 23:32:03 +02:00
MHSanaei 52442cb50c fix(sub): fall back to the raw subscription when an auto-detected format has no content
With format auto-detection enabled, a client whose User-Agent matched the
Clash or JSON regex was routed straight to that format handler. For a
subscription whose entries convert to neither format (an MTProto-only
subscription, for example) the handler returns an empty document and the
request ended as 404, breaking a URL that served the raw list before the
toggle. The auto-detect branches now serve the detected format only when
it produces content and otherwise continue to the raw response; the
explicit format endpoints keep answering 404 for empty documents.
2026-07-14 23:07:15 +02:00
MHSanaei 9ffbeb4938 fix(email): report a missing sender address from the SMTP connection test
TestConnection skipped the empty-from guard that Send enforces, so with
no sender and no username configured the test issued the null reverse-path
and could report success against a lenient relay while every real
notification send kept failing with the missing-sender error. Guard the
test path the same way and surface a dedicated translated message.
2026-07-14 23:00:24 +02:00
MHSanaei 97dd724424 fix(email): resolve a name-addr smtpFrom into bare envelope address and display name
The save-time validator accepts any RFC 5322 address form, so a value
like '3x-ui Panel <panel(at)example.com>' passes validation, but Send and
TestConnection fed that raw string to MAIL FROM, which strict servers
reject with 501, and buildMessage mangled it into a quoted local part.
Parse the configured sender at the point of use: the envelope gets the
bare address and, when no explicit sender name is set, the display name
embedded in the setting is used for the From header.
2026-07-14 22:57:26 +02:00
Tomi lla 129f50d92a feat(sub): auto-detect subscription format by User-Agent (Updated) (#5826)
* feat(settings): add subscription format controls

* feat(sub): auto-detect subscription formats

* fix(xray): validate balancer regexes before save

* Revert "fix(xray): validate balancer regexes before save"

This reverts commit 8a208ce71b.

* doc(endpoints): align indent spaces

* doc(settings): improve error message formatting in validateSubUserAgentRegex

- Use NewErrorf with proper formatting instead of NewError with string concatenation
- Add comment explaining the rationale for returning original pattern value
- This preserves the intentional design where empty input is stored as empty
  in the DB and inherited as the runtime default at read time

---------

Co-authored-by: Tomilla <5007859+Tomilla@users.noreply.github.com>
Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-07-14 13:01:40 +02:00
H-TTTTT f2b17397f4 fix(frontend): stabilize speed tags on inbound and client pages (#5930)
* fix(frontend): add shared stable speed-tag style

Give live up/down rate tags a fixed width, centered layout, nowrap,
and tabular numerals so digit/unit changes cannot reflow the Speed column.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>

* fix(frontend): stabilize InboundSpeedTag and ClientSpeedTag layout

Apply the shared speed-tag class/style to both live rate tags and lock
the behavior with a focused component test for small and large rates.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>

* fix(frontend): align speed columns with stable tag width

Widen inbound/client Speed columns to match the fixed tag and apply the
same stable style to idle dash cells so active/idle swaps do not jitter.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>

* fix(frontend): scope stable speed tags to table cells and fit content

---------

Co-authored-by: x06579 <x06579@ai-dashboard>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-07-14 13:00:25 +02:00
Sangeeth Thilakarathna 658e6ab3d3 feat(frontend): show client comments on mobile cards (#5942)
* feat(frontend): show client comments on mobile cards

* fix(frontend): bound mobile comment height

---------

Co-authored-by: sanmaxdev <sanmaxdev@users.noreply.github.com>
2026-07-14 12:59:55 +02:00
Yuri Khachaturyan 1cfd7b49b0 fix(email): build an RFC 5322 message with a proper From address and name (#5941)
The notification/test email carried only From/To/Subject/MIME headers, and
the From header was the raw SMTP username. Two problems:

- When the SMTP login is not a bare email address (common with relays and
  submission services), the From header has no valid address and strict
  receivers reject the message — e.g. Gmail returns "550-5.7.1 ... Messages
  missing a valid address in From: header".
- There was no Date (mandatory per RFC 5322 section 3.6) and no Message-ID,
  which also raises spam score.

Add smtpFrom (sender address) and smtpFromName (display name) settings and
assemble the message with net/mail: a name-addr From ("Name" <addr>), a
Date, a Message-ID, and an RFC 2047 encoded Subject, in a deterministic
header order. From falls back to the username when smtpFrom is empty, so
existing setups keep working. Wire the settings through the model, the SMTP
send and test paths, the Email settings UI, and all 13 locale files;
regenerate the Zod/OpenAPI artifacts.

Validate smtpFrom in AllSetting.CheckValid (reject anything net/mail cannot
parse), which surfaces a bad address at configuration time and prevents CRLF
header injection; strip CR/LF in buildMessage as defense in depth. Add
buildMessage and CheckValid tests.
2026-07-14 12:55:46 +02:00
Matt Van Horn ae0da4c51f fix: stop forcing port 53 on DoH/DoQ DNS server entries (#5950)
Object-form DNS server entries always received port: 53, because
DnsServerObjectInnerSchema defaulted the port unconditionally and the
DnsServerModal wire adapter always wrote it. Per Xray-core, encrypted
schemes must not carry a port field; a non-standard port is embedded in
the URL instead.

Default the port to 53 only for non-encrypted addresses and omit it for
the encrypted DNS schemes Xray dispatches without a port - https,
https+local, h2c, h2c+local and quic+local - both in the Zod schema and
in the modal's valuesToWire adapter. Schemes are matched
case-insensitively to mirror Xray-core's EqualFold comparison. A shared
isEncryptedDnsAddress helper backs both paths.

Fixes #5920

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
2026-07-14 12:55:10 +02:00
Sangeeth Thilakarathna 65b5074b60 fix(script): remove release download time limit (#5952)
* fix(script): remove release download time limit

* fix(script): stop stalled release downloads

---------

Co-authored-by: sanmaxdev <sanmaxdev@users.noreply.github.com>
2026-07-14 12:44:55 +02:00
Mikhail Grigorev b18c87dc4b fix(script): Remove old mtg binary (#5955)
Co-authored-by: Mikhail Grigorev <grigorev_mm@magnit.ru>
2026-07-14 12:44:22 +02:00
MHSanaei b11ceac18e fix(ci): install the docs-pinned pnpm instead of floating on 11.x
pnpm/action-setup resolved 'version: 11' to the newest 11.x, and its self-installer crashes upgrading to 11.12.0 (Cannot use 'in' operator to search for 'integrity'), failing both docs workflows at setup. Reading docs/package.json instead installs the exact packageManager pin (pnpm@11.9.0), which also keeps the workflows and the lockfile toolchain on a single source of truth.
2026-07-14 03:50:16 +02:00
MHSanaei bbc4163768 chore: standardize the toolchain on Node 24 LTS
The repo now pins Node 24 everywhere instead of mixing 22 and hardcoded workflow versions. The docs workflows read .nvmrc like the main CI already did, so the Storybook bundle in the Pages deploy builds on the same runtime as the PR gate. The docs gen:api script runs its TypeScript entry natively, dropping the experimental type-stripping flag that Node 24 makes default; the matching frontend cleanup (engines and gen:api) landed with the Storybook commit.
2026-07-14 03:39:03 +02:00
MHSanaei ee9a6067c2 refactor(frontend): migrate off deprecated Ant Design 6 props
The repo's type-aware deprecation sweep (eslint.deprecated.config.js) reported fourteen findings; it now reports zero. Alert message becomes title and closable+onClose becomes closable.onClose; Select optionFilterProp moves into showSearch.optionFilterProp and suffixIcon becomes suffix; Drawer width becomes size; Progress trailColor becomes railColor. Behavior is unchanged apart from a few single-mode selects gaining type-to-filter, which the old prop already implied.
2026-07-14 03:38:41 +02:00
MHSanaei 60316c831f fix(frontend): resolve every axe accessibility violation in the component library
Running the stories under axe surfaced real panel defects, not just story cosmetics. FormField never associated its Form.Item label with the wrapped control, so no RHF form field in the panel had a programmatic label; it now generates an id and wires htmlFor. Unnamed controls get accessible names: the prompt and text modal inputs (from the modal title), the client traffic progress bar (used/limit values), the CPU and RAM threshold inputs in the notification groups (event label threaded through the extra renderer), and the JSON editor's contenteditable surface.

ConfigBlock's collapse header carried role=button around focusable action buttons; collapsible=header scopes the toggle to the label. Light theme gains contrast-safe tokens shared by the panel and Storybook: darker description, placeholder, error and success text, a darker primary button blue, and a readable gold tag, all meeting the WCAG AA 4.5:1 ratio. The infinity badge swaps a prohibited bare aria-label for role=img.
2026-07-14 03:38:14 +02:00
MHSanaei df3ba568d1 feat(docs): publish the component Storybook on the docs site
The docs site and the component workbench were entirely disconnected. The Pages deploy now builds the frontend Storybook and bundles it into the artifact under /storybook, so the live component reference ships with the documentation, and the navbar links to it. Story changes trigger a redeploy so the published workbench cannot go stale.
2026-07-14 03:37:55 +02:00
MHSanaei 7078abc14a feat(frontend): make Storybook a validated, fully covered component workbench
Storybook existed only as an undocumented local tool: 9 of 24 reusable components had stories, autodocs pages were bare prop tables, nothing built or tested the stories, and no contributor doc mentioned the workbench existed.

Every reusable component under src/components/ now has a co-located story with enriched autodocs (component descriptions plus per-prop argTypes, kept as string metadata since the repo bans line comments). Stories double as headless Chromium tests through the Storybook vitest addon, with axe accessibility checks enforced as errors and play-function interaction tests covering the modals, the RHF field bridge, the config block, and the select-all buttons. The preview now mirrors the panel's real theme DOM (body class, shared AntD theme config, seeded theme storage) so what stories render matches production.

CI and make verify gain a static Storybook build as a compile gate, and the frontend test job installs Chromium so story tests run on every PR. Contributor docs (frontend README, CONTRIBUTING, agent guides) document the workbench, the story conventions, and the Controls setup. Node engines move to 24 LTS and gen:api drops the type-stripping flags that Node 24 makes default.
2026-07-14 03:37:21 +02:00
205 changed files with 7253 additions and 777 deletions
+6
View File
@@ -168,12 +168,18 @@ jobs:
- name: Typecheck
run: npm run typecheck
working-directory: frontend
- name: Install Playwright Chromium (Storybook story tests)
run: npx playwright install --with-deps chromium
working-directory: frontend
- name: Test
run: npm test
working-directory: frontend
- name: Build
run: npm run build
working-directory: frontend
- name: Build Storybook
run: npm run build-storybook
working-directory: frontend
- name: Audit
run: npm audit --audit-level=high
working-directory: frontend
+2 -2
View File
@@ -26,11 +26,11 @@ jobs:
- uses: pnpm/action-setup@v6
with:
version: 11
package_json_file: docs/package.json
- uses: actions/setup-node@v6
with:
node-version: 22
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: docs/pnpm-lock.yaml
+12 -2
View File
@@ -9,6 +9,9 @@ on:
branches: [main]
paths:
- 'docs/**'
- 'frontend/src/components/**'
- 'frontend/.storybook/**'
- 'frontend/package-lock.json'
- '.github/workflows/docs-deploy.yml'
workflow_dispatch:
@@ -32,10 +35,10 @@ jobs:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
with:
version: 11
package_json_file: docs/package.json
- uses: actions/setup-node@v6
with:
node-version: 22
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: docs/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
@@ -52,6 +55,13 @@ jobs:
# in place. That way both /docs/... and /en/docs/... resolve. Other
# locales stay under /fa, /ru, /zh.
run: cp -a out/en/. out/
- name: Build the component Storybook (frontend/)
working-directory: frontend
run: |
npm ci
npm run build-storybook
- name: Bundle Storybook at /storybook
run: cp -a ../frontend/storybook-static out/storybook
- uses: actions/upload-pages-artifact@v5
with:
path: docs/out
+1 -1
View File
@@ -1 +1 @@
22
24
+6 -4
View File
@@ -5,7 +5,7 @@ Thanks for taking the time to contribute to 3x-ui. This guide gets a development
## Prerequisites
- **Go 1.26+** (the version pinned in `go.mod`)
- **Node.js 22+** and npm 10+ (for the React frontend)
- **Node.js 24 LTS** (the version pinned in `.nvmrc`) and npm 10+ (for the React frontend)
- **Git**
- **A C compiler** — required by the CGo SQLite driver (`github.com/mattn/go-sqlite3`). Linux and macOS already ship one; for Windows see below.
@@ -157,12 +157,13 @@ Panel navigation happens client-side through React Router, and per-route code is
Locale strings live in `internal/web/translation/<locale>.json`, **not** under `frontend/`. The Go binary embeds the same JSON and serves it to both backend templates and `react-i18next` (initialized in `src/i18n/react.ts`). When a new English key is added it must also land in **every** non-English locale — missing keys do not break the build, they just render the raw key in the UI.
### Two dev workflows
### Dev workflows
| Goal | Command |
|------|---------|
| Iterate on UI changes with HMR | `cd frontend && npm run dev` (Vite on `:5173`, proxies `/panel/*` and the WebSocket to the Go panel on `:2053`). Start the Go panel first. |
| Verify what end users actually see | `cd frontend && npm run build`, then `go run .`. The Go binary serves the built bundle — embedded in release mode, off disk in debug mode. |
| Develop/preview a reusable component in isolation | `cd frontend && npm run storybook` (Storybook workbench + autodocs on `:6006`). |
The Vite dev proxy serves the admin SPA for any `/panel/*` URL — `bypassMigratedRoute` in `vite.config.js` rewrites those requests to `index.html` and lets React Router take over — while forwarding `/panel/api/*`, `/panel/api/setting/*`, `/panel/api/xray/*`, and the WebSocket to the Go panel. Because routing is now client-side, new panel routes need no proxy or allowlist changes.
@@ -189,6 +190,7 @@ Only a genuinely **standalone bundle** (like `login` or `subpage`, reachable wit
- **Document new endpoints.** Every new `g.POST`/`g.GET` in `internal/web/controller/` needs a matching entry in `src/pages/api-docs/endpoints.ts` — it drives both the in-panel API docs and the generated OpenAPI/Zod (`npm run gen:api` / `gen:zod`).
- **Do not break link generation.** Share-link logic lives in `src/lib/xray/` (`inbound-link.ts`, `outbound-link-parser.ts`, …) and is round-tripped by the golden fixture suite — run `npm run test` after any change to URL generation, defaults, or TLS/Reality handling, and regenerate snapshots (`npx vitest run -u`) only for intentional changes. Two runtime paths consume it: the **inbounds page** and the **clients page** subscription links (`/panel/api/clients/subLinks/:subId` → backend `GetSubs`); exercise both.
- **Vite is pinned to an exact version** (no `^`) in `frontend/package.json` — read the live version there rather than trusting a number quoted here — so local, CI, and release builds resolve identically. Bump it deliberately and verify both `npm run dev` and `npm run build` afterward.
- **Reusable components are documented in Storybook.** When you add or change a component in `frontend/src/components/`, add or update its co-located `<Component>.stories.tsx` (`tags: ['autodocs']`), documenting props via `argTypes` / `parameters.docs` string metadata rather than JSDoc. CI compile-checks every story via `npm run build-storybook` and runs each story as a headless-browser test via `@storybook/addon-vitest` (`npm run test`, needs `npx playwright install chromium`); run `npm run storybook` to preview locally.
### Project layout
@@ -277,7 +279,7 @@ CI runs this for you nightly (and on demand) via `.github/workflows/mutation.yml
### CI
`.github/workflows/ci.yml` runs per PR: `go-test` (with `-shuffle -count=1`), a `race` job (`-race -shuffle -count=1`), a `fuzz-smoke` job on the critical parsers, and the frontend `typecheck`/`lint`/`test`/`build`. Snapshots are regression guards — regenerate them (`npx vitest run -u`) only for intentional output changes, never to make a red test green.
`.github/workflows/ci.yml` runs per PR: `go-test` (with `-shuffle -count=1`), a `race` job (`-race -shuffle -count=1`), a `fuzz-smoke` job on the critical parsers, and the frontend `typecheck`/`lint`/`test`/`build`/`build-storybook`. Snapshots are regression guards — regenerate them (`npx vitest run -u`) only for intentional output changes, never to make a red test green.
## Sending a pull request
@@ -286,7 +288,7 @@ CI runs this for you nightly (and on demand) via `.github/workflows/mutation.yml
3. Run the relevant checks before pushing:
- `go build ./...`
- `go test ./...` (when Go code changed)
- `cd frontend && npm run typecheck && npm run lint && npm run test && npm run build` (when the frontend changed; CI runs this same set on every PR via `.github/workflows/ci.yml`)
- `cd frontend && npm run typecheck && npm run lint && npm run test && npm run build && npm run build-storybook` (when the frontend changed; CI runs this same set on every PR via `.github/workflows/ci.yml`)
4. Commit messages follow the existing pattern in `git log` — `<area>: short imperative summary`, then a body explaining the *why*. Conventional-commit prefixes (`feat`, `fix`, `refactor`, `chore`, `style`, `docs`) are encouraged.
5. Open the PR against `main` with a brief description of what changed and how to test it.
+6 -2
View File
@@ -68,8 +68,12 @@ build-fe: ## Build the Vite bundles into internal/web/dist
build: build-fe ## Build the frontend then the Go binary
go build ./...
.PHONY: build-storybook
build-storybook: ## Build the static Storybook (compile-checks all stories)
cd $(FRONTEND) && npm run build-storybook
# The PR gate. Matches ci.yml: codegen freshness, both linters, typecheck,
# both test suites, and a full build.
# both test suites, a full build, and the Storybook compile-check.
.PHONY: verify
verify: gen-check lint typecheck test build ## Full local gate (mirrors CI)
verify: gen-check lint typecheck test build build-storybook ## Full local gate (mirrors CI)
@echo "verify: OK"
+7 -1
View File
@@ -2,7 +2,7 @@ import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
import { Heart } from 'lucide-react';
import { Logo } from '@/components/logo';
import { TelegramIcon } from '@/components/icons';
import { appName, productRepoUrl, telegramChannel, telegramChannelUrl, donateUrl } from './shared';
import { appName, productRepoUrl, telegramChannel, telegramChannelUrl, donateUrl, siteUrl } from './shared';
import { getSiteMessages } from './site-i18n';
// Build locale-aware shared layout options. With `hideLocale: 'default-locale'`,
@@ -28,6 +28,12 @@ export function baseOptions(lang: string): BaseLayoutProps {
url: `${prefix}/docs`,
active: 'nested-url',
},
// Live component workbench built from frontend/ and published alongside the docs.
{
text: 'Storybook',
url: `${siteUrl}/storybook/`,
external: true,
},
{
type: 'icon',
label: `Telegram channel (@${telegramChannel})`,
+1 -1
View File
@@ -9,7 +9,7 @@
"build": "next build",
"start": "next start",
"postinstall": "fumadocs-mdx",
"gen:api": "node --experimental-strip-types scripts/gen-openapi.ts",
"gen:api": "node scripts/gen-openapi.ts",
"typecheck": "fumadocs-mdx && next typegen && tsc --noEmit",
"lint": "eslint .",
"format": "prettier --write .",
+5 -1
View File
@@ -6,7 +6,11 @@ const config: StorybookConfig = {
options: {},
},
stories: ['../src/**/*.stories.@(ts|tsx)'],
addons: ['@storybook/addon-docs', '@storybook/addon-a11y'],
addons: [
'@storybook/addon-docs',
'@storybook/addon-a11y',
'@storybook/addon-vitest'
],
viteFinal: (viteConfig) => {
if (viteConfig.build) {
viteConfig.build.outDir = undefined;
+6
View File
@@ -0,0 +1,6 @@
<script>
if (localStorage.getItem('dark-mode') === null) localStorage.setItem('dark-mode', 'false');
if (localStorage.getItem('isUltraDarkThemeEnabled') === null) {
localStorage.setItem('isUltraDarkThemeEnabled', 'false');
}
</script>
+9 -2
View File
@@ -1,9 +1,10 @@
import { useEffect } from 'react';
import type { Decorator, Preview } from '@storybook/react-vite';
import { ConfigProvider, theme as antdTheme } from 'antd';
import { ConfigProvider } from 'antd';
import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import { buildAntdThemeConfig } from '@/hooks/useTheme';
import enUS from '../../internal/web/translation/en-US.json';
if (!i18next.isInitialized) {
@@ -19,10 +20,11 @@ if (!i18next.isInitialized) {
const withTheme: Decorator = (Story, context) => {
const dark = context.globals.theme === 'dark';
useEffect(() => {
document.body.setAttribute('class', dark ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
}, [dark]);
return (
<ConfigProvider theme={{ algorithm: dark ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm }}>
<ConfigProvider theme={buildAntdThemeConfig(dark, false)}>
<div style={{ padding: 24, minWidth: 320 }}>
<Story />
</div>
@@ -49,11 +51,16 @@ const preview: Preview = {
},
parameters: {
controls: {
expanded: true,
sort: 'requiredFirst',
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
a11y: {
test: 'error',
},
},
};
+4
View File
@@ -63,5 +63,9 @@ Only standalone bundles (login/subpage) need a new `.html` + `src/entries/*` +
- `npm run typecheck` / `npm run lint` / `npm run test` / `npm run build`.
- `npm run gen` = `gen:zod` (Go → `src/generated/`) + `gen:api`
(`build-openapi.mjs``public/openapi.json`).
- `npm run storybook` (workbench on :6006) / `npm run build-storybook` (CI
compile-checks every story). Reusable `src/components/` get a co-located
`<Component>.stories.tsx` with `tags: ['autodocs']`; document props via
`argTypes` / `parameters.docs` string metadata, never JSDoc.
- After `npm run build`, RESTART `go run .` (see the XUI_DEBUG gotcha in root
CLAUDE.md) before checking the panel.
+36 -3
View File
@@ -36,11 +36,13 @@ production-style links work without round-tripping through Go.
| `npm run lint` | ESLint flat config (`@typescript-eslint` + `react-hooks`) |
| `npm run test` | Vitest single run (schema fixtures, link parsers, …) |
| `npm run test:watch` | Vitest watch mode |
| `npm run storybook` | Storybook dev server on `:6006` (component workbench + autodocs) |
| `npm run build-storybook` | Static Storybook build — CI compile-checks every story |
| `npm run gen:api` | Build `public/openapi.json` from `pages/api-docs/endpoints.ts` |
| `npm run gen:zod` | Run the Go-side openapigen tool → `src/generated/{zod,types}.ts` |
CI runs `typecheck`, `lint`, `test`, and `build` on every PR
(see `../.github/workflows/ci.yml`).
CI runs `typecheck`, `lint`, `test`, `build`, and `build-storybook` on
every PR (see `../.github/workflows/ci.yml`).
### One-off: scan for deprecated APIs
@@ -79,6 +81,7 @@ frontend/
│ # usages of APIs marked with JSDoc @deprecated
├── vitest.config.ts
├── vite.config.js
├── .storybook/ # Storybook config (main.ts, preview.tsx)
├── scripts/
│ └── build-openapi.mjs # endpoints.ts → openapi.json
└── src/
@@ -89,7 +92,7 @@ frontend/
│ ├── index/, login/, inbounds/, clients/, xray/, nodes/,
│ ├── settings/, api-docs/, sub/
├── layouts/ # AdminLayout (sidebar + header + outlet)
├── components/ # Cross-page React components
├── components/ # Cross-page React components (+ co-located *.stories.tsx)
├── hooks/ # useClients, useTheme, useWebSocket, …
├── api/ # fetch client + CSRF handling, TanStack Query bridge,
│ # WebSocket client + queryClient.ts
@@ -187,6 +190,36 @@ npx vitest run -u
Fixtures live in `src/test/golden/fixtures/` and are auto-discovered
via `import.meta.glob`.
## Storybook
Reusable components in `src/components/` are developed and documented in
**Storybook** (`@storybook/react-vite`). It is a component workbench, not part
of the shipped panel — nothing here is embedded into the Go binary. The built
Storybook is published with the docs site at
[docs.sanaei.dev/storybook](https://docs.sanaei.dev/storybook/) by
`.github/workflows/docs-deploy.yml`.
```sh
npm run storybook # dev server on http://localhost:6006
npm run build-storybook # static build; CI runs this to compile-check every story
```
Addons: `@storybook/addon-docs` renders an autodocs page per component,
`@storybook/addon-a11y` flags accessibility issues in the canvas, and
`@storybook/addon-vitest` runs every story as a headless-browser test under
`npm run test` (Playwright/Chromium — run `npx playwright install chromium` once
locally). The `.storybook/preview.tsx` decorator wraps every story in the AntD
`ConfigProvider` and adds a light/dark theme toggle to the toolbar.
Conventions for a story:
- Co-locate it with its component as `<Component>.stories.tsx`.
- Set `tags: ['autodocs']` so it gets a generated docs page.
- Document props via story metadata, not JSDoc (the repo bans `//` comments): a
component summary in `parameters.docs.description.component` and per-prop text
in `argTypes[prop].description`. `satisfies Meta<typeof Component>` keeps the
metadata type-checked.
## Adding a new page
Most new routes go inside the admin SPA (`index.html`) via
+392 -197
View File
File diff suppressed because it is too large Load Diff
+8 -5
View File
@@ -5,7 +5,7 @@
"type": "module",
"description": "3x-ui panel frontend (React 19 + Ant Design 6 + Vite 8).",
"engines": {
"node": ">=22.0.0",
"node": ">=24.0.0",
"npm": ">=10.0.0"
},
"scripts": {
@@ -19,7 +19,7 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"gen": "npm run gen:zod && npm run gen:api",
"gen:api": "node --experimental-strip-types --disable-warning=ExperimentalWarning scripts/build-openapi.mjs",
"gen:api": "node scripts/build-openapi.mjs",
"gen:zod": "cd .. && go run ./tools/openapigen",
"prepare": "cd .. && husky frontend/.husky || true"
},
@@ -34,7 +34,7 @@
"@noble/hashes": "^2.2.0",
"@tanstack/react-query": "^5.101.2",
"@tanstack/react-query-devtools": "^5.101.2",
"antd": "^6.5.0",
"antd": "^6.5.1",
"codemirror": "^6.0.2",
"dayjs": "^1.11.21",
"i18next": "^26.3.6",
@@ -53,6 +53,7 @@
"@eslint/js": "^10.0.1",
"@storybook/addon-a11y": "^10.5.0",
"@storybook/addon-docs": "^10.5.0",
"@storybook/addon-vitest": "^10.5.0",
"@storybook/react-vite": "^10.5.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/react": "^16.3.2",
@@ -71,9 +72,11 @@
"msw": "^2.15.0",
"storybook": "^10.5.0",
"typescript": "^6.0.3",
"typescript-eslint": "^8.63.0",
"typescript-eslint": "^8.64.0",
"vite": "8.1.4",
"vitest": "^4.1.10"
"vitest": "^4.1.10",
"@vitest/browser-playwright": "4.1.10",
"playwright": "^1.61.1"
},
"overrides": {
"eslint-plugin-jsx-a11y": {
+103
View File
@@ -142,6 +142,12 @@
"smtpEncryptionType": {
"type": "string"
},
"smtpFrom": {
"type": "string"
},
"smtpFromName": {
"type": "string"
},
"smtpHost": {
"type": "string"
},
@@ -170,6 +176,9 @@
"subCertFile": {
"type": "string"
},
"subClashAutoDetect": {
"type": "boolean"
},
"subClashEnable": {
"type": "boolean"
},
@@ -185,6 +194,9 @@
"subClashURI": {
"type": "string"
},
"subClashUserAgentRegex": {
"type": "string"
},
"subDomain": {
"type": "string"
},
@@ -206,6 +218,12 @@
"subIncyRoutingRules": {
"type": "string"
},
"subJsonAlwaysArray": {
"type": "boolean"
},
"subJsonAutoDetect": {
"type": "boolean"
},
"subJsonEnable": {
"type": "boolean"
},
@@ -224,6 +242,9 @@
"subJsonURI": {
"type": "string"
},
"subJsonUserAgentRegex": {
"type": "string"
},
"subKeyFile": {
"type": "string"
},
@@ -375,6 +396,8 @@
"smtpEnable",
"smtpEnabledEvents",
"smtpEncryptionType",
"smtpFrom",
"smtpFromName",
"smtpHost",
"smtpMemory",
"smtpPassword",
@@ -383,11 +406,13 @@
"smtpUsername",
"subAnnounce",
"subCertFile",
"subClashAutoDetect",
"subClashEnable",
"subClashEnableRouting",
"subClashPath",
"subClashRules",
"subClashURI",
"subClashUserAgentRegex",
"subDomain",
"subEnable",
"subEnableRouting",
@@ -395,12 +420,15 @@
"subHideSettings",
"subIncyEnableRouting",
"subIncyRoutingRules",
"subJsonAlwaysArray",
"subJsonAutoDetect",
"subJsonEnable",
"subJsonFinalMask",
"subJsonMux",
"subJsonPath",
"subJsonRules",
"subJsonURI",
"subJsonUserAgentRegex",
"subKeyFile",
"subListen",
"subPath",
@@ -575,6 +603,12 @@
"smtpEncryptionType": {
"type": "string"
},
"smtpFrom": {
"type": "string"
},
"smtpFromName": {
"type": "string"
},
"smtpHost": {
"type": "string"
},
@@ -603,6 +637,9 @@
"subCertFile": {
"type": "string"
},
"subClashAutoDetect": {
"type": "boolean"
},
"subClashEnable": {
"type": "boolean"
},
@@ -618,6 +655,9 @@
"subClashURI": {
"type": "string"
},
"subClashUserAgentRegex": {
"type": "string"
},
"subDomain": {
"type": "string"
},
@@ -639,6 +679,12 @@
"subIncyRoutingRules": {
"type": "string"
},
"subJsonAlwaysArray": {
"type": "boolean"
},
"subJsonAutoDetect": {
"type": "boolean"
},
"subJsonEnable": {
"type": "boolean"
},
@@ -657,6 +703,9 @@
"subJsonURI": {
"type": "string"
},
"subJsonUserAgentRegex": {
"type": "string"
},
"subKeyFile": {
"type": "string"
},
@@ -815,6 +864,8 @@
"smtpEnable",
"smtpEnabledEvents",
"smtpEncryptionType",
"smtpFrom",
"smtpFromName",
"smtpHost",
"smtpMemory",
"smtpPassword",
@@ -823,11 +874,13 @@
"smtpUsername",
"subAnnounce",
"subCertFile",
"subClashAutoDetect",
"subClashEnable",
"subClashEnableRouting",
"subClashPath",
"subClashRules",
"subClashURI",
"subClashUserAgentRegex",
"subDomain",
"subEnable",
"subEnableRouting",
@@ -835,12 +888,15 @@
"subHideSettings",
"subIncyEnableRouting",
"subIncyRoutingRules",
"subJsonAlwaysArray",
"subJsonAutoDetect",
"subJsonEnable",
"subJsonFinalMask",
"subJsonMux",
"subJsonPath",
"subJsonRules",
"subJsonURI",
"subJsonUserAgentRegex",
"subKeyFile",
"subListen",
"subPath",
@@ -9247,6 +9303,53 @@
}
}
},
"/panel/api/setting/validateRegex": {
"post": {
"tags": [
"Settings"
],
"summary": "Validate any regular expression with the backend Go RE2 compiler without saving it.",
"operationId": "post_panel_api_setting_validateRegex",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object"
},
"example": {
"regex": "(?m)^general-purpose$"
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"msg": ""
}
}
}
}
}
}
},
"/panel/api/setting/updateUser": {
"post": {
"tags": [
+5 -2
View File
@@ -152,8 +152,11 @@ export async function httpRequest(
if (res.status === 403 && !SAFE_METHODS.has(method.toUpperCase())) {
csrfToken = null;
const fresh = await ensureCsrfToken();
if (fresh) res = await performFetch(method, url, data, options, fresh);
const fresh = await fetchCsrfToken();
if (fresh) {
csrfToken = fresh;
res = await performFetch(method, url, data, options, fresh);
}
}
if (res.status === 401) {
+9
View File
@@ -190,3 +190,12 @@ export class WebSocketClient {
}
}
}
let sharedClient: WebSocketClient | null = null;
export function getSharedWebSocketClient(): WebSocketClient {
if (sharedClient) return sharedClient;
const basePath = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '';
sharedClient = new WebSocketClient(basePath);
return sharedClient;
}
+3 -17
View File
@@ -1,34 +1,19 @@
import { useEffect } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { WebSocketClient } from '@/api/websocket';
import { getSharedWebSocketClient } from '@/api/websocket';
import { keys } from '@/api/queryKeys';
import { isRecentLocalInvalidate } from '@/api/invalidationTracker';
type Handler = (payload: unknown) => void;
interface SharedClient {
connect(): void;
on(event: string, fn: Handler): void;
off(event: string, fn: Handler): void;
}
let sharedClient: SharedClient | null = null;
function getSharedClient(): SharedClient {
if (sharedClient) return sharedClient;
const basePath = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '';
sharedClient = new WebSocketClient(basePath) as SharedClient;
return sharedClient;
}
let invalidateTimer: number | null = null;
export function useWebSocketBridge() {
const queryClient = useQueryClient();
useEffect(() => {
const client = getSharedClient();
const client = getSharedWebSocketClient();
const onInvalidate: Handler = (payload) => {
const p = payload as { type?: string } | undefined;
@@ -46,6 +31,7 @@ export function useWebSocketBridge() {
};
const onOutbounds: Handler = (payload) => {
if (!Array.isArray(payload)) return;
queryClient.setQueryData(keys.xray.outboundsTraffic(), payload);
};
@@ -0,0 +1,14 @@
type ClientCardCommentProps = {
comment?: string;
className?: string;
};
export default function ClientCardComment({ comment, className = 'client-card-comment' }: ClientCardCommentProps) {
if (!comment) return null;
return (
<span className={className} title={comment}>
{comment}
</span>
);
}
@@ -6,6 +6,17 @@ const meta = {
title: 'Clients/ClientSpeedTag',
component: ClientSpeedTag,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'Blue tag showing a live upload/download speed for one client, formatted for readability. Shown next to online clients that have active traffic.',
},
},
},
argTypes: {
speed: { description: 'Live upload/download rate in bytes per second (`{ up, down }`).' },
},
} satisfies Meta<typeof ClientSpeedTag>;
export default meta;
@@ -2,6 +2,7 @@ import { Tag } from 'antd';
import { SizeFormatter } from '@/utils';
import type { ClientSpeedEntry } from '@/hooks/useClients';
import { SPEED_TAG_CLASS_NAME, SPEED_TAG_STYLE } from '@/components/utility/speedTagStyle';
export type { ClientSpeedEntry };
@@ -11,11 +12,16 @@ export function isActiveSpeed(speed?: ClientSpeedEntry): speed is ClientSpeedEnt
interface ClientSpeedTagProps {
speed: ClientSpeedEntry;
tableCell?: boolean;
}
export function ClientSpeedTag({ speed }: ClientSpeedTagProps) {
export function ClientSpeedTag({ speed, tableCell = false }: ClientSpeedTagProps) {
return (
<Tag color="blue">
<Tag
color="blue"
className={tableCell ? SPEED_TAG_CLASS_NAME : undefined}
style={tableCell ? SPEED_TAG_STYLE : undefined}
>
{SizeFormatter.speedFormat(speed.up)}
{' / '}
{SizeFormatter.speedFormat(speed.down)}
@@ -0,0 +1,77 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { ThemeProvider } from '@/hooks/useTheme';
import ClientTrafficCell from './ClientTrafficCell';
const GiB = 1024 ** 3;
const meta = {
title: 'Clients/ClientTrafficCell',
component: ClientTrafficCell,
tags: ['autodocs'],
decorators: [
(Story) => (
<ThemeProvider>
<Story />
</ThemeProvider>
),
],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Traffic usage cell for the clients table: used bytes, a color-coded progress bar, and the quota (or an infinity icon for unlimited clients), with an upload/download/remaining breakdown in a hover popover.',
},
},
},
argTypes: {
up: { description: 'Uploaded bytes counted against the client.' },
down: { description: 'Downloaded bytes counted against the client.' },
total: { description: 'Traffic quota in bytes; 0 or less renders as unlimited.' },
enabled: { description: 'Grays the bar out when the client is disabled.' },
trafficDiff: { description: 'Headroom in bytes below the quota at which the bar shifts from green to orange.' },
compact: { description: 'Smaller bar and tighter layout for dense table rows.' },
},
} satisfies Meta<typeof ClientTrafficCell>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
up: 6 * GiB,
down: 35 * GiB,
total: 100 * GiB,
trafficDiff: 5 * GiB,
},
};
export const Unlimited: Story = {
args: {
up: 87 * GiB,
down: 940 * GiB,
total: 0,
},
};
export const Depleted: Story = {
args: {
up: 9 * GiB,
down: 42 * GiB,
total: 50 * GiB,
trafficDiff: 5 * GiB,
},
};
export const DisabledCompact: Story = {
args: {
up: 2 * GiB,
down: 11 * GiB,
total: 40 * GiB,
enabled: false,
compact: true,
},
};
@@ -64,6 +64,7 @@ export default function ClientTrafficCell({
<span className="client-traffic-cell-used">{SizeFormatter.sizeFormat(display.used)}</span>
<Progress
className="client-traffic-cell-bar"
aria-label={`${SizeFormatter.sizeFormat(display.used)} / ${display.isUnlimited ? t('subscription.unlimited') : SizeFormatter.sizeFormat(total)}`}
percent={display.percent}
showInfo={false}
strokeColor={display.strokeColor}
@@ -72,7 +73,7 @@ export default function ClientTrafficCell({
/>
<span className="client-traffic-cell-limit">
{display.isUnlimited ? (
<span className="client-traffic-cell-infinity" aria-label={t('subscription.unlimited')}>
<span className="client-traffic-cell-infinity" role="img" aria-label={t('subscription.unlimited')}>
<InfinityIcon />
</span>
) : (
@@ -12,6 +12,10 @@
min-width: 0;
}
body.light .config-block .ant-tag.ant-tag-filled.ant-tag-gold {
color: #874d00;
}
.config-block .ant-collapse-extra {
display: flex;
align-items: center;
@@ -34,6 +38,7 @@
word-break: break-all;
white-space: pre-wrap;
padding: 6px 8px;
color: var(--ant-color-text);
background: var(--ant-color-fill-tertiary);
border-radius: 4px;
user-select: all;
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, waitFor } from 'storybook/test';
import ConfigBlock from './ConfigBlock';
@@ -6,7 +7,24 @@ const meta = {
title: 'Clients/ConfigBlock',
component: ConfigBlock,
tags: ['autodocs'],
parameters: { layout: 'padded' },
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Collapsible panel that displays a client config or share link with copy, download, and QR-code actions. Used on the clients and inbounds pages to present generated links.',
},
},
},
argTypes: {
label: { description: 'Protocol/type badge shown on the panel header (e.g. `vless`, `trojan`).' },
text: { description: 'The config or share-link text to display, copy, download, and encode as a QR code.' },
fileName: { description: 'File name used when downloading the text.' },
qrRemark: { description: 'Optional remark embedded in the QR panel; falls back to `label`.' },
showQr: { description: 'Whether to show the QR-code action button.' },
tagColor: { description: 'Ant Design tag color for the header badge.' },
defaultOpen: { description: 'Whether the panel starts expanded.' },
},
} satisfies Meta<typeof ConfigBlock>;
export default meta;
@@ -18,6 +36,15 @@ const sampleLink = 'vless://11112222-3333-4444-5555-666677778888@panel.example.c
export const Collapsed: Story = {
args: { label: 'vless', text: sampleLink, fileName: 'client-config.txt' },
play: async ({ canvas, userEvent }) => {
await expect(canvas.queryByText(/vless:\/\/11112222/)).not.toBeInTheDocument();
await userEvent.click(canvas.getByText('vless'));
const configText = await canvas.findByText(/vless:\/\/11112222/);
await waitFor(() => expect(configText).toBeVisible());
await expect(canvas.getByRole('button', { name: 'Copy' })).toBeVisible();
await expect(canvas.getByRole('button', { name: 'Download' })).toBeVisible();
await expect(canvas.getByRole('button', { name: 'QR Code' })).toBeVisible();
},
};
export const Expanded: Story = {
@@ -68,6 +68,7 @@ export default function ConfigBlock({
{messageContextHolder}
<Collapse
className="config-block"
collapsible="header"
defaultActiveKey={defaultOpen ? ['cfg'] : []}
items={[{
key: 'cfg',
@@ -1,5 +1,6 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, waitFor, within } from 'storybook/test';
import { Button } from 'antd';
import PromptModal from './PromptModal';
@@ -8,6 +9,25 @@ const meta = {
title: 'Feedback/PromptModal',
component: PromptModal,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'Modal that prompts for a single value — a plain input, a multi-line textarea, or a JSON editor. Confirms on Enter (input) or Ctrl+S (textarea) and returns the entered text.',
},
},
},
argTypes: {
open: { description: 'Whether the modal is visible.' },
title: { description: 'Modal title text.' },
okText: { description: 'Confirm button label; defaults to the translated "confirm".' },
type: { description: 'Editor variant: single-line `input` or multi-line `textarea`.' },
initialValue: { description: 'Value pre-filled when the modal opens.' },
loading: { description: 'Shows a loading state on the confirm button.' },
json: { description: 'Render a JSON editor instead of a plain field.' },
onConfirm: { description: 'Called with the entered value on confirm.' },
onClose: { description: 'Called when the modal is dismissed.' },
},
} satisfies Meta<typeof PromptModal>;
export default meta;
@@ -62,9 +82,25 @@ const placeholderArgs = {
export const Input: Story = {
args: placeholderArgs,
render: () => <InputDemo />,
play: async ({ canvas, canvasElement, userEvent }) => {
const body = within(canvasElement.ownerDocument.body);
await userEvent.click(canvas.getByRole('button', { name: 'Rename client' }));
const input = await body.findByRole('textbox');
await userEvent.type(input, 'new-name');
await userEvent.keyboard('{Enter}');
await expect(await canvas.findByText(/Last confirmed: new-name/)).toBeVisible();
},
};
export const Textarea: Story = {
args: placeholderArgs,
render: () => <TextareaDemo />,
play: async ({ canvas, canvasElement, userEvent }) => {
const body = within(canvasElement.ownerDocument.body);
await userEvent.click(canvas.getByRole('button', { name: 'Edit note' }));
const textarea = await body.findByRole('textbox');
await expect(textarea).toHaveValue('line one\nline two');
await userEvent.click(body.getByRole('button', { name: 'Confirm' }));
await waitFor(() => expect(body.queryByRole('dialog')).not.toBeInTheDocument());
},
};
@@ -72,6 +72,7 @@ export default function PromptModal({
) : type === 'textarea' ? (
<Input.TextArea
ref={(el) => { textareaRef.current = (el as unknown as { resizableTextArea?: { textArea: HTMLTextAreaElement } })?.resizableTextArea?.textArea ?? null; }}
aria-label={title}
value={value}
onChange={(e) => setValue(e.target.value)}
autoSize={{ minRows: 10, maxRows: 20 }}
@@ -80,6 +81,7 @@ export default function PromptModal({
) : (
<Input
ref={inputRef}
aria-label={title}
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyDown={onKeydown}
@@ -1,5 +1,6 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, waitFor, within } from 'storybook/test';
import { Button } from 'antd';
import TextModal from './TextModal';
@@ -8,6 +9,23 @@ const meta = {
title: 'Feedback/TextModal',
component: TextModal,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'Read-only modal for viewing generated text or JSON — a client config, subscription, or exported settings — with copy and optional download actions, plus optional tabs for multiple documents.',
},
},
},
argTypes: {
open: { description: 'Whether the modal is visible.' },
title: { description: 'Modal title text.' },
content: { description: 'Text shown when no `tabs` are provided.' },
fileName: { description: 'When set, adds a download button that saves the active content under this name.' },
json: { description: 'Render the content in a read-only JSON editor with syntax highlighting.' },
tabs: { description: 'Optional list of `{ key, label, content }` documents shown as tabs.' },
onClose: { description: 'Called when the modal is dismissed.' },
},
} satisfies Meta<typeof TextModal>;
export default meta;
@@ -43,6 +61,13 @@ const placeholderArgs = {
export const PlainText: Story = {
args: placeholderArgs,
render: () => <Demo fileName="client.txt" />,
play: async ({ canvas, canvasElement, userEvent }) => {
const body = within(canvasElement.ownerDocument.body);
await userEvent.click(canvas.getByRole('button', { name: 'Show config' }));
const content = await body.findByDisplayValue(/vless:\/\/uuid@example\.com/);
await waitFor(() => expect(content).toBeVisible());
await expect(body.getByRole('button', { name: /client\.txt/ })).toBeEnabled();
},
};
export const Json: Story = {
@@ -75,6 +75,7 @@ export default function TextModal({ open, onClose, title, content, fileName = ''
<JsonEditor value={activeContent} readOnly minHeight="240px" maxHeight="60vh" />
) : (
<Input.TextArea
aria-label={title}
value={activeContent}
readOnly
autoSize={{ minRows: 10, maxRows: 20 }}
@@ -0,0 +1,96 @@
import { useEffect, useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Typography } from 'antd';
import dayjs from 'dayjs';
import type { Dayjs } from 'dayjs';
import { setDatepicker } from '@/hooks/useDatepicker';
import { ThemeProvider } from '@/hooks/useTheme';
import DateTimePicker from './DateTimePicker';
setDatepicker('gregorian');
function ClientExpiryDemo() {
const [value, setValue] = useState<Dayjs | null>(dayjs('2026-12-31 23:59:59'));
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<DateTimePicker value={value} onChange={setValue} placeholder="Expiry date" />
<Typography.Text type="secondary">
{value ? `user1@node-de expiryTime: ${value.valueOf()}` : 'user1@node-de expiryTime: 0 (never expires)'}
</Typography.Text>
</div>
);
}
function JalaliDemo() {
const [value, setValue] = useState<Dayjs | null>(dayjs('2026-12-31 23:59:59'));
useEffect(() => {
setDatepicker('jalalian');
return () => setDatepicker('gregorian');
}, []);
return <DateTimePicker value={value} onChange={setValue} placeholder="Expiry date" />;
}
const meta = {
title: 'Form/DateTimePicker',
component: DateTimePicker,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Calendar-aware date/time picker used for client and inbound expiry dates. Renders an AntD DatePicker by default and switches to a Persian (Jalali) calendar — with theme-matched colors and an overlaid clear button — when the panel datepicker setting is jalalian.',
},
},
},
decorators: [
(Story) => (
<ThemeProvider>
<Story />
</ThemeProvider>
),
],
argTypes: {
value: { description: 'Selected moment as a Dayjs instance, or null when unset.' },
onChange: { description: 'Called with the picked Dayjs value, or null when cleared.' },
showTime: { description: 'Include an hour/minute/second selector alongside the date.' },
format: { description: 'Display format for the Gregorian picker input.' },
placeholder: { description: 'Input placeholder shown while no value is set.' },
disabled: { description: 'Disables the input and hides the clear button.' },
},
} satisfies Meta<typeof DateTimePicker>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Empty: Story = {
args: {
value: null,
onChange: () => undefined,
placeholder: 'Leave blank to never expire',
},
};
export const ClientExpiry: Story = {
args: { value: null, onChange: () => undefined },
render: () => <ClientExpiryDemo />,
};
export const DateOnly: Story = {
args: {
value: dayjs('2026-08-01'),
onChange: () => undefined,
showTime: false,
format: 'YYYY-MM-DD',
placeholder: 'Start date',
},
};
export const JalaliCalendar: Story = {
args: { value: null, onChange: () => undefined },
parameters: { docs: { disable: true } },
render: () => <JalaliDemo />,
};
@@ -0,0 +1,63 @@
import { useRef, useState } from 'react';
import { Input, Typography } from 'antd';
import { HttpUtil } from '@/utils';
interface GoRegexInputProps {
value: string;
ariaLabel?: string;
placeholder?: string;
maxLength?: number;
onChange: (value: string) => void;
externalError?: string;
}
export async function validateGoRegex(value: string): Promise<string> {
const result = await HttpUtil.post(
'/panel/api/setting/validateRegex',
{ regex: value },
{ silent: true },
);
return result.success ? '' : result.msg || 'Invalid Go RE2 regular expression';
}
export default function GoRegexInput({
value,
ariaLabel,
placeholder,
maxLength = 2048,
onChange,
externalError,
}: GoRegexInputProps) {
const [error, setError] = useState('');
const validationSequence = useRef(0);
async function validate() {
const sequence = ++validationSequence.current;
const nextError = await validateGoRegex(value);
if (sequence === validationSequence.current) {
setError(nextError);
}
}
const displayError = externalError ?? error;
return (
<div style={{ width: '100%' }}>
<Input
value={value}
aria-label={ariaLabel}
placeholder={placeholder}
maxLength={maxLength}
status={displayError ? 'error' : undefined}
onChange={(event) => {
validationSequence.current += 1;
setError('');
onChange(event.target.value);
}}
onBlur={() => void validate()}
/>
{displayError && <Typography.Text type="danger">{displayError}</Typography.Text>}
</div>
);
}
@@ -0,0 +1,76 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import HeaderMapEditor, { type HeaderMapValue } from './HeaderMapEditor';
const meta = {
title: 'Form/HeaderMapEditor',
component: HeaderMapEditor,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Row-based editor for Xray HTTP header maps, used in the inbound/outbound stream forms. Mode `v1` emits one string per header name (WS / HTTPUpgrade / Hysteria masquerade); mode `v2` emits string arrays so headers can repeat (TCP HTTP camouflage request/response).',
},
},
},
argTypes: {
mode: { description: 'Wire shape: `v1` = string per name, `v2` = string[] per name (repeatable headers).' },
value: { description: 'Header map in the wire shape matching `mode`; converted to editable rows internally.' },
onChange: { description: 'Called with the rebuilt wire-shape map after every row edit, add, or remove.' },
},
} satisfies Meta<typeof HeaderMapEditor>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Empty: Story = {
args: { mode: 'v1', onChange: () => undefined },
};
export const WsHostHeaders: Story = {
args: {
mode: 'v1',
value: {
Host: 'cdn.example.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
},
onChange: () => undefined,
},
};
export const TcpCamouflageRequest: Story = {
args: {
mode: 'v2',
value: {
Accept: ['text/html,application/xhtml+xml', 'application/json'],
'Accept-Encoding': ['gzip, deflate'],
Connection: ['keep-alive'],
Pragma: ['no-cache'],
},
onChange: () => undefined,
},
};
function WireShapeDemo() {
const [value, setValue] = useState<HeaderMapValue>({
Accept: ['text/html', 'application/json'],
'X-Forwarded-For': ['203.0.113.7'],
});
return (
<div style={{ maxWidth: 560 }}>
<HeaderMapEditor mode="v2" value={value} onChange={setValue} />
<pre style={{ marginTop: 16, padding: 12, borderRadius: 8, background: 'rgba(128, 128, 128, 0.12)' }}>
{JSON.stringify(value ?? {}, null, 2)}
</pre>
</div>
);
}
export const LiveWireShape: Story = {
args: { mode: 'v2', onChange: () => undefined },
render: () => <WireShapeDemo />,
};
@@ -0,0 +1,132 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Typography } from 'antd';
import { ThemeProvider } from '@/hooks/useTheme';
import JsonEditor from './JsonEditor';
const warpOutbound = JSON.stringify(
{
tag: 'warp-out',
protocol: 'wireguard',
settings: {
secretKey: 'yFXfmXX3Zn5tnpNJ7HAcbLvqcMVioqPDGV1GXn2FeV0=',
address: ['172.16.0.2/32', '2606:4700:110:8f81::2/128'],
peers: [
{
publicKey: 'bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=',
allowedIPs: ['0.0.0.0/0', '::/0'],
endpoint: 'engage.cloudflareclient.com:2408',
},
],
mtu: 1280,
},
},
null,
2,
);
const realityStreamSettings = JSON.stringify(
{
network: 'tcp',
security: 'reality',
realitySettings: {
show: false,
dest: 'yahoo.com:443',
xver: 0,
serverNames: ['yahoo.com', 'www.yahoo.com'],
privateKey: 'wLc4dpQvRt8mK1nS9jH2fXaU7yEoB3iZ6vNqTgCkW5A',
shortIds: ['6ba85179e30d4fc2'],
},
},
null,
2,
);
const brokenInboundSettings = [
'{',
' "clients": [',
' {',
' "id": "9f4c3a2b-7d61-4e8a-b5c0-1f2e3d4a5b6c",',
' "email": "user1@node-de",',
' "flow": "xtls-rprx-vision",',
' }',
' ],',
' "decryption": "none"',
].join('\n');
function ControlledDemo() {
const [value, setValue] = useState(warpOutbound);
let parseError = '';
try {
JSON.parse(value);
} catch (err) {
parseError = err instanceof Error ? err.message : String(err);
}
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<JsonEditor value={value} onChange={setValue} minHeight="220px" maxHeight="360px" />
<Typography.Text type={parseError ? 'danger' : 'success'}>
{parseError ? `Parse error: ${parseError}` : `Valid JSON (${value.length} chars)`}
</Typography.Text>
</div>
);
}
const meta = {
title: 'Form/JsonEditor',
component: JsonEditor,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'CodeMirror-based JSON editor with syntax highlighting, live parse linting, and theme-aware styling. The panel uses it for raw xray config snippets — inbound settings, stream settings, and outbound JSON in the modals and settings pages.',
},
},
},
decorators: [
(Story) => (
<ThemeProvider>
<Story />
</ThemeProvider>
),
],
argTypes: {
value: { description: 'JSON document text; the editor resyncs when this prop changes.' },
onChange: { description: 'Called with the full document text on every edit.' },
minHeight: { description: 'CSS min-height of the scrollable editor area.' },
maxHeight: { description: 'CSS max-height before the editor scrolls internally.' },
readOnly: { description: 'Disables editing while keeping selection and scrolling.' },
},
} satisfies Meta<typeof JsonEditor>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: { value: warpOutbound },
};
export const ReadOnly: Story = {
args: { value: realityStreamSettings, readOnly: true, minHeight: '200px' },
};
export const LintErrors: Story = {
args: { value: brokenInboundSettings, minHeight: '220px' },
};
export const Controlled: Story = {
args: { value: '' },
parameters: {
a11y: {
config: {
rules: [{ id: 'scrollable-region-focusable', enabled: false }],
},
},
},
render: () => <ControlledDemo />,
};
@@ -120,6 +120,7 @@ const JsonEditor = forwardRef<JsonEditorHandle, JsonEditorProps>(function JsonEd
doc: value,
extensions: [
basicSetup,
EditorView.contentAttributes.of({ 'aria-label': t('jsonEditor') }),
keymap.of([indentWithTab]),
json(),
linter(jsonParseLinter()),
@@ -0,0 +1,68 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import RemarkTemplateField from './RemarkTemplateField';
const meta = {
title: 'Form/RemarkTemplateField',
component: RemarkTemplateField,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Text input augmented with a {{VAR}} token picker (insert-at-caret) and a live sample-based preview of the expanded remark. The panel uses it in subscription settings for the global Remark Template.',
},
},
},
argTypes: {
value: { description: 'Current template string; any {{VAR}} token enables the live preview below the input.' },
onChange: { description: 'Called with the updated template on typing or token insertion.' },
maxLength: { description: 'Maximum template length; picker insertions are clamped to it.' },
placeholder: { description: 'Placeholder shown while the template is empty.' },
},
} satisfies Meta<typeof RemarkTemplateField>;
export default meta;
type Story = StoryObj<typeof meta>;
function InteractiveDemo() {
const [value, setValue] = useState('{{STATUS_EMOJI}} {{INBOUND}}-{{EMAIL}} | {{TRAFFIC_LEFT}}');
return <RemarkTemplateField value={value} onChange={setValue} maxLength={256} placeholder="{{INBOUND}}-{{EMAIL}}" />;
}
export const Empty: Story = {
args: {
value: '',
onChange: () => undefined,
placeholder: '{{INBOUND}}-{{EMAIL}}',
},
};
export const TokenTemplate: Story = {
args: {
value: '{{INBOUND}}-{{EMAIL}} | {{TRAFFIC_LEFT}} left | {{DAYS_LEFT}}d',
onChange: () => undefined,
maxLength: 256,
placeholder: '{{INBOUND}}-{{EMAIL}}',
},
};
export const PlainRemark: Story = {
args: {
value: 'Germany CDN node',
onChange: () => undefined,
maxLength: 256,
placeholder: '{{INBOUND}}-{{EMAIL}}',
},
};
export const Interactive: Story = {
args: {
value: '',
onChange: () => undefined,
},
render: () => <InteractiveDemo />,
};
@@ -0,0 +1,78 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Button, Input, Popover, Typography } from 'antd';
import { previewRemark, wrapToken } from '@/lib/remark/remarkVariables';
import RemarkVarPicker from './RemarkVarPicker';
const meta = {
title: 'Form/RemarkVarPicker',
component: RemarkVarPicker,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Grouped, tooltipped chip list of the {{VAR}} tokens the backend substitutes per client in subscription remarks. The hosts page shows it in a popover beside the remark-template field so operators can insert placeholders like {{EMAIL}} or {{TRAFFIC_LEFT}}.',
},
},
},
argTypes: {
onPick: { description: 'Called with the bare token (e.g. "EMAIL") when a chip is clicked or activated via keyboard.' },
},
} satisfies Meta<typeof RemarkVarPicker>;
export default meta;
type Story = StoryObj<typeof meta>;
function TemplateBuilderDemo() {
const [template, setTemplate] = useState('{{INBOUND}}-{{EMAIL}} {{STATUS_EMOJI}} {{TRAFFIC_LEFT}} left');
return (
<div style={{ maxWidth: 520 }}>
<Input
value={template}
onChange={(e) => setTemplate(e.target.value)}
aria-label="Remark template"
style={{ fontFamily: 'monospace' }}
/>
<Typography.Paragraph type="secondary" style={{ margin: '8px 0 16px' }}>
Preview: {previewRemark(template)}
</Typography.Paragraph>
<RemarkVarPicker onPick={(token) => setTemplate((prev) => `${prev}${wrapToken(token)}`)} />
</div>
);
}
function PopoverDemo() {
const [lastPicked, setLastPicked] = useState('');
return (
<>
<Popover
content={<RemarkVarPicker onPick={(token) => setLastPicked(wrapToken(token))} />}
trigger="click"
placement="bottomRight"
title="Remark variables"
>
<Button>Insert variable</Button>
</Popover>
<div style={{ marginTop: 12 }}>Last picked: {lastPicked || '—'}</div>
</>
);
}
export const Default: Story = {
args: { onPick: () => undefined },
};
export const TemplateBuilder: Story = {
args: { onPick: () => undefined },
render: () => <TemplateBuilderDemo />,
};
export const InsidePopover: Story = {
args: { onPick: () => undefined },
render: () => <PopoverDemo />,
};
@@ -0,0 +1,132 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect } from 'storybook/test';
import { Select } from 'antd';
import SelectAllClearButtons from './SelectAllClearButtons';
const inboundOptions: Array<{ value: number; label: string }> = [
{ value: 1, label: 'VLESS Reality — 443' },
{ value: 2, label: 'VMess WS — 8443' },
{ value: 3, label: 'Trojan TCP — 2053' },
{ value: 4, label: 'Shadowsocks — 8388' },
];
const clientEmailOptions: Array<{ value: string; label: string }> = [
{ value: 'ava@corp.example', label: 'ava@corp.example' },
{ value: 'reza.mobile', label: 'reza.mobile' },
{ value: 'office-tv', label: 'office-tv' },
{ value: 'guest-42', label: 'guest-42' },
];
const meta = {
title: 'Form/SelectAllClearButtons',
component: SelectAllClearButtons,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Small "Select all" / "Clear all" button pair rendered above a multi-select. The panel places it over the attached-inbounds picker in the client form and the bulk attach/detach modals.',
},
},
},
argTypes: {
options: { description: 'Option list whose values define the "all" set; matches the AntD Select option shape.' },
value: { description: 'Currently selected values (controlled).' },
onChange: { description: 'Called with the union of the current selection and every option value, or with an empty array on clear.' },
selectAllLabel: { description: 'Override for the "Select all" button text; defaults to the translated inbound copy.' },
clearLabel: { description: 'Override for the "Clear all" button text; defaults to the translated inbound copy.' },
},
} satisfies Meta<typeof SelectAllClearButtons>;
export default meta;
type Story = StoryObj<typeof meta>;
function InboundPickerDemo() {
const [selected, setSelected] = useState<number[]>([1]);
return (
<div style={{ maxWidth: 360 }}>
<SelectAllClearButtons options={inboundOptions} value={selected} onChange={setSelected} />
<Select
mode="multiple"
style={{ width: '100%' }}
value={selected}
onChange={setSelected}
options={inboundOptions}
placeholder="Select inbounds"
aria-label="Select inbounds"
maxTagCount="responsive"
/>
</div>
);
}
function ClientEmailsDemo() {
const [selected, setSelected] = useState<string[]>(['ava@corp.example']);
return (
<div style={{ maxWidth: 360 }}>
<SelectAllClearButtons
options={clientEmailOptions}
value={selected}
onChange={setSelected}
selectAllLabel="Select all clients"
clearLabel="Deselect clients"
/>
<Select
mode="multiple"
style={{ width: '100%' }}
value={selected}
onChange={setSelected}
options={clientEmailOptions}
placeholder="Select clients"
aria-label="Select clients"
maxTagCount="responsive"
/>
</div>
);
}
const placeholderArgs = {
options: [],
value: [],
onChange: () => undefined,
};
export const PartiallySelected: Story = {
args: {
options: [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }],
value: [1, 3],
onChange: () => undefined,
},
};
export const AllSelected: Story = {
args: {
options: [{ value: 1 }, { value: 2 }, { value: 3 }],
value: [1, 2, 3],
onChange: () => undefined,
},
};
export const WithInboundSelect: Story = {
args: placeholderArgs,
render: () => <InboundPickerDemo />,
};
export const CustomLabels: Story = {
args: placeholderArgs,
render: () => <ClientEmailsDemo />,
play: async ({ canvas, userEvent }) => {
const selectAll = canvas.getByRole('button', { name: 'Select all clients' });
const clearAll = canvas.getByRole('button', { name: 'Deselect clients' });
await expect(selectAll).toBeEnabled();
await userEvent.click(selectAll);
await expect(selectAll).toBeDisabled();
await userEvent.click(clearAll);
await expect(clearAll).toBeDisabled();
await expect(selectAll).toBeEnabled();
},
};
+1
View File
@@ -1,6 +1,7 @@
export { default as DateTimePicker } from './DateTimePicker';
export { default as JsonEditor } from './JsonEditor';
export { default as HeaderMapEditor } from './HeaderMapEditor';
export { default as GoRegexInput, validateGoRegex } from './GoRegexInput';
export { default as SelectAllClearButtons } from './SelectAllClearButtons';
export { default as RemarkTemplateField } from './RemarkTemplateField';
export { default as RemarkVarPicker } from './RemarkVarPicker';
@@ -0,0 +1,210 @@
import { useEffect } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, waitFor } from 'storybook/test';
import { Button, Form, Input, InputNumber, Select, Switch, Typography } from 'antd';
import { FormProvider } from 'react-hook-form';
import { z } from 'zod';
import { FormField } from './FormField';
import { useZodForm } from './useZodForm';
const GB = 1024 * 1024 * 1024;
const meta = {
title: 'Form/RHF/FormField',
component: FormField,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Bridges one Ant Design control into react-hook-form: wraps the child in a Controller plus Form.Item, normalizes the onChange payload, and surfaces resolver errors as translated help text. Every RHF panel form (client, inbound, outbound, and host modals) builds its fields with it.',
},
},
},
argTypes: {
name: { description: 'Field path — a dotted string or an array of segments joined with dots.' },
control: { description: 'Optional react-hook-form control; falls back to the surrounding FormProvider.' },
label: { description: 'Form.Item label.' },
tooltip: { description: 'Form.Item tooltip shown next to the label.' },
extra: { description: 'Helper text rendered below the input.' },
valueProp: { description: 'Prop the child receives the value on: `value` (default) or `checked` for switches.' },
transform: { description: 'Optional input/output mappers, e.g. bytes stored in the form but GB shown in the input.' },
onAfterChange: { description: 'Called with the stored value after every change.' },
rules: { description: 'Controller-level validation rules applied on top of the form resolver.' },
required: { description: 'Marks the label with the required asterisk.' },
noStyle: { description: 'Render the bare input without Form.Item chrome.' },
children: { description: 'The single Ant Design control to wire up.' },
},
} satisfies Meta<typeof FormField>;
export default meta;
type Story = StoryObj<typeof meta>;
const ClientSchema = z.object({
email: z.string(),
flow: z.string(),
enable: z.boolean(),
});
function ClientDemo() {
const methods = useZodForm(ClientSchema, {
defaultValues: { email: 'user1@example.com', flow: 'xtls-rprx-vision', enable: true },
});
return (
<FormProvider {...methods}>
<Form layout="vertical" style={{ maxWidth: 360 }}>
<FormField name="email" label="Email" tooltip="Unique identifier used to match client traffic" required>
<Input placeholder="user1@example.com" />
</FormField>
<FormField name="flow" label="Flow" extra="Only applies to VLESS over raw TLS">
<Select
options={[
{ label: 'none', value: '' },
{ label: 'xtls-rprx-vision', value: 'xtls-rprx-vision' },
]}
/>
</FormField>
<FormField name="enable" label="Enable" valueProp="checked">
<Switch />
</FormField>
</Form>
</FormProvider>
);
}
const TrafficSchema = z.object({
totalBytes: z.number(),
});
function TrafficDemo() {
const methods = useZodForm(TrafficSchema, { defaultValues: { totalBytes: 50 * GB } });
const totalBytes = methods.watch('totalBytes');
return (
<FormProvider {...methods}>
<Form layout="vertical" style={{ maxWidth: 360 }}>
<FormField
name="totalBytes"
label="Total traffic (GB)"
extra="Stored on the client as bytes; 0 means unlimited"
transform={{
input: (value) => (typeof value === 'number' ? value / GB : value),
output: (value) => (typeof value === 'number' ? value * GB : 0),
}}
>
<InputNumber min={0} style={{ width: '100%' }} />
</FormField>
<Typography.Text type="secondary">Form state: {totalBytes.toLocaleString()} bytes</Typography.Text>
</Form>
</FormProvider>
);
}
const InboundSchema = z.object({
remark: z.string().min(1, 'Remark is required'),
port: z
.number()
.min(1, 'Port must be between 1 and 65535')
.max(65535, 'Port must be between 1 and 65535'),
});
function ValidationDemo() {
const methods = useZodForm(InboundSchema, { defaultValues: { remark: '', port: 0 } });
useEffect(() => {
void methods.trigger();
}, [methods]);
return (
<FormProvider {...methods}>
<Form layout="vertical" style={{ maxWidth: 360 }}>
<FormField name="remark" label="Remark" required>
<Input placeholder="vless-reality-443" />
</FormField>
<FormField name="port" label="Port" required>
<InputNumber style={{ width: '100%' }} />
</FormField>
<Button onClick={() => void methods.trigger()}>Validate</Button>
</Form>
</FormProvider>
);
}
const RealitySchema = z.object({
streamSettings: z.object({
realitySettings: z.object({
dest: z.string(),
serverNames: z.string(),
}),
}),
});
function NestedDemo() {
const methods = useZodForm(RealitySchema, {
defaultValues: {
streamSettings: {
realitySettings: { dest: 'yahoo.com:443', serverNames: 'yahoo.com,www.yahoo.com' },
},
},
});
return (
<FormProvider {...methods}>
<Form layout="vertical" style={{ maxWidth: 360 }}>
<FormField
name={['streamSettings', 'realitySettings', 'dest']}
label="Dest"
tooltip="Camouflage target the REALITY handshake is proxied to"
>
<Input />
</FormField>
<FormField
name="streamSettings.realitySettings.serverNames"
label="Server names"
extra="Comma-separated SNI list offered to clients"
>
<Input />
</FormField>
</Form>
</FormProvider>
);
}
const placeholderArgs = {
name: 'email',
children: <Input />,
};
export const ClientFields: Story = {
args: placeholderArgs,
render: () => <ClientDemo />,
};
export const TrafficTransform: Story = {
args: placeholderArgs,
render: () => <TrafficDemo />,
play: async ({ canvas, userEvent }) => {
const input = canvas.getByRole('spinbutton');
await userEvent.clear(input);
await userEvent.type(input, '100');
await expect(await canvas.findByText(/107,374,182,400 bytes/)).toBeVisible();
},
};
export const ValidationErrors: Story = {
args: placeholderArgs,
render: () => <ValidationDemo />,
play: async ({ canvas, userEvent }) => {
const remarkError = await canvas.findByText('Remark is required');
await waitFor(() => expect(remarkError).toBeVisible());
await waitFor(() => expect(canvas.getByText('Port must be between 1 and 65535')).toBeVisible());
await userEvent.type(canvas.getByPlaceholderText('vless-reality-443'), 'vless-reality-443');
await userEvent.click(canvas.getByRole('button', { name: 'Validate' }));
await waitFor(() => expect(canvas.queryByText('Remark is required')).not.toBeInTheDocument());
await expect(canvas.getByText('Port must be between 1 and 65535')).toBeVisible();
},
};
export const NestedNames: Story = {
args: placeholderArgs,
render: () => <NestedDemo />,
};
@@ -1,4 +1,4 @@
import { cloneElement } from 'react';
import { cloneElement, useId } from 'react';
import type { CSSProperties, ReactElement, ReactNode } from 'react';
import { Controller } from 'react-hook-form';
import type { Control, ControllerProps, FieldValues, Path } from 'react-hook-form';
@@ -48,6 +48,9 @@ export function FormField<T extends FieldValues = FieldValues>({
}: FormFieldProps<T>) {
const { t } = useTranslation();
const dottedName = toDotted(name) as Path<T>;
const generatedId = useId();
const explicitId = (children as ReactElement<{ id?: string }>).props.id;
const fieldId = explicitId ?? generatedId;
return (
<Controller
@@ -60,6 +63,7 @@ export function FormField<T extends FieldValues = FieldValues>({
? t(fieldState.error.message, { defaultValue: fieldState.error.message })
: undefined;
const childProps: Record<string, unknown> = {
id: fieldId,
[valueProp]: displayValue,
onChange: (...args: unknown[]) => {
const raw = normalizeAntdOnChange(args, valueProp);
@@ -73,6 +77,7 @@ export function FormField<T extends FieldValues = FieldValues>({
return (
<Form.Item
label={label}
htmlFor={label ? fieldId : undefined}
tooltip={tooltip}
extra={extra}
required={required}
@@ -6,6 +6,18 @@ const meta = {
title: 'UI/InfinityIcon',
component: InfinityIcon,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'Inline SVG infinity glyph used to denote an unlimited value (e.g. unlimited traffic or no expiry). Inherits the current text color.',
},
},
},
argTypes: {
width: { description: 'Icon width in pixels or any CSS length.' },
height: { description: 'Icon height in pixels or any CSS length.' },
},
} satisfies Meta<typeof InfinityIcon>;
export default meta;
@@ -7,6 +7,21 @@ const meta = {
title: 'UI/InputAddon',
component: InputAddon,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component:
'Prefix/suffix addon styled to sit flush against an Ant Design input. Becomes a keyboard-accessible button (role, tabIndex, Enter/Space) when `onClick` is provided.',
},
},
},
argTypes: {
children: { description: 'Addon content (text or an icon).' },
onClick: { description: 'When set, the addon becomes an activatable button.' },
ariaLabel: { description: 'Accessible label; used only when `onClick` is set.' },
className: { description: 'Extra CSS class appended to the addon.' },
style: { description: 'Inline styles for the addon element.' },
},
} satisfies Meta<typeof InputAddon>;
export default meta;
@@ -26,7 +41,7 @@ export const BesideInput: Story = {
render: () => (
<Space.Compact>
<InputAddon>https://</InputAddon>
<Input defaultValue="panel.example.com" style={{ width: 220 }} />
<Input defaultValue="panel.example.com" aria-label="Panel host" style={{ width: 220 }} />
</Space.Compact>
),
};
@@ -7,7 +7,22 @@ const meta = {
title: 'UI/SettingListItem',
component: SettingListItem,
tags: ['autodocs'],
parameters: { layout: 'padded' },
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Two-column settings row: a title and description on the left, and a control (Switch, InputNumber, …) on the right. Associates the title with the control via `aria-labelledby` for accessibility.',
},
},
},
argTypes: {
title: { description: 'Setting name shown on the left.' },
description: { description: 'Secondary help text under the title.' },
control: { description: 'The control rendered on the right (Switch, InputNumber, …).' },
children: { description: 'Alternative to `control`; used when no explicit control is passed.' },
paddings: { description: 'Row density: `default` or the tighter `small`.' },
},
} satisfies Meta<typeof SettingListItem>;
export default meta;
@@ -0,0 +1,85 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { AllSetting } from '@/models/setting';
import { EmailNotifications } from './EmailNotifications';
const meta = {
title: 'UI/Notifications/EmailNotifications',
component: EmailNotifications,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Grid of grouped event checkboxes on the settings page that picks which panel events (outbound/node health, Xray crashes, CPU/RAM thresholds, login attempts) trigger an SMTP email, stored as a comma-separated list in smtpEnabledEvents.',
},
},
},
argTypes: {
allSetting: {
description:
'Panel settings snapshot; smtpEnabledEvents holds the selected event keys and smtpCpu/smtpMemory the alert threshold percentages.',
},
updateSetting: {
description: 'Receives a partial settings patch when an event is toggled or a threshold input changes.',
},
},
} satisfies Meta<typeof EmailNotifications>;
export default meta;
type Story = StoryObj<typeof meta>;
function StatefulDemo({ initial }: { initial: AllSetting }) {
const [settings, setSettings] = useState(initial);
return (
<EmailNotifications
allSetting={settings}
updateSetting={(patch) => setSettings((prev) => new AllSetting({ ...prev, ...patch }))}
/>
);
}
const placeholderArgs = {
allSetting: new AllSetting(),
updateSetting: () => undefined,
};
export const NothingSelected: Story = {
args: placeholderArgs,
render: () => <StatefulDemo initial={new AllSetting()} />,
};
export const SystemThresholdAlerts: Story = {
args: placeholderArgs,
render: () => (
<StatefulDemo
initial={new AllSetting({ smtpEnabledEvents: 'cpu.high,memory.high', smtpCpu: 85, smtpMemory: 90 })}
/>
),
};
export const InfrastructureOnly: Story = {
args: placeholderArgs,
render: () => (
<StatefulDemo initial={new AllSetting({ smtpEnabledEvents: 'outbound.down,node.down,node.up,xray.crash' })} />
),
};
export const AllEventsEnabled: Story = {
args: placeholderArgs,
render: () => (
<StatefulDemo
initial={
new AllSetting({
smtpEnabledEvents:
'outbound.down,outbound.up,xray.crash,node.down,node.up,cpu.high,memory.high,login.attempt',
smtpCpu: 80,
smtpMemory: 80,
})
}
/>
),
};
@@ -37,16 +37,16 @@ const GROUPS: NotificationGroupConfig[] = [
key: 'cpu.high',
label: 'eventCPUHigh',
settingKey: 'smtpCpu',
extra: ({ value, onChange }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} style={{ width: 80 }} />
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
{
key: 'memory.high',
label: 'eventMemoryHigh',
settingKey: 'smtpMemory',
extra: ({ value, onChange }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} style={{ width: 80 }} />
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
],
@@ -8,7 +8,21 @@ const meta = {
title: 'UI/Notifications/NotificationCard',
component: NotificationCard,
tags: ['autodocs'],
parameters: { layout: 'padded' },
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Small outlined card that groups a notification channel — an icon and title in the header, a control in the top-right `extra` slot (typically a toggle), and the channel settings as its body.',
},
},
},
argTypes: {
icon: { description: 'Leading icon shown before the title.' },
title: { description: 'Channel name shown in the header.' },
extra: { description: 'Top-right slot, typically an enable/disable Switch.' },
children: { description: 'Card body — the channel settings.' },
},
} satisfies Meta<typeof NotificationCard>;
export default meta;
@@ -19,7 +33,7 @@ export const Default: Story = {
args: {
icon: <BellOutlined />,
title: 'Telegram',
extra: <Switch defaultChecked />,
extra: <Switch defaultChecked aria-label="Enable Telegram notifications" />,
children: <span>Push a message to the configured chat when an event fires.</span>,
},
};
@@ -28,7 +42,7 @@ export const Disabled: Story = {
args: {
icon: <BellOutlined />,
title: 'Email',
extra: <Switch />,
extra: <Switch aria-label="Enable email notifications" />,
children: <span>Email delivery is turned off for this channel.</span>,
},
};
@@ -0,0 +1,77 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { InputNumber } from 'antd';
import { NotificationEvent } from './NotificationEvent';
const meta = {
title: 'UI/Notifications/NotificationEvent',
component: NotificationEvent,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Single toggleable notification event row used inside the Telegram and email notification groups on the settings page. Renders a checkbox with a translated label and, when checked, an optional indented extra control such as a threshold input.',
},
},
},
argTypes: {
label: { description: 'i18n key (or already-translated text) shown next to the checkbox.' },
checked: { description: 'Whether the event notification is enabled.' },
onToggle: { description: 'Called when the checkbox is clicked.' },
children: { description: 'Extra control rendered indented below the label while checked.' },
},
} satisfies Meta<typeof NotificationEvent>;
export default meta;
type Story = StoryObj<typeof meta>;
function CpuThresholdDemo() {
const [checked, setChecked] = useState(true);
const [threshold, setThreshold] = useState(80);
return (
<NotificationEvent
label="pages.settings.eventCPUHigh"
checked={checked}
onToggle={() => setChecked((prev) => !prev)}
>
<InputNumber
size="small"
min={0}
max={100}
value={threshold}
onChange={(v) => setThreshold(v ?? 0)}
aria-label="CPU usage threshold percent"
style={{ width: 80 }}
/>
</NotificationEvent>
);
}
export const Unchecked: Story = {
args: {
label: 'pages.settings.eventLoginAttempt',
checked: false,
onToggle: () => undefined,
},
};
export const Checked: Story = {
args: {
label: 'pages.settings.eventXrayCrash',
checked: true,
onToggle: () => undefined,
},
};
export const CpuThreshold: Story = {
args: {
label: 'pages.settings.eventCPUHigh',
checked: true,
onToggle: () => undefined,
},
render: () => <CpuThresholdDemo />,
};
@@ -0,0 +1,131 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { InputNumber } from 'antd';
import { CloudServerOutlined, DashboardOutlined } from '@ant-design/icons';
import { AllSetting } from '@/models/setting';
import { NotificationGroup } from './NotificationGroup';
import type { NotificationGroupConfig } from './types';
const systemGroup: NotificationGroupConfig = {
icon: <DashboardOutlined />,
title: 'eventGroupSystem',
events: [
{
key: 'cpu.high',
label: 'eventCPUHigh',
settingKey: 'tgCpu',
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
{
key: 'memory.high',
label: 'eventMemoryHigh',
settingKey: 'tgMemory',
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
],
};
const outboundGroup: NotificationGroupConfig = {
icon: <CloudServerOutlined />,
title: 'eventGroupOutbound',
events: [
{ key: 'outbound.down', label: 'eventOutboundDown', settingKey: '' },
{ key: 'outbound.up', label: 'eventOutboundUp', settingKey: '' },
],
};
const meta = {
title: 'UI/Notifications/NotificationGroup',
component: NotificationGroup,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Card for one notification event group (outbound, Xray, node, system, security) with a per-group select-all checkbox, a selected-count tag, and optional per-event threshold inputs. Composed by the Telegram and email notification tabs on the settings page.',
},
},
},
argTypes: {
config: { description: 'Group definition: icon, `pages.settings` title key, and the event rows to render.' },
selected: { description: 'Enabled event keys; drives each checkbox and the header count.' },
onToggle: { description: 'Called with the event key when a single checkbox is clicked.' },
onToggleAll: { description: 'Called with every event key in the group when the master checkbox is clicked.' },
allSetting: { description: 'Panel settings snapshot; threshold values such as `tgCpu` are read from it.' },
updateSetting: { description: 'Called with a partial settings patch when a threshold input changes.' },
},
} satisfies Meta<typeof NotificationGroup>;
export default meta;
type Story = StoryObj<typeof meta>;
function Demo() {
const [selected, setSelected] = useState<string[]>(['cpu.high']);
const [settings, setSettings] = useState(new AllSetting({ tgCpu: 85, tgMemory: 90 }));
return (
<NotificationGroup
config={systemGroup}
selected={selected}
onToggle={(key) =>
setSelected((prev) => (prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key]))
}
onToggleAll={(keys) =>
setSelected((prev) => (keys.every((k) => prev.includes(k)) ? prev.filter((k) => !keys.includes(k)) : [...new Set([...prev, ...keys])]))
}
allSetting={settings}
updateSetting={(patch) => setSettings((prev) => new AllSetting({ ...prev, ...patch }))}
/>
);
}
export const AllSelected: Story = {
args: {
config: systemGroup,
selected: ['cpu.high', 'memory.high'],
onToggle: () => undefined,
onToggleAll: () => undefined,
allSetting: new AllSetting({ tgCpu: 85, tgMemory: 90 }),
updateSetting: () => undefined,
},
};
export const PartiallySelected: Story = {
args: {
config: systemGroup,
selected: ['cpu.high'],
onToggle: () => undefined,
onToggleAll: () => undefined,
allSetting: new AllSetting(),
updateSetting: () => undefined,
},
};
export const NoneSelected: Story = {
args: {
config: outboundGroup,
selected: [],
onToggle: () => undefined,
onToggleAll: () => undefined,
allSetting: new AllSetting(),
updateSetting: () => undefined,
},
};
export const Interactive: Story = {
args: {
config: systemGroup,
selected: [],
onToggle: () => undefined,
onToggleAll: () => undefined,
allSetting: new AllSetting(),
updateSetting: () => undefined,
},
render: () => <Demo />,
};
@@ -51,6 +51,7 @@ export function NotificationGroup({ config, selected, onToggle, onToggleAll, all
{event.extra?.({
value: Number((allSetting as unknown as Record<string, unknown>)[event.settingKey]) || 0,
onChange: (v) => updateSetting({ [event.settingKey]: v }),
ariaLabel: t(`pages.settings.${event.label}`),
})}
</NotificationEvent>
))}
@@ -0,0 +1,104 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Checkbox } from 'antd';
import { NotificationHeader } from './NotificationHeader';
const meta = {
title: 'UI/Notifications/NotificationHeader',
component: NotificationHeader,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Selection summary for a notification group header — a `count/total` tag plus a tri-state master checkbox that selects or clears every event in the group. Rendered in the `extra` slot of the Telegram/email notification cards on the settings page.',
},
},
},
argTypes: {
count: { description: 'Number of events currently selected in the group.' },
total: { description: 'Total number of events the group offers.' },
allSelected: { description: 'Checks the master checkbox when every event is selected.' },
indeterminate: { description: 'Shows the dash state when only some events are selected.' },
onToggleAll: { description: 'Called when the master checkbox is clicked to select or clear all events.' },
},
} satisfies Meta<typeof NotificationHeader>;
export default meta;
type Story = StoryObj<typeof meta>;
export const NoneSelected: Story = {
args: {
count: 0,
total: 6,
allSelected: false,
indeterminate: false,
onToggleAll: () => undefined,
},
};
export const PartialSelection: Story = {
args: {
count: 3,
total: 6,
allSelected: false,
indeterminate: true,
onToggleAll: () => undefined,
},
};
export const AllSelected: Story = {
args: {
count: 6,
total: 6,
allSelected: true,
indeterminate: false,
onToggleAll: () => undefined,
},
};
const events = ['Panel login', 'Xray crashed', 'CPU high', 'Client depleted'];
function GroupDemo() {
const [selected, setSelected] = useState<string[]>(['Panel login', 'CPU high']);
const count = selected.length;
const total = events.length;
function toggleAll() {
setSelected(count === total ? [] : [...events]);
}
function toggle(name: string) {
setSelected((prev) => (prev.includes(name) ? prev.filter((e) => e !== name) : [...prev, name]));
}
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, maxWidth: 260 }}>
<NotificationHeader
count={count}
total={total}
allSelected={count === total}
indeterminate={count > 0 && count < total}
onToggleAll={toggleAll}
/>
{events.map((name) => (
<Checkbox key={name} checked={selected.includes(name)} onChange={() => toggle(name)}>
{name}
</Checkbox>
))}
</div>
);
}
const placeholderArgs = {
count: 0,
total: 0,
allSelected: false,
indeterminate: false,
onToggleAll: () => undefined,
};
export const Interactive: Story = {
args: placeholderArgs,
render: () => <GroupDemo />,
};
@@ -0,0 +1,146 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { InputNumber, Space } from 'antd';
import {
CloudServerOutlined,
DashboardOutlined,
DesktopOutlined,
SafetyOutlined,
ThunderboltOutlined,
} from '@ant-design/icons';
import { NotificationLayout } from './NotificationLayout';
import { NotificationCard } from './NotificationCard';
import { NotificationEvent } from './NotificationEvent';
import { NotificationHeader } from './NotificationHeader';
const noop = () => undefined;
function OutboundGroup() {
return (
<NotificationCard
icon={<CloudServerOutlined />}
title="Outbound"
extra={<NotificationHeader count={1} total={2} allSelected={false} indeterminate onToggleAll={noop} />}
>
<Space orientation="vertical" size={8} style={{ width: '100%' }}>
<NotificationEvent label="Outbound went down" checked onToggle={noop} />
<NotificationEvent label="Outbound recovered" checked={false} onToggle={noop} />
</Space>
</NotificationCard>
);
}
function XrayGroup() {
return (
<NotificationCard
icon={<ThunderboltOutlined />}
title="Xray"
extra={<NotificationHeader count={1} total={1} allSelected indeterminate={false} onToggleAll={noop} />}
>
<Space orientation="vertical" size={8} style={{ width: '100%' }}>
<NotificationEvent label="Xray crashed" checked onToggle={noop} />
</Space>
</NotificationCard>
);
}
function NodeGroup() {
return (
<NotificationCard
icon={<DesktopOutlined />}
title="Nodes"
extra={<NotificationHeader count={0} total={2} allSelected={false} indeterminate={false} onToggleAll={noop} />}
>
<Space orientation="vertical" size={8} style={{ width: '100%' }}>
<NotificationEvent label="Node went offline" checked={false} onToggle={noop} />
<NotificationEvent label="Node back online" checked={false} onToggle={noop} />
</Space>
</NotificationCard>
);
}
function SystemGroup() {
return (
<NotificationCard
icon={<DashboardOutlined />}
title="System"
extra={<NotificationHeader count={2} total={2} allSelected indeterminate={false} onToggleAll={noop} />}
>
<Space orientation="vertical" size={8} style={{ width: '100%' }}>
<NotificationEvent label="CPU usage above threshold (%)" checked onToggle={noop}>
<InputNumber size="small" min={0} max={100} defaultValue={80} aria-label="CPU usage threshold percent" style={{ width: 80 }} />
</NotificationEvent>
<NotificationEvent label="Memory usage above threshold (%)" checked onToggle={noop}>
<InputNumber size="small" min={0} max={100} defaultValue={90} aria-label="Memory usage threshold percent" style={{ width: 80 }} />
</NotificationEvent>
</Space>
</NotificationCard>
);
}
function SecurityGroup() {
return (
<NotificationCard
icon={<SafetyOutlined />}
title="Security"
extra={<NotificationHeader count={1} total={1} allSelected indeterminate={false} onToggleAll={noop} />}
>
<Space orientation="vertical" size={8} style={{ width: '100%' }}>
<NotificationEvent label="Panel login attempt" checked onToggle={noop} />
</Space>
</NotificationCard>
);
}
const meta = {
title: 'UI/Notifications/NotificationLayout',
component: NotificationLayout,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Responsive auto-fit grid (min 260px columns) that arranges notification event-group cards; the Telegram and email notification tabs on the settings page render their groups inside it.',
},
},
},
argTypes: {
children: { description: 'Grid items, typically one NotificationCard per event group.' },
},
} satisfies Meta<typeof NotificationLayout>;
export default meta;
type Story = StoryObj<typeof meta>;
export const AllEventGroups: Story = {
args: {
children: (
<>
<OutboundGroup />
<XrayGroup />
<NodeGroup />
<SystemGroup />
<SecurityGroup />
</>
),
},
};
export const TwoGroups: Story = {
args: {
children: (
<>
<SystemGroup />
<SecurityGroup />
</>
),
},
};
export const SingleGroup: Story = {
args: {
children: <OutboundGroup />,
},
};
@@ -0,0 +1,82 @@
import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { AllSetting } from '@/models/setting';
import { TelegramNotifications } from './TelegramNotifications';
const meta = {
title: 'UI/Notifications/TelegramNotifications',
component: TelegramNotifications,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Grid of event-group cards (outbound, Xray, node, system, security) that pick which panel events the Telegram bot reports, with per-group select-all and CPU/RAM threshold inputs. Used on the settings page Telegram tab to edit `tgEnabledEvents`.',
},
},
},
argTypes: {
allSetting: { description: 'Panel settings snapshot; reads `tgEnabledEvents` plus the `tgCpu`/`tgMemory` thresholds.' },
updateSetting: { description: 'Called with a partial settings patch when an event toggle or threshold changes.' },
},
} satisfies Meta<typeof TelegramNotifications>;
export default meta;
type Story = StoryObj<typeof meta>;
function Demo({ initial }: { initial: AllSetting }) {
const [settings, setSettings] = useState(initial);
return (
<TelegramNotifications
allSetting={settings}
updateSetting={(patch) => setSettings((prev) => new AllSetting({ ...prev, ...patch }))}
/>
);
}
const placeholderArgs = {
allSetting: new AllSetting(),
updateSetting: () => undefined,
};
export const NothingSelected: Story = {
args: placeholderArgs,
render: () => <Demo initial={new AllSetting()} />,
};
export const TypicalMonitoring: Story = {
args: placeholderArgs,
render: () => (
<Demo
initial={
new AllSetting({
tgBotEnable: true,
tgBotChatId: '123456789',
tgEnabledEvents: 'xray.crash,node.down,cpu.high,memory.high,login.attempt',
tgCpu: 85,
tgMemory: 90,
})
}
/>
),
};
export const EverythingEnabled: Story = {
args: placeholderArgs,
render: () => (
<Demo
initial={
new AllSetting({
tgBotEnable: true,
tgEnabledEvents:
'outbound.down,outbound.up,xray.crash,node.down,node.up,cpu.high,memory.high,login.attempt',
tgCpu: 70,
tgMemory: 75,
})
}
/>
),
};
@@ -37,16 +37,16 @@ const GROUPS: NotificationGroupConfig[] = [
key: 'cpu.high',
label: 'eventCPUHigh',
settingKey: 'tgCpu',
extra: ({ value, onChange }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} style={{ width: 80 }} />
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
{
key: 'memory.high',
label: 'eventMemoryHigh',
settingKey: 'tgMemory',
extra: ({ value, onChange }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} style={{ width: 80 }} />
extra: ({ value, onChange, ariaLabel }) => (
<InputNumber size="small" min={0} max={100} value={value} onChange={onChange} aria-label={ariaLabel} style={{ width: 80 }} />
),
},
],
@@ -4,7 +4,7 @@ export interface NotificationEventConfig {
key: string;
label: string;
settingKey: string;
extra?: (props: { value: number; onChange: (v: number | null) => void }) => ReactNode;
extra?: (props: { value: number; onChange: (v: number | null) => void; ariaLabel: string }) => ReactNode;
}
export interface NotificationGroupConfig {
@@ -0,0 +1,138 @@
import { lazy, useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Alert, Button, Card, Skeleton, Space, Switch, Tag, Typography } from 'antd';
import LazyMount from './LazyMount';
const meta = {
title: 'Utility/LazyMount',
component: LazyMount,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Mounts its children the first time `when` becomes true and keeps them mounted afterwards, wrapped in Suspense. The panel pairs it with React.lazy modal imports on heavy list pages so modals load on demand while their close animations still play.',
},
},
},
argTypes: {
when: { description: 'Children mount the first time this becomes true and stay mounted afterwards.' },
fallback: { description: 'Suspense fallback shown while a React.lazy child is still loading.' },
children: { description: 'Content to mount on demand, typically a lazily imported modal.' },
},
} satisfies Meta<typeof LazyMount>;
export default meta;
type Story = StoryObj<typeof meta>;
function MountBadge() {
const [mountedAt] = useState(() => new Date().toLocaleTimeString());
return <Tag color="green">mounted at {mountedAt}</Tag>;
}
function OnDemandDemo() {
const [visible, setVisible] = useState(false);
return (
<Space orientation="vertical" size="middle" style={{ width: '100%' }}>
<Space>
<Switch checked={visible} onChange={setVisible} aria-label="Mount the client card" />
<Typography.Text>when = {String(visible)}</Typography.Text>
</Space>
<LazyMount when={visible}>
<Card size="small" title="alice@corp.example" style={{ maxWidth: 480 }}>
<Space orientation="vertical" size={4}>
<MountBadge />
<Typography.Text type="secondary">Traffic: 42.7 GB of 100 GB</Typography.Text>
<Typography.Text code copyable style={{ fontSize: 12 }}>
vless://b831381d-6324-4d53-ad4f-8cda48b30811@vpn.example.com:443?type=tcp&security=reality&fp=chrome&sni=yahoo.com#alice
</Typography.Text>
</Space>
</Card>
</LazyMount>
<Typography.Text type="secondary">
The card mounts the first time the switch turns on and stays mounted after turning it off; the mount time never changes.
</Typography.Text>
</Space>
);
}
const xrayConfigSnippet = JSON.stringify(
{
inbounds: [
{
tag: 'inbound-443',
protocol: 'vless',
port: 443,
settings: {
clients: [{ id: 'b831381d-6324-4d53-ad4f-8cda48b30811', email: 'alice@corp.example', flow: 'xtls-rprx-vision' }],
decryption: 'none',
},
streamSettings: { network: 'tcp', security: 'reality' },
},
],
},
null,
2,
);
function XrayConfigPreview() {
return (
<Card size="small" title="Generated xray config">
<pre style={{ margin: 0, overflowX: 'auto', fontSize: 12 }}>{xrayConfigSnippet}</pre>
</Card>
);
}
const SlowXrayConfigPreview = lazy(
() =>
new Promise<{ default: typeof XrayConfigPreview }>((resolve) => {
setTimeout(() => resolve({ default: XrayConfigPreview }), 1200);
}),
);
function LazyChildDemo() {
const [open, setOpen] = useState(false);
return (
<Space orientation="vertical" size="middle" style={{ width: '100%', maxWidth: 560 }}>
<Button type="primary" onClick={() => setOpen(true)} disabled={open}>
Load config preview
</Button>
<LazyMount when={open} fallback={<Skeleton active paragraph={{ rows: 4 }} />}>
<SlowXrayConfigPreview />
</LazyMount>
</Space>
);
}
const placeholderArgs = {
when: false,
children: null,
};
export const MountOnDemand: Story = {
args: placeholderArgs,
render: () => <OnDemandDemo />,
};
export const LazyChildWithFallback: Story = {
args: placeholderArgs,
render: () => <LazyChildDemo />,
};
export const MountedImmediately: Story = {
args: {
when: true,
children: (
<Alert
type="warning"
showIcon
title="Client depleted"
description="bob@corp.example used 100 GB of 100 GB and was disabled by the traffic job."
style={{ maxWidth: 480 }}
/>
),
},
};
@@ -0,0 +1,21 @@
import type { CSSProperties } from 'react';
export const SPEED_TAG_CLASS_NAME = 'table-speed-tag' as const;
export const SPEED_TAG_WIDTH = 200 as const;
export const SPEED_TABLE_CELL_INLINE_PADDING = 8 as const;
export const SPEED_TAG_STYLE = {
width: SPEED_TAG_WIDTH,
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
whiteSpace: 'nowrap',
fontVariantNumeric: 'tabular-nums',
marginInlineEnd: 0,
boxSizing: 'border-box',
overflow: 'hidden',
textOverflow: 'ellipsis',
} as const satisfies CSSProperties;
export const SPEED_COLUMN_WIDTH = SPEED_TAG_WIDTH + SPEED_TABLE_CELL_INLINE_PADDING * 2;
@@ -9,7 +9,27 @@ const meta = {
title: 'Viz/Sparkline',
component: Sparkline,
tags: ['autodocs'],
parameters: { layout: 'padded' },
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Compact canvas line chart (uPlot) for CPU, memory, and traffic trends. Supports up to three series, optional axes/grid, a hover tooltip, min/max markers, reference lines, and light/dark theming.',
},
},
},
argTypes: {
data: { description: 'Primary series values, oldest to newest.' },
data2: { description: 'Optional second series (e.g. download vs upload).' },
data3: { description: 'Optional third series.' },
height: { description: 'Chart height in pixels.' },
name1: { description: 'Legend/tooltip label for the primary series.' },
name2: { description: 'Legend/tooltip label for the second series.' },
showAxes: { description: 'Render x/y axes and tick labels.' },
showGrid: { description: 'Draw horizontal grid lines.' },
showTooltip: { description: 'Show a value tooltip on hover.' },
extrema: { description: 'Highlight the min and max points (single-series only).' },
},
} satisfies Meta<typeof Sparkline>;
export default meta;
+14
View File
@@ -35,6 +35,8 @@ export const EXAMPLES: Record<string, unknown> = {
"smtpEnable": false,
"smtpEnabledEvents": "",
"smtpEncryptionType": "",
"smtpFrom": "",
"smtpFromName": "",
"smtpHost": "",
"smtpMemory": 0,
"smtpPassword": "",
@@ -43,11 +45,13 @@ export const EXAMPLES: Record<string, unknown> = {
"smtpUsername": "",
"subAnnounce": "",
"subCertFile": "",
"subClashAutoDetect": false,
"subClashEnable": false,
"subClashEnableRouting": false,
"subClashPath": "",
"subClashRules": "",
"subClashURI": "",
"subClashUserAgentRegex": "",
"subDomain": "",
"subEnable": false,
"subEnableRouting": false,
@@ -55,12 +59,15 @@ export const EXAMPLES: Record<string, unknown> = {
"subHideSettings": false,
"subIncyEnableRouting": false,
"subIncyRoutingRules": "",
"subJsonAlwaysArray": false,
"subJsonAutoDetect": false,
"subJsonEnable": false,
"subJsonFinalMask": "",
"subJsonMux": "",
"subJsonPath": "",
"subJsonRules": "",
"subJsonURI": "",
"subJsonUserAgentRegex": "",
"subKeyFile": "",
"subListen": "",
"subPath": "",
@@ -138,6 +145,8 @@ export const EXAMPLES: Record<string, unknown> = {
"smtpEnable": false,
"smtpEnabledEvents": "",
"smtpEncryptionType": "",
"smtpFrom": "",
"smtpFromName": "",
"smtpHost": "",
"smtpMemory": 0,
"smtpPassword": "",
@@ -146,11 +155,13 @@ export const EXAMPLES: Record<string, unknown> = {
"smtpUsername": "",
"subAnnounce": "",
"subCertFile": "",
"subClashAutoDetect": false,
"subClashEnable": false,
"subClashEnableRouting": false,
"subClashPath": "",
"subClashRules": "",
"subClashURI": "",
"subClashUserAgentRegex": "",
"subDomain": "",
"subEnable": false,
"subEnableRouting": false,
@@ -158,12 +169,15 @@ export const EXAMPLES: Record<string, unknown> = {
"subHideSettings": false,
"subIncyEnableRouting": false,
"subIncyRoutingRules": "",
"subJsonAlwaysArray": false,
"subJsonAutoDetect": false,
"subJsonEnable": false,
"subJsonFinalMask": "",
"subJsonMux": "",
"subJsonPath": "",
"subJsonRules": "",
"subJsonURI": "",
"subJsonUserAgentRegex": "",
"subKeyFile": "",
"subListen": "",
"subPath": "",
+56
View File
@@ -116,6 +116,12 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpEncryptionType": {
"type": "string"
},
"smtpFrom": {
"type": "string"
},
"smtpFromName": {
"type": "string"
},
"smtpHost": {
"type": "string"
},
@@ -144,6 +150,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subCertFile": {
"type": "string"
},
"subClashAutoDetect": {
"type": "boolean"
},
"subClashEnable": {
"type": "boolean"
},
@@ -159,6 +168,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subClashURI": {
"type": "string"
},
"subClashUserAgentRegex": {
"type": "string"
},
"subDomain": {
"type": "string"
},
@@ -180,6 +192,12 @@ export const SCHEMAS: Record<string, unknown> = {
"subIncyRoutingRules": {
"type": "string"
},
"subJsonAlwaysArray": {
"type": "boolean"
},
"subJsonAutoDetect": {
"type": "boolean"
},
"subJsonEnable": {
"type": "boolean"
},
@@ -198,6 +216,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subJsonURI": {
"type": "string"
},
"subJsonUserAgentRegex": {
"type": "string"
},
"subKeyFile": {
"type": "string"
},
@@ -349,6 +370,8 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpEnable",
"smtpEnabledEvents",
"smtpEncryptionType",
"smtpFrom",
"smtpFromName",
"smtpHost",
"smtpMemory",
"smtpPassword",
@@ -357,11 +380,13 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpUsername",
"subAnnounce",
"subCertFile",
"subClashAutoDetect",
"subClashEnable",
"subClashEnableRouting",
"subClashPath",
"subClashRules",
"subClashURI",
"subClashUserAgentRegex",
"subDomain",
"subEnable",
"subEnableRouting",
@@ -369,12 +394,15 @@ export const SCHEMAS: Record<string, unknown> = {
"subHideSettings",
"subIncyEnableRouting",
"subIncyRoutingRules",
"subJsonAlwaysArray",
"subJsonAutoDetect",
"subJsonEnable",
"subJsonFinalMask",
"subJsonMux",
"subJsonPath",
"subJsonRules",
"subJsonURI",
"subJsonUserAgentRegex",
"subKeyFile",
"subListen",
"subPath",
@@ -549,6 +577,12 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpEncryptionType": {
"type": "string"
},
"smtpFrom": {
"type": "string"
},
"smtpFromName": {
"type": "string"
},
"smtpHost": {
"type": "string"
},
@@ -577,6 +611,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subCertFile": {
"type": "string"
},
"subClashAutoDetect": {
"type": "boolean"
},
"subClashEnable": {
"type": "boolean"
},
@@ -592,6 +629,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subClashURI": {
"type": "string"
},
"subClashUserAgentRegex": {
"type": "string"
},
"subDomain": {
"type": "string"
},
@@ -613,6 +653,12 @@ export const SCHEMAS: Record<string, unknown> = {
"subIncyRoutingRules": {
"type": "string"
},
"subJsonAlwaysArray": {
"type": "boolean"
},
"subJsonAutoDetect": {
"type": "boolean"
},
"subJsonEnable": {
"type": "boolean"
},
@@ -631,6 +677,9 @@ export const SCHEMAS: Record<string, unknown> = {
"subJsonURI": {
"type": "string"
},
"subJsonUserAgentRegex": {
"type": "string"
},
"subKeyFile": {
"type": "string"
},
@@ -789,6 +838,8 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpEnable",
"smtpEnabledEvents",
"smtpEncryptionType",
"smtpFrom",
"smtpFromName",
"smtpHost",
"smtpMemory",
"smtpPassword",
@@ -797,11 +848,13 @@ export const SCHEMAS: Record<string, unknown> = {
"smtpUsername",
"subAnnounce",
"subCertFile",
"subClashAutoDetect",
"subClashEnable",
"subClashEnableRouting",
"subClashPath",
"subClashRules",
"subClashURI",
"subClashUserAgentRegex",
"subDomain",
"subEnable",
"subEnableRouting",
@@ -809,12 +862,15 @@ export const SCHEMAS: Record<string, unknown> = {
"subHideSettings",
"subIncyEnableRouting",
"subIncyRoutingRules",
"subJsonAlwaysArray",
"subJsonAutoDetect",
"subJsonEnable",
"subJsonFinalMask",
"subJsonMux",
"subJsonPath",
"subJsonRules",
"subJsonURI",
"subJsonUserAgentRegex",
"subKeyFile",
"subListen",
"subPath",
+14
View File
@@ -41,6 +41,8 @@ export interface AllSetting {
smtpEnable: boolean;
smtpEnabledEvents: string;
smtpEncryptionType: string;
smtpFrom: string;
smtpFromName: string;
smtpHost: string;
smtpMemory: number;
smtpPassword: string;
@@ -49,11 +51,13 @@ export interface AllSetting {
smtpUsername: string;
subAnnounce: string;
subCertFile: string;
subClashAutoDetect: boolean;
subClashEnable: boolean;
subClashEnableRouting: boolean;
subClashPath: string;
subClashRules: string;
subClashURI: string;
subClashUserAgentRegex: string;
subDomain: string;
subEnable: boolean;
subEnableRouting: boolean;
@@ -61,12 +65,15 @@ export interface AllSetting {
subHideSettings: boolean;
subIncyEnableRouting: boolean;
subIncyRoutingRules: string;
subJsonAlwaysArray: boolean;
subJsonAutoDetect: boolean;
subJsonEnable: boolean;
subJsonFinalMask: string;
subJsonMux: string;
subJsonPath: string;
subJsonRules: string;
subJsonURI: string;
subJsonUserAgentRegex: string;
subKeyFile: string;
subListen: string;
subPath: string;
@@ -145,6 +152,8 @@ export interface AllSettingView {
smtpEnable: boolean;
smtpEnabledEvents: string;
smtpEncryptionType: string;
smtpFrom: string;
smtpFromName: string;
smtpHost: string;
smtpMemory: number;
smtpPassword: string;
@@ -153,11 +162,13 @@ export interface AllSettingView {
smtpUsername: string;
subAnnounce: string;
subCertFile: string;
subClashAutoDetect: boolean;
subClashEnable: boolean;
subClashEnableRouting: boolean;
subClashPath: string;
subClashRules: string;
subClashURI: string;
subClashUserAgentRegex: string;
subDomain: string;
subEnable: boolean;
subEnableRouting: boolean;
@@ -165,12 +176,15 @@ export interface AllSettingView {
subHideSettings: boolean;
subIncyEnableRouting: boolean;
subIncyRoutingRules: string;
subJsonAlwaysArray: boolean;
subJsonAutoDetect: boolean;
subJsonEnable: boolean;
subJsonFinalMask: string;
subJsonMux: string;
subJsonPath: string;
subJsonRules: string;
subJsonURI: string;
subJsonUserAgentRegex: string;
subKeyFile: string;
subListen: string;
subPath: string;
+14
View File
@@ -53,6 +53,8 @@ export const AllSettingSchema = z.object({
smtpEnable: z.boolean(),
smtpEnabledEvents: z.string(),
smtpEncryptionType: z.string(),
smtpFrom: z.string(),
smtpFromName: z.string(),
smtpHost: z.string(),
smtpMemory: z.number().int().min(0).max(100),
smtpPassword: z.string(),
@@ -61,11 +63,13 @@ export const AllSettingSchema = z.object({
smtpUsername: z.string(),
subAnnounce: z.string(),
subCertFile: z.string(),
subClashAutoDetect: z.boolean(),
subClashEnable: z.boolean(),
subClashEnableRouting: z.boolean(),
subClashPath: z.string(),
subClashRules: z.string(),
subClashURI: z.string(),
subClashUserAgentRegex: z.string(),
subDomain: z.string(),
subEnable: z.boolean(),
subEnableRouting: z.boolean(),
@@ -73,12 +77,15 @@ export const AllSettingSchema = z.object({
subHideSettings: z.boolean(),
subIncyEnableRouting: z.boolean(),
subIncyRoutingRules: z.string(),
subJsonAlwaysArray: z.boolean(),
subJsonAutoDetect: z.boolean(),
subJsonEnable: z.boolean(),
subJsonFinalMask: z.string(),
subJsonMux: z.string(),
subJsonPath: z.string(),
subJsonRules: z.string(),
subJsonURI: z.string(),
subJsonUserAgentRegex: z.string(),
subKeyFile: z.string(),
subListen: z.string(),
subPath: z.string(),
@@ -158,6 +165,8 @@ export const AllSettingViewSchema = z.object({
smtpEnable: z.boolean(),
smtpEnabledEvents: z.string(),
smtpEncryptionType: z.string(),
smtpFrom: z.string(),
smtpFromName: z.string(),
smtpHost: z.string(),
smtpMemory: z.number().int().min(0).max(100),
smtpPassword: z.string(),
@@ -166,11 +175,13 @@ export const AllSettingViewSchema = z.object({
smtpUsername: z.string(),
subAnnounce: z.string(),
subCertFile: z.string(),
subClashAutoDetect: z.boolean(),
subClashEnable: z.boolean(),
subClashEnableRouting: z.boolean(),
subClashPath: z.string(),
subClashRules: z.string(),
subClashURI: z.string(),
subClashUserAgentRegex: z.string(),
subDomain: z.string(),
subEnable: z.boolean(),
subEnableRouting: z.boolean(),
@@ -178,12 +189,15 @@ export const AllSettingViewSchema = z.object({
subHideSettings: z.boolean(),
subIncyEnableRouting: z.boolean(),
subIncyRoutingRules: z.string(),
subJsonAlwaysArray: z.boolean(),
subJsonAutoDetect: z.boolean(),
subJsonEnable: z.boolean(),
subJsonFinalMask: z.string(),
subJsonMux: z.string(),
subJsonPath: z.string(),
subJsonRules: z.string(),
subJsonURI: z.string(),
subJsonUserAgentRegex: z.string(),
subKeyFile: z.string(),
subListen: z.string(),
subPath: z.string(),
+15
View File
@@ -78,13 +78,28 @@ const STATISTIC_TOKENS = {
contentFontSize: 17,
titleFontSize: 11,
};
const LIGHT_CONTRAST_TOKENS = {
colorTextDescription: 'rgba(0, 0, 0, 0.58)',
colorTextTertiary: 'rgba(0, 0, 0, 0.58)',
colorTextPlaceholder: '#767676',
colorError: '#cf1322',
colorErrorText: '#cf1322',
colorSuccessText: '#237804',
};
const LIGHT_BUTTON_TOKENS = {
colorPrimary: '#0958d9',
colorPrimaryHover: '#2468e5',
colorPrimaryActive: '#073ea8',
};
export function buildAntdThemeConfig(isDark: boolean, isUltra: boolean): ThemeConfig {
if (!isDark) {
return {
algorithm: antdTheme.defaultAlgorithm,
token: LIGHT_CONTRAST_TOKENS,
components: {
Statistic: STATISTIC_TOKENS,
Button: LIGHT_BUTTON_TOKENS,
},
};
}
+2 -17
View File
@@ -1,26 +1,11 @@
import { useEffect } from 'react';
import { WebSocketClient } from '@/api/websocket';
import { getSharedWebSocketClient } from '@/api/websocket';
type Handler = (payload: unknown) => void;
interface SharedClient {
connect(): void;
on(event: string, fn: Handler): void;
off(event: string, fn: Handler): void;
}
let sharedClient: SharedClient | null = null;
function getSharedClient(): SharedClient {
if (sharedClient) return sharedClient;
const basePath = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '';
sharedClient = new WebSocketClient(basePath) as SharedClient;
return sharedClient;
}
export function useWebSocket(handlers: Record<string, Handler>) {
useEffect(() => {
const client = getSharedClient();
const client = getSharedWebSocketClient();
const entries = Object.entries(handlers);
for (const [event, fn] of entries) client.on(event, fn);
client.connect();
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import { Form } from 'antd';
import SniffingFields from '@/lib/xray/forms/SniffingFields';
import type { Sniffing } from '@/schemas/primitives/sniffing';
import { SniffingSchema, type Sniffing } from '@/schemas/primitives/sniffing';
interface SniffingFieldProps {
value?: Sniffing;
@@ -12,12 +12,12 @@ interface SniffingFieldProps {
export default function SniffingField({ value, onChange, enableLabel }: SniffingFieldProps) {
const [form] = Form.useForm();
const [initial] = useState(() => value ?? ({} as Sniffing));
const [initial] = useState(() => value ?? SniffingSchema.parse({}));
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
const lastEmitted = useRef(JSON.stringify(initial));
const sniffing = Form.useWatch('sniffing', form) as Sniffing | undefined;
const sniffing = Form.useWatch('sniffing', { form, preserve: true }) as Sniffing | undefined;
useEffect(() => {
if (sniffing === undefined) return;
@@ -27,6 +27,14 @@ export default function SniffingField({ value, onChange, enableLabel }: Sniffing
onChangeRef.current?.(sniffing);
}, [sniffing]);
useEffect(() => {
if (value === undefined) return;
const serialized = JSON.stringify(value);
if (serialized === lastEmitted.current) return;
lastEmitted.current = serialized;
form.setFieldsValue({ sniffing: value });
}, [value, form]);
return (
<Form
form={form}
+7
View File
@@ -29,6 +29,11 @@ export class AllSetting {
xrayTemplateConfig = '';
subEnable = true;
subJsonEnable = false;
subJsonAutoDetect = false;
subJsonAlwaysArray = false;
subJsonUserAgentRegex = '';
subClashAutoDetect = false;
subClashUserAgentRegex = '';
subTitle = '';
subSupportUrl = '';
subProfileUrl = '';
@@ -91,6 +96,8 @@ export class AllSetting {
smtpPort = 587;
smtpUsername = '';
smtpPassword = '';
smtpFrom = '';
smtpFromName = '';
smtpTo = '';
smtpEncryptionType = 'starttls';
smtpEnabledEvents = '';
+9 -2
View File
@@ -1145,7 +1145,7 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/setting/all',
summary: 'Return every panel setting: web server, Telegram bot, subscription, security, LDAP. The full JSON blob that the Settings page edits.',
response: '{\n "success": true,\n "obj": {\n "webPort": 2053,\n "webCertFile": "",\n "webKeyFile": "",\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "tgBotEnable": false,\n "tgBotToken": "",\n ...\n }\n}',
response: '{\n "success": true,\n "obj": {\n "webPort": 2053,\n "webCertFile": "",\n "webKeyFile": "",\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "subClashAutoDetect": false,\n "subClashUserAgentRegex": "",\n "subJsonEnable": false,\n "subJsonAutoDetect": false,\n "subJsonAlwaysArray": false,\n "subJsonUserAgentRegex": "",\n "subJsonPath": "/json/",\n "subJsonURI": "https://sub.example.com/json/",\n "subClashEnable": true,\n "subClashPath": "/clash/",\n "subClashURI": "https://sub.example.com/clash/",\n "tgBotEnable": false,\n "tgBotToken": "",\n ...\n }\n}',
},
{
method: 'POST',
@@ -1156,7 +1156,14 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/setting/update',
summary: 'Persist every setting at once. The body mirrors the shape returned by /all. Invalid values (bad ports, missing cert pairs, etc.) are rejected before write.',
body: '{\n "webPort": 2053,\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "tgBotEnable": false,\n ...\n}',
body: '{\n "webPort": 2053,\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "subClashAutoDetect": false,\n "subClashUserAgentRegex": "",\n "subJsonEnable": false,\n "subJsonAutoDetect": false,\n "subJsonAlwaysArray": false,\n "subJsonUserAgentRegex": "",\n "subJsonPath": "/json/",\n "subJsonURI": "https://sub.example.com/json/",\n "subClashEnable": true,\n "subClashPath": "/clash/",\n "subClashURI": "https://sub.example.com/clash/",\n "tgBotEnable": false,\n ...\n}',
},
{
method: 'POST',
path: '/panel/api/setting/validateRegex',
summary: 'Validate any regular expression with the backend Go RE2 compiler without saving it.',
body: '{\n "regex": "(?m)^general-purpose$"\n}',
response: '{\n "success": true,\n "msg": ""\n}',
},
{
method: 'POST',
@@ -96,7 +96,7 @@ export default function BulkAttachInboundsModal({
onChange={setTargetIds}
options={targetOptions}
placeholder={t('pages.clients.attachToInboundsTargets')}
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
autoFocus
/>
</>
@@ -96,7 +96,7 @@ export default function BulkDetachInboundsModal({
onChange={setTargetIds}
options={targetOptions}
placeholder={t('pages.clients.detachFromInboundsTargets')}
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
autoFocus
/>
</>
+10 -2
View File
@@ -146,11 +146,18 @@ function bytesToGB(bytes: number): number {
return Math.round((bytes / (1024 * 1024 * 1024)) * 100) / 100;
}
function gbToBytes(gb: number): number {
export function gbToBytes(gb: number): number {
if (!gb || gb <= 0) return 0;
return Math.round(gb * 1024 * 1024 * 1024);
}
export function resolveTotalBytes(originalBytes: number | null | undefined, displayedGB: number): number {
if (originalBytes != null && displayedGB === bytesToGB(originalBytes)) {
return originalBytes;
}
return gbToBytes(displayedGB);
}
export default function ClientFormModal({
open,
mode,
@@ -491,6 +498,7 @@ export default function ClientFormModal({
const expiryTime = values.delayedStart
? -86400000 * (Number(values.delayedDays) || 0)
: (values.expiryDate || 0);
const totalBytes = resolveTotalBytes(client ? (client.totalGB ?? 0) : null, values.totalGB);
const clientPayload: Record<string, unknown> = {
email: values.email.trim(),
subId: values.subId,
@@ -499,7 +507,7 @@ export default function ClientFormModal({
auth: values.auth,
flow: showFlow ? (values.flow || '') : '',
security: showSecurity ? (values.security || 'auto') : 'auto',
totalGB: gbToBytes(values.totalGB),
totalGB: totalBytes,
expiryTime,
reset: Number(values.reset) || 0,
limitIp: Number(values.limitIp) || 0,
@@ -162,6 +162,17 @@
background: color-mix(in srgb, var(--ant-color-primary) 6%, transparent);
}
.client-card-comment {
display: block;
margin-top: 6px;
color: var(--ant-color-text-secondary);
font-size: 12px;
max-height: 4.5em;
overflow-y: auto;
overflow-wrap: anywhere;
white-space: pre-wrap;
}
.client-card-speed {
margin-top: 6px;
font-size: 12px;
+10 -5
View File
@@ -62,10 +62,12 @@ import { useDatepicker } from '@/hooks/useDatepicker';
import type { ClientRecord, InboundOption, ExternalLink, ExternalLinkInput } from '@/hooks/useClients';
import ClientTrafficCell from '@/components/clients/ClientTrafficCell';
import ClientSpeedTag, { isActiveSpeed } from '@/components/clients/ClientSpeedTag';
import ClientCardComment from '@/components/clients/ClientCardComment';
import AppSidebar from '@/layouts/AppSidebar';
import { IntlUtil, SizeFormatter } from '@/utils';
import { setMessageInstance } from '@/utils/messageBus';
import { LazyMount } from '@/components/utility';
import { SPEED_COLUMN_WIDTH, SPEED_TAG_CLASS_NAME, SPEED_TAG_STYLE } from '@/components/utility/speedTagStyle';
const ClientFormModal = lazy(() => import('./ClientFormModal'));
const ClientInfoModal = lazy(() => import('./ClientInfoModal'));
const ClientQrModal = lazy(() => import('./ClientQrModal'));
@@ -818,7 +820,7 @@ export default function ClientsPage() {
<div className="email-cell">
<span className="email">{record.email}</span>
{record.subId && <span className="sub" title={record.subId}>{record.subId}</span>}
{record.comment && <span className="sub" title={record.comment}>{record.comment}</span>}
<ClientCardComment comment={record.comment} className="sub" />
</div>
),
},
@@ -907,12 +909,14 @@ export default function ClientsPage() {
{
title: t('pages.clients.speed'),
key: 'speed',
width: 110,
width: SPEED_COLUMN_WIDTH,
align: 'center',
render: (_v, record) => {
const speed = clientSpeed[record.email];
if (!isActiveSpeed(speed)) return <Tag color="default"></Tag>;
return <ClientSpeedTag speed={speed} />;
if (!isActiveSpeed(speed)) {
return <Tag color="default" className={SPEED_TAG_CLASS_NAME} style={SPEED_TAG_STYLE}></Tag>;
}
return <ClientSpeedTag speed={speed} tableCell />;
},
},
{
@@ -1212,7 +1216,7 @@ export default function ClientsPage() {
value={sortValueFor(sortColumn, sortOrder)}
aria-label={t('sort')}
size={isMobile ? 'small' : 'middle'}
suffixIcon={<SortAscendingOutlined />}
suffix={<SortAscendingOutlined />}
style={{ minWidth: isMobile ? 130 : 200 }}
onChange={(value) => {
const opt = SORT_OPTIONS.find((o) => o.value === value);
@@ -1433,6 +1437,7 @@ export default function ClientsPage() {
</Dropdown>
</div>
</div>
<ClientCardComment comment={row.comment} />
<ClientTrafficCell
compact
up={row.traffic?.up}
+4 -7
View File
@@ -89,7 +89,7 @@ export default function FilterDrawer({
title={t('pages.clients.filterTitle')}
open={open}
onClose={() => onOpenChange(false)}
width={420}
size={420}
destroyOnHidden
footer={
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
@@ -139,8 +139,7 @@ export default function FilterDrawer({
placeholder={t('inbounds')}
maxTagCount="responsive"
allowClear
showSearch
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
listHeight={220}
/>
</Form.Item>
@@ -155,8 +154,7 @@ export default function FilterDrawer({
placeholder={t('pages.clients.filters.nodes')}
maxTagCount="responsive"
allowClear
showSearch
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
listHeight={220}
/>
</Form.Item>
@@ -171,8 +169,7 @@ export default function FilterDrawer({
placeholder={t('pages.clients.groupPlaceholder')}
maxTagCount="responsive"
allowClear
showSearch
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
listHeight={220}
/>
</Form.Item>
+2 -3
View File
@@ -191,8 +191,7 @@ export default function HostFormModal({ open, mode, host, inboundOptions, existi
<Select
mode="multiple"
options={inboundSelectOptions}
showSearch
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
placeholder={t('pages.hosts.selectInbound')}
/>
</FormField>
@@ -211,7 +210,7 @@ export default function HostFormModal({ open, mode, host, inboundOptions, existi
<Select mode="tags" allowClear tokenSeparators={[',']} />
</FormField>
<FormField name="nodeGuids" label={t('pages.hosts.fields.nodeGuids')} tooltip={t('pages.hosts.hints.nodeGuids')}>
<Select mode="multiple" allowClear options={nodeSelectOptions} optionFilterProp="label" />
<Select mode="multiple" allowClear options={nodeSelectOptions} showSearch={{ optionFilterProp: 'label' }} />
</FormField>
<FormField name="enable" label={t('pages.hosts.fields.enable')} valueProp="checked">
<Switch />
@@ -203,7 +203,7 @@ export default function AttachClientsModal({
onChange={setTargetIds}
options={targetOptions}
placeholder={t('pages.inbounds.attachClientsTargets')}
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
/>
)}
</Modal>
@@ -203,7 +203,7 @@ export default function AttachExistingClientsModal({
options={groupOptions}
placeholder={t('pages.clients.group')}
style={{ minWidth: 160 }}
optionFilterProp="label"
showSearch={{ optionFilterProp: 'label' }}
/>
)}
</Space>
@@ -1,6 +1,7 @@
import { Tag, Tooltip } from 'antd';
import { SizeFormatter } from '@/utils';
import { SPEED_TAG_CLASS_NAME, SPEED_TAG_STYLE } from '@/components/utility/speedTagStyle';
import type { InboundSpeedEntry } from './types';
@@ -12,12 +13,17 @@ export function isActiveSpeed(speed?: InboundSpeedEntry): speed is InboundSpeedE
interface InboundSpeedTagProps {
speed: InboundSpeedEntry;
withTooltip?: boolean;
tableCell?: boolean;
}
// Blue "↑ up / ↓ down" rate tag, optionally with a stacked breakdown tooltip.
export function InboundSpeedTag({ speed, withTooltip = false }: InboundSpeedTagProps) {
export function InboundSpeedTag({ speed, withTooltip = false, tableCell = false }: InboundSpeedTagProps) {
const tag = (
<Tag color="blue">
<Tag
color="blue"
className={tableCell ? SPEED_TAG_CLASS_NAME : undefined}
style={tableCell ? SPEED_TAG_STYLE : undefined}
>
{SizeFormatter.speedFormat(speed.up)}
{' / '}
{SizeFormatter.speedFormat(speed.down)}
@@ -10,6 +10,7 @@ import type { NodeRecord } from '@/api/queries/useNodesQuery';
import { coerceInboundJsonField } from '@/models/dbinbound';
import { RowActionsCell } from './RowActions';
import { SPEED_COLUMN_WIDTH, SPEED_TAG_CLASS_NAME, SPEED_TAG_STYLE } from '@/components/utility/speedTagStyle';
import { InboundSpeedTag, isActiveSpeed } from './InboundSpeedTag';
import {
readStreamHints,
@@ -324,14 +325,14 @@ export function useInboundColumns({
title: t('pages.inbounds.speed'),
key: 'speed',
align: 'center',
width: 110,
width: SPEED_COLUMN_WIDTH,
sorter: (a, b) => speedTotal(a) - speedTotal(b),
render: (_, record) => {
const speed = inboundSpeed[record.id];
if (!isActiveSpeed(speed)) {
return <Tag color='default'></Tag>;
return <Tag color="default" className={SPEED_TAG_CLASS_NAME} style={SPEED_TAG_STYLE}></Tag>;
}
return <InboundSpeedTag speed={speed} withTooltip />;
return <InboundSpeedTag speed={speed} withTooltip tableCell />;
},
},
{
+1 -1
View File
@@ -650,7 +650,7 @@ export default function NodeList({
loading={loading}
scroll={{ x: 'max-content' }}
size="middle"
rowKey="id"
rowKey="key"
rowSelection={dataSource.length > 1 ? {
selectedRowKeys: selectedIds,
onChange: (keys) => onSelectionChange(keys.filter((k) => typeof k === 'number') as number[]),
+11 -2
View File
@@ -82,6 +82,16 @@ export default function EmailTab({ allSetting, updateSetting }: EmailTabProps) {
onClearArmedChange={(armed) => updateSetting({ clearSmtpPassword: armed })} />
</SettingListItem>
<SettingListItem paddings="small" title={t('pages.settings.smtpFrom')} description={t('pages.settings.smtpFromDesc')}>
<Input value={allSetting.smtpFrom} placeholder="user@gmail.com"
onChange={(e) => updateSetting({ smtpFrom: e.target.value })} />
</SettingListItem>
<SettingListItem paddings="small" title={t('pages.settings.smtpFromName')} description={t('pages.settings.smtpFromNameDesc')}>
<Input value={allSetting.smtpFromName} placeholder="3x-ui"
onChange={(e) => updateSetting({ smtpFromName: e.target.value })} />
</SettingListItem>
<SettingListItem paddings="small" title={t('pages.settings.smtpTo')} description={t('pages.settings.smtpToDesc')}>
<Input value={allSetting.smtpTo} placeholder="admin@example.com, ops@example.com"
onChange={(e) => updateSetting({ smtpTo: e.target.value })} />
@@ -113,8 +123,7 @@ export default function EmailTab({ allSetting, updateSetting }: EmailTabProps) {
: <span><b>{stageLabel[testResult.stage || ''] || testResult.stage}:</b> {t('pages.settings.' + testResult.msg)}</span>
}
showIcon
closable
onClose={() => setTestResult(null)}
closable={{ onClose: () => setTestResult(null) }}
/>
)}
</Space>
@@ -1,3 +1,18 @@
.subscription-format-sections {
display: grid;
gap: 16px;
}
.subscription-format-card-title {
display: inline-flex;
align-items: center;
gap: 8px;
}
.subscription-format-card .ant-card-body {
padding: 0;
}
.format-settings {
margin-bottom: 8px;
border: 1px solid var(--ant-color-border-secondary);
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import {
Card,
Input,
InputNumber,
Select,
@@ -8,6 +9,8 @@ import {
Tabs,
} from 'antd';
import {
FileTextOutlined,
NodeIndexOutlined,
PartitionOutlined,
RocketOutlined,
SendOutlined,
@@ -15,6 +18,7 @@ import {
} from '@ant-design/icons';
import type { AllSetting } from '@/models/setting';
import { SettingListItem } from '@/components/ui';
import { GoRegexInput } from '@/components/form';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { catTabLabel } from './catTabLabel';
import { sanitizePath, normalizePath } from './uriPath';
@@ -148,9 +152,18 @@ export default function SubscriptionFormatsTab({ allSetting, updateSetting }: Su
key: '1',
label: catTabLabel(<SettingOutlined />, t('pages.settings.panelSettings'), isMobile),
children: (
<>
<div className="subscription-format-sections">
{allSetting.subJsonEnable && (
<>
<Card
size="small"
className="subscription-format-card"
title={(
<span className="subscription-format-card-title">
<FileTextOutlined />
{t('pages.settings.subJsonEnableTitle')}
</span>
)}
>
<SettingListItem paddings="small" title={<>JSON {t('pages.settings.subPath')}</>} description={t('pages.settings.subPathDesc')}>
<Input
value={allSetting.subJsonPath}
@@ -166,10 +179,40 @@ export default function SubscriptionFormatsTab({ allSetting, updateSetting }: Su
onChange={(e) => updateSetting({ subJsonURI: e.target.value })}
/>
</SettingListItem>
</>
<SettingListItem
paddings="small"
title={t('pages.settings.subJsonAlwaysArray')}
description={t('pages.settings.subJsonAlwaysArrayDesc')}
>
<Switch checked={allSetting.subJsonAlwaysArray} onChange={(value) => updateSetting({ subJsonAlwaysArray: value })} />
</SettingListItem>
<SettingListItem paddings="small" title={t('pages.settings.subJsonAutoDetect')} description={t('pages.settings.subJsonAutoDetectDesc')}>
<Switch checked={allSetting.subJsonAutoDetect} onChange={(v) => updateSetting({ subJsonAutoDetect: v })} />
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subJsonUserAgentRegex')}
description={t('pages.settings.subJsonUserAgentRegexDesc')}
>
<GoRegexInput
value={allSetting.subJsonUserAgentRegex}
placeholder="(?i)^myclient([ /]|$)"
onChange={(value) => updateSetting({ subJsonUserAgentRegex: value })}
/>
</SettingListItem>
</Card>
)}
{allSetting.subClashEnable && (
<>
<Card
size="small"
className="subscription-format-card"
title={(
<span className="subscription-format-card-title">
<NodeIndexOutlined />
{t('pages.settings.subClashEnableTitle')}
</span>
)}
>
<SettingListItem paddings="small" title={<>Clash {t('pages.settings.subPath')}</>} description={t('pages.settings.subPathDesc')}>
<Input
value={allSetting.subClashPath}
@@ -185,9 +228,30 @@ export default function SubscriptionFormatsTab({ allSetting, updateSetting }: Su
onChange={(e) => updateSetting({ subClashURI: e.target.value })}
/>
</SettingListItem>
</>
<SettingListItem
paddings="small"
title={t('pages.settings.subClashAutoDetect')}
description={t('pages.settings.subClashAutoDetectDesc')}
>
<Switch
checked={allSetting.subClashAutoDetect}
onChange={(v) => updateSetting({ subClashAutoDetect: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subClashUserAgentRegex')}
description={t('pages.settings.subClashUserAgentRegexDesc')}
>
<GoRegexInput
value={allSetting.subClashUserAgentRegex}
placeholder="(?i)(clash|mihomo)"
onChange={(value) => updateSetting({ subClashUserAgentRegex: value })}
/>
</SettingListItem>
</Card>
)}
</>
</div>
),
},
{
@@ -1,6 +1,7 @@
import { Input, InputNumber, Switch, Tabs } from 'antd';
import { Alert, Button, Input, InputNumber, Switch, Tabs } from 'antd';
import { BranchesOutlined, CompassOutlined, IdcardOutlined, InfoCircleOutlined, NodeIndexOutlined, SafetyCertificateOutlined, SettingOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import type { AllSetting } from '@/models/setting';
import { SettingListItem } from '@/components/ui';
import { RemarkTemplateField } from '@/components/form';
@@ -15,6 +16,7 @@ interface SubscriptionGeneralTabProps {
export default function SubscriptionGeneralTab({ allSetting, updateSetting }: SubscriptionGeneralTabProps) {
const { t } = useTranslation();
const navigate = useNavigate();
const { isMobile } = useMediaQuery();
return (
@@ -33,6 +35,20 @@ export default function SubscriptionGeneralTab({ allSetting, updateSetting }: Su
<SettingListItem paddings="small" title={t('pages.settings.subClashEnableTitle')}>
<Switch checked={allSetting.subClashEnable} onChange={(v) => updateSetting({ subClashEnable: v })} />
</SettingListItem>
{(allSetting.subJsonEnable || allSetting.subClashEnable) && (
<Alert
type="info"
showIcon
style={{ margin: '12px 20px' }}
title={t('pages.settings.subFormatsTipTitle')}
description={t('pages.settings.subFormatsTipDesc')}
action={(
<Button size="small" onClick={() => navigate('/settings#subscription-formats')}>
{t('pages.settings.subFormatsTipAction')}
</Button>
)}
/>
)}
<SettingListItem paddings="small" title={t('pages.settings.subListen')} description={t('pages.settings.subListenDesc')}>
<Input value={allSetting.subListen} onChange={(e) => updateSetting({ subListen: e.target.value })} />
</SettingListItem>
+1 -2
View File
@@ -233,8 +233,7 @@ export default function TelegramTab({ allSetting, updateSetting }: TelegramTabPr
type={testResult.success ? 'success' : 'error'}
title={testResult.msg}
showIcon
closable
onClose={() => setTestResult(null)}
closable={{ onClose: () => setTestResult(null) }}
/>
)}
</Space>
+1 -1
View File
@@ -286,7 +286,7 @@ export default function SubPage() {
<Col xs={24} sm={22} md={18} lg={14} xl={12}>
<Card hoverable className="subscription-card" title={cardTitle} extra={cardExtra}>
{announce && (
<Alert type="info" showIcon message={announce} style={{ marginBottom: 16 }} />
<Alert type="info" showIcon title={announce} style={{ marginBottom: 16 }} />
)}
<Descriptions
bordered
+1 -1
View File
@@ -78,7 +78,7 @@ export default function SubUsageSummary({
percent={pct}
showInfo={false}
strokeColor={{ '0%': stroke.from, '100%': stroke.to }}
trailColor="var(--ant-color-fill-secondary)"
railColor="var(--ant-color-fill-secondary)"
strokeWidth={10}
className="usage-summary-bar"
/>
@@ -257,7 +257,7 @@ export default function BalancerFormModal({
<Alert
type="info"
showIcon
message={t('pages.xray.balancer.balancerFallbackInfo')}
title={t('pages.xray.balancer.balancerFallbackInfo')}
style={{ marginBottom: 16 }}
/>
)}
@@ -265,7 +265,7 @@ export default function BalancerFormModal({
<Alert
type="error"
showIcon
message={t('pages.xray.balancer.balancerFallbackCycle')}
title={t('pages.xray.balancer.balancerFallbackCycle')}
style={{ marginBottom: 16 }}
/>
)}
+2 -1
View File
@@ -115,7 +115,8 @@ export default function BasicsTab({
?.sockopt;
const raw = sockopt?.happyEyeballs;
if (raw == null || typeof raw !== 'object') return null;
return HappyEyeballsSchema.parse(raw);
const parsed = HappyEyeballsSchema.safeParse(raw);
return parsed.success ? parsed.data : null;
})();
const setDirectHappyEyeballs = useCallback(
@@ -86,7 +86,7 @@ export default function DnsPresetsModal({ open, onClose, onInstall }: DnsPresets
type="warning"
showIcon
className="preset-warning"
message={t('pages.xray.dns.dnsLeakWarning')}
title={t('pages.xray.dns.dnsLeakWarning')}
/>
<div className="preset-list">
{PRESETS.map((preset) => (
@@ -10,6 +10,7 @@ import {
DnsQueryStrategySchema,
DnsServerObjectInnerSchema,
DnsServerObjectSchema,
isEncryptedDnsAddress,
type DnsServerObject,
} from '@/schemas/dns';
@@ -109,7 +110,6 @@ function valuesToWire(values: DnsServerForm): DnsServerValue {
const out: Record<string, unknown> = {
address: values.address,
port: values.port,
domains: values.domains.filter(Boolean),
expectedIPs: values.expectedIPs.filter(Boolean),
unexpectedIPs: values.unexpectedIPs.filter(Boolean),
@@ -121,6 +121,7 @@ function valuesToWire(values: DnsServerForm): DnsServerValue {
serveExpiredTTL: values.serveExpiredTTL,
timeoutMs: values.timeoutMs,
};
if (!isEncryptedDnsAddress(values.address)) out.port = values.port;
if (values.tag) out.tag = values.tag;
if (values.clientIP) out.clientIP = values.clientIP;
return out as DnsServerValue;
+1 -1
View File
@@ -240,7 +240,7 @@ export default function DnsTab({ templateSettings, setTemplateSettings }: DnsTab
<Alert
type="warning"
showIcon
message={t('pages.xray.dns.dnsLeakWarning')}
title={t('pages.xray.dns.dnsLeakWarning')}
style={{ marginBottom: 12 }}
/>
<SettingListItem
@@ -63,8 +63,8 @@ export default function OutboundCardList({
setShowEgressIp((prev) => ({ ...prev, [key]: visible }));
};
const renderEgress = (index: number, rowKey: string) => {
const result = testResult(outboundTestStates, index);
const renderEgress = (testKey: number, rowKey: string) => {
const result = testResult(outboundTestStates, testKey);
const egress = result?.egress;
const isEgressVisible = !!showEgressIp[rowKey];
const flag = countryFlag(egress?.country);
@@ -156,26 +156,26 @@ export default function OutboundCardList({
))}
</div>
)}
{renderEgress(index, String(record.key))}
{renderEgress(record.key, String(record.key))}
<div className="card-foot">
<span className="traffic-up"> {SizeFormatter.sizeFormat(trafficFor(outboundsTraffic, record).up)}</span>
<span className="traffic-sep" />
<span className="traffic-down"> {SizeFormatter.sizeFormat(trafficFor(outboundsTraffic, record).down)}</span>
<span className="card-test">
{testResult(outboundTestStates, index) ? (
<TestResultPopover result={testResult(outboundTestStates, index)!} />
) : isTesting(outboundTestStates, index) ? (
{testResult(outboundTestStates, record.key) ? (
<TestResultPopover result={testResult(outboundTestStates, record.key)!} />
) : isTesting(outboundTestStates, record.key) ? (
<LoadingOutlined />
) : null}
<Button
type="primary"
shape="circle"
size="small"
loading={isTesting(outboundTestStates, index)}
disabled={isUntestable(record) || isTesting(outboundTestStates, index)}
loading={isTesting(outboundTestStates, record.key)}
disabled={isUntestable(record) || isTesting(outboundTestStates, record.key)}
icon={<ThunderboltOutlined />}
aria-label={t('check')}
onClick={() => onTest(index, testMode)}
onClick={() => onTest(record.key, testMode)}
/>
</span>
</div>
@@ -1,4 +1,4 @@
import { useCallback, useMemo, useState } from 'react';
import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Button,
@@ -50,6 +50,7 @@ import type { XraySettingsValue, SetTemplate, OutboundTestMode, OutboundTestStat
import './OutboundsTab.css';
import type { OutboundRow } from './outbounds-tab-types';
import { originalOutboundIndex } from './outbounds-tab-helpers';
import { useOutboundColumns } from './useOutboundColumns';
import OutboundCardList from './OutboundCardList';
import SubscriptionOutbounds from './SubscriptionOutbounds';
@@ -150,6 +151,8 @@ export default function OutboundsTab({
.filter((o) => !isBalancerLoopbackTag(o.tag || '')),
[outbounds],
);
const rowsRef = useRef<OutboundRow[]>([]);
rowsRef.current = rows;
const dialerProxyTags = useMemo(() => {
const tags = new Set<string>();
@@ -188,11 +191,12 @@ export default function OutboundsTab({
loadSubs();
}
function openEdit(idx: number) {
setEditingOutbound((templateSettings?.outbounds || [])[idx] as Record<string, unknown>);
setEditingIndex(idx);
const target = originalOutboundIndex(rowsRef.current, idx);
setEditingOutbound((templateSettings?.outbounds || [])[target] as Record<string, unknown>);
setEditingIndex(target);
setExistingTags(
(templateSettings?.outbounds || [])
.filter((_, i) => i !== idx)
.filter((_, i) => i !== target)
.map((o) => o?.tag)
.filter((tg): tg is string => !!tg),
);
@@ -217,8 +221,9 @@ export default function OutboundsTab({
}
function confirmDelete(idx: number) {
const target = originalOutboundIndex(rowsRef.current, idx);
const impact = templateSettings
? planOutboundDeletion(templateSettings, idx)
? planOutboundDeletion(templateSettings, target)
: { rules: [], balancers: [], observatory: false, burst: false };
modal.confirm({
title: `${t('delete')} ${t('pages.xray.Outbounds')} #${idx + 1}?`,
@@ -226,27 +231,33 @@ export default function OutboundsTab({
okText: t('delete'),
okType: 'danger',
cancelText: t('cancel'),
onOk: () => mutate((tt) => applyOutboundDeletion(tt, idx)),
onOk: () => mutate((tt) => applyOutboundDeletion(tt, target)),
});
}
function setFirst(idx: number) {
const target = originalOutboundIndex(rowsRef.current, idx);
mutate((tt) => {
if (!tt.outbounds) return;
const [moved] = tt.outbounds.splice(idx, 1);
const [moved] = tt.outbounds.splice(target, 1);
tt.outbounds.unshift(moved);
});
}
function moveUp(idx: number) {
if (idx <= 0) return;
const target = originalOutboundIndex(rowsRef.current, idx);
const prev = originalOutboundIndex(rowsRef.current, idx - 1);
mutate((tt) => {
if (!tt.outbounds) return;
[tt.outbounds[idx - 1], tt.outbounds[idx]] = [tt.outbounds[idx], tt.outbounds[idx - 1]];
[tt.outbounds[prev], tt.outbounds[target]] = [tt.outbounds[target], tt.outbounds[prev]];
});
}
function moveDown(idx: number) {
if (idx >= rowsRef.current.length - 1) return;
const target = originalOutboundIndex(rowsRef.current, idx);
const next = originalOutboundIndex(rowsRef.current, idx + 1);
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]];
if (!tt.outbounds) return;
[tt.outbounds[next], tt.outbounds[target]] = [tt.outbounds[target], tt.outbounds[next]];
});
}
@@ -6,6 +6,19 @@ import type { OutboundTestMode, OutboundTestState, OutboundTrafficRow } from '@/
import type { OutboundRow } from './outbounds-tab-types';
/**
* Translate a table row's positional index into that outbound's index in the
* full, unfiltered outbounds array. The table hides balancer-loopback outbounds
* but keeps each visible row's original index in `key`, so any handler that
* mutates the outbounds array (or probes an outbound by index) must map the
* positional index back through `key` or it operates on the wrong outbound once
* a hidden loopback precedes it.
*/
export function originalOutboundIndex(rows: OutboundRow[], positionalIndex: number): number {
const row = rows[positionalIndex];
return row ? row.key : positionalIndex;
}
export function outboundAddresses(o: OutboundRow): string[] {
const settings = o.settings as Record<string, unknown> | undefined;
switch (o.protocol) {
@@ -158,8 +158,8 @@ export function useOutboundColumns({
key: 'egress',
align: 'left',
width: 210,
render: (_v, _record, index) => {
const egress = testResult(outboundTestStates, index)?.egress;
render: (_v, record) => {
const egress = testResult(outboundTestStates, record.key)?.egress;
const addresses = [
egress?.ipv4 ? { label: 'v4', value: egress.ipv4 } : null,
egress?.ipv6 ? { label: 'v6', value: egress.ipv6 } : null,
@@ -190,8 +190,8 @@ export function useOutboundColumns({
key: 'egressCountry',
align: 'left',
width: 160,
render: (_v, _record, index) => {
const egress = testResult(outboundTestStates, index)?.egress;
render: (_v, record) => {
const egress = testResult(outboundTestStates, record.key)?.egress;
if (!egress?.country) {
return (
<Tooltip title={t('pages.xray.outbound.egressHint')}>
@@ -229,9 +229,9 @@ export function useOutboundColumns({
key: 'testResult',
align: 'left',
width: 140,
render: (_v, _record, index) => {
const r = testResult(outboundTestStates, index);
if (!r) return isTesting(outboundTestStates, index) ? <LoadingOutlined /> : <span className="empty"></span>;
render: (_v, record) => {
const r = testResult(outboundTestStates, record.key);
if (!r) return isTesting(outboundTestStates, record.key) ? <LoadingOutlined /> : <span className="empty"></span>;
return <TestResultPopover result={r} />;
},
},
@@ -240,16 +240,16 @@ export function useOutboundColumns({
key: 'test',
align: 'center',
width: 80,
render: (_v, record, index) => (
render: (_v, record) => (
<Tooltip title={`${t('check')} (${testModeLabel(effectiveTestMode(record, testMode), t)})`}>
<Button
type="primary"
shape="circle"
loading={isTesting(outboundTestStates, index)}
disabled={isUntestable(record) || isTesting(outboundTestStates, index)}
loading={isTesting(outboundTestStates, record.key)}
disabled={isUntestable(record) || isTesting(outboundTestStates, record.key)}
icon={<ThunderboltOutlined />}
aria-label={t('check')}
onClick={() => onTest(index, testMode)}
onClick={() => onTest(record.key, testMode)}
/>
</Tooltip>
),
+24 -12
View File
@@ -21,7 +21,7 @@ import RuleFormModal from './RuleFormModal';
import type { RoutingRule } from './RuleFormModal';
import RuleCardList from './RuleCardList';
import { useRoutingColumns } from './useRoutingColumns';
import { arrJoin } from './helpers';
import { arrJoin, originalRuleIndex } from './helpers';
import type { RuleRow } from './types';
import type { XraySettingsValue, SetTemplate } from '@/hooks/useXraySetting';
import type { RuleObject } from '@/schemas/routing';
@@ -64,6 +64,7 @@ export default function RoutingTab({
);
const rulesRef = useRef(rules);
rulesRef.current = rules;
const rowsRef = useRef<RuleRow[]>([]);
const rows: RuleRow[] = useMemo(
() =>
@@ -94,6 +95,7 @@ export default function RoutingTab({
}),
[rules],
);
rowsRef.current = rows;
const mutate = useCallback(
(mutator: (next: XraySettingsValue) => void) => {
@@ -193,8 +195,9 @@ export default function RoutingTab({
setRuleModalOpen(true);
}
function openEdit(idx: number) {
setEditingRule(rulesRef.current[idx]);
setEditingIndex(idx);
const target = originalRuleIndex(rowsRef.current, idx);
setEditingRule(rulesRef.current[target]);
setEditingIndex(target);
setRuleModalOpen(true);
}
function onRuleConfirm(rule: Record<string, unknown>) {
@@ -213,37 +216,44 @@ export default function RoutingTab({
}
function confirmDelete(idx: number) {
const target = originalRuleIndex(rowsRef.current, idx);
modal.confirm({
title: `${t('delete')} ${t('pages.xray.Routings')} #${idx + 1}?`,
okText: t('delete'),
okType: 'danger',
cancelText: t('cancel'),
onOk: () => mutate((tt) => {
tt.routing?.rules?.splice(idx, 1);
tt.routing?.rules?.splice(target, 1);
}),
});
}
function moveUp(idx: number) {
if (idx <= 0) return;
const target = originalRuleIndex(rowsRef.current, idx);
const prev = originalRuleIndex(rowsRef.current, idx - 1);
mutate((tt) => {
const list = tt.routing?.rules;
if (!list) return;
[list[idx - 1], list[idx]] = [list[idx], list[idx - 1]];
if (!list || !list[target] || !list[prev]) return;
[list[prev], list[target]] = [list[target], list[prev]];
});
}
function moveDown(idx: number) {
if (idx >= rowsRef.current.length - 1) return;
const target = originalRuleIndex(rowsRef.current, idx);
const next = originalRuleIndex(rowsRef.current, idx + 1);
mutate((tt) => {
const list = tt.routing?.rules;
if (!list || idx >= list.length - 1) return;
[list[idx + 1], list[idx]] = [list[idx], list[idx + 1]];
if (!list || !list[target] || !list[next]) return;
[list[next], list[target]] = [list[target], list[next]];
});
}
function toggleRule(idx: number, enabled: boolean) {
const target = originalRuleIndex(rowsRef.current, idx);
mutate((tt) => {
const list = tt.routing?.rules;
if (!list || !list[idx]) return;
list[idx].enabled = enabled;
if (!list || !list[target]) return;
list[target].enabled = enabled;
});
}
@@ -282,11 +292,13 @@ export default function RoutingTab({
setDraggedIndex(null);
setDropTargetIndex(null);
if (!moved || from == null || to == null || from === to) return;
const fromOrig = originalRuleIndex(rowsRef.current, from);
const toOrig = originalRuleIndex(rowsRef.current, to);
mutate((tt) => {
const list = tt.routing?.rules;
if (!list) return;
const [movedItem] = list.splice(from, 1);
list.splice(to, 0, movedItem);
const [movedItem] = list.splice(fromOrig, 1);
list.splice(toOrig, 0, movedItem);
});
};
@@ -126,7 +126,13 @@ export default function RuleFormModal({
outboundTag: v.outboundTag === '' ? undefined : v.outboundTag,
balancerTag: v.balancerTag === '' ? undefined : v.balancerTag,
};
const managedKeys = new Set(Object.keys(built));
const out: Record<string, unknown> = {};
if (rule) {
for (const [key, value] of Object.entries(rule)) {
if (!managedKeys.has(key) && value !== undefined) out[key] = value;
}
}
for (const [k, v] of Object.entries(built)) {
if (v == null) continue;
if (Array.isArray(v) && v.length === 0) continue;
@@ -6,6 +6,18 @@ export function arrJoin(v: unknown): string | undefined {
return String(v);
}
/**
* Translate a table row's positional index into that rule's index in the full,
* unfiltered routing.rules array. The table hides balancer-loopback rules but
* keeps each visible row's original index in `key`, so any handler that mutates
* routing.rules must map the positional index back through `key` or it operates
* on the wrong rule once a hidden loopback precedes it.
*/
export function originalRuleIndex(rows: RuleRow[], positionalIndex: number): number {
const row = rows[positionalIndex];
return row ? row.key : positionalIndex;
}
export function csv(value?: string): string[] {
if (!value) return [];
return String(value).split(',').map((s) => s.trim()).filter(Boolean);
+11 -2
View File
@@ -14,9 +14,13 @@ const DnsHostValueSchema = z.union([z.string(), z.array(z.string())]);
export const DnsHostsSchema = z.record(z.string(), DnsHostValueSchema);
export type DnsHosts = z.infer<typeof DnsHostsSchema>;
export function isEncryptedDnsAddress(address: string): boolean {
return /^(https|https\+local|h2c|h2c\+local|quic\+local):\/\//i.test(address);
}
export const DnsServerObjectInnerSchema = z.object({
address: z.string(),
port: PortSchema.default(53),
port: PortSchema.optional(),
domains: z.array(z.string()).optional(),
expectedIPs: z.array(z.string()).optional(),
unexpectedIPs: z.array(z.string()).optional(),
@@ -41,7 +45,12 @@ export const DnsServerObjectSchema = z.preprocess(
return val;
},
DnsServerObjectInnerSchema,
);
).transform((v) => {
if (v.port === undefined && !isEncryptedDnsAddress(v.address)) {
return { ...v, port: 53 };
}
return v;
});
export type DnsServerObject = z.infer<typeof DnsServerObjectSchema>;
export const DnsServerEntrySchema = z.union([z.string(), DnsServerObjectSchema]);

Some files were not shown because too many files have changed in this diff Show More