From 438307e908c166df67033f3f6cc669458df3b112 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sat, 10 Aug 2024 12:31:44 +0330 Subject: [PATCH] Extract traffic data --- core/scripts/hysteria2/get_user.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/scripts/hysteria2/get_user.sh b/core/scripts/hysteria2/get_user.sh index d67b4c1..026c7e2 100644 --- a/core/scripts/hysteria2/get_user.sh +++ b/core/scripts/hysteria2/get_user.sh @@ -2,8 +2,6 @@ source /etc/hysteria/core/scripts/path.sh - -# Check if a username is provided if [ -z "$1" ]; then echo "Usage: $0 " exit 1 @@ -11,22 +9,33 @@ fi USERNAME=$1 -# Check if users.json file exists if [ ! -f "$USERS_FILE" ]; then echo "users.json file not found!" exit 1 fi -# Extract user info using jq +if [ ! -f "$TRAFFIC_FILE" ]; then + echo "traffic_data.json file not found!" + exit 1 +fi + USER_INFO=$(jq -r --arg username "$USERNAME" '.[$username] // empty' $USERS_FILE) -# Check if user info is found if [ -z "$USER_INFO" ]; then echo "User '$USERNAME' not found." exit 1 fi -# Print user info +TRAFFIC_INFO=$(jq -r --arg username "$USERNAME" '.[$username] // empty' $TRAFFIC_FILE) + +echo "User Information:" echo "$USER_INFO" | jq . +echo "Traffic Information:" +if [ -z "$TRAFFIC_INFO" ]; then + echo "No traffic data found for user '$USERNAME'." +else + echo "$TRAFFIC_INFO" | jq . +fi + exit 0