Update URI
This commit is contained in:
@ -1,57 +1,86 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Source the path.sh script to load the configuration variables
|
|
||||||
source /etc/hysteria/core/scripts/path.sh
|
source /etc/hysteria/core/scripts/path.sh
|
||||||
|
|
||||||
# Function to show URI if Hysteria2 is installed and active
|
|
||||||
show_uri() {
|
show_uri() {
|
||||||
if [ -f "$USERS_FILE" ]; then
|
if [ -f "$USERS_FILE" ]; then
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
# Check if the username is provided as an argument
|
local username
|
||||||
if [ -z "$1" ]; then
|
local generate_qrcode=false
|
||||||
echo "Usage: $0 <username>"
|
local ip_version=4
|
||||||
|
local show_all=false
|
||||||
|
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-u|--username) username="$2"; shift ;;
|
||||||
|
-qr|--qrcode) generate_qrcode=true ;;
|
||||||
|
-ip) ip_version="$2"; shift ;;
|
||||||
|
-a|--all) show_all=true ;;
|
||||||
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$username" ]; then
|
||||||
|
echo "Usage: $0 -u <username> [-qr] [-ip <4|6>] [-a]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
username=$1
|
|
||||||
|
|
||||||
# Validate the username
|
|
||||||
if jq -e "has(\"$username\")" "$USERS_FILE" > /dev/null; then
|
if jq -e "has(\"$username\")" "$USERS_FILE" > /dev/null; then
|
||||||
# Get the selected user's details
|
|
||||||
authpassword=$(jq -r ".\"$username\".password" "$USERS_FILE")
|
authpassword=$(jq -r ".\"$username\".password" "$USERS_FILE")
|
||||||
port=$(jq -r '.listen' "$CONFIG_FILE" | cut -d':' -f2)
|
port=$(jq -r '.listen' "$CONFIG_FILE" | cut -d':' -f2)
|
||||||
sha256=$(jq -r '.tls.pinSHA256' "$CONFIG_FILE")
|
sha256=$(jq -r '.tls.pinSHA256' "$CONFIG_FILE")
|
||||||
obfspassword=$(jq -r '.obfs.salamander.password' "$CONFIG_FILE")
|
obfspassword=$(jq -r '.obfs.salamander.password' "$CONFIG_FILE")
|
||||||
|
|
||||||
# Get IP addresses
|
generate_uri() {
|
||||||
IP=$(curl -s -4 ip.gs)
|
local ip_version=$1
|
||||||
IP6=$(curl -s -6 ip.gs)
|
local ip=$2
|
||||||
|
if [ "$ip_version" -eq 4 ]; then
|
||||||
|
echo "hy2://$username%3A$authpassword@$ip:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv4"
|
||||||
|
elif [ "$ip_version" -eq 6 ]; then
|
||||||
|
echo "hy2://$username%3A$authpassword@[$ip]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv6"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Construct URI
|
if [ "$show_all" = true ]; then
|
||||||
URI="hy2://$username%3A$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv4"
|
IP=$(curl -s -4 ip.gs)
|
||||||
URI6="hy2://$username%3A$authpassword@[$IP6]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv6"
|
URI=$(generate_uri 4 "$IP")
|
||||||
|
IP6=$(curl -s -6 ip.gs)
|
||||||
|
URI6=$(generate_uri 6 "$IP6")
|
||||||
|
echo -e "\nIPv4:\n$URI\n"
|
||||||
|
echo -e "\nIPv6:\n$URI6\n"
|
||||||
|
else
|
||||||
|
if [ "$ip_version" -eq 4 ]; then
|
||||||
|
IP=$(curl -s -4 ip.gs)
|
||||||
|
URI=$(generate_uri 4 "$IP")
|
||||||
|
echo -e "\nIPv4:\n$URI\n"
|
||||||
|
elif [ "$ip_version" -eq 6 ]; then
|
||||||
|
IP6=$(curl -s -6 ip.gs)
|
||||||
|
URI6=$(generate_uri 6 "$IP6")
|
||||||
|
echo -e "\nIPv6:\n$URI6\n"
|
||||||
|
else
|
||||||
|
echo "Invalid IP version. Use 4 for IPv4 or 6 for IPv6."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Generate QR codes
|
if [ "$generate_qrcode" = true ]; then
|
||||||
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
cols=$(tput cols)
|
||||||
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
if [ -n "$URI" ]; then
|
||||||
|
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
# Display QR codes and URIs
|
echo -e "\nIPv4 QR Code:\n"
|
||||||
cols=$(tput cols)
|
echo "$qr1" | while IFS= read -r line; do
|
||||||
echo -e "\nIPv4:\n"
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
echo "$qr1" | while IFS= read -r line; do
|
done
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
fi
|
||||||
done
|
if [ -n "$URI6" ]; then
|
||||||
|
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
echo -e "\nIPv6:\n"
|
echo -e "\nIPv6 QR Code:\n"
|
||||||
echo "$qr2" | while IFS= read -r line; do
|
echo "$qr2" | while IFS= read -r line; do
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
echo
|
fi
|
||||||
echo "IPv4: $URI"
|
|
||||||
echo
|
|
||||||
echo "IPv6: $URI6"
|
|
||||||
echo
|
|
||||||
else
|
else
|
||||||
echo "Invalid username. Please try again."
|
echo "Invalid username. Please try again."
|
||||||
fi
|
fi
|
||||||
@ -63,5 +92,4 @@ show_uri() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call the function with the provided username argument
|
show_uri "$@"
|
||||||
show_uri "$1"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user