[PR #6994] feat(scripts): allow random or custom Web Base Path from menu #6567

Open
opened 2026-11-02 04:09:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6994
Author: @HamedSanaei
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: feat/custom-web-base-path-menu


📝 Commits (1)

  • c5df14b feat(scripts): support custom web base path in menu

📊 Changes

2 files changed (+340 additions, -9 deletions)

View changed files

➕ scripts_menu_base_path_test.go (+242 -0)
📝 x-ui.sh (+98 -9)

📄 Description

Summary

  • Extend existing menu option 8 with random, custom, and cancel choices; keep the existing 18-character random generator.
  • Validate custom paths and normalize them to /path/, preserving capitalization and accepting short/nested paths such as /a/ and /private/admin/.
  • Show the proposed path and require a final confirmation for both modes. Accept case-insensitive yes/no answers; empty confirmation cancels. Invalid choices/paths retry, and EOF cancels without a write.
  • Read the current normalized path, skip an identical value, check the CLI update acknowledgment, and read back the saved setting before restarting exactly once. Failed reads/writes/verification never produce the new success notice or restart the panel.

Motivation

Option 8 previously always generated a random path. Administrators could not select a memorable or predefined path through the menu, and the handler reported success and restarted even when the CLI failed.

The new input allowlist accepts letters, digits, hyphens and underscores in single-slash-separated segments. It rejects empty/root-only values, traversal/dot segments, repeated separators, whitespace/control characters, query strings, fragments, backslashes and other unsafe characters. An invalid custom value is never replaced with randomness.

Released CLIs can print an error with exit status zero. The handler therefore requires the existing Base URI path set successfully acknowledgment and independently verifies the stored webBasePath from setting -show. Settings reads reject missing/duplicate/malformed path records and reported getter/database errors.

Compatibility

  • No new top-level menu item, dependencies, migrations, API contracts, or frontend changes.
  • Only setting -webBasePath is used for the mutation. Credentials, port, TLS configuration and database settings are preserved.
  • Existing random generation remains available, with a preview and final confirmation added.
  • Related work: #6964 fixes the separate update/reinstall bug that overwrites short paths. This PR leaves install.sh and update.sh untouched and does not duplicate that work. Short-path preservation on future updates/reinstalls requires #6964 to be merged; this menu feature alone does not fix that existing bug. The changed files do not overlap.
  • An isolated composition check against #6964 at a99be10d499b09278075bd0f2cbf2f3e8fe8163c confirmed that menu-selected /a/, /ab/, /mypanel/, and /private/admin/ survive two consecutive install/update configuration passes without another write, random generation, or path-related restart.

Testing

  • Regression baseline: the new menu suite failed 76 of 79 scenarios on the original handler, reproducing missing custom selection, validation, confirmation and persistence safeguards.
  • gofmt -w scripts_menu_base_path_test.go — completed.
  • bash -n x-ui.sh — passed.
  • shellcheck --severity=error x-ui.sh — passed with 0.9.0 and 0.11.0.
  • go test -run '^TestMenuWebBasePath$' -count=1 -v . — 79 scenarios passed under Linux/Go 1.27.3.
  • Full root-package test binary (go test -c, then -test.count=1 -test.v) — all 14 test functions passed, including the 79 menu scenarios, as UID/GID 65534:65534 in a container with a read-only repository mount.
  • go test -race -run '^TestMenuWebBasePath$' -count=1 . — passed.
  • go vet . — passed.
  • golangci-lint run . — passed, 0 issues (v2.15.0).
  • git diff --check and git diff --cached --check — passed.

The Go tests execute only extracted Bash function definitions, with temporary CLI/state fixtures and a mocked restart. They inspect the actual CLI argument, stored path, write/read/restart order, no-change/cancel behavior, all affirmative forms, unsafe-input retries, random failures, zero-exit errors, malformed settings reads, persistence mismatch, EOF, quoted executable paths, and unchanged unrelated settings. They run automatically in the existing Go CI suite; native Windows skips these POSIX menu tests with instructions to run under Linux/WSL.

No real installer, updater entry point, production panel, network service, or service restart was executed. If a write occurs but subsequent verification fails, the handler reports an error and leaves the running panel untouched; it does not guess the database state or automatically roll it back.


🔄 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/6994 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/custom-web-base-path-menu` --- ### 📝 Commits (1) - [`c5df14b`](https://github.com/MHSanaei/3x-ui/commit/c5df14b2164d5275712bb98eb1b7bf728ecf20c3) feat(scripts): support custom web base path in menu ### 📊 Changes **2 files changed** (+340 additions, -9 deletions) <details> <summary>View changed files</summary> ➕ `scripts_menu_base_path_test.go` (+242 -0) 📝 `x-ui.sh` (+98 -9) </details> ### 📄 Description ## Summary - Extend existing menu option **8** with random, custom, and cancel choices; keep the existing 18-character random generator. - Validate custom paths and normalize them to `/path/`, preserving capitalization and accepting short/nested paths such as `/a/` and `/private/admin/`. - Show the proposed path and require a final confirmation for both modes. Accept case-insensitive yes/no answers; empty confirmation cancels. Invalid choices/paths retry, and EOF cancels without a write. - Read the current normalized path, skip an identical value, check the CLI update acknowledgment, and read back the saved setting before restarting exactly once. Failed reads/writes/verification never produce the new success notice or restart the panel. ## Motivation Option 8 previously always generated a random path. Administrators could not select a memorable or predefined path through the menu, and the handler reported success and restarted even when the CLI failed. The new input allowlist accepts letters, digits, hyphens and underscores in single-slash-separated segments. It rejects empty/root-only values, traversal/dot segments, repeated separators, whitespace/control characters, query strings, fragments, backslashes and other unsafe characters. An invalid custom value is never replaced with randomness. Released CLIs can print an error with exit status zero. The handler therefore requires the existing `Base URI path set successfully` acknowledgment and independently verifies the stored `webBasePath` from `setting -show`. Settings reads reject missing/duplicate/malformed path records and reported getter/database errors. ## Compatibility - No new top-level menu item, dependencies, migrations, API contracts, or frontend changes. - Only `setting -webBasePath` is used for the mutation. Credentials, port, TLS configuration and database settings are preserved. - Existing random generation remains available, with a preview and final confirmation added. - **Related work: #6964** fixes the separate update/reinstall bug that overwrites short paths. This PR leaves `install.sh` and `update.sh` untouched and does not duplicate that work. Short-path preservation on future updates/reinstalls requires #6964 to be merged; this menu feature alone does not fix that existing bug. The changed files do not overlap. - An isolated composition check against #6964 at `a99be10d499b09278075bd0f2cbf2f3e8fe8163c` confirmed that menu-selected `/a/`, `/ab/`, `/mypanel/`, and `/private/admin/` survive two consecutive install/update configuration passes without another write, random generation, or path-related restart. ## Testing - Regression baseline: the new menu suite failed **76 of 79 scenarios** on the original handler, reproducing missing custom selection, validation, confirmation and persistence safeguards. - `gofmt -w scripts_menu_base_path_test.go` — completed. - `bash -n x-ui.sh` — passed. - `shellcheck --severity=error x-ui.sh` — passed with **0.9.0** and **0.11.0**. - `go test -run '^TestMenuWebBasePath$' -count=1 -v .` — **79 scenarios passed** under Linux/Go 1.27.3. - Full root-package test binary (`go test -c`, then `-test.count=1 -test.v`) — **all 14 test functions passed**, including the 79 menu scenarios, as UID/GID `65534:65534` in a container with a read-only repository mount. - `go test -race -run '^TestMenuWebBasePath$' -count=1 .` — passed. - `go vet .` — passed. - `golangci-lint run .` — passed, **0 issues** (v2.15.0). - `git diff --check` and `git diff --cached --check` — passed. The Go tests execute only extracted Bash function definitions, with temporary CLI/state fixtures and a mocked restart. They inspect the actual CLI argument, stored path, write/read/restart order, no-change/cancel behavior, all affirmative forms, unsafe-input retries, random failures, zero-exit errors, malformed settings reads, persistence mismatch, EOF, quoted executable paths, and unchanged unrelated settings. They run automatically in the existing Go CI suite; native Windows skips these POSIX menu tests with instructions to run under Linux/WSL. No real installer, updater entry point, production panel, network service, or service restart was executed. If a write occurs but subsequent verification fails, the handler reports an error and leaves the running panel untouched; it does not guess the database state or automatically roll it back. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#6567
No description provided.