| 1 |
<?php |
| 2 |
|
| 3 |
if (! (defined('ABSPATH') || defined('MCDATAPATH')) ) exit; |
| 4 |
if (!class_exists('BVFWConfig')) : |
| 5 |
|
| 6 |
class BVFWConfig { |
| 7 |
public $mode; |
| 8 |
public $requestProfilingMode; |
| 9 |
public $roleLevel; |
| 10 |
public $ipCookieMode; |
| 11 |
public $adminCookieMode; |
| 12 |
public $bypassLevel; |
| 13 |
public $customRoles; |
| 14 |
public $cookieKey; |
| 15 |
public $cookiePath; |
| 16 |
public $cookieDomain; |
| 17 |
public $loggingMode; |
| 18 |
public $rulesMode; |
| 19 |
public $isGeoBlocking; |
| 20 |
|
| 21 |
public static $requests_table = 'fw_requests'; |
| 22 |
public static $roleLevels = array( |
| 23 |
'administrator' => BVFWConfig::ROLE_LEVEL_ADMIN, |
| 24 |
'editor' => BVFWConfig::ROLE_LEVEL_EDITOR, |
| 25 |
'author' => BVFWConfig::ROLE_LEVEL_AUTHOR, |
| 26 |
'contributor' => BVFWConfig::ROLE_LEVEL_CONTRIBUTOR, |
| 27 |
'subscriber' => BVFWConfig::ROLE_LEVEL_SUBSCRIBER |
| 28 |
); |
| 29 |
|
| 30 |
function __construct($confHash) { |
| 31 |
$this->mode = array_key_exists('mode', $confHash) ? intval($confHash['mode']) : BVFWConfig::DISABLED; |
| 32 |
$this->requestProfilingMode = array_key_exists('reqprofilingmode', $confHash) ? intval($confHash['reqprofilingmode']) : BVFWConfig::REQ_PROFILING_MODE_DISABLED; |
| 33 |
$this->ipCookieMode = array_key_exists('ipcookiemode', $confHash) ? intval($confHash['ipcookiemode']) : BVFWConfig::IP_COOKIE_MODE_DISABLED; |
| 34 |
$this->adminCookieMode = array_key_exists('admincookiemode', $confHash) ? intval($confHash['admincookiemode']) : BVFWConfig::ADMIN_COOKIE_MODE_DISABLED; |
| 35 |
$this->loggingMode = array_key_exists('loggingmode', $confHash) ? intval($confHash['loggingmode']) : BVFWConfig::LOGGING_MODE_VISITOR; |
| 36 |
$this->bypassLevel = array_key_exists('bypasslevel', $confHash) ? intval($confHash['bypasslevel']) : BVFWConfig::ROLE_LEVEL_CONTRIBUTOR; |
| 37 |
$this->customRoles = array_key_exists('customroles', $confHash) ? $confHash['customroles'] : array(); |
| 38 |
$this->cookieKey = array_key_exists('cookiekey', $confHash) ? $confHash['cookiekey'] : ""; |
| 39 |
$this->cookiePath = array_key_exists('cookiepath', $confHash) ? $confHash['cookiepath'] : ""; |
| 40 |
$this->cookieDomain = array_key_exists('cookiedomain', $confHash) ? $confHash['cookiedomain'] : ""; |
| 41 |
$this->canSetCachePreventionCookie = array_key_exists('cansetcachepreventioncookie', $confHash) ? |
| 42 |
$confHash['cansetcachepreventioncookie'] : false; |
| 43 |
$this->rulesMode = array_key_exists('rulesmode', $confHash) ? intval($confHash['rulesmode']) : BVFWConfig::DISABLED; |
| 44 |
$this->isGeoBlocking = array_key_exists('isgeoblocking', $confHash) ? $confHash['isgeoblocking'] : false; |
| 45 |
} |
| 46 |
|
| 47 |
#mode |
| 48 |
const DISABLED = 1; |
| 49 |
const AUDIT = 2; |
| 50 |
const PROTECT = 3; |
| 51 |
|
| 52 |
#Request Profiling Mode |
| 53 |
const REQ_PROFILING_MODE_DISABLED = 1; |
| 54 |
const REQ_PROFILING_MODE_NORMAL = 2; |
| 55 |
const REQ_PROFILING_MODE_DEBUG = 3; |
| 56 |
|
| 57 |
#IP Cookie Mode |
| 58 |
const IP_COOKIE_MODE_ENABLED = 1; |
| 59 |
const IP_COOKIE_MODE_DISABLED = 2; |
| 60 |
|
| 61 |
#Admin Cookie Mode |
| 62 |
const ADMIN_COOKIE_MODE_ENABLED = 1; |
| 63 |
const ADMIN_COOKIE_MODE_DISABLED = 2; |
| 64 |
|
| 65 |
#Role Level |
| 66 |
const ROLE_LEVEL_SUBSCRIBER = 1; |
| 67 |
const ROLE_LEVEL_CONTRIBUTOR = 2; |
| 68 |
const ROLE_LEVEL_AUTHOR = 3; |
| 69 |
const ROLE_LEVEL_EDITOR = 4; |
| 70 |
const ROLE_LEVEL_ADMIN = 5; |
| 71 |
const ROLE_LEVEL_CUSTOM = 6; |
| 72 |
|
| 73 |
#WebServer Conf Mode |
| 74 |
const MODE_APACHEMODPHP = 1; |
| 75 |
const MODE_APACHESUPHP = 2; |
| 76 |
const MODE_CGI_FASTCGI = 3; |
| 77 |
const MODE_NGINX = 4; |
| 78 |
const MODE_LITESPEED = 5; |
| 79 |
const MODE_IIS = 6; |
| 80 |
|
| 81 |
#Logging Mode |
| 82 |
const LOGGING_MODE_VISITOR = 1; |
| 83 |
const LOGGING_MODE_COMPLETE = 2; |
| 84 |
const LOGGING_MODE_DISABLED = 3; |
| 85 |
|
| 86 |
#Valid mc_data filenames (not used anywhere) |
| 87 |
public static $validMcDataFilenames = array('mc.conf', 'mc_ips.conf', 'mc_rules.json'); |
| 88 |
public static $validDeletableFiles = array('mc.conf', 'mc_ips.conf', 'malcare-waf.php', 'mc.log', 'mc_data', 'mc_rules.json'); |
| 89 |
|
| 90 |
public function isActive() { |
| 91 |
return ($this->mode !== BVFWConfig::DISABLED); |
| 92 |
} |
| 93 |
|
| 94 |
public function isProtecting() { |
| 95 |
return ($this->mode === BVFWConfig::PROTECT); |
| 96 |
} |
| 97 |
|
| 98 |
public function isAuditing() { |
| 99 |
return ($this->mode === BVFWConfig::AUDIT); |
| 100 |
} |
| 101 |
|
| 102 |
public function isReqProfilingModeDebug() { |
| 103 |
return ($this->requestProfilingMode === BVFWConfig::REQ_PROFILING_MODE_DEBUG); |
| 104 |
} |
| 105 |
|
| 106 |
public function canProfileReqInfo() { |
| 107 |
return ($this->requestProfilingMode !== BVFWConfig::REQ_PROFILING_MODE_DISABLED); |
| 108 |
} |
| 109 |
|
| 110 |
public function isCompleteLoggingEnabled() { |
| 111 |
return ($this->loggingMode === BVFWConfig::LOGGING_MODE_COMPLETE); |
| 112 |
} |
| 113 |
|
| 114 |
public function isVisitorLoggingEnabled() { |
| 115 |
return ($this->loggingMode === BVFWConfig::LOGGING_MODE_VISITOR); |
| 116 |
} |
| 117 |
|
| 118 |
public function isLoggingDisabled() { |
| 119 |
return ($this->loggingMode === BVFWConfig::LOGGING_MODE_DISABLED); |
| 120 |
} |
| 121 |
|
| 122 |
public function isRulesModeEnabled() { |
| 123 |
return ($this->rulesMode === BVFWConfig::PROTECT); |
| 124 |
} |
| 125 |
} |
| 126 |
endif; |