Skip to content

Commit

Permalink
class.abuseipdb_observer.php optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
webchills committed May 31, 2023
1 parent a79ad04 commit 71087c9
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -5,7 +5,7 @@
* Copyright 2023 marcopolo
* see https://github.com/CcMarc/AbuseIPDB
* License: GNU General Public License (GPL)
* version $Id: class.abuseipdb_observer.php 2023-05-31 10:02:16Z webchills $
* version $Id: class.abuseipdb_observer.php 2023-05-31 22:12:16Z webchills $
*/

class abuseipdb_observer extends base {
Expand Down Expand Up @@ -75,6 +75,8 @@ protected function checkAbusiveIP() {
$debug_mode = ABUSEIPDB_DEBUG === 'true';
$spider_allow = ABUSEIPDB_SPIDER_ALLOW;
$spider_log_enabled = ABUSEIPDB_SPIDER_ALLOW_LOG;
$blacklist_enable = ABUSEIPDB_BLACKLIST_ENABLE === 'true';
$blacklist_file_path = ABUSEIPDB_BLACKLIST_FILE_PATH;

if ($debug_mode == true) {
error_log('API Key: ' . $api_key);
Expand All @@ -96,10 +98,10 @@ protected function checkAbusiveIP() {
return;
}

// Define the path to your blacklist file, and if it exists, load its content into the $file_blocked_ips array
// Define the path to your blacklist file, and if it exists and ABUSEIPDB_BLACKLIST_ENABLE is true, load its content into the $file_blocked_ips array
$file_blocked_ips = array();
if (defined('ABUSEIPDB_BLACKLIST_ENABLE') && ABUSEIPDB_BLACKLIST_ENABLE && defined('ABUSEIPDB_BLACKLIST_FILE_PATH') && file_exists(ABUSEIPDB_BLACKLIST_FILE_PATH)) {
$file_blocked_ips = file(ABUSEIPDB_BLACKLIST_FILE_PATH, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($blacklist_enable && file_exists($blacklist_file_path)) {
$file_blocked_ips = file($blacklist_file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}

// Check if the IP is manually blocked
Expand All @@ -111,7 +113,7 @@ protected function checkAbusiveIP() {
}

// If the IP is not found in the array, check in the file, only if ABUSEIPDB_BLACKLIST_ENABLE is true
if (!$ip_blocked && defined('ABUSEIPDB_BLACKLIST_ENABLE') && ABUSEIPDB_BLACKLIST_ENABLE) {
if (!$ip_blocked && $blacklist_enable) {
foreach ($file_blocked_ips as $blocked_ip) {
if (strpos($ip, $blocked_ip) === 0) { // if the current IP starts with the blocked IP
$ip_blocked = true;
Expand Down

0 comments on commit 71087c9

Please sign in to comment.