| 1 |
<?php |
| 2 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 3 |
|
| 4 |
if (!class_exists('WPRProtectIpstoreFS_V541')) : |
| 5 |
class WPRProtectIpstoreFS_V541 { |
| 6 |
private $whitelisted_ips; |
| 7 |
private $blacklisted_ips; |
| 8 |
|
| 9 |
const IP_TYPE_BLACKLISTED = 0; |
| 10 |
const IP_TYPE_WHITELISTED = 1; |
| 11 |
|
| 12 |
function __construct() { |
| 13 |
$ip_store_file = MCDATAPATH . MCCONFKEY . '-' . 'mc_ips.conf'; |
| 14 |
$ips = WPRProtectUtils_V541::parseFile($ip_store_file); |
| 15 |
$this->whitelisted_ips = array_key_exists('whitelisted', $ips) ? $ips['whitelisted'] : array(); |
| 16 |
$this->blacklisted_ips = array_key_exists('blacklisted', $ips) ? $ips['blacklisted'] : array(); |
| 17 |
} |
| 18 |
|
| 19 |
public function getTypeIfBlacklistedIP($ip) { |
| 20 |
return $this->getIPType($ip, WPRProtectIpstoreFS_V541::IP_TYPE_BLACKLISTED); |
| 21 |
} |
| 22 |
|
| 23 |
public function isFWIPBlacklisted($ip) { |
| 24 |
return $this->checkIPPresent($ip, WPRProtectIpstoreFS_V541::IP_TYPE_BLACKLISTED); |
| 25 |
} |
| 26 |
|
| 27 |
public function isFWIPWhitelisted($ip) { |
| 28 |
return $this->checkIPPresent($ip, WPRProtectIpstoreFS_V541::IP_TYPE_WHITELISTED); |
| 29 |
} |
| 30 |
|
| 31 |
private function checkIPPresent($ip, $type) { |
| 32 |
$ip_category = $this->getIPType($ip, $type); |
| 33 |
return isset($ip_category) ? true : false; |
| 34 |
} |
| 35 |
|
| 36 |
#XNOTE: getIPCategory or getIPType? |
| 37 |
private function getIPType($ip, $type) { |
| 38 |
switch ($type) { |
| 39 |
case WPRProtectIpstoreFS_V541::IP_TYPE_BLACKLISTED: |
| 40 |
return isset($this->blacklisted_ips[$ip]) ? $this->blacklisted_ips[$ip] : null; |
| 41 |
case WPRProtectIpstoreFS_V541::IP_TYPE_WHITELISTED: |
| 42 |
return isset($this->whitelisted_ips[$ip]) ? $this->whitelisted_ips[$ip] : null; |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
endif; |