<?php
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use GeoIp2\Database\Reader;
class plgSystemUSOnly extends CMSPlugin
{
public function onAfterInitialise()
{
// Enable error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Path to the GeoLite2 database file
$databasePath = ('database.mmdb');
// Get user's IP address
$userIp = $_SERVER['REMOTE_ADDR'];
try {
// Create a Reader object
$reader = new Reader($databasePath);
// Look up the user's IP address
$record = $reader->city($userIp);
// Check if the country is 'US' or in Europe
$allowedCountries = ['US', 'GB', 'DE', 'FR', 'IT', 'ES', 'PL', 'RO', 'NL', 'BE', 'GR', 'CZ', 'PT', 'HU', 'SE', 'AT', 'BG', 'DK', 'FI', 'SK', 'IE', 'HR', 'LT', 'SI', 'LV', 'EE', 'CY', 'LU', 'MT', 'IS', 'NO', 'CH', 'LI'];
if (!in_array($record->country->isoCode, $allowedCountries)) {
// Redirect to the blocked page
JFactory::getApplication()->redirect('/blocked.php');
} else {
// Redirect to the index page
JFactory::getApplication()->redirect('/index.php');
}
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
// The IP address is not in the database.
die('IP address not found in database: ' . $e->getMessage());
} catch (\Exception $e) {
// Handle general exceptions
die('An error occurred: ' . $e->getMessage());
}
}
}
// Display the loading page
echo <<<HTML
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
font-family: Arial, sans-serif;
}
.loading-bar {
position: relative;
height: 20px;
width: 100%;
background-color: #f3f3f3;
}
.loading-bar:before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 0;
height: 100%;
background-color: #3498db;
animation: loading 2s linear infinite;
}
@keyframes loading {
from { width: 0; }
to { width: 100%; }
}
</style>
</head>
<body>
<h1>Checking for Malicious Uses and Loading...</h1>
<div class="loading-bar"></div>
</body>
</html>
HTML;
?>