<?php
// TB2X Firewall Snippet (non-WordPress PHP)
// Plaats zo hoog mogelijk (bovenaan index.php / bootstrap / init)

$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
$country = $_SERVER['HTTP_GEOIP_COUNTRY_CODE'] ?? ($_SERVER['GEOIP_COUNTRY_CODE'] ?? 'N/A');
$scheme = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS']==='off') ? 'http' : 'https';
$website = $scheme.'://'.($_SERVER['HTTP_HOST'] ?? '').($_SERVER['REQUEST_URI'] ?? '/');

$url = 'https://www.tb2x.com/admin/firewall.php?' . http_build_query([
  'ip'=>$ip,'country'=>$country,'website'=>$website,'agent'=>$agent
]);

if (function_exists('curl_init')) {
  $ch = curl_init($url);
  curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 8,
    CURLOPT_CONNECTTIMEOUT => 4,
  ]);
  $resp = curl_exec($ch);
  $code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  if ($code === 200 && $resp) {
    $data = json_decode($resp, true);
    if (!empty($data['blocked'])) {
      header('Location: https://www.google.com', true, 302);
      exit;
    }
  }
}