mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-07 05:34:17 +00:00
fix: accept direct panel port input in install flow
This commit is contained in:
parent
e23e69bc48
commit
afa0d5a5bd
3 changed files with 84 additions and 14 deletions
43
docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md
Normal file
43
docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
Task Record:
|
||||||
|
|
||||||
|
Date: 2026-04-22
|
||||||
|
Related Module: install script (`install.sh`)
|
||||||
|
Change Type: Fix
|
||||||
|
|
||||||
|
Background
|
||||||
|
|
||||||
|
The panel port setup in fresh install used a `y/n` confirmation before reading the port.
|
||||||
|
When users directly entered a numeric port like `443` at the confirmation prompt, it was treated as non-`y` and the script generated a random port, causing unexpected behavior.
|
||||||
|
|
||||||
|
Changes
|
||||||
|
|
||||||
|
Replaced the two-step `y/n` + port input flow with a single direct input flow in `install.sh`.
|
||||||
|
Now the script asks for panel port directly:
|
||||||
|
- Empty input: generate random panel port.
|
||||||
|
- Valid numeric port (`1-65535`): use as panel port.
|
||||||
|
- Invalid input: show error and prompt again.
|
||||||
|
|
||||||
|
Added `tests/panel_port_prompt_test.sh` to verify the expected prompt and validation logic exists and the legacy `y/n` prompt is removed.
|
||||||
|
|
||||||
|
Impact
|
||||||
|
|
||||||
|
Affected files:
|
||||||
|
- `install.sh`
|
||||||
|
- `tests/panel_port_prompt_test.sh`
|
||||||
|
|
||||||
|
No API, database schema, or build pipeline changes.
|
||||||
|
Runtime install interaction is changed for fresh install panel-port setup only.
|
||||||
|
|
||||||
|
Verification
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
- `bash tests/panel_port_prompt_test.sh`
|
||||||
|
- `bash tests/mariadb_install_switch_test.sh`
|
||||||
|
|
||||||
|
Result:
|
||||||
|
- Both scripts passed.
|
||||||
|
|
||||||
|
Risks And Follow-Up
|
||||||
|
|
||||||
|
Current verification is static prompt/logic assertion, not full interactive E2E install simulation.
|
||||||
|
If needed, add an automated pty-based interaction test to validate runtime behavior across shells.
|
||||||
27
install.sh
27
install.sh
|
|
@ -1092,22 +1092,21 @@ config_after_install() {
|
||||||
echo -e "${green}已生成随机 Web 路径:${config_webBasePath}${plain}"
|
echo -e "${green}已生成随机 Web 路径:${config_webBasePath}${plain}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -rp "是否要自定义面板端口?(否则将使用随机端口)[y/n]:" config_confirm
|
while true; do
|
||||||
if [[ "${config_confirm}" == "y" || "${config_confirm}" == "Y" ]]; then
|
read -rp "请输入面板端口(留空将随机生成):" config_port
|
||||||
while true; do
|
config_port="${config_port// /}"
|
||||||
read -rp "请设置面板端口:" config_port
|
if [[ -z "${config_port}" ]]; then
|
||||||
config_port="${config_port// /}"
|
config_port=$(shuf -i 1024-62000 -n 1)
|
||||||
if ! [[ "${config_port}" =~ ^[0-9]+$ ]] || ((config_port < 1 || config_port > 65535)); then
|
echo -e "${yellow}已生成随机端口:${config_port}${plain}"
|
||||||
echo -e "${red}无效端口,请输入 1-65535 之间的数字。${plain}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
break
|
break
|
||||||
done
|
fi
|
||||||
|
if ! [[ "${config_port}" =~ ^[0-9]+$ ]] || ((config_port < 1 || config_port > 65535)); then
|
||||||
|
echo -e "${red}无效端口,请输入 1-65535 之间的数字。${plain}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
echo -e "${yellow}您的面板端口为:${config_port}${plain}"
|
echo -e "${yellow}您的面板端口为:${config_port}${plain}"
|
||||||
else
|
break
|
||||||
local config_port=$(shuf -i 1024-62000 -n 1)
|
done
|
||||||
echo -e "${yellow}已生成随机端口:${config_port}${plain}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -rp "Database type [mariadb]: " db_type
|
read -rp "Database type [mariadb]: " db_type
|
||||||
db_type=$(echo "${db_type:-mariadb}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
|
db_type=$(echo "${db_type:-mariadb}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
|
||||||
|
|
|
||||||
28
tests/panel_port_prompt_test.sh
Normal file
28
tests/panel_port_prompt_test.sh
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
assert_contains() {
|
||||||
|
local file="$1"
|
||||||
|
local pattern="$2"
|
||||||
|
if ! grep -Fq "$pattern" "$file"; then
|
||||||
|
echo "missing pattern in $file: $pattern" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_not_contains() {
|
||||||
|
local file="$1"
|
||||||
|
local pattern="$2"
|
||||||
|
if grep -Fq "$pattern" "$file"; then
|
||||||
|
echo "unexpected pattern in $file: $pattern" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_contains "install.sh" "请输入面板端口(留空将随机生成):"
|
||||||
|
assert_contains "install.sh" "if [[ -z \"\${config_port}\" ]]; then"
|
||||||
|
assert_contains "install.sh" "已生成随机端口:"
|
||||||
|
assert_contains "install.sh" "无效端口,请输入 1-65535 之间的数字。"
|
||||||
|
assert_not_contains "install.sh" "是否要自定义面板端口?(否则将使用随机端口)[y/n]:"
|
||||||
|
|
||||||
|
echo "panel port prompt flow looks correct"
|
||||||
Loading…
Reference in a new issue