diff --git a/Mullvad/Mullvad_Account_Expiry_Notifier/README.md b/Mullvad/Mullvad_Account_Expiry_Notifier/README.md new file mode 100644 index 0000000..2b244d3 --- /dev/null +++ b/Mullvad/Mullvad_Account_Expiry_Notifier/README.md @@ -0,0 +1,63 @@ +# Mullvad Account Expiry Notifier + +## # Features + +* Reads 16-digit account numbers from a file (accounts.txt). +* Fetches expiration dates from the Mullvad API. +* Sends alerts to a specified Discord webhook if an account is nearing expiration. +* Ensures valid account numbers and handles API response errors gracefully. + +### Prerequisites + +- A valid accounts.txt file containing Mullvad account numbers (one per line). +- A Discord webhook URL for notifications. +- Required dependencies: curl, jq, and date. + +### Installation + +Ensure the script has execution permissions: + +``` +chmod +x check_mullvad_account_expiry.sh + +``` +### Usage + +Create a file named accounts.txt and list Mullvad account numbers: + +``` +1234567890123456 +9876543210987654 +``` + +Set your Discord webhook URL in the script: + +``` +DISCORD_WEBHOOK_URL="your_discord_webhook_url" +``` + +Run the script: + +``` +./check_mullvad_account_expiry.sh +``` + +### Configuration + +- TXT_FILE: The file containing Mullvad account numbers (default: accounts.txt). + +- DAYS_THRESHOLD: Number of days before expiry to trigger an alert (default: 14). + +- DISCORD_WEBHOOK_URL: The webhook URL to send alerts to Discord. + +#### Example Output + +Account 1234567890123456 expires in 10 days. +Sending Discord notification... +Account 9876543210987654 expires in 20 days. + +### Notes + +Ensure the accounts.txt file contains only valid 16-digit Mullvad account numbers. +The script adds a small delay between API requests to prevent rate-limiting. +Modify DAYS_THRESHOLD to adjust the notification period. diff --git a/Mullvad/Mullvad_Account_Expiry_Notifier/check_mullvad_account_expiry.sh b/Mullvad/Mullvad_Account_Expiry_Notifier/check_mullvad_account_expiry.sh new file mode 100644 index 0000000..af9e3c0 --- /dev/null +++ b/Mullvad/Mullvad_Account_Expiry_Notifier/check_mullvad_account_expiry.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# Configuration +TXT_FILE="accounts.txt" # File containing 16-digit account numbers +DAYS_THRESHOLD=14 # Number of days before expiry to trigger alert +DISCORD_WEBHOOK_URL="your_discord_webhook_url" + +# Function to send a Discord notification +send_discord_notification() { + local account_id="$1" + local expiry="$2" + local message="Account $account_id is expiring soon! Expiry date: $expiry" + +curl -H "Content-Type: application/json" -X POST --data @- "$DISCORD_WEBHOOK_URL" < /dev/null 2>&1; then + echo "Invalid response for account $account_id" + continue + fi + + expiry=$(echo "$response" | jq -r '.expiry') + + # Check if expiry field is valid + if [[ "$expiry" == "null" || -z "$expiry" ]]; then + echo "No expiry date found for account $account_id" + continue + fi + + # Convert expiry date to epoch time + expiry_epoch=$(date -d "$expiry" +%s) + current_epoch=$(date +%s) + + # Calculate days until expiry + days_until_expiry=$(( (expiry_epoch - current_epoch) / 86400 )) + + echo "Account $account_id expires in $days_until_expiry days." + + # Trigger alert if expiry is within the threshold + if (( days_until_expiry <= DAYS_THRESHOLD )); then + send_discord_notification "$account_id" "$expiry" + fi + + # Small delay to prevent API rate limits + sleep 1 + +done < "$TXT_FILE" +