[PR #6545] [MERGED] feat(happ): add routing editor, optional ad blocking, and LAN bypass preset #6342

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6545
Author: @NgaiYeanCoi
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei

Base: main ← Head: feat/happ-presets-adblock


📝 Commits (8)

  • 8f7f8e2 feat(happ): make ad blocking optional in routing presets
  • 72282ef feat: add visual routing editor with JSON support and localization updates
  • 5e249ce Merge branch 'main' into feat/happ-presets-adblock
  • f0ce53a feat: update routing editor to preserve null lists in profiles and enhance validation messages
  • 12bbc96 Merge branch 'feat/happ-presets-adblock' of github.com:NgaiYeanCoi/3x-ui into feat/happ-presets-adblock
  • 940cee7 Merge branch 'main' into feat/happ-presets-adblock
  • a223e98 Merge branch 'main' into feat/happ-presets-adblock
  • a6a28f9 Merge branch 'main' into feat/happ-presets-adblock

📊 Changes

22 files changed (+1356 additions, -202 deletions)

View changed files

➕ frontend/src/pages/settings/HappRoutingEditorModal.tsx (+204 -0)
📝 frontend/src/pages/settings/HappSettingsContent.tsx (+28 -104)
📝 frontend/src/pages/settings/happPresets.ts (+57 -27)
➕ frontend/src/pages/settings/happRoutingEditor.ts (+90 -0)
➕ frontend/src/schemas/happRouting.ts (+16 -0)
📝 frontend/src/test/happ-presets.test.ts (+77 -19)
➕ frontend/src/test/happ-routing-editor-helpers.test.ts (+156 -0)
➕ frontend/src/test/happ-routing-editor.test.tsx (+322 -0)
➕ frontend/src/test/happ-settings-presets.test.tsx (+211 -0)
📝 internal/web/translation/ar-EG.json (+15 -4)
📝 internal/web/translation/en-US.json (+15 -4)
📝 internal/web/translation/es-ES.json (+15 -4)
📝 internal/web/translation/fa-IR.json (+15 -4)
📝 internal/web/translation/id-ID.json (+15 -4)
📝 internal/web/translation/ja-JP.json (+15 -4)
📝 internal/web/translation/pt-BR.json (+15 -4)
📝 internal/web/translation/ru-RU.json (+15 -4)
📝 internal/web/translation/tr-TR.json (+15 -4)
📝 internal/web/translation/uk-UA.json (+15 -4)
📝 internal/web/translation/vi-VN.json (+15 -4)

...and 2 more files

📄 Description

Summary

Adds basic and advanced JSON editing for existing Happ routing profiles, optional ad blocking, and a separate Global Bypass Local Network preset.

  • Preserve DNS settings, custom fields, and the original add / onadd mode when editing.
  • Replace the standalone AdBlock preset with an Include AdBlock switch.
  • Keep existing Global Proxy routing behavior.

Why

The previous rule generator started from empty lists. Editing an existing profile therefore required manually decoding its link and carrying over settings such as DNS configuration, routing strategy, and custom fields.

Ad blocking was also bundled into the Iran and China presets, while a separate AdBlock preset represented another routing configuration. This made it difficult to choose a routing policy and independently decide whether to include ad blocking.

During the preset review, I used the v2rayNG routing presets as references for private-network and regional bypass rules . The resulting profiles use Happ's routing format and retain a separate choice for users who want global proxying with local-network access.

1. Routing presets and optional ad blocking

Generated profile Direct routing groups Domain strategy
Iran Bypass Private networks and Iranian domains/IPs IPIfNonMatch
Bypass-CN Private networks and Chinese domains/IPs IPIfNonMatch
Global Proxy Empty direct lists AsIs
Global Bypass Local Network geosite:private and geoip:private AsIs

All four profiles use GlobalProxy: "true" as the proxy fallback. Explicit direct rules provide the bypass behavior.

The LAN preset uses a separate lan-bypass identifier in the panel and the profile name Global Bypass Local Network, avoiding a name collision with the existing Global Proxy profile.

Include AdBlock defaults to off. Enabling it adds:

{
  "BlockSites": ["geosite:category-ads-all"]
}

The switch is a generator option. Its effect is stored in the generated profile when the page is saved.

The standalone AdBlock preset is removed. Off continues to generate happ://routing/off, with the AdBlock control disabled.

2. Regional preset adjustments

The Iran preset uses domain:ir together with geosite:category-ir and private-network rules. This replaces the previous .ir regular expression.

The China profile is special optimize generated as Bypass-CN and includes:

  • Cloudflare DoH for remote DNS.
  • AliDNS DoH for domestic DNS.
  • DNS host mappings for both resolver names.
  • Chinese and private-network direct rules.
  • IPIfNonMatch, disabled FakeDNS, and enabled chunk files.

Profiles for other regions require dedicated optimization by other contributors.

Both regional presets explicitly use RouteOrder: "block-proxy-direct".

3. Preserving fields during editing

The Basic rules tab exposes the six domain and IP lists for direct, proxy, and block routing.

Only edited lists are replaced. Untouched lists, absent fields, DNS settings, and unknown extension fields survive regeneration. Preservation applies to profile values; JSON formatting and Base64 representation may normalize.

The Advanced editor exposes the complete JSON object. Switching between tabs synchronizes valid changes in both directions.
Invalid JSON prevents generation and switching back to Basic rules until it is corrected.

4. Validation and compatibility boundaries

Validation checks that the profile is a JSON object and that each supported routing list, when present, is an array of strings.

Other Happ fields and extension values are preserved without full semantic validation. The editor does not verify individual rule syntax, geodata availability, DNS reachability, or the resulting traffic behavior.

Private-network matching depends on the geodata available to the Happ client. Automated frontend tests cover generated payloads and editor behavior.

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?

cd frontend
npm test -- --project unit src/test/happ-presets.test.ts src/test/happ-routing-editor-helpers.test.ts
npm test -- --project components src/test/happ-settings-presets.test.tsx src/test/happ-routing-editor.test.tsx
npm run typecheck
npm run lint
cd ..
make build build-storybook
make verify

Screenshots / recordings

image image image image

Breaking changes

None

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.

🔄 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/6545 **Author:** [@NgaiYeanCoi](https://github.com/NgaiYeanCoi) **Created:** 9/15/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/happ-presets-adblock` --- ### 📝 Commits (8) - [`8f7f8e2`](https://github.com/MHSanaei/3x-ui/commit/8f7f8e2e9a157fab1ddf44fa6e9882c18ba7918f) feat(happ): make ad blocking optional in routing presets - [`72282ef`](https://github.com/MHSanaei/3x-ui/commit/72282ef4d111816f0684a82f34359220496263a3) feat: add visual routing editor with JSON support and localization updates - [`5e249ce`](https://github.com/MHSanaei/3x-ui/commit/5e249ce2180b9d297f7790f54540c2e8cd792a19) Merge branch 'main' into feat/happ-presets-adblock - [`f0ce53a`](https://github.com/MHSanaei/3x-ui/commit/f0ce53a1a083c37559bd3853278e0511c48d0052) feat: update routing editor to preserve null lists in profiles and enhance validation messages - [`12bbc96`](https://github.com/MHSanaei/3x-ui/commit/12bbc962f7953982ee2a5a7a6ab9601e9d743761) Merge branch 'feat/happ-presets-adblock' of github.com:NgaiYeanCoi/3x-ui into feat/happ-presets-adblock - [`940cee7`](https://github.com/MHSanaei/3x-ui/commit/940cee706e933619e5f8e42c1a6eb9f997be121e) Merge branch 'main' into feat/happ-presets-adblock - [`a223e98`](https://github.com/MHSanaei/3x-ui/commit/a223e9839ec693857e791bfb1f9f8365c0b78b34) Merge branch 'main' into feat/happ-presets-adblock - [`a6a28f9`](https://github.com/MHSanaei/3x-ui/commit/a6a28f923193d4970d06a9ba1a8383f0edb435f4) Merge branch 'main' into feat/happ-presets-adblock ### 📊 Changes **22 files changed** (+1356 additions, -202 deletions) <details> <summary>View changed files</summary> ➕ `frontend/src/pages/settings/HappRoutingEditorModal.tsx` (+204 -0) 📝 `frontend/src/pages/settings/HappSettingsContent.tsx` (+28 -104) 📝 `frontend/src/pages/settings/happPresets.ts` (+57 -27) ➕ `frontend/src/pages/settings/happRoutingEditor.ts` (+90 -0) ➕ `frontend/src/schemas/happRouting.ts` (+16 -0) 📝 `frontend/src/test/happ-presets.test.ts` (+77 -19) ➕ `frontend/src/test/happ-routing-editor-helpers.test.ts` (+156 -0) ➕ `frontend/src/test/happ-routing-editor.test.tsx` (+322 -0) ➕ `frontend/src/test/happ-settings-presets.test.tsx` (+211 -0) 📝 `internal/web/translation/ar-EG.json` (+15 -4) 📝 `internal/web/translation/en-US.json` (+15 -4) 📝 `internal/web/translation/es-ES.json` (+15 -4) 📝 `internal/web/translation/fa-IR.json` (+15 -4) 📝 `internal/web/translation/id-ID.json` (+15 -4) 📝 `internal/web/translation/ja-JP.json` (+15 -4) 📝 `internal/web/translation/pt-BR.json` (+15 -4) 📝 `internal/web/translation/ru-RU.json` (+15 -4) 📝 `internal/web/translation/tr-TR.json` (+15 -4) 📝 `internal/web/translation/uk-UA.json` (+15 -4) 📝 `internal/web/translation/vi-VN.json` (+15 -4) _...and 2 more files_ </details> ### 📄 Description ## Summary <!-- What does this PR do? One or two sentences. --> Adds basic and advanced JSON editing for existing Happ routing profiles, optional ad blocking, and a separate **Global Bypass Local Network** preset. - Preserve DNS settings, custom fields, and the original `add` / `onadd` mode when editing. - Replace the standalone AdBlock preset with an **Include AdBlock** switch. - Keep existing Global Proxy routing behavior. ## Why <!-- What problem does this solve, or what use case does it enable? Link related issues here: "Closes #123", "Refs #456". --> The previous rule generator started from empty lists. Editing an existing profile therefore required manually decoding its link and carrying over settings such as DNS configuration, routing strategy, and custom fields. Ad blocking was also bundled into the Iran and China presets, while a separate AdBlock preset represented another routing configuration. This made it difficult to choose a routing policy and independently decide whether to include ad blocking. During the preset review, I used the [v2rayNG routing presets](https://github.com/2dust/v2rayNG/tree/a9b1242686aff04f4b3d06f03f29379642fbfd26/V2rayNG/app/src/main/assets) as references for private-network and regional bypass rules . The resulting profiles use Happ's routing format and retain a separate choice for users who want global proxying with local-network access. ### 1. Routing presets and optional ad blocking | Generated profile | Direct routing groups | Domain strategy | | --- | --- | --- | | Iran Bypass | Private networks and Iranian domains/IPs | `IPIfNonMatch` | | Bypass-CN | Private networks and Chinese domains/IPs | `IPIfNonMatch` | | Global Proxy | Empty direct lists | `AsIs` | | Global Bypass Local Network | `geosite:private` and `geoip:private` | `AsIs` | All four profiles use `GlobalProxy: "true"` as the proxy fallback. Explicit direct rules provide the bypass behavior. The LAN preset uses a separate `lan-bypass` identifier in the panel and the profile name `Global Bypass Local Network`, avoiding a name collision with the existing `Global Proxy` profile. **Include AdBlock** defaults to off. Enabling it adds: ```json { "BlockSites": ["geosite:category-ads-all"] } ``` The switch is a generator option. Its effect is stored in the generated profile when the page is saved. The standalone AdBlock preset is removed. **Off** continues to generate `happ://routing/off`, with the AdBlock control disabled. ### 2. Regional preset adjustments The Iran preset uses `domain:ir` together with `geosite:category-ir` and private-network rules. This replaces the previous `.ir` regular expression. The China profile is special optimize generated as `Bypass-CN` and includes: - Cloudflare DoH for remote DNS. - AliDNS DoH for domestic DNS. - DNS host mappings for both resolver names. - Chinese and private-network direct rules. - `IPIfNonMatch`, disabled FakeDNS, and enabled chunk files. **Profiles for other regions require dedicated optimization by other contributors.** Both regional presets explicitly use `RouteOrder: "block-proxy-direct"`. ### 3. Preserving fields during editing The Basic rules tab exposes the six domain and IP lists for direct, proxy, and block routing. Only edited lists are replaced. Untouched lists, absent fields, DNS settings, and unknown extension fields survive regeneration. Preservation applies to profile values; JSON formatting and Base64 representation may normalize. The Advanced editor exposes the complete JSON object. Switching between tabs synchronizes valid changes in both directions. Invalid JSON prevents generation and switching back to Basic rules until it is corrected. ### 4. Validation and compatibility boundaries Validation checks that the profile is a JSON object and that each supported routing list, when present, is an array of strings. Other Happ fields and extension values are preserved without full semantic validation. The editor does not verify individual rule syntax, geodata availability, DNS reachability, or the resulting traffic behavior. Private-network matching depends on the geodata available to the Happ client. Automated frontend tests cover generated payloads and editor behavior. ## Type of change - [X] Bug fix - [X] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [X] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [X] 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? <!-- Concrete steps the reviewer can repeat. For UI changes: which page, which actions, which browser. For backend: which endpoint, which payload, which response. Mention any new unit/integration tests added. --> ```bash cd frontend npm test -- --project unit src/test/happ-presets.test.ts src/test/happ-routing-editor-helpers.test.ts npm test -- --project components src/test/happ-settings-presets.test.tsx src/test/happ-routing-editor.test.tsx npm run typecheck npm run lint cd .. make build build-storybook make verify ``` ## Screenshots / recordings <!-- Required for UI changes. Drag images or GIFs here. Remove if N/A. --> <img width="979" height="797" alt="image" src="https://github.com/user-attachments/assets/da9bfb59-7f3c-48bd-add5-f349fa3fe8c2" /> <img width="1791" height="684" alt="image" src="https://github.com/user-attachments/assets/ed6bff0c-96dc-4d44-a1cb-7d16f8ef6d5b" /> <img width="664" height="944" alt="image" src="https://github.com/user-attachments/assets/178a2d1a-1459-48f6-8672-8b30995933d2" /> <img width="728" height="748" alt="image" src="https://github.com/user-attachments/assets/9d3c4b41-7f8e-4090-9459-6e5f377a88c6" /> ## Breaking changes None <!-- Does this change require existing users to update their config, run a migration, or change their API calls? If yes, describe the migration path. Write "None" if there are no breaking changes. --> ## Checklist - [X] I tested the change locally and confirmed the described behavior. - [X] I added or updated tests for the new behavior (when applicable). - [X] `go build ./...` and the test suite pass locally. - [X] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [X] I updated the Wiki / README / API docs if user-facing behavior changed. - [X] My commits follow the project's existing message style. - [X] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:05 +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#6342
No description provided.