From 169199d4e44175a3cad6b913a31b841278d007db Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:02:34 +0330 Subject: [PATCH] Update traffic Function --- menu.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/menu.sh b/menu.sh index b9f3eaa..1b529f1 100644 --- a/menu.sh +++ b/menu.sh @@ -182,10 +182,27 @@ show_uri() { # Function to check traffic status for each user traffic_status() { if [ -f "/etc/hysteria/traffic.py" ]; then - python3 /etc/hysteria/traffic.py + python3 /etc/hysteria/traffic.py >/dev/null 2>&1 else echo "Error: /etc/hysteria/traffic.py not found." + exit 1 fi + + if [ ! -f "/etc/hysteria/traffic_data.json" ]; then + echo "Error: /etc/hysteria/traffic_data.json not found." + exit 1 + fi + + data=$(cat /etc/hysteria/traffic_data.json) + echo "Traffic Data:" + echo "---------------------------------------------------------------------------" + echo -e "User Upload (TX) Download (RX) Status" + echo "---------------------------------------------------------------------------" + + echo "$data" | jq -r 'to_entries[] | [.key, (.value.upload_bytes / 1024 / 1024), (.value.download_bytes / 1024 / 1024), .value.status] | @tsv' | while IFS=$'\t' read -r user upload download status; do + printf "${yellow}%-15s ${cyan}%-15s ${green}%-15s ${NC}%-10s\n" "$user" "$(printf "%.2fMB" "$upload")" "$(printf "%.2fMB" "$download")" "$status" + echo "---------------------------------------------------------------------------" + done } # Function to restart Hysteria2 service