Commit Graph
66 Commits
Author SHA1 Message Date
naiba 353151b940 Merge pull request #159 from weblate/weblate-nezha-admin-frontend
Translations update from Hosted Weblate
2026-06-05 00:12:32 +08:00
naiba 005b4a0b3b feat(service): replace show-in-service with hide-for-guest toggle
Mirror the server HideForGuest flag on services: rename the
enable_show_in_service field to hide_for_guest across the form, schema
and generated types, reuse the existing HideForGuest label, and drop the
now-orphaned ShowInService i18n keys. Services are now visible to guests
by default and hidden only when the box is checked, matching servers.
2026-06-02 03:07:36 +00:00
naiba 66e20c3860 feat(api-tokens): split inventory scope out of server scope
Surface the new nezha:inventory:{read,delete,*} scopes that gate listing
and deleting servers/server-groups, separate from nezha:server:* which now
covers per-server runtime operations. Refine server-scope descriptions to
match the backend split.
2026-05-31 15:10:03 +00:00
naibaandcloudcode 7057aa3098 test(e2e): fix revoke empty-list crash and password-restore CSRF cascade
Two CI-only failures surfaced against a fresh backend DB:

- The revoke test read after.data.find(), but the list endpoint omits data
  entirely when the admin has zero tokens, throwing on undefined. Default to [].
- The password-change test's restore POST hit a 403: changing the password
  triggers a refresh-token that re-mints the nz-csrf cookie, so the X-CSRF-Token
  read just before the request can be stale. A failed restore left the admin on
  the rotated password and cascaded into cron/fm/visibility login failures.
  Add csrfRequest(), which retries once on 403 after re-reading the cookie, and
  use it for both profile mutations.

Verified 8/8 passing across repeated fresh-DB CI-mode runs.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-31 08:45:19 +00:00
naibaandcloudcode 22ebc51a08 test(e2e): send CSRF token on mutating requests and fix PAT UI selectors
The backend CSRF double-submit gate rejects unsafe methods unless
X-CSRF-Token mirrors the signed nz-csrf cookie. page.request bypasses the
SPA JS that does this, so every mutating E2E call got 403, failing the suite.

- Add csrfHeaders(page) helper that mirrors the nz-csrf cookie into the
  header, polling until the cookie is readable to avoid the post-login race.
- Apply it to all cookie-authenticated POST/PATCH/DELETE calls (the /mcp
  Bearer calls stay header-free since PAT requests are CSRF-exempt).
- loginAs waits for the nz-csrf cookie before returning.
- Fix the create-token dialog submit selector: the button is labelled
  'Create API token' (t('CreateApiToken')), not 'Create'.

Verified 8/8 passing across repeated CI-mode runs against a real backend.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-31 08:17:15 +00:00
naibaandcloudcode 013770bf46 fix(security): guard external hrefs and refine CSRF/auth-loading handling
- Add safeExternalHref(): only render http(s) URLs as clickable hrefs,
  blocking attacker-controlled template metadata from becoming
  javascript:/data: links.
- Refine CSRF header attachment and auth-loading state in the fetcher,
  api-tokens client, useAuth, and settings route.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-31 05:51:39 +00:00
naibaandcloudcode 964684f1bf feat(settings): add reserved hosts field and surface NAT errors
Add the reserved_hosts setting (input + i18n across all locales) so operators
behind a reverse proxy can declare public dashboard hostnames members must not
register as NAT domains (GHSA-x6fg-52vr-hj4w).

Show the backend error message on NAT create/update failure instead of a
generic "unexpected error", so a reserved-host rejection is explained.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-31 02:04:47 +00:00
naibaandcloudcode f07c557029 feat(api-tokens): add PAT management UI, CSRF handling, and auth-loading fixes
Add an API tokens management route to create, list, and revoke PATs, showing
the plaintext token once on creation with scope and server-id selection.

Mirror the nz-csrf cookie into the X-CSRF-Token header on unsafe fetcher
methods (POST/PUT/PATCH/DELETE) for the server-side double-submit check, and
self-heal expired sessions via refresh-token without a recursive fetch loop.

Gate protected routes behind resolved auth state to avoid pre-auth SWR fetches,
and fix the login loading/race so stale probes cannot clobber the session.

Add i18n keys for the new screens across all locales.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-30 15:56:53 +00:00
f47d4a8772 ci(e2e): bind Vite dev server to loopback
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 05:56:12 +00:00
f380a8c4ac ci(e2e): prebuild dashboard before backend health check
The GitHub runner can spend more than the readiness window compiling go run ./cmd/dashboard, leaving dashboard.log empty while the backend has not started yet. Build the dashboard binary during preparation and health-check only the actual server startup. Keep README instructions aligned with CI.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 05:36:09 +00:00
e961fdb131 ci(e2e): make backend stubs embeddable and keep vitest scoped
The dashboard embed pattern ignores hidden-only dist directories, so the CI backend stub must create visible index.html files. Keep the README in sync and exclude Playwright specs from Vitest so npm run test remains a unit-test command.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 05:27:46 +00:00
naibaandcloudcode baec84bdc2 docs(e2e): describe how to run Playwright suite locally and read CI artifacts
Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:36:03 +00:00
naibaandcloudcode 52f67d22ba ci: run Playwright e2e against a real Go backend in GitHub Actions
Boot a fresh dashboard from nezhahq/nezha master inside the runner:

- Checkout admin-frontend and the backend repo into two paths.
- Generate the two embed stubs and swag docs so cmd/dashboard builds.
- Inject NZ_JWTSECRETKEY (env-first config story) and start the
  backend on 127.0.0.1:8008 with a tmp SQLite db.
- Wait on /api/v1/setting before letting Playwright launch.
- Playwright config brings up Vite dev which proxies /api to 8008.
- Upload playwright-report and dashboard.log on failure for triage.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:34:43 +00:00
naibaandcloudcode dc0cfd0ecb test(e2e): add Playwright suite for auth + CSRF + visibility fixes
Covers the security fixes that landed across both repos:

- auth.spec.ts: login persists nz-jwt cookie and getProfile succeeds;
  password change bumps TokenVersion + revokes the old cookie so the
  pre-change JWT can no longer auth (regression guard for the
  keyId+session backend rewrite).
- cron-csrf.spec.ts: POST /api/v1/cron/:id/manual succeeds while GET
  is no longer routable (regression guard for the cron CSRF fix).
- fm-csrf.spec.ts: POST /api/v1/file is reachable while GET is no
  longer routable (regression guard for the FM CSRF fix).
- visibility.spec.ts: an anonymous caller cannot see a server-group
  that contains zero guest-visible servers (regression guard for the
  server-group leak fix).

Fixtures wrap the noisy login + cleanup boilerplate. tsconfig is
scoped to tests/e2e so the suite stays out of the production tsc
project graph.

Playwright config starts the Vite dev server (npm run dev) and
expects a backend reachable at the URL Vite proxies to. CI workflow
follow-up commit wires the backend up.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:34:43 +00:00
naibaandcloudcode c80899a753 fix(fm): switch createFM to POST to match backend CSRF fix
Backend moves /api/v1/file from GET to POST so SameSite=Lax cookies
can no longer expose this state-changing endpoint to cross-site
CSRF. Update createFM() accordingly.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:07:52 +00:00
naibaandcloudcode f2fea38e10 fix(cron): switch manual trigger to POST to match backend CSRF fix
Backend GHSA-8qhj-4f8c-j8qg moves /api/v1/cron/:id/manual from GET to
POST so SameSite=Lax cookies no longer expose this state-changing
endpoint to cross-site CSRF. Update runCron() accordingly.

Co-authored-by: cloudcode <cloudcode@users.noreply.github.com>
2026-05-26 04:00:15 +00:00
naiba b23a6c0be1 feat: server transfer rotation 2026-05-25 10:15:24 +00:00
naibaandnaiba/CloudCode 142fc19469 fix: hide admin settings tabs for members
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-16 00:46:15 +08:00
naibaandnaiba/CloudCode b77ac7af93 fix: use Combobox for notification group selection in settings page
Settings page used a plain number input for ip_change_notification_group_id,
requiring users to manually enter a group ID. Replace it with a searchable
Combobox component (consistent with alert-rule/service/cron pages) and wrap
the settings route with NotificationProvider to load notification group data.

Closes nezhahq/nezha#1174

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-03-01 01:11:37 +00:00
奶爸andnaiba 6ddcd0eaea fix: public_note validation rejects non-object JSON values, preventing second edit (#154)
Co-authored-by: naiba <naiba@users.noreply.github.com>
2026-02-19 14:30:10 +08:00
naiba 1b9c82ca5a fix: server edit dialog submit button unresponsive after first save (#1132)
Upgrade react-hook-form 7.63→7.71 to fix form.reset() race condition
that silently broke zod validation on subsequent submissions.

Reset form and public-note state (publicNoteObj/Raw/Mode/Errors)
from latest data when the edit dialog opens, preventing stale state
from a previous edit session.
2026-02-14 12:11:47 +08:00
naiba 13c78a8302 fix: immutable release 2026-01-01 11:58:11 +08:00
naiba 8ae5bee0c0 chore: fix import 2025-10-09 09:48:07 +08:00
naiba 4806ff35fe 💩 f*ck react 2025-10-02 17:15:20 +08:00
naiba 61186143bd fix: Cannot read properties of undefined (reading 'displayName') 2025-10-02 15:26:31 +08:00
naiba 10a04a2daf chore: add locales 2025-08-23 21:09:54 +08:00
naiba 01ed6eae54 feat: 批量转移服务器给其他用户 2025-06-16 23:44:30 +08:00
naiba adac229ab4 chore(i18n): add locale config options 2025-03-29 13:21:14 +08:00
naiba 223cb9c1ae feat(i18n): add locales 2025-03-27 19:11:56 +08:00
naiba 66945cdb15 chore: update locale 2025-03-22 22:37:01 +08:00
naiba f6ce25d466 feat: disable nat 2025-01-21 22:21:52 +08:00
naiba aa00431f8b chore: add type 2024-12-30 21:15:17 +08:00
naiba 718bff0abb feat: oauth2 登录 2024-12-28 23:50:24 +08:00
naiba 8130e336a9 fix: block button 2024-12-23 19:47:57 +08:00
naiba 86115547a5 fix: member role menu 2024-12-23 19:24:46 +08:00
naiba 76f868d242 fix: typo & render error 2024-12-17 22:19:22 +08:00
naiba a1ca16b297 feat: implement InjectContext for dynamic resource injection 2024-12-17 22:03:21 +08:00
naiba 9204e0ae37 chore: refactor 2024-12-15 20:26:35 +08:00
naiba 1a2c5a5a44 chore: change key 2024-12-15 15:27:23 +08:00
naiba 71e2f1a699 feat: 后台自定义代码 & 后端语言优先 2024-12-15 15:08:57 +08:00
naiba 5bd0e1c073 fix: animate man position 2024-12-15 10:57:47 +08:00
naiba 97d49de6be refactor: enum i18n 2024-12-14 10:39:07 +08:00
naiba dc2f28979f feat: api update 2024-12-10 22:19:31 +08:00
naiba e2027a0ef0 fix: local debug 2024-12-09 23:11:17 +08:00
naiba 2e814e6f5e fix: websocket 2024-12-02 23:51:24 +08:00
naiba 4cdb11059a fix: websocket 2024-12-02 22:10:07 +08:00
naiba 7f3f6e8af1 chore: i18n 2024-12-01 21:50:59 +08:00
naiba c49bbb54e1 fix: waf page 2024-11-30 21:31:55 +08:00
naiba ef70277ff4 feat: 优化复制安装命令提示 2024-11-30 20:14:49 +08:00
naiba a3c9fcec73 fix: copy to clipboard 2024-11-30 17:08:47 +08:00
naiba c98632bc17 feat: 修改用户名,简化代码 2024-11-30 15:02:42 +08:00
naiba 3e9a75125a feat: 调整安装脚本复制位置 2024-11-30 12:58:53 +08:00
naiba 48cdd6f4d5 Merge pull request #1 from uubulb/dev 2024-11-25 13:37:19 +08:00
naiba f17bdbf760 fix: logout & login page home button 2024-11-23 10:25:54 +08:00
naiba 135cdf1111 rename 2024-11-23 01:18:01 +08:00
naiba be2f5a519f chore: fetch depth 0 2024-11-20 22:32:02 +08:00
naiba 48ea9ca76a fix: build ignore error 2024-11-20 22:29:08 +08:00
naiba 4c93d1643b release 2024-11-20 22:04:08 +08:00
naiba 0c38d52025 Merge pull request #2 from uubulb/dev
init service page
2024-11-15 23:06:26 +08:00
naiba f842d5aeec feat: auto generate api types 2024-11-09 00:07:21 +08:00
naiba 680dc219d3 feat: server table 1/10 2024-11-06 00:09:03 +08:00
naiba bfdae2838f feat: refresh token 2024-11-05 00:02:43 +08:00
naiba b1a0b607da feat: login & check user 2024-11-03 23:29:32 +08:00
naiba 772d66334e 🚧 server/service 2024-11-02 22:58:56 +08:00
naiba 017e6cfdcf login page 2024-11-02 22:34:43 +08:00
naiba d945ca97c1 🎉 init vite & shadcn-ui 2024-11-01 22:47:49 +08:00