| 1 |
<?php |
| 2 |
if (!defined('MCDATAPATH')) exit; |
| 3 |
|
| 4 |
if (!class_exists('BVPrependIPStore')) : |
| 5 |
class BVPrependIPStore { |
| 6 |
public $whitelistedIPs; |
| 7 |
public $blacklistedIPs; |
| 8 |
|
| 9 |
#TYPE |
| 10 |
const BLACKLISTED = 1; |
| 11 |
const WHITELISTED = 2; |
| 12 |
|
| 13 |
#CATEGORY |
| 14 |
const FW = 3; |
| 15 |
|
| 16 |
function __construct($confHash) { |
| 17 |
$this->whitelistedIPs = array_key_exists('whitelisted', $confHash) ? $confHash['whitelisted'] : array(); |
| 18 |
$this->blacklistedIPs = array_key_exists('blacklisted', $confHash) ? $confHash['blacklisted'] : array(); |
| 19 |
} |
| 20 |
|
| 21 |
public function isFWIPBlacklisted($ip) { |
| 22 |
return $this->checkIPPresent($ip, BVPrependIPStore::BLACKLISTED); |
| 23 |
} |
| 24 |
|
| 25 |
public function isFWIPWhitelisted($ip) { |
| 26 |
return $this->checkIPPresent($ip, BVPrependIPStore::WHITELISTED); |
| 27 |
} |
| 28 |
|
| 29 |
public function checkIPPresent($ip, $type) { |
| 30 |
$flag = false; |
| 31 |
|
| 32 |
switch($type) { |
| 33 |
|
| 34 |
case BVPrependIPStore::BLACKLISTED: |
| 35 |
if (isset($this->blacklistedIPs[$ip])) |
| 36 |
$flag = true; |
| 37 |
break; |
| 38 |
|
| 39 |
case BVPrependIPStore::WHITELISTED: |
| 40 |
if (isset($this->whitelistedIPs[$ip])) |
| 41 |
$flag = true; |
| 42 |
break; |
| 43 |
} |
| 44 |
|
| 45 |
return $flag; |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
endif; |