Use users.json

This commit is contained in:
Whispering Wind
2024-08-23 12:01:33 +03:30
committed by GitHub
parent ff93ebe175
commit 959e5be86a

View File

@ -1,29 +1,21 @@
#!/bin/bash
# Source the path.sh script to load the necessary variables
source /etc/hysteria/core/scripts/path.sh
source /etc/hysteria/core/scripts/utils.sh
define_colors
# Function to remove a user from the configuration
remove_user() {
if [ $# -ne 1 ]; then
echo "Usage: $0 <username>"
exit 1
fi
username=$1
local username=$1
if [ -f "$USERS_FILE" ]; then
# Check if the username exists in the users.json file
if jq -e "has(\"$username\")" "$USERS_FILE" > /dev/null; then
jq --arg username "$username" 'del(.[$username])' "$USERS_FILE" > "${USERS_FILE}.temp" && mv "${USERS_FILE}.temp" "$USERS_FILE"
if [ -f "$TRAFFIC_FILE" ]; then
jq --arg username "$username" 'del(.[$username])' "$TRAFFIC_FILE" > "${TRAFFIC_FILE}.temp" && mv "${TRAFFIC_FILE}.temp" "$TRAFFIC_FILE"
fi
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
echo "User $username removed successfully."
else
echo -e "${red}Error:${NC} User $username not found."
@ -33,5 +25,4 @@ remove_user() {
fi
}
# Call the function with the provided username argument
remove_user "$1"