Update UserPass Method
This commit is contained in:
163
menu.sh
163
menu.sh
@ -57,36 +57,52 @@ change_port() {
|
|||||||
# Function to show URI if Hysteria2 is installed and active
|
# Function to show URI if Hysteria2 is installed and active
|
||||||
show_uri() {
|
show_uri() {
|
||||||
if [ -f "/etc/hysteria/config.json" ]; then
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
port=$(jq -r '.listen' /etc/hysteria/config.json | cut -d':' -f2)
|
|
||||||
sha256=$(jq -r '.tls.pinSHA256' /etc/hysteria/config.json)
|
|
||||||
obfspassword=$(jq -r '.obfs.salamander.password' /etc/hysteria/config.json)
|
|
||||||
authpassword=$(jq -r '.auth.userpass.default' /etc/hysteria/config.json)
|
|
||||||
|
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
IP=$(curl -s -4 ip.sb)
|
# Get the list of configured usernames
|
||||||
IP6=$(curl -s -6 ip.sb)
|
usernames=$(jq -r '.auth.userpass | keys_unsorted[]' /etc/hysteria/config.json)
|
||||||
URI="hy2://default:$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#Hysteria2-IPv4"
|
|
||||||
URI6="hy2://:default$authpassword@[$IP6]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#Hysteria2-IPv6"
|
|
||||||
|
|
||||||
cols=$(tput cols)
|
# Prompt the user to select a username
|
||||||
rows=$(tput lines)
|
PS3="Select a username: "
|
||||||
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
select username in $usernames; do
|
||||||
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
if [ -n "$username" ]; then
|
||||||
|
# Get the selected user's password and other required parameters
|
||||||
|
authpassword=$(jq -r ".auth.userpass[\"$username\"]" /etc/hysteria/config.json)
|
||||||
|
port=$(jq -r '.listen' /etc/hysteria/config.json | cut -d':' -f2)
|
||||||
|
sha256=$(jq -r '.tls.pinSHA256' /etc/hysteria/config.json)
|
||||||
|
obfspassword=$(jq -r '.obfs.salamander.password' /etc/hysteria/config.json)
|
||||||
|
|
||||||
echo -e "\nIPv4:\n"
|
# Get IP addresses
|
||||||
echo "$qr1" | while IFS= read -r line; do
|
IP=$(curl -s -4 ip.sb)
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
IP6=$(curl -s -6 ip.sb)
|
||||||
|
|
||||||
|
# Construct URI
|
||||||
|
URI="hy2://$username:$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#Hysteria2-IPv4"
|
||||||
|
URI6="hy2://$username:$authpassword@[$IP6]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#Hysteria2-IPv6"
|
||||||
|
|
||||||
|
cols=$(tput cols)
|
||||||
|
rows=$(tput lines)
|
||||||
|
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
|
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
|
|
||||||
|
echo -e "\nIPv4:\n"
|
||||||
|
echo "$qr1" | while IFS= read -r line; do
|
||||||
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "\nIPv6:\n"
|
||||||
|
echo "$qr2" | while IFS= read -r line; do
|
||||||
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
echo "IPv4: $URI"
|
||||||
|
echo
|
||||||
|
echo "IPv6: $URI6"
|
||||||
|
echo
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Invalid selection. Please try again."
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "\nIPv6:\n"
|
|
||||||
echo "$qr2" | while IFS= read -r line; do
|
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echo "IPv4: $URI"
|
|
||||||
echo
|
|
||||||
echo "IPv6: $URI6"
|
|
||||||
echo
|
|
||||||
else
|
else
|
||||||
echo "Error: Hysteria2 is not active."
|
echo "Error: Hysteria2 is not active."
|
||||||
fi
|
fi
|
||||||
@ -95,7 +111,7 @@ show_uri() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to check traffic status
|
# Function to check traffic status for each user
|
||||||
traffic_status() {
|
traffic_status() {
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
cyan='\033[0;36m'
|
cyan='\033[0;36m'
|
||||||
@ -109,32 +125,47 @@ traffic_status() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
response=$(curl -s -H "Authorization: $secret" http://127.0.0.1:25413/traffic)
|
response=$(curl -s -H "Authorization: $secret" http://127.0.0.1:25413/traffic)
|
||||||
|
|
||||||
if [ -z "$response" ] || [ "$response" = "{}" ]; then
|
if [ -z "$response" ] || [ "$response" = "{}" ]; then
|
||||||
echo -e "Upload (TX): ${green}0B${NC}"
|
echo -e "No traffic data available."
|
||||||
echo -e "Download (RX): ${cyan}0B${NC}"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tx_bytes=$(echo "$response" | jq -r '.user.tx // 0')
|
echo "Traffic status for each user:"
|
||||||
rx_bytes=$(echo "$response" | jq -r '.user.rx // 0')
|
echo "-------------------------------------------------"
|
||||||
|
printf "%-15s %-15s %-15s\n" "User" "Upload (TX)" "Download (RX)"
|
||||||
|
echo "-------------------------------------------------"
|
||||||
|
|
||||||
format_bytes() {
|
# Iterate over each user in the response
|
||||||
bytes=$1
|
users=$(echo "$response" | jq -r 'keys[]')
|
||||||
if [ "$bytes" -lt 1024 ]; then
|
for user in $users; do
|
||||||
echo "${bytes}B"
|
tx_bytes=$(echo "$response" | jq -r ".[\"$user\"].tx // 0")
|
||||||
elif [ "$bytes" -lt 1048576 ]; then
|
rx_bytes=$(echo "$response" | jq -r ".[\"$user\"].rx // 0")
|
||||||
echo "$(bc <<< "scale=2; $bytes / 1024")KB"
|
|
||||||
elif [ "$bytes" -lt 1073741824 ]; then
|
|
||||||
echo "$(bc <<< "scale=2; $bytes / 1048576")MB"
|
|
||||||
elif [ "$bytes" -lt 1099511627776 ]; then
|
|
||||||
echo "$(bc <<< "scale=2; $bytes / 1073741824")GB"
|
|
||||||
else
|
|
||||||
echo "$(bc <<< "scale=2; $bytes / 1099511627776")TB"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
echo -e "Upload (TX): ${green}$(format_bytes "$tx_bytes")${NC}"
|
# Format the bytes into human-readable format
|
||||||
echo -e "Download (RX): ${cyan}$(format_bytes "$rx_bytes")${NC}"
|
formatted_tx=$(format_bytes "$tx_bytes")
|
||||||
|
formatted_rx=$(format_bytes "$rx_bytes")
|
||||||
|
|
||||||
|
# Print user traffic information with color formatting
|
||||||
|
printf "%-15s ${green}%-15s${NC} ${cyan}%-15s${NC}\n" "$user" "$formatted_tx" "$formatted_rx"
|
||||||
|
echo "-------------------------------------------------"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper function to format bytes into human-readable format
|
||||||
|
format_bytes() {
|
||||||
|
bytes=$1
|
||||||
|
if [ "$bytes" -lt 1024 ]; then
|
||||||
|
echo "${bytes}B"
|
||||||
|
elif [ "$bytes" -lt 1048576 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1024")KB"
|
||||||
|
elif [ "$bytes" -lt 1073741824 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1048576")MB"
|
||||||
|
elif [ "$bytes" -lt 1099511627776 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1073741824")GB"
|
||||||
|
else
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1099511627776")TB"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to uninstall Hysteria2
|
# Function to uninstall Hysteria2
|
||||||
@ -240,29 +271,43 @@ configure_warp() {
|
|||||||
echo "Error: Config file /etc/hysteria/config.json not found."
|
echo "Error: Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
# Function to add a new user to the configuration
|
||||||
|
add_user() {
|
||||||
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
|
read -p "Enter the username: " username
|
||||||
|
password=$(curl -s "https://api.genratr.com/?length=32&uppercase&lowercase&numbers" | jq -r '.password')
|
||||||
|
|
||||||
|
jq --arg username "$username" --arg password "$password" '.auth.userpass[$username] = $password' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||||
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
|
echo "User $username added successfully."
|
||||||
|
else
|
||||||
|
echo "Error: Config file /etc/hysteria/config.json not found."
|
||||||
|
fi
|
||||||
|
}
|
||||||
# Hysteria2 menu
|
# Hysteria2 menu
|
||||||
hysteria2_menu() {
|
hysteria2_menu() {
|
||||||
clear
|
clear
|
||||||
echo "===== Hysteria2 Menu ====="
|
echo "===== Hysteria2 Menu ====="
|
||||||
echo "1. Install and Configure"
|
echo "1. Install and Configure"
|
||||||
echo "2. Update Core"
|
echo "2. Add User"
|
||||||
echo "3. Change Port"
|
echo "3. Show URI"
|
||||||
echo "4. Show URI"
|
echo "4. Check Traffic Status"
|
||||||
echo "5. Check Traffic Status"
|
echo "5. Change Port"
|
||||||
echo "6. Uninstall"
|
echo "6. Update Core"
|
||||||
echo "7. Back to Main Menu"
|
echo "7. Uninstall"
|
||||||
|
echo "8. Back to Main Menu"
|
||||||
echo "=========================="
|
echo "=========================="
|
||||||
|
|
||||||
read -p "Enter your choice: " choice
|
read -p "Enter your choice: " choice
|
||||||
case $choice in
|
case $choice in
|
||||||
1) install_and_configure ;;
|
1) install_and_configure ;;
|
||||||
2) update_core ;;
|
2) add_user ;;
|
||||||
3) change_port ;;
|
3) show_uri ;;
|
||||||
4) show_uri ;;
|
4) traffic_status ;;
|
||||||
5) traffic_status ;;
|
5) change_port ;;
|
||||||
6) uninstall_hysteria ;;
|
6) update_core ;;
|
||||||
7) return ;;
|
7) uninstall_hysteria ;;
|
||||||
|
8) return ;;
|
||||||
*) echo "Invalid option. Please try again." ;;
|
*) echo "Invalid option. Please try again." ;;
|
||||||
esac
|
esac
|
||||||
read -p "Press any key to return to the Hysteria2 menu..."
|
read -p "Press any key to return to the Hysteria2 menu..."
|
||||||
|
|||||||
Reference in New Issue
Block a user