Closed gotspatel closed 3 hours ago
Unfortunately, this would result in your host's IP being blocked from ip-api.com due to hammering their API.
You are correct, i am trying to updating it to use localhosted maxmind data https://github.com/palinkas-jo-reggelt/GeoIP_Server
That certainly is an option anyone can do on their own, but will not be implemented into hMailAdmin as it requires constant db updates with new data.
yes and I am posting here the function (for If anyone wants to use it)
USE WITH CAUTION it requires https://github.com/palinkas-jo-reggelt/GeoIP_Server
ALSO CHANGE the YOUR_GEOIP_URL in here ---> http://YOUR_GEOIP_URL/api.php?geoip=
function GeoIp($ip) {
global $obLanguage;
if ($ip === '0.0.0.0') return Translate('Unknown');
$regex = '/(127\.0\.0\.1)|^(10\.)|^(192\.168\.)|^(169\.254\.)|^(172\.(1[6-9]|2[0-9]|3[0-1]))/';
if (preg_match($regex, $ip)) return Translate('Local IP range');
set_error_handler(function() { /* Ignore errors */ });
try {
// Fetch the JSON data from the LOCAL API
$json = file_get_contents('http://YOUR_GEOIP_URL/api.php?geoip=' . $ip);
$parsed = json_decode($json);
// Access country_code and country_name directly
if (isset($parsed->data->country_code)) {
return '<p><img src="flags/' . $parsed->data->country_code . '.gif" style="margin-right:5px;">' . $parsed->data->country_name . '</p>';
} else {
return Translate('Unknown');
}
} catch (Exception $e) {
// Handle the error if necessary
}
restore_error_handler();
}
Country and Flag is better outside in hm_securityranges instead of hm_securityrange, that way we don't have to open each IP to know where it is from, what do you say?
hm_securityranges.php changes as below if you approve
....