functions.php: add note on rejected ip for IP API

This commit is contained in:
Zankaria 2024-10-10 23:50:44 +02:00
parent 9b9698210b
commit ad2431893c

View file

@ -1828,6 +1828,15 @@ function buildJavascript() {
* @return bool True if the IP should be blocked.
*/
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;
if (!$config['ip_api']['iphub']['enabled']) {
@ -1918,10 +1927,28 @@ function checkIPAPI(string $ip): bool {
return false;
}
if (($config['ip_api']['ip_block'] == 1 && $ret['block'] == 1)
|| $config['ip_api']['ip_block'] == 2 && $ret['block'] != 0
|| array_search($ret['isp'], $config['ip_api']['isp_blacklist']) !== false
|| array_search($ret['asn'], $config['ip_api']['asn_blacklist']) !== false) {
$add_note_mode = (int)$config['ip_api']['add_note'];
if (($config['ip_api']['ip_block'] == 1 && $ret['block'] == 1) || ($config['ip_api']['ip_block'] == 2 && $ret['block'] != 0)) {
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']);
return true;
}