mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #7035] feat(logs): add a read-only Logs page with charts and a country map #6589
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6589
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/7035
Author: @ahmadi-ali
Created: 10/31/2026
Status: 🔄 Open
Base:
main← Head:feat/logs-page📝 Commits (1)
baabc4afeat(logs): add a read-only Logs page with charts and a country map📊 Changes
61 files changed (+9726 additions, -25 deletions)
View changed files
📝
docs/architecture.md(+2 -0)➕
docs/content/docs/en/reference/api/logs.mdx(+53 -0)📝
docs/content/docs/en/reference/api/meta.json(+1 -0)📝
docs/public/openapi.json(+903 -0)📝
frontend/public/openapi.json(+903 -0)➕
frontend/scripts/build-world-map.mjs(+79 -0)➕
frontend/src/api/queries/useLogs.ts(+75 -0)📝
frontend/src/api/queryKeys.ts(+6 -0)📝
frontend/src/components/command-palette/CommandPalette.tsx(+1 -0)📝
frontend/src/components/viz/Sparkline.css(+4 -0)📝
frontend/src/components/viz/Sparkline.stories.tsx(+2 -0)📝
frontend/src/components/viz/Sparkline.tsx(+12 -3)📝
frontend/src/generated/examples.ts(+160 -0)📝
frontend/src/generated/schemas.ts(+431 -0)📝
frontend/src/generated/types.ts(+91 -0)📝
frontend/src/generated/zod.ts(+101 -0)➕
frontend/src/lib/logs/countryScale.ts(+17 -0)➕
frontend/src/lib/logs/logQuery.ts(+126 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+113 -0)➕
frontend/src/pages/logs/LogsFilterBar.tsx(+173 -0)...and 41 more files
📄 Description
Summary
Adds a read-only Logs page to the panel (
/panel/logs). It has an Overview tab with interactive charts and a world map of requests by country, and a raw-log tab with search and filters. All of it is served by three newGETendpoints that only read files insideXUI_LOG_FOLDER.Why
To investigate traffic or errors today, an admin has to SSH into the server, or use the Overview log modal, which offers a line count and a text filter but no breakdowns. This page answers the common questions directly in the panel: which IPs, users and hosts are busiest, when errors spiked, and where requests come from. Clicking a chart filters the whole page down to the matching log lines.
Type of change
Areas affected
How was this tested?
To try it
"log": { "access": "/var/log/x-ui/access.log" }(the access log is off by default and must be insideXUI_LOG_FOLDER), then restart Xray and send some traffic.access.log.GET /panel/api/logs/read?file=../../etc/passwdis rejected, and a symlink placed in the log folder is neither listed nor readable.Automated tests added
internal/web/service/logview: parsing, paging, gzip, oversized lines, symlinks, truncation during a read, the country cache, plus theFuzzParseLinefuzz test.internal/web/controller/logs_test.go: routes are read-only, restricted tokens get 403, query binding, errors don't leak paths.internal/xray/geodata/country_test.go: country lookup, including nested and adjacent ranges and the ends of the address space.frontend/src/test/logs-page.test.tsx,logs-query.test.ts,sparkline-point-click.test.tsx.I also removed behaviours one at a time to confirm the tests fail: 15 in the map UI and 14 in the backend.
Results
golangci-lintclean,go test -shuffle=on ./...passes (53 packages),-raceclean ongeodata,logviewandcontroller, fuzz smoke passes.buildandbuild-storybookpass.npm testpasses 2,078 of 2,079. The one failure,no-static-message.test.ts, is a timeout in a Linux container over a Windows bind mount; it also times out on untouchedmainin that setup and passes natively on Windows.make genoutput is clean, and the OpenAPI copies and API docs are regenerated.geoip.datand generated logs, in light and dark themes and at mobile width, with no console errors or horizontal overflow. Filtering to one country returned exactly the count the map showed.Not tested
make verifyas a single command (each step was run separately), the live-Postgres job,make node-e2e,make vulncheckand the docs site's CI checks.Screenshots / recordings
Breaking changes
None. No database changes, no change to the default config, and the API changes only add endpoints.
Notes for reviewers
Security. Files are opened through
os.Rootafter a filename allowlist, must be regular files, and are never read through a symlink. Nothing shells out totailorgrep.Privacy. Countries come from the local
geoip.dat. No IP address is sent to an external service.Resource limits. Each request scans at most 64 MiB, with 4 concurrent scans and a 16 KiB limit per line. No new dependencies.
geoip.datThings I'd like your view on
frontend/scripts/build-world-map.mjs; that script's dependencies are deliberately not inpackage.json.Small changes to existing code.
Sparklinegains optionalonPointClickandrightPaddingprops.assetDir()now delegates to the newxray.AssetDir(), andcidrBytesingeodata/reader.gois split so the newparseCIDRcan be reused.Diff size. Of about 9,700 added lines, roughly 3,700 are source and map data. The rest is tests (2,270), generated files and OpenAPI (2,590) and translations (1,180).
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.