Add IPHub querying support

This commit is contained in:
Zeke Roa 2019-04-26 17:28:27 -07:00 committed by Zankaria
parent 169bf13f5d
commit 44e07295e5
2 changed files with 55 additions and 0 deletions

View file

@ -1823,6 +1823,47 @@ function buildJavascript() {
file_write($config['file_script'], $script);
}
function checkIPAPI() {
global $config;
// query IPHub's database with the poster's IP
if (isset($config['iphub_key']) && $config['iphub_key'] !== "") {
if (isset($config['iphub_whitelisted_ips']) && array_search($_SERVER['REMOTE_ADDR'], $config['iphub_whitelisted_ips']) !== false) {
// IP is whitelisted, don't bother querying
error("return true;");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://v2.api.iphub.info/ip/" . $_SERVER['REMOTE_ADDR']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Key: " . $config['iphub_key']));
$reply = curl_exec($ch);
if ($reply == "") {
return false;
}
$json = json_decode($reply);
if (isset($json->error)) {
$logdata = array();
$logdata['time'] = date(DATE_ATOM);
$logdata['action'] = 'iphub_query';
$logdata['msg'] = $json->error;
$logline = json_encode($logdata);
error_log($logline);
return false;
}
if ($json->block == 1
|| (isset($config['iphub_banned_asns']) && array_search($json->asn, $config['iphub_banned_asns']) !== false)
|| (isset($config['iphub_banned_isps']) && array_search($json->isp, $config['iphub_banned_isps']) !== false)) {
error($config['error']['proxy']);
return true;
}
}
return false;
}
function checkDNSBL() {
global $config;