Added Mullvad_Account_Expiry_Notifier project
This commit is contained in:
		
							parent
							
								
									e7b97e1b5a
								
							
						
					
					
						commit
						e76649adad
					
				
							
								
								
									
										63
									
								
								Mullvad/Mullvad_Account_Expiry_Notifier/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Mullvad/Mullvad_Account_Expiry_Notifier/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -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. | ||||
| @ -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" <<EOF | ||||
| { | ||||
|   "content": "", | ||||
|   "embeds": [ | ||||
|     { | ||||
|       "title": "Mullvad Account Alert - $account_id", | ||||
|       "description": "Mullvad account $account_id is due to expire.", | ||||
|       "url": "https://mullvad.net/en/account", | ||||
|       "color": 16755968, | ||||
|       "fields": [ | ||||
|         { | ||||
|           "name": "Days until Expiry:", | ||||
|           "value": "$days_until_expiry" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Expiry Date:", | ||||
|           "value": "$expiry" | ||||
|         } | ||||
|       ], | ||||
|       "footer": { | ||||
|         "text": "Mullvad Account URL: https://mullvad.net/en/account" | ||||
|       } | ||||
|     } | ||||
|   ], | ||||
|   "attachments": [] | ||||
| } | ||||
| EOF | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| # Read each line in the text file | ||||
| while IFS= read -r account_id; do | ||||
|     # Validate account_id (ensure it's a 16-digit number) | ||||
|     if [[ ! "$account_id" =~ ^[0-9]{16}$ ]]; then | ||||
|         echo "Skipping invalid account ID: $account_id" | ||||
|         continue | ||||
|     fi | ||||
|      | ||||
|     # Fetch account details with error handling | ||||
|     response=$(curl -s --fail "https://api.mullvad.net/public/accounts/v1/$account_id") | ||||
| 
 | ||||
|     # Check if response is valid JSON and not empty | ||||
|     if [[ -z "$response" ]] || ! echo "$response" | jq empty > /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" | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user