[PR #6992] [MERGED] fix(install): handle yes responses and validate panel ports #6566

Closed
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/6992
Author: @HamedSanaei
Created: 10/28/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @MHSanaei

Base: main ← Head: fix/installer-panel-port-validation


📝 Commits (4)

  • d7dd280 fix(install): accept yes and validate custom panel port
  • fb7685f test(amneziawg): avoid fixed ports in forwarding lifecycle tests
  • c7338b9 Merge remote-tracking branch 'origin/main' into pr/6992
  • 30941df test(scripts): give the base-path script test the port helpers it now calls

📊 Changes

4 files changed (+407 additions, -25 deletions)

View changed files

📝 .github/workflows/ci.yml (+7 -1)
➕ deploy/test/installer-panel-port.sh (+304 -0)
📝 install.sh (+83 -21)
📝 scripts_base_path_test.go (+13 -3)

📄 Description

Problem

The panel-port confirmation accepts only y/Y: typing yes, Yes, or YES unexpectedly selects a random port. Empty, nonnumeric, and out-of-range custom ports reach x-ui setting without validation, and the installer continues to SSL setup and a success banner even when configuration fails.

Background: #3896 describes the related validation problem but is already closed. Closed PR #6904 included an overlapping fix among broader script/Docker changes; this PR focuses on panel-port selection and configuration failure handling.

Solution

  • Accept case-insensitive y/yes and n/no, trimming surrounding whitespace. Enter defaults to No, displayed as [y/N]; other answers retry. EOF aborts instead of silently selecting a default or looping forever.
  • After Yes, keep asking until an available integer TCP port in 1–65535 is supplied. Never replace a custom choice with a random port. Strip leading zeros as decimal before passing the port to Go's flag parser; validate digits/length before arithmetic to avoid octal interpretation, overflow, or expression evaluation.
  • Reuse the existing availability helper. Fix its ss/netstat parsing: the old awk END {exit 1} overrode a successful match, and the netstat pattern expected whitespace inside $4. Keep the existing random range 1024–62000, retry occupied candidates, and fail after 100 attempts or a generator error.
  • Noninteractive installs never prompt: a supplied XUI_PANEL_PORT is validated, including availability; an unset variable selects a random port. An explicitly empty or otherwise invalid value fails clearly.
  • Abort before SSL, credential persistence, and the completion banner if applying settings fails. Released CLIs can print a database/per-setting error yet exit zero, so checking only $? is insufficient: also require the existing port, credential, and base-path success acknowledgments. Those messages are present in the inspected v3.10.2 and v3.11.0 CLI sources.
  • Run the new focused Bash suite in shell-lint, and include installer/test changes in the CI path filters.

Testing

All executions below completed successfully on the final change unless explicitly marked as the regression baseline:

  • bash deploy/test/installer-panel-port.sh — 59 passed, 0 failed, in an Ubuntu 24.04 container as UID/GID 65534:65534, with a read-only repository mount. The same suite against unmodified upstream main reports 15 passed, 44 failed, reproducing the confirmation, validation, availability, and configuration-failure bugs.
  • bash -n install.sh and bash -n deploy/test/installer-panel-port.sh — passed.
  • Existing CI ShellCheck gate: --severity=style for DockerInit.sh, DockerEntrypoint.sh, deploy/test/smoke-noninteractive.sh, and the new test; --severity=error for install.sh, update.sh, and x-ui.sh — passed with ShellCheck 0.9.0.
  • New test at --severity=style and installer at --severity=error — also passed with ShellCheck 0.11.0.
  • go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color -shellcheck= — passed.
  • Additional unprivileged real TCP listener check: extracted the production is_port_in_use, opened an ephemeral localhost listener with socat, verified detection through ss, closed it, and verified that the port became free — passed.
  • git diff --check and git diff --cached --check — passed.
  • Initial GitHub Actions shell-lint — passed, including actionlint, ShellCheck, and the new installer regression suite. Every initial CI job passed except go-test, which encountered the unrelated fixed-port collision described below.

The suite extracts only named function definitions from the installer and mocks the panel CLI, network discovery, SSL setup, randomness, and persistence. It checks actual configuration arguments and recorded results, all requested response forms, retries, decimal normalization, numeric boundaries/invalid strings, all three availability backends, random exhaustion, noninteractive inputs, EOF, nonzero CLI failures, and zero-exit database/partial-setting failures. It does not execute the installer entry point, download/install a panel, require root, or contact external services.

Compatibility

No database migration or new dependencies. Existing valid noninteractive installations remain supported, and the username/password generation, database selection, SSL configuration flow, and WebBasePath behavior are unchanged. Only port selection, the shared TCP-listener lookup, and the fresh-install settings-success guard change.

Port availability is checked using the existing ss/netstat/lsof tools when available; it cannot reserve the socket until the panel starts. Configuration success checking intentionally depends on the existing CLI acknowledgments so zero-exit failures are not reported as success. No real installation or production deployment was performed.

CI fixture follow-up

The initial go-test failure was TestPortForwardSetReconcileOpensAndClosesListeners: its hardcoded TCP port 58910 was already in use on the runner, leaving only the UDP listener open. This fixture predates the installer changes. Re-running the failed upstream job was denied because the connected account lacks repository admin rights.

The follow-up changes only internal/amneziawgnet/portfwd_test.go: both listener-lifecycle fixtures now select an OS-allocated port and probe availability on both TCP and UDP. The intentional TCP collision test still keeps its blocker open and verifies that the other three listeners work. Cleanup now closes the forwarding sets even after a fatal assertion. No assertions were removed, and no production AWG or installer behavior changed in this follow-up.

Validation:

  • A controlled, unprivileged Linux container held all three old port numbers (58910–58912) on TCP and UDP. Both original fixtures failed; both modified fixtures passed with those same sockets still occupied.
  • go test ./internal/amneziawgnet -shuffle=on -count=1 — passed.
  • go test -race ./internal/amneziawgnet -run '^TestPortForwardSetReconcile' -shuffle=on -count=100 — passed (100 runs of each lifecycle test).
  • golangci-lint run ./internal/amneziawgnet/... — passed, 0 issues.
  • gofmt and git diff --check — passed.
  • Follow-up CI on fb7685f0 — all 11 jobs passed, including go-test, race, the installer regressions in shell-lint, frontend, PostgreSQL checks, and master/node end-to-end tests.

🔄 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/6992 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/installer-panel-port-validation` --- ### 📝 Commits (4) - [`d7dd280`](https://github.com/MHSanaei/3x-ui/commit/d7dd280b63b3126911f17f61ff83bb98d7a75bef) fix(install): accept yes and validate custom panel port - [`fb7685f`](https://github.com/MHSanaei/3x-ui/commit/fb7685f03fabb14ab298270b2d427a5095b2c7d5) test(amneziawg): avoid fixed ports in forwarding lifecycle tests - [`c7338b9`](https://github.com/MHSanaei/3x-ui/commit/c7338b9b0464577a4f9d550a18dd2e02fb060b7e) Merge remote-tracking branch 'origin/main' into pr/6992 - [`30941df`](https://github.com/MHSanaei/3x-ui/commit/30941dfc3720851ec066db6f894f26b4e164c417) test(scripts): give the base-path script test the port helpers it now calls ### 📊 Changes **4 files changed** (+407 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+7 -1) ➕ `deploy/test/installer-panel-port.sh` (+304 -0) 📝 `install.sh` (+83 -21) 📝 `scripts_base_path_test.go` (+13 -3) </details> ### 📄 Description ## Problem The panel-port confirmation accepts only `y`/`Y`: typing `yes`, `Yes`, or `YES` unexpectedly selects a random port. Empty, nonnumeric, and out-of-range custom ports reach `x-ui setting` without validation, and the installer continues to SSL setup and a success banner even when configuration fails. Background: #3896 describes the related validation problem but is already closed. Closed PR #6904 included an overlapping fix among broader script/Docker changes; this PR focuses on panel-port selection and configuration failure handling. ## Solution - Accept case-insensitive `y`/`yes` and `n`/`no`, trimming surrounding whitespace. Enter defaults to No, displayed as `[y/N]`; other answers retry. EOF aborts instead of silently selecting a default or looping forever. - After Yes, keep asking until an available integer TCP port in `1–65535` is supplied. Never replace a custom choice with a random port. Strip leading zeros as decimal before passing the port to Go's flag parser; validate digits/length before arithmetic to avoid octal interpretation, overflow, or expression evaluation. - Reuse the existing availability helper. Fix its `ss`/`netstat` parsing: the old awk `END {exit 1}` overrode a successful match, and the netstat pattern expected whitespace inside `$4`. Keep the existing random range `1024–62000`, retry occupied candidates, and fail after 100 attempts or a generator error. - Noninteractive installs never prompt: a supplied `XUI_PANEL_PORT` is validated, including availability; an unset variable selects a random port. An explicitly empty or otherwise invalid value fails clearly. - Abort before SSL, credential persistence, and the completion banner if applying settings fails. Released CLIs can print a database/per-setting error yet exit zero, so checking only `$?` is insufficient: also require the existing port, credential, and base-path success acknowledgments. Those messages are present in the inspected v3.10.2 and v3.11.0 CLI sources. - Run the new focused Bash suite in `shell-lint`, and include installer/test changes in the CI path filters. ## Testing All executions below completed successfully on the final change unless explicitly marked as the regression baseline: - `bash deploy/test/installer-panel-port.sh` — **59 passed, 0 failed**, in an Ubuntu 24.04 container as UID/GID `65534:65534`, with a read-only repository mount. The same suite against unmodified upstream `main` reports **15 passed, 44 failed**, reproducing the confirmation, validation, availability, and configuration-failure bugs. - `bash -n install.sh` and `bash -n deploy/test/installer-panel-port.sh` — passed. - Existing CI ShellCheck gate: `--severity=style` for `DockerInit.sh`, `DockerEntrypoint.sh`, `deploy/test/smoke-noninteractive.sh`, and the new test; `--severity=error` for `install.sh`, `update.sh`, and `x-ui.sh` — passed with ShellCheck **0.9.0**. - New test at `--severity=style` and installer at `--severity=error` — also passed with ShellCheck **0.11.0**. - `go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color -shellcheck=` — passed. - Additional unprivileged real TCP listener check: extracted the production `is_port_in_use`, opened an ephemeral localhost listener with socat, verified detection through `ss`, closed it, and verified that the port became free — passed. - `git diff --check` and `git diff --cached --check` — passed. - [Initial GitHub Actions `shell-lint`](https://github.com/MHSanaei/3x-ui/actions/runs/40695816513/job/122842165951) — passed, including actionlint, ShellCheck, and the new installer regression suite. Every initial CI job passed except `go-test`, which encountered the unrelated fixed-port collision described below. The suite extracts only named function definitions from the installer and mocks the panel CLI, network discovery, SSL setup, randomness, and persistence. It checks actual configuration arguments and recorded results, all requested response forms, retries, decimal normalization, numeric boundaries/invalid strings, all three availability backends, random exhaustion, noninteractive inputs, EOF, nonzero CLI failures, and zero-exit database/partial-setting failures. It does not execute the installer entry point, download/install a panel, require root, or contact external services. ## Compatibility No database migration or new dependencies. Existing valid noninteractive installations remain supported, and the username/password generation, database selection, SSL configuration flow, and WebBasePath behavior are unchanged. Only port selection, the shared TCP-listener lookup, and the fresh-install settings-success guard change. Port availability is checked using the existing `ss`/`netstat`/`lsof` tools when available; it cannot reserve the socket until the panel starts. Configuration success checking intentionally depends on the existing CLI acknowledgments so zero-exit failures are not reported as success. No real installation or production deployment was performed. ## CI fixture follow-up The initial `go-test` failure was `TestPortForwardSetReconcileOpensAndClosesListeners`: its hardcoded TCP port `58910` was already in use on the runner, leaving only the UDP listener open. This fixture predates the installer changes. Re-running the failed upstream job was denied because the connected account lacks repository admin rights. The follow-up changes only `internal/amneziawgnet/portfwd_test.go`: both listener-lifecycle fixtures now select an OS-allocated port and probe availability on both TCP and UDP. The intentional TCP collision test still keeps its blocker open and verifies that the other three listeners work. Cleanup now closes the forwarding sets even after a fatal assertion. No assertions were removed, and no production AWG or installer behavior changed in this follow-up. Validation: - A controlled, unprivileged Linux container held all three old port numbers (`58910`–`58912`) on TCP and UDP. Both original fixtures failed; both modified fixtures passed with those same sockets still occupied. - `go test ./internal/amneziawgnet -shuffle=on -count=1` — passed. - `go test -race ./internal/amneziawgnet -run '^TestPortForwardSetReconcile' -shuffle=on -count=100` — passed (100 runs of each lifecycle test). - `golangci-lint run ./internal/amneziawgnet/...` — passed, 0 issues. - `gofmt` and `git diff --check` — passed. - [Follow-up CI on `fb7685f0`](https://github.com/MHSanaei/3x-ui/actions/runs/40700188671) — **all 11 jobs passed**, including `go-test`, `race`, the installer regressions in `shell-lint`, frontend, PostgreSQL checks, and master/node end-to-end tests. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #6992] fix(install): handle yes responses and validate panel ports to [PR #6992] [MERGED] fix(install): handle yes responses and validate panel ports 2026-11-07 14:34:01 +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#6566
No description provided.