commit ebc70066954d148cd5f3380e914f45cbb760da1f Author: Clarth Date: Tue Sep 17 14:31:03 2024 -0400 Add expire.sh diff --git a/expire.sh b/expire.sh new file mode 100644 index 0000000..f019eb3 --- /dev/null +++ b/expire.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Function to get the expiration date from Xtream Codes and check if it is less than 10 days away +get_xtream_expiry() { + local panel_url=$1 + local username=$2 + local password=$3 + local bot_token=$4 + local chat_id=$5 + + # API URL + local api_url="${panel_url}/player_api.php" + + # Make the API request using curl + response=$(curl -s "${api_url}" --get --data-urlencode "username=${username}" --data-urlencode "password=${password}" --data-urlencode "action=get_account_info") + + # Check if jq is available + if ! command -v jq &> /dev/null + then + echo "jq is required but not installed. Please install it using: sudo apt install jq" + exit 1 + fi + + # Extract the expiration date using jq + expiry_date=$(echo "$response" | jq -r '.user_info.exp_date') + + if [ "$expiry_date" != "null" ] && [ -n "$expiry_date" ]; then + # Convert the expiration date from Unix timestamp to human-readable format + expiry_date_readable=$(date -d @"$expiry_date" +"%Y-%m-%d %H:%M:%S") + echo "Expiry Date: $expiry_date_readable" + + # Get the current date and expiration date in seconds since epoch + current_date=$(date +%s) + expiry_date_seconds=$(date -d @"$expiry_date" +%s) + + # Calculate the difference in days + days_left=$(( (expiry_date_seconds - current_date) / 86400 )) + + # Debugging: Print days left + echo "Days Left: $days_left" + + # Check if the expiration date has passed + if [ "$days_left" -lt 0 ]; then + echo "The subscription has already expired on $expiry_date_readable. No messages will be sent." + return 0 # Exit the function without sending a message + fi + + # Check if it's less than 10 days away + if [ "$days_left" -lt 10 ]; then + echo "The subscription will expire in less than a week ($days_left days left). Sending Telegram alert..." + + # Construct the message + message="⚠️ Warning: Your Xtream Codes subscription will expire in $days_left days on $expiry_date_readable." + + # Debugging: Print message content + echo "Message: $message" + + # Send a message to Telegram using curl + curl -s -X POST "https://api.telegram.org/bot${bot_token}/sendMessage" \ + -d chat_id="${chat_id}" \ + -d text="${message}" \ + -d parse_mode="Markdown" + fi + else + echo "Expiration date not found or is null." + fi +} + +# Usage +panel_url="http://your_xtream_panel_url:port" +username="your_username" +password="your_password" +bot_token="your_telegram_bot_token" # Replace with your Telegram bot token +chat_id="your_chat_id" # Replace with your Telegram chat ID + +get_xtream_expiry "$panel_url" "$username" "$password" "$bot_token" "$chat_id"