feat: allow updating IPv4, IPv6, or domain in IP Address Manager

fix: remove brackets from IPv6 URI when using a domain
This commit is contained in:
Night Owl
2025-03-19 19:27:35 +03:30
committed by GitHub
parent 58905e2075
commit 9a07b7b74c
2 changed files with 27 additions and 16 deletions

View File

@ -16,7 +16,7 @@ get_singbox_domain_and_port() {
get_normalsub_domain_and_port() { get_normalsub_domain_and_port() {
if [ -f "$NORMALSUB_ENV" ]; then if [ -f "$NORMALSUB_ENV" ]; then
local domain port local domain port subpath
domain=$(grep -E '^HYSTERIA_DOMAIN=' "$NORMALSUB_ENV" | cut -d'=' -f2) domain=$(grep -E '^HYSTERIA_DOMAIN=' "$NORMALSUB_ENV" | cut -d'=' -f2)
port=$(grep -E '^HYSTERIA_PORT=' "$NORMALSUB_ENV" | cut -d'=' -f2) port=$(grep -E '^HYSTERIA_PORT=' "$NORMALSUB_ENV" | cut -d'=' -f2)
subpath=$(grep -E '^SUBPATH=' "$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" local uri_base="hy2://$username%3A$authpassword@$ip:$port"
if [ "$ip_version" -eq 6 ]; then 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 fi
local params="" local params=""

35
menu.sh
View File

@ -323,35 +323,42 @@ hysteria2_change_sni_handler() {
edit_ips() { edit_ips() {
while true; do while true; do
echo "======================================" echo "======================================"
echo " IP Address Manager " echo " IP/Domain Address Manager "
echo "======================================" echo "======================================"
echo "1. Change IP4" echo "1. Change IPv4 or Domain"
echo "2. Change IP6" echo "2. Change IPv6 or Domain"
echo "0. Back" echo "0. Back"
echo "======================================" echo "======================================"
read -p "Enter your choice [1-3]: " choice read -p "Enter your choice [0-2]: " choice
case $choice in case $choice in
1) 1)
read -p "Enter the new IPv4 address: " new_ip4 read -p "Enter the new IPv4 address or domain: " new_ip4_or_domain
if [[ $new_ip4 =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then if [[ $new_ip4_or_domain =~ ^([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 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." echo "Error: Invalid IPv4 address. Values must be between 0 and 255."
else 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 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 else
echo "Error: Invalid IPv4 address format." echo "Error: Invalid IPv4 or domain format."
fi fi
break break
;; ;;
2) 2)
read -p "Enter the new IPv6 address: " new_ip6 read -p "Enter the new IPv6 address or domain: " new_ip6_or_domain
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 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" python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6_or_domain"
echo "IPv6 address has been updated to $new_ip6." 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 else
echo "Error: Invalid IPv6 address format." echo "Error: Invalid IPv6 or domain format."
fi fi
break break
;; ;;