forked from leftypol/leftypol
functions.php: add note on rejected ip for IP API
This commit is contained in:
parent
9b9698210b
commit
ad2431893c
1 changed files with 31 additions and 4 deletions
|
@ -1828,6 +1828,15 @@ function buildJavascript() {
|
||||||
* @return bool True if the IP should be blocked.
|
* @return bool True if the IP should be blocked.
|
||||||
*/
|
*/
|
||||||
function checkIPAPI(string $ip): bool {
|
function checkIPAPI(string $ip): bool {
|
||||||
|
function add_note(string $ip, string $note) {
|
||||||
|
$query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||||
|
$query->bindValue(':ip', $ip);
|
||||||
|
$query->bindValue(':mod', -1, PDO::PARAM_INT);
|
||||||
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
||||||
|
$query->bindValue(':body', "IP API automatic note: $note");
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
}
|
||||||
|
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if (!$config['ip_api']['iphub']['enabled']) {
|
if (!$config['ip_api']['iphub']['enabled']) {
|
||||||
|
@ -1918,10 +1927,28 @@ function checkIPAPI(string $ip): bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($config['ip_api']['ip_block'] == 1 && $ret['block'] == 1)
|
$add_note_mode = (int)$config['ip_api']['add_note'];
|
||||||
|| $config['ip_api']['ip_block'] == 2 && $ret['block'] != 0
|
|
||||||
|| array_search($ret['isp'], $config['ip_api']['isp_blacklist']) !== false
|
if (($config['ip_api']['ip_block'] == 1 && $ret['block'] == 1) || ($config['ip_api']['ip_block'] == 2 && $ret['block'] != 0)) {
|
||||||
|| array_search($ret['asn'], $config['ip_api']['asn_blacklist']) !== false) {
|
if ($add_note_mode !== 0) {
|
||||||
|
add_note($ip, _('IP was rejected for being blacklisted by the API'));
|
||||||
|
}
|
||||||
|
error($config['error']['proxy']);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_search($ret['isp'], $config['ip_api']['isp_blacklist']) !== false) {
|
||||||
|
if ($add_note_mode !== 0) {
|
||||||
|
add_note($ip, _("IP was rejected because the \"{$ret['isp']}\" ISP is blacklisted."));
|
||||||
|
}
|
||||||
|
error($config['error']['proxy']);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_search($ret['asn'], $config['ip_api']['asn_blacklist']) !== false) {
|
||||||
|
if ($add_note_mode !== 0) {
|
||||||
|
add_note($ip, _("IP was rejected because the \"{$ret['asn']}\" ASN is blacklisted."));
|
||||||
|
}
|
||||||
error($config['error']['proxy']);
|
error($config['error']['proxy']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue