Skip to content

feat(sub): allow admins to edit JSON subscription base template#5380

Open
aleskxyz wants to merge 1 commit into
MHSanaei:mainfrom
aleskxyz:custom-json-sub
Open

feat(sub): allow admins to edit JSON subscription base template#5380
aleskxyz wants to merge 1 commit into
MHSanaei:mainfrom
aleskxyz:custom-json-sub

Conversation

@aleskxyz

Copy link
Copy Markdown
Contributor

Summary

Adds an admin-editable JSON subscription base template (subJsonTemplate) so the skeleton of each JSON subscription (dns, inbounds, policy, routing, tail outbounds) can be changed from the panel. Proxy outbounds and remarks are still generated per client.

Why

JSON subscriptions were built from a fixed embedded skeleton with no panel setting to customize dns, inbounds, policy, routing, or tail outbounds. This adds subJsonTemplate, seeded from default.json on first start, with a settings UI and API to edit and reset the template.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Backend

  • go test ./internal/sub/... — custom base template, rules overlay without routing, null-template fallback
  • go test ./internal/web/service/... -run 'SubJson|SeedSubJson' — seeding, CheckValid (including non-object rejection)

Frontend

  • npm run typecheck, npm run lint, npm run test — all pass (541 tests)

Manual

  1. Settings → Subscription formats → Base JSON template tab
  2. Edit template JSON, save settings, restart panel
  3. Fetch a client JSON subscription and confirm skeleton matches template + generated proxy outbound
  4. Reset to default → confirm dialog → editor loads built-in default.json → save + restart applies

Screenshots / recordings

N/A (new settings tab with JSON editor and reset button; no screenshots attached).

Breaking changes

None. Existing installs get the embedded default seeded when the setting is empty. Default subscription output is unchanged until an admin edits the template.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

Note: go test ./... currently fails on one pre-existing unrelated check: TestAPIRoutesDocumented — missing docs for POST /panel/api/clients/clientIpsByGuid. All tests for this feature pass.

@forwork10

Copy link
Copy Markdown

I would also like to see the ability to configure the balancer, for example, add an "Auto" outbound that will connect to one of the servers from the config

JSON subscriptions were built from a hard-coded skeleton, so
customizing dns/inbounds/policy/routing/tail outbounds required
nginx sub_filter or manual DB edits. Store the skeleton in a new
subJsonTemplate setting, seeded from embedded default.json on
first start; proxy outbounds and remarks are still generated per
client.

Add a Base JSON template tab under subscription format settings,
GET /panel/api/setting/getDefaultSubJsonTemplate for reset, and
save-time validation that the template must be a JSON object.
Reject non-object roots at save; fall back to the embedded default
at runtime when parsing fails. Panel restart is required for
subscription output to pick up changes.

Signed-off-by: aleskxyz <39186039+aleskxyz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants