[PR #5079] [MERGED] feat: customizable subscription page templates #5773

Closed
opened 2026-11-02 04:03:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5079
Author: @rqzbeh
Created: 6/8/2026
Status: ✅ Merged
Merged: 6/8/2026
Merged by: @MHSanaei

Base: main ← Head: feature/custom-sub-templates


📝 Commits (10+)

  • 900c080 feat: add support for subscription-based outbounds with auto-update
  • 9f8a186 Merge pull request #1 from rqzbeh/feat/outbound-subscriptions
  • cbb0653 Merge branch 'main' into main
  • 37d2cb7 Merge branch 'main' into main
  • f9dbf1f fix: resolve frontend lint/type errors and Go build break
  • 5c7c72a fix(xray): make outbound subscription creation work end-to-end
  • 602162e feat(xray): show traffic/test for subscription outbounds; harden + test the feature
  • 837286c fix(xray): make outbound-subs feature pass CI (test compile, route docs, openapi)
  • ddbb1be feat(xray): per-subscription allow-private, gap-filled tags, UI tweaks, delete refresh
  • b3d97c6 i18n(xray): translate outbound-subscription UI into all locales

📊 Changes

25 files changed (+369 additions, -21 deletions)

View changed files

📝 frontend/public/openapi.json (+10 -0)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+10 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/models/setting.ts (+1 -0)
📝 frontend/src/pages/settings/SubscriptionGeneralTab.tsx (+5 -0)
📝 sub/subController.go (+111 -21)
➕ sub/subController_test.go (+149 -0)
➕ sub_templates/README.md (+44 -0)
📝 web/entity/entity.go (+1 -0)
📝 web/service/setting.go (+6 -0)
📝 web/translation/ar-EG.json (+2 -0)
📝 web/translation/en-US.json (+2 -0)
📝 web/translation/es-ES.json (+2 -0)
📝 web/translation/fa-IR.json (+2 -0)
📝 web/translation/id-ID.json (+2 -0)
📝 web/translation/ja-JP.json (+2 -0)
📝 web/translation/pt-BR.json (+2 -0)
📝 web/translation/ru-RU.json (+2 -0)

...and 5 more files

📄 Description

Summary

Adds support for custom subscription page HTML templates. Panel admins can replace the default React subscription page with their own HTML template, rendered server-side with Go's html/template.

How it works

When a browser opens a subscription URL, if the Sub Theme Directory setting points to a folder containing sub.html or index.html, that template is rendered with all subscription data injected as template variables (sub.html takes precedence over index.html).

If the path is empty, missing, not a directory, or the template fails to parse/execute, the panel logs the reason and falls back to the default built-in React page — the response is rendered into a buffer first, so a failed template can never leave a half-written/corrupt response.

Rendering notes:

  • Templates are parsed once and cached, re-parsed only when the file's modification time changes — so admin edits are picked up live, without re-reading and re-parsing the file on every request.
  • html/template is used deliberately: its context-aware auto-escaping protects against XSS from user-influenced data (e.g. remarks inside config links).

New setting: Sub Theme Directory

Settings → Subscription → Information → Sub Theme Directory

Set it to an absolute path (e.g. /etc/3x-ui/sub_templates/my-theme/) to activate a custom template; leave it empty for the default page. The setting is read live per request (no restart needed) and its label/description are translated into all locales.

Templates are admin-provided — create the folder on your server, put an index.html/sub.html in it, and point the setting at it. Nothing is bundled into the binary or auto-deployed.

Available template variables

Variable Type Description
.sId string Subscription ID
.enabled bool Whether the subscription is active
.download / .upload string Formatted download / upload
.total / .used / .remained string Formatted total / used / remaining
.downloadByte / .uploadByte / .totalByte int64 Exact byte counts
.expire int64 Expiry — Unix timestamp in seconds (0 = never)
.lastOnline int64 Last online — Unix timestamp in milliseconds (0 = never)
.subUrl / .subJsonUrl / .subClashUrl string Subscription / JSON / Clash URLs
.subTitle string Subscription title from settings (page branding)
.subSupportUrl string Support URL from settings
.links []string All config links ({{ range .links }}…{{ end }})
.emails []string Client emails
.datepicker string "gregorian" or "jalali"

The authoring guide lives in sub_templates/README.md.

Files changed

File Change
sub/subController.go Custom-template loading/rendering: buffered fallback, mtime cache, IsDir guard + diagnostic logs, subTitle/subSupportUrl variables
sub/subController_test.go Unit tests: render, sub.html precedence, fallback cases, malformed template, mtime cache invalidation
web/service/setting.go, web/entity/entity.go subThemeDir setting default + GetSubThemeDir()
frontend/src/models/setting.ts, frontend/src/pages/settings/SubscriptionGeneralTab.tsx Sub Theme Directory input (i18n)
web/translation/*.json subThemeDir / subThemeDirDesc in all locales
sub_templates/README.md Template authoring guide

Testing

Verified end-to-end in Docker:

  • Valid template renders with every variable (incl. subTitle/subSupportUrl).
  • sub.html takes precedence over index.html.
  • Empty / non-existent path / non-directory / malformed template all fall back to the clean default page — no response corruption (superfluous WriteHeader never occurs).
  • The mtime cache reflects live edits without a restart.

Go unit tests cover the loader; frontend lint + typecheck pass.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5079 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/8/2026 **Status:** ✅ Merged **Merged:** 6/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feature/custom-sub-templates` --- ### 📝 Commits (10+) - [`900c080`](https://github.com/MHSanaei/3x-ui/commit/900c08042b89eed95a5b4bf9af25dfac39e7a2d6) feat: add support for subscription-based outbounds with auto-update - [`9f8a186`](https://github.com/MHSanaei/3x-ui/commit/9f8a186cd4acdfc6989171faea5076e6983ac250) Merge pull request #1 from rqzbeh/feat/outbound-subscriptions - [`cbb0653`](https://github.com/MHSanaei/3x-ui/commit/cbb0653eeebd9f2810096249f49fd33a2a08a103) Merge branch 'main' into main - [`37d2cb7`](https://github.com/MHSanaei/3x-ui/commit/37d2cb786c2ff59c4d8a43609f965eed1cb582f9) Merge branch 'main' into main - [`f9dbf1f`](https://github.com/MHSanaei/3x-ui/commit/f9dbf1f1e0257a4d45a5112fd604b8641a490c92) fix: resolve frontend lint/type errors and Go build break - [`5c7c72a`](https://github.com/MHSanaei/3x-ui/commit/5c7c72a3e3c22cacb9054bb9c3d07c5d1498609a) fix(xray): make outbound subscription creation work end-to-end - [`602162e`](https://github.com/MHSanaei/3x-ui/commit/602162e7eca576828bd622b78de27787adfa8284) feat(xray): show traffic/test for subscription outbounds; harden + test the feature - [`837286c`](https://github.com/MHSanaei/3x-ui/commit/837286cb51933f1425f6d56c9843f91565fc6070) fix(xray): make outbound-subs feature pass CI (test compile, route docs, openapi) - [`ddbb1be`](https://github.com/MHSanaei/3x-ui/commit/ddbb1befe5caa5fe990f44aab01202436a99318e) feat(xray): per-subscription allow-private, gap-filled tags, UI tweaks, delete refresh - [`b3d97c6`](https://github.com/MHSanaei/3x-ui/commit/b3d97c6f036799eed0032160ec46dbdccd1173d3) i18n(xray): translate outbound-subscription UI into all locales ### 📊 Changes **25 files changed** (+369 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+10 -0) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+10 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/models/setting.ts` (+1 -0) 📝 `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` (+5 -0) 📝 `sub/subController.go` (+111 -21) ➕ `sub/subController_test.go` (+149 -0) ➕ `sub_templates/README.md` (+44 -0) 📝 `web/entity/entity.go` (+1 -0) 📝 `web/service/setting.go` (+6 -0) 📝 `web/translation/ar-EG.json` (+2 -0) 📝 `web/translation/en-US.json` (+2 -0) 📝 `web/translation/es-ES.json` (+2 -0) 📝 `web/translation/fa-IR.json` (+2 -0) 📝 `web/translation/id-ID.json` (+2 -0) 📝 `web/translation/ja-JP.json` (+2 -0) 📝 `web/translation/pt-BR.json` (+2 -0) 📝 `web/translation/ru-RU.json` (+2 -0) _...and 5 more files_ </details> ### 📄 Description ## Summary Adds support for **custom subscription page HTML templates**. Panel admins can replace the default React subscription page with their own HTML template, rendered server-side with Go's `html/template`. ## How it works When a browser opens a subscription URL, if the **Sub Theme Directory** setting points to a folder containing `sub.html` or `index.html`, that template is rendered with all subscription data injected as template variables (`sub.html` takes precedence over `index.html`). If the path is empty, missing, not a directory, or the template fails to parse/execute, the panel logs the reason and falls back to the default built-in React page — the response is rendered into a buffer first, so a failed template can never leave a half-written/corrupt response. Rendering notes: - Templates are parsed once and cached, re-parsed only when the file's modification time changes — so admin edits are picked up live, without re-reading and re-parsing the file on every request. - `html/template` is used deliberately: its context-aware auto-escaping protects against XSS from user-influenced data (e.g. remarks inside config links). ## New setting: Sub Theme Directory **Settings → Subscription → Information → Sub Theme Directory** Set it to an absolute path (e.g. `/etc/3x-ui/sub_templates/my-theme/`) to activate a custom template; leave it empty for the default page. The setting is read live per request (no restart needed) and its label/description are translated into all locales. > Templates are admin-provided — create the folder on your server, put an `index.html`/`sub.html` in it, and point the setting at it. Nothing is bundled into the binary or auto-deployed. ## Available template variables | Variable | Type | Description | |---|---|---| | `.sId` | string | Subscription ID | | `.enabled` | bool | Whether the subscription is active | | `.download` / `.upload` | string | Formatted download / upload | | `.total` / `.used` / `.remained` | string | Formatted total / used / remaining | | `.downloadByte` / `.uploadByte` / `.totalByte` | int64 | Exact byte counts | | `.expire` | int64 | Expiry — Unix timestamp in **seconds** (`0` = never) | | `.lastOnline` | int64 | Last online — Unix timestamp in **milliseconds** (`0` = never) | | `.subUrl` / `.subJsonUrl` / `.subClashUrl` | string | Subscription / JSON / Clash URLs | | `.subTitle` | string | Subscription title from settings (page branding) | | `.subSupportUrl` | string | Support URL from settings | | `.links` | []string | All config links (`{{ range .links }}…{{ end }}`) | | `.emails` | []string | Client emails | | `.datepicker` | string | `"gregorian"` or `"jalali"` | The authoring guide lives in `sub_templates/README.md`. ## Files changed | File | Change | |---|---| | `sub/subController.go` | Custom-template loading/rendering: buffered fallback, mtime cache, `IsDir` guard + diagnostic logs, `subTitle`/`subSupportUrl` variables | | `sub/subController_test.go` | Unit tests: render, `sub.html` precedence, fallback cases, malformed template, mtime cache invalidation | | `web/service/setting.go`, `web/entity/entity.go` | `subThemeDir` setting default + `GetSubThemeDir()` | | `frontend/src/models/setting.ts`, `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` | Sub Theme Directory input (i18n) | | `web/translation/*.json` | `subThemeDir` / `subThemeDirDesc` in all locales | | `sub_templates/README.md` | Template authoring guide | ## Testing Verified end-to-end in Docker: - Valid template renders with every variable (incl. `subTitle`/`subSupportUrl`). - `sub.html` takes precedence over `index.html`. - Empty / non-existent path / non-directory / malformed template all fall back to the clean default page — no response corruption (`superfluous WriteHeader` never occurs). - The mtime cache reflects live edits without a restart. Go unit tests cover the loader; frontend `lint` + `typecheck` pass. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5773
No description provided.