feat: add password confirmation loop and mask input

- Implements a validation loop that requires the user to re-enter their password until both inputs match.
- Adds the '-s' flag to the 'read' to prevent form being echoed to the terminal.
This commit is contained in:
YerdosNar
2025-12-03 20:21:41 +09:00
parent 07e8915492
commit bcb03c3d5b

106
menu.sh
View File

@ -8,7 +8,7 @@ check_services() {
for service in "${services[@]}"; do for service in "${services[@]}"; do
service_base_name=$(basename "$service" .service) service_base_name=$(basename "$service" .service)
display_name=$(echo "$service_base_name" | sed -E 's/([^-]+)-?/\u\1/g') display_name=$(echo "$service_base_name" | sed -E 's/([^-]+)-?/\u\1/g')
if systemctl is-active --quiet "$service"; then if systemctl is-active --quiet "$service"; then
echo -e "${NC}${display_name}:${green} Active${NC}" echo -e "${NC}${display_name}:${green} Active${NC}"
@ -29,7 +29,7 @@ hysteria2_install_handler() {
while true; do while true; do
read -p "Enter the SNI (default: bts.com): " sni read -p "Enter the SNI (default: bts.com): " sni
sni=${sni:-bts.com} sni=${sni:-bts.com}
read -p "Enter the port number you want to use: " port read -p "Enter the port number you want to use: " port
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo "Invalid port number. Please enter a number between 1 and 65535." echo "Invalid port number. Please enter a number between 1 and 65535."
@ -38,7 +38,7 @@ hysteria2_install_handler() {
fi fi
done done
python3 $CLI_PATH install-hysteria2 --port "$port" --sni "$sni" python3 $CLI_PATH install-hysteria2 --port "$port" --sni "$sni"
cat <<EOF > /etc/hysteria/.configs.env cat <<EOF > /etc/hysteria/.configs.env
@ -64,7 +64,7 @@ hysteria2_add_user_handler() {
read -p "Enter the traffic limit (in GB): " traffic_limit_GB read -p "Enter the traffic limit (in GB): " traffic_limit_GB
read -p "Enter the expiration days: " expiration_days read -p "Enter the expiration days: " expiration_days
local unlimited_arg="" local unlimited_arg=""
while true; do while true; do
read -p "Exempt user from IP limit checks (unlimited IP)? (y/n) [n]: " unlimited_choice read -p "Exempt user from IP limit checks (unlimited IP)? (y/n) [n]: " unlimited_choice
@ -74,7 +74,7 @@ hysteria2_add_user_handler() {
*) echo -e "${red}Error:${NC} Please answer 'y' or 'n'." ;; *) echo -e "${red}Error:${NC} Please answer 'y' or 'n'." ;;
esac esac
done done
password=$(pwgen -s 32 1) password=$(pwgen -s 32 1)
creation_date=$(date +%Y-%m-%d) creation_date=$(date +%Y-%m-%d)
@ -231,24 +231,24 @@ hysteria2_get_user_handler() {
hysteria2_list_users_handler() { hysteria2_list_users_handler() {
users_json=$(python3 $CLI_PATH list-users 2>/dev/null) users_json=$(python3 $CLI_PATH list-users 2>/dev/null)
if [ $? -ne 0 ] || [ -z "$users_json" ]; then if [ $? -ne 0 ] || [ -z "$users_json" ]; then
echo -e "${red}Error:${NC} Failed to list users." echo -e "${red}Error:${NC} Failed to list users."
return 1 return 1
fi fi
user_count=$(echo "$users_json" | jq 'length') user_count=$(echo "$users_json" | jq 'length')
if [ "$user_count" -eq 0 ]; then if [ "$user_count" -eq 0 ]; then
echo -e "${red}Error:${NC} No users found." echo -e "${red}Error:${NC} No users found."
return 1 return 1
fi fi
printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s %-10s\n" \ printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s %-10s\n" \
"Username" "Traffic(GB)" "Expiry(Days)" "Created" "Password" "Blocked" "Status" "Down(MB)" "Up(MB)" "Username" "Traffic(GB)" "Expiry(Days)" "Created" "Password" "Blocked" "Status" "Down(MB)" "Up(MB)"
echo "$users_json" | jq -r '.[] | echo "$users_json" | jq -r '.[] |
[.username, [.username,
(if .max_download_bytes == 0 then "Unlimited" else (.max_download_bytes / 1073741824 | tostring) end), (if .max_download_bytes == 0 then "Unlimited" else (.max_download_bytes / 1073741824 | tostring) end),
(if .expiration_days == 0 then "Never" else (.expiration_days | tostring) end), (if .expiration_days == 0 then "Never" else (.expiration_days | tostring) end),
(.account_creation_date // "N/A"), (.account_creation_date // "N/A"),
@ -257,7 +257,7 @@ hysteria2_list_users_handler() {
.status, .status,
((.download_bytes // 0) / 1048576 | floor), ((.download_bytes // 0) / 1048576 | floor),
((.upload_bytes // 0) / 1048576 | floor), ((.upload_bytes // 0) / 1048576 | floor),
.online_count] | .online_count] |
@tsv' | \ @tsv' | \
while IFS=$'\t' read -r username traffic expiry created password blocked status down up online; do while IFS=$'\t' read -r username traffic expiry created password blocked status down up online; do
printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s %-10s\n" \ printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s %-10s\n" \
@ -293,7 +293,7 @@ hysteria2_show_user_uri_handler() {
done done
flags="" flags=""
if check_service_active "hysteria-singbox.service"; then if check_service_active "hysteria-singbox.service"; then
flags+=" -s" flags+=" -s"
fi fi
@ -405,12 +405,12 @@ warp_configure_handler() {
if systemctl is-active --quiet "$service_name"; then if systemctl is-active --quiet "$service_name"; then
echo -e "${cyan}=== WARP Status ===${NC}" echo -e "${cyan}=== WARP Status ===${NC}"
status_json=$(python3 $CLI_PATH warp-status) status_json=$(python3 $CLI_PATH warp-status)
all_traffic=$(echo "$status_json" | grep -o '"all_traffic_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "') all_traffic=$(echo "$status_json" | grep -o '"all_traffic_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
popular_sites=$(echo "$status_json" | grep -o '"popular_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "') popular_sites=$(echo "$status_json" | grep -o '"popular_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
domestic_sites_via_warp=$(echo "$status_json" | grep -o '"domestic_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "') domestic_sites_via_warp=$(echo "$status_json" | grep -o '"domestic_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
block_adult=$(echo "$status_json" | grep -o '"block_adult_content": *[^,}]*' | cut -d':' -f2 | tr -d ' "') block_adult=$(echo "$status_json" | grep -o '"block_adult_content": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
display_status() { display_status() {
local label="$1" local label="$1"
local status_val="$2" local status_val="$2"
@ -420,15 +420,15 @@ warp_configure_handler() {
echo -e " ${red}${NC} $label: ${red}Disabled${NC}" echo -e " ${red}${NC} $label: ${red}Disabled${NC}"
fi fi
} }
display_status "All Traffic via WARP" "$all_traffic" display_status "All Traffic via WARP" "$all_traffic"
display_status "Popular Sites via WARP" "$popular_sites" display_status "Popular Sites via WARP" "$popular_sites"
display_status "Domestic Sites via WARP" "$domestic_sites_via_warp" display_status "Domestic Sites via WARP" "$domestic_sites_via_warp"
display_status "Block Adult Content" "$block_adult" display_status "Block Adult Content" "$block_adult"
echo -e "${cyan}==================${NC}" echo -e "${cyan}==================${NC}"
echo echo
echo "Configure WARP Options (Toggle):" echo "Configure WARP Options (Toggle):"
echo "1. All traffic via WARP" echo "1. All traffic via WARP"
echo "2. Popular sites via WARP" echo "2. Popular sites via WARP"
@ -443,43 +443,43 @@ warp_configure_handler() {
read -p "Select an option to toggle: " option read -p "Select an option to toggle: " option
case $option in case $option in
1) 1)
target_state=$([ "$all_traffic" = "true" ] && echo "off" || echo "on") target_state=$([ "$all_traffic" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-all "$target_state" ;; python3 $CLI_PATH configure-warp --set-all "$target_state" ;;
2) 2)
target_state=$([ "$popular_sites" = "true" ] && echo "off" || echo "on") target_state=$([ "$popular_sites" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-popular-sites "$target_state" ;; python3 $CLI_PATH configure-warp --set-popular-sites "$target_state" ;;
3) 3)
target_state=$([ "$domestic_sites_via_warp" = "true" ] && echo "off" || echo "on") target_state=$([ "$domestic_sites_via_warp" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-domestic-sites "$target_state" ;; python3 $CLI_PATH configure-warp --set-domestic-sites "$target_state" ;;
4) 4)
target_state=$([ "$block_adult" = "true" ] && echo "off" || echo "on") target_state=$([ "$block_adult" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-block-adult-sites "$target_state" ;; python3 $CLI_PATH configure-warp --set-block-adult-sites "$target_state" ;;
5) 5)
current_ip=$(python3 $CLI_PATH warp-status | grep -o '"ip": *"[^"]*"' | cut -d':' -f2- | tr -d '" ') current_ip=$(python3 $CLI_PATH warp-status | grep -o '"ip": *"[^"]*"' | cut -d':' -f2- | tr -d '" ')
if [ -z "$current_ip" ]; then if [ -z "$current_ip" ]; then
current_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A") current_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
fi fi
cd /etc/warp/ && wgcf status cd /etc/warp/ && wgcf status
echo echo
echo -e "${yellow}Warp IP:${NC} ${cyan}${current_ip}${NC}" echo -e "${yellow}Warp IP:${NC} ${cyan}${current_ip}${NC}"
;; ;;
6) 6)
old_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A") old_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
echo -e "${yellow}Current IP:${NC} ${cyan}$old_ip${NC}" echo -e "${yellow}Current IP:${NC} ${cyan}$old_ip${NC}"
echo "Restarting $service_name to attempt IP change..." echo "Restarting $service_name to attempt IP change..."
systemctl restart "$service_name" systemctl restart "$service_name"
echo -n "Waiting for service to restart" echo -n "Waiting for service to restart"
for i in {1..5}; do for i in {1..5}; do
echo -n "." echo -n "."
sleep 1 sleep 1
done done
echo echo
new_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A") new_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
echo -e "${yellow}New IP:${NC} ${green}$new_ip${NC}" echo -e "${yellow}New IP:${NC} ${green}$new_ip${NC}"
if [ "$old_ip" != "N/A" ] && [ "$new_ip" != "N/A" ] && [ "$old_ip" != "$new_ip" ]; then if [ "$old_ip" != "N/A" ] && [ "$new_ip" != "N/A" ] && [ "$old_ip" != "$new_ip" ]; then
echo -e "${green}✓ IP address changed successfully${NC}" echo -e "${green}✓ IP address changed successfully${NC}"
elif [ "$old_ip" = "$new_ip" ] && [ "$old_ip" != "N/A" ]; then elif [ "$old_ip" = "$new_ip" ] && [ "$old_ip" != "N/A" ]; then
@ -491,18 +491,18 @@ warp_configure_handler() {
7) 7)
echo -e "${yellow}Switching to WARP Plus...${NC}" echo -e "${yellow}Switching to WARP Plus...${NC}"
read -p "Enter your WARP Plus license key: " warp_key read -p "Enter your WARP Plus license key: " warp_key
if [ -z "$warp_key" ]; then if [ -z "$warp_key" ]; then
echo -e "${red}Error: WARP Plus key is required.${NC}" echo -e "${red}Error: WARP Plus key is required.${NC}"
else else
echo "Stopping WARP service..." echo "Stopping WARP service..."
systemctl stop "$service_name" 2>/dev/null systemctl stop "$service_name" 2>/dev/null
cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; } cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; }
echo "Updating WARP Plus configuration..." echo "Updating WARP Plus configuration..."
WGCF_LICENSE_KEY="$warp_key" wgcf update WGCF_LICENSE_KEY="$warp_key" wgcf update
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Starting WARP service..." echo "Starting WARP service..."
systemctl start "$service_name" systemctl start "$service_name"
@ -518,17 +518,17 @@ warp_configure_handler() {
echo -e "${yellow}Switching to Normal WARP...${NC}" echo -e "${yellow}Switching to Normal WARP...${NC}"
echo "This will create a new WARP account. Continue? (y/N)" echo "This will create a new WARP account. Continue? (y/N)"
read -p "" confirm read -p "" confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then if [[ "$confirm" =~ ^[Yy]$ ]]; then
echo "Stopping WARP service..." echo "Stopping WARP service..."
systemctl stop "$service_name" 2>/dev/null systemctl stop "$service_name" 2>/dev/null
cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; } cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; }
echo "Creating new WARP account..." echo "Creating new WARP account..."
rm -f wgcf-account.toml rm -f wgcf-account.toml
yes | wgcf register yes | wgcf register
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Starting WARP service..." echo "Starting WARP service..."
systemctl start "$service_name" systemctl start "$service_name"
@ -728,12 +728,24 @@ webpanel_handler() {
done done
while true; do while true; do
read -e -p "Enter the admin password: " admin_password read -sp "Enter the admin password: " admin_password
echo ""
if [ -z "$admin_password" ]; then if [ -z "$admin_password" ]; then
echo "Admin password cannot be empty. Please try again." echo "Admin password cannot be empty. Please try again."
else continue
fi
local check_password
read -sp "Enter the admin password again: " check_password
echo ""
if [ -z "$check_password" ]; then
echo "Admin password cannot be empty. Please try again."
continue
fi
if [ "$check_password" == "$admin_password" ]; then
echo "Password is set!"
break break
fi fi
echo "Passwords did NOT match. Please try again."
done done
python3 $CLI_PATH webpanel -a start -d "$domain" -p "$port" -au "$admin_username" -ap "$admin_password" python3 $CLI_PATH webpanel -a start -d "$domain" -p "$port" -au "$admin_username" -ap "$admin_password"
@ -773,20 +785,20 @@ webpanel_handler() {
if [ -n "$new_password" ]; then if [ -n "$new_password" ]; then
cmd_args+=("-p" "$new_password") cmd_args+=("-p" "$new_password")
fi fi
if [ -z "$new_username" ]; then if [ -z "$new_username" ]; then
cmd_args=() cmd_args=()
if [ -n "$new_password" ]; then if [ -n "$new_password" ]; then
cmd_args+=("-p" "$new_password") cmd_args+=("-p" "$new_password")
fi fi
fi fi
echo "Attempting to reset credentials..." echo "Attempting to reset credentials..."
python3 "$CLI_PATH" reset-webpanel-creds "${cmd_args[@]}" python3 "$CLI_PATH" reset-webpanel-creds "${cmd_args[@]}"
fi fi
fi fi
;; ;;
6) 6)
if ! systemctl is-active --quiet hysteria-webpanel.service; then if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}" echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else else
@ -808,7 +820,7 @@ webpanel_handler() {
fi fi
fi fi
;; ;;
7) 7)
if ! systemctl is-active --quiet hysteria-webpanel.service; then if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}" echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else else
@ -821,7 +833,7 @@ webpanel_handler() {
python3 "$CLI_PATH" change-webpanel-root "${cmd_args[@]}" python3 "$CLI_PATH" change-webpanel-root "${cmd_args[@]}"
fi fi
;; ;;
8) 8)
if ! systemctl is-active --quiet hysteria-webpanel.service; then if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}" echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else else
@ -926,7 +938,7 @@ geo_update_handler() {
masquerade_handler() { masquerade_handler() {
while true; do while true; do
status=$(python3 $CLI_PATH masquerade -s) status=$(python3 $CLI_PATH masquerade -s)
echo "--------------------------" echo "--------------------------"
if [ "$status" == "Enabled" ]; then if [ "$status" == "Enabled" ]; then
echo -e "Masquerade Status: ${green}${status}${NC}" echo -e "Masquerade Status: ${green}${status}${NC}"
@ -1067,7 +1079,7 @@ display_main_menu() {
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}" echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
check_services check_services
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}" echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
echo -e "${yellow} ☼ Main Menu ☼ ${NC}" echo -e "${yellow} ☼ Main Menu ☼ ${NC}"
@ -1216,4 +1228,4 @@ advance_menu() {
} }
# Main function to run the script # Main function to run the script
define_colors define_colors
main_menu main_menu