<?php

function checkProxy($ip){
		$contactEmail="malifaturahman8@gmail.com";
		$timeout=5; //by default, wait no longer than 5 secs for a response
		$banOnProbability=0.99; //if getIPIntel returns a value higher than this, function returns true, set to 0.99 by default
		
		//init and set cURL options
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

		//if you're using custom flags (like flags=m), change the URL below
		curl_setopt($ch, CURLOPT_URL, "http://check.getipintel.net/check.php?ip=$ip&contact=$contactEmail");
		$response=curl_exec($ch);
		
		curl_close($ch);
		
		
		if ($response > $banOnProbability) {
				return true;
		} else {
			if ($response < 0 || strcmp($response, "") == 0 ) {

			}
				return false;
		}
}


$ip=$_SERVER['REMOTE_ADDR'];

// Jika terdeteksi sebagai bot, tampilkan pesan kesalahan dan kirim data IP ke chat ID Telegram
if (checkProxy($_SERVER['REMOTE_ADDR'])) {
    $ip = $_SERVER['REMOTE_ADDR'];
    $telegramToken = '5838787993:AAFWHH1Sv57o5JIcyX9iOkdtUl_z_9OrztY';
    $chatId = '805289480'; 
    
    $url = "https://api.telegram.org/bot$telegramToken/sendMessage";

    // Data yang akan dikirimkan
    $data = [
        'chat_id' => $chatId,
        'text' => "Detected Proxy / VPN / Bad IP: $ip"
    ];

    // Konversi data menjadi format query string
    $queryString = http_build_query($data);

    // Buat permintaan HTTP POST
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Menampilkan pesan kesalahan
    echo "
    <html>
    <head>
        <title>Web-Protection</title>
        <link rel=\"stylesheet\" href=\"styles.css\" type=\"text/css\"/>
    </head>
    <body>
    <div class=\"container\">
        <div class=\"text error\">Whoops, something went wrong.</div>
        <div class=\"subtext\">It appears you're using a Proxy / VPN / bad IP.<br>Please contact the administrator for more information.</div>
    </div>
    </body>
    </html>";

    exit();
}

?>