diff --git a/core/scripts/hysteria2/show_user_uri.sh b/core/scripts/hysteria2/show_user_uri.sh index c86dc50..3ba648d 100644 --- a/core/scripts/hysteria2/show_user_uri.sh +++ b/core/scripts/hysteria2/show_user_uri.sh @@ -16,7 +16,7 @@ get_singbox_domain_and_port() { get_normalsub_domain_and_port() { if [ -f "$NORMALSUB_ENV" ]; then - local domain port + local domain port subpath domain=$(grep -E '^HYSTERIA_DOMAIN=' "$NORMALSUB_ENV" | cut -d'=' -f2) port=$(grep -E '^HYSTERIA_PORT=' "$NORMALSUB_ENV" | cut -d'=' -f2) subpath=$(grep -E '^SUBPATH=' "$NORMALSUB_ENV" | cut -d'=' -f2) @@ -81,7 +81,11 @@ show_uri() { local uri_base="hy2://$username%3A$authpassword@$ip:$port" if [ "$ip_version" -eq 6 ]; then - uri_base="hy2://$username%3A$authpassword@[$ip]:$port" + if [[ "$ip" =~ ^[0-9a-fA-F:]+$ ]]; then + uri_base="hy2://$username%3A$authpassword@[$ip]:$port" + else + uri_base="hy2://$username%3A$authpassword@$ip:$port" + fi fi local params="" diff --git a/menu.sh b/menu.sh index 17e8680..b39960c 100644 --- a/menu.sh +++ b/menu.sh @@ -323,35 +323,42 @@ hysteria2_change_sni_handler() { edit_ips() { while true; do echo "======================================" - echo " IP Address Manager " + echo " IP/Domain Address Manager " echo "======================================" - echo "1. Change IP4" - echo "2. Change IP6" + echo "1. Change IPv4 or Domain" + echo "2. Change IPv6 or Domain" echo "0. Back" echo "======================================" - read -p "Enter your choice [1-3]: " choice + read -p "Enter your choice [0-2]: " choice case $choice in 1) - read -p "Enter the new IPv4 address: " new_ip4 - if [[ $new_ip4 =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then - if [[ $(echo "$new_ip4" | awk -F. '{for (i=1;i<=NF;i++) if ($i>255) exit 1}') ]]; then + read -p "Enter the new IPv4 address or domain: " new_ip4_or_domain + if [[ $new_ip4_or_domain =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then + if [[ $(echo "$new_ip4_or_domain" | awk -F. '{for (i=1;i<=NF;i++) if ($i>255) exit 1}') ]]; then echo "Error: Invalid IPv4 address. Values must be between 0 and 255." else - python3 "$CLI_PATH" ip-address --edit -4 "$new_ip4" + python3 "$CLI_PATH" ip-address --edit -4 "$new_ip4_or_domain" + echo "IPv4 address has been updated to $new_ip4_or_domain." fi + elif [[ $new_ip4_or_domain =~ ^[a-zA-Z0-9.-]+$ ]] && [[ ! $new_ip4_or_domain =~ [/:] ]]; then + python3 "$CLI_PATH" ip-address --edit -4 "$new_ip4_or_domain" + echo "Domain has been updated to $new_ip4_or_domain." else - echo "Error: Invalid IPv4 address format." + echo "Error: Invalid IPv4 or domain format." fi break ;; 2) - read -p "Enter the new IPv6 address: " new_ip6 - if [[ $new_ip6 =~ ^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$ ]]; then - python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6" - echo "IPv6 address has been updated to $new_ip6." + read -p "Enter the new IPv6 address or domain: " new_ip6_or_domain + if [[ $new_ip6_or_domain =~ ^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$ ]]; then + python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6_or_domain" + echo "IPv6 address has been updated to $new_ip6_or_domain." + elif [[ $new_ip6_or_domain =~ ^[a-zA-Z0-9.-]+$ ]] && [[ ! $new_ip6_or_domain =~ [/:] ]]; then + python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6_or_domain" + echo "Domain has been updated to $new_ip6_or_domain." else - echo "Error: Invalid IPv6 address format." + echo "Error: Invalid IPv6 or domain format." fi break ;;