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

@ -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.');

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;