diff --git a/changelog b/changelog index bef334f..46c03d7 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,3 @@ -1. Fix: Changed geo category(block adult sites) -2. Reject(malware, phishing, cryptominers) -3. Add: GeoCountry(Iran, China, and Russia) -4. Add: Geo Update flag --country option(cli) -5. Add: CPU monitoring module(Telegram-Bot) -6. Add: Search users by the `blocked` status(Telegram-Bot) +1. Fix: Block users based on total data usage +2. Increasing the chunk size to 32768 bytes(GeoFiles) +3. Update Requirements diff --git a/core/scripts/hysteria2/kick.sh b/core/scripts/hysteria2/kick.sh index aa29ad0..2b9f08b 100644 --- a/core/scripts/hysteria2/kick.sh +++ b/core/scripts/hysteria2/kick.sh @@ -46,6 +46,9 @@ for USERNAME in $(jq -r 'keys[]' "$USERS_FILE"); do EXPIRATION_DAYS=$(jq -r --arg user "$USERNAME" '.[$user].expiration_days // 0' "$USERS_FILE") ACCOUNT_CREATION_DATE=$(jq -r --arg user "$USERNAME" '.[$user].account_creation_date' "$USERS_FILE") CURRENT_DOWNLOAD_BYTES=$(jq -r --arg user "$USERNAME" '.[$user].download_bytes // 0' "$USERS_FILE") + CURRENT_UPLOAD_BYTES=$(jq -r --arg user "$USERNAME" '.[$user].upload_bytes // 0' "$USERS_FILE") + + TOTAL_BYTES=$((CURRENT_DOWNLOAD_BYTES + CURRENT_UPLOAD_BYTES)) if [ -z "$ACCOUNT_CREATION_DATE" ]; then echo "$(date): [INFO] Skipping $USERNAME due to missing account creation date." >> $LOGFILE @@ -55,8 +58,8 @@ for USERNAME in $(jq -r 'keys[]' "$USERS_FILE"); do CURRENT_DATE=$(date +%s) EXPIRATION_DATE=$(date -d "$ACCOUNT_CREATION_DATE + $EXPIRATION_DAYS days" +%s) - if [ "$MAX_DOWNLOAD_BYTES" -gt 0 ] && [ "$CURRENT_DOWNLOAD_BYTES" -ge 0 ] && [ "$EXPIRATION_DAYS" -gt 0 ]; then - if [ "$CURRENT_DOWNLOAD_BYTES" -ge "$MAX_DOWNLOAD_BYTES" ] || [ "$CURRENT_DATE" -ge "$EXPIRATION_DATE" ]; then + if [ "$MAX_DOWNLOAD_BYTES" -gt 0 ] && [ "$TOTAL_BYTES" -ge 0 ] && [ "$EXPIRATION_DAYS" -gt 0 ]; then + if [ "$TOTAL_BYTES" -ge "$MAX_DOWNLOAD_BYTES" ] || [ "$CURRENT_DATE" -ge "$EXPIRATION_DATE" ]; then for i in {1..3}; do jq --arg user "$USERNAME" '.[$user].blocked = true' "$USERS_FILE" > temp.json && mv temp.json "$USERS_FILE" && break sleep 1 diff --git a/core/scripts/hysteria2/update_geo.py b/core/scripts/hysteria2/update_geo.py index ba25ff3..4c63505 100644 --- a/core/scripts/hysteria2/update_geo.py +++ b/core/scripts/hysteria2/update_geo.py @@ -31,7 +31,7 @@ def remove_file(file_path): except Exception as e: print(f"Error removing file {file_path}: {e}") -def download_file(url, destination, chunk_size=8192): +def download_file(url, destination, chunk_size=32768): try: destination_dir = os.path.dirname(destination) if destination_dir and not os.path.exists(destination_dir): diff --git a/core/scripts/hysteria2/user.sh b/core/scripts/hysteria2/user.sh index f185e8e..67cf08e 100644 --- a/core/scripts/hysteria2/user.sh +++ b/core/scripts/hysteria2/user.sh @@ -14,6 +14,9 @@ EXPIRATION_DAYS=$(jq -r --arg user "$USERNAME" '.[$user].expiration_days' "$USER ACCOUNT_CREATION_DATE=$(jq -r --arg user "$USERNAME" '.[$user].account_creation_date' "$USERS_FILE") BLOCKED=$(jq -r --arg user "$USERNAME" '.[$user].blocked' "$USERS_FILE") CURRENT_DOWNLOAD_BYTES=$(jq -r --arg user "$USERNAME" '.[$user].download_bytes' "$USERS_FILE") +CURRENT_UPLOAD_BYTES=$(jq -r --arg user "$USERNAME" '.[$user].upload_bytes' "$USERS_FILE") + +TOTAL_BYTES=$((CURRENT_DOWNLOAD_BYTES + CURRENT_UPLOAD_BYTES)) if [ "$BLOCKED" == "true" ]; then sleep 20 @@ -33,7 +36,7 @@ if [ "$CURRENT_DATE" -ge "$EXPIRATION_DATE" ]; then exit 1 fi -if [ "$CURRENT_DOWNLOAD_BYTES" -ge "$MAX_DOWNLOAD_BYTES" ]; then +if [ "$TOTAL_BYTES" -ge "$MAX_DOWNLOAD_BYTES" ]; then SECRET=$(jq -r '.trafficStats.secret' "$CONFIG_FILE") KICK_ENDPOINT="http://127.0.0.1:25413/kick" curl -s -H "Authorization: $SECRET" -X POST -d "[\"$USERNAME\"]" "$KICK_ENDPOINT" diff --git a/requirements.txt b/requirements.txt index 836d506..cfec43e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,22 @@ -pyTelegramBotAPI==4.22.1 -qrcode==7.4.2 -python-dotenv==1.0.1 -requests==2.32.3 -aiohttp==3.10.5 -click==8.1.7 +aiohappyeyeballs==2.4.4 +aiohttp==3.11.11 +aiosignal==1.3.2 +async-timeout==4.0.3 +attrs==24.3.0 +certifi==2024.12.14 +charset-normalizer==3.4.1 +click==8.1.8 +frozenlist==1.5.0 +idna==3.10 +multidict==6.1.0 +pillow==11.1.0 +propcache==0.2.1 psutil==6.1.1 +pypng==0.20220715.0 +pyTelegramBotAPI==4.26.0 +python-dotenv==1.0.1 +qrcode==8.0 +requests==2.32.3 +typing_extensions==4.12.2 +urllib3==2.3.0 +yarl==1.18.3