<?php
$config = include 'config.php';

// Get IP safely (Cloudflare support)
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] 
      ?? $_SERVER['REMOTE_ADDR'] 
      ?? 'Unknown';

// Optional geo lookup
$geo = @json_decode(file_get_contents("http://ip-api.com/json/{$ip}"), true);

$country = $geo['country'] ?? 'Unknown';
$city    = $geo['city'] ?? 'Unknown';

// Message
$message = "📥 New Download\n";
$message .= "IP: {$ip}\n";
$message .= "Location: {$city}, {$country}";

// Send to Telegram
$url = "https://api.telegram.org/bot{$config['bot_url']}/sendMessage";

file_get_contents($url . "?" . http_build_query([
    'chat_id' => $config['chat_id'],
    'text' => $message
]));