diff --git a/inc/config.php b/inc/config.php index 746fcad6..da37ab93 100644 --- a/inc/config.php +++ b/inc/config.php @@ -236,6 +236,19 @@ // To prevent bump atacks; returns the thread to last position after the last post is deleted. $config['anti_bump_flood'] = false; + // IPHub API key for checking for bad proxies (leave blank to not use IPHub) https://iphub.info/api + $config['iphub_key'] = ""; + + // If you find that a lot of spammers are comming from a specific ISP, or ASN, + // you can put the ISP in iphub_banned_isps and/or the ASN in iphub_banned_asns + // USE THIS WITH CAUTION, IT MAY PREVENT NON-SPAMMERS FROM POSTING + $config['iphub_banned_isps'] = []; + $config['iphub_banned_asns'] = []; + + // IPs in this array won't be checked by IPHub + // This can be used if legitimate posters are getting blocked by IPHub + $config['iphub_whitelisted_ips'] = []; + /* * Introduction to Tinyboard's spam filter: * @@ -1198,6 +1211,7 @@ // Error messages $config['error']['bot'] = _('You look like a bot.'); + $config['error']['proxy'] = _('You seem to be using an unathorized proxy.'); $config['error']['referer'] = _('Your browser sent an invalid or no HTTP referer.'); $config['error']['toolong'] = _('The %s field was too long.'); $config['error']['toolong_body'] = _('The body was too long.'); diff --git a/inc/functions.php b/inc/functions.php index 644cefbe..6df52894 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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;