forked from leftypol/leftypol
functions.php: use updated config format
This commit is contained in:
parent
1cc87c31aa
commit
f008f8879d
1 changed files with 44 additions and 36 deletions
|
@ -1830,9 +1830,17 @@ function buildJavascript() {
|
||||||
function checkIPAPI(string $ip): bool {
|
function checkIPAPI(string $ip): bool {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
if (!$config['ip_api']['iphub']['enabled']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$iphub_key = $config['ip_api']['iphub']['key'];
|
||||||
|
if (empty($iphub_key)) {
|
||||||
|
error_log('IP api backend is enabled but IPHub API is empty!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Query IPHub's database with the poster's IP.
|
// Query IPHub's database with the poster's IP.
|
||||||
if ($config['iphub_key'] && !empty($config['iphub_key'])) {
|
if (array_search($ip, $config['ip_api']['ip_whitelist']) !== false) {
|
||||||
if (array_search($ip, $config['iphub_whitelisted_ips']) !== false) {
|
|
||||||
// IP is whitelisted, don't bother querying.
|
// IP is whitelisted, don't bother querying.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1840,7 +1848,7 @@ function checkIPAPI(string $ip): bool {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, "http://v2.api.iphub.info/ip/$ip");
|
curl_setopt($ch, CURLOPT_URL, "http://v2.api.iphub.info/ip/$ip");
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Key: {$config['iphub_key']}" ]);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Key: $iphub_key" ]);
|
||||||
$reply = curl_exec($ch);
|
$reply = curl_exec($ch);
|
||||||
if ($reply === false) {
|
if ($reply === false) {
|
||||||
$curl_err = curl_error($ch);
|
$curl_err = curl_error($ch);
|
||||||
|
@ -1861,12 +1869,12 @@ function checkIPAPI(string $ip): bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($json->block == 1
|
if ($json->block == 1
|
||||||
|| array_search($json->asn, $config['iphub_banned_asns']) !== false
|
|| array_search($json->isp, $config['ip_api']['isps_blacklist']) !== false
|
||||||
|| array_search($json->isp, $config['iphub_banned_isps']) !== false) {
|
|| array_search($json->asn, $config['ip_api']['asns_blacklist']) !== false) {
|
||||||
error($config['error']['proxy']);
|
error($config['error']['proxy']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue