diff --git a/core/scripts/hysteria2/get_user.sh b/core/scripts/hysteria2/get_user.sh index 026c7e2..5694c40 100644 --- a/core/scripts/hysteria2/get_user.sh +++ b/core/scripts/hysteria2/get_user.sh @@ -2,23 +2,33 @@ source /etc/hysteria/core/scripts/path.sh -if [ -z "$1" ]; then - echo "Usage: $0 " +SHOW_TRAFFIC=true + +while getopts ":u:t" opt; do + case ${opt} in + u ) + USERNAME=$OPTARG + ;; + t ) + SHOW_TRAFFIC=false + ;; + \? ) + echo "Usage: $0 -u [-t]" + exit 1 + ;; + esac +done + +if [ -z "$USERNAME" ]; then + echo "Usage: $0 -u [-t]" exit 1 fi -USERNAME=$1 - if [ ! -f "$USERS_FILE" ]; then echo "users.json file not found!" exit 1 fi -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) if [ -z "$USER_INFO" ]; then @@ -26,16 +36,21 @@ if [ -z "$USER_INFO" ]; then exit 1 fi -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 . +if [ "$SHOW_TRAFFIC" = true ]; then + if [ ! -f "$TRAFFIC_FILE" ]; then + echo "traffic_data.json file not found!" + exit 1 + fi + + TRAFFIC_INFO=$(jq -r --arg username "$USERNAME" '.[$username] // empty' $TRAFFIC_FILE) + + if [ -z "$TRAFFIC_INFO" ]; then + echo "No traffic data found for user '$USERNAME'." + else + echo "$TRAFFIC_INFO" | jq . + fi fi exit 0