| 1 |
<?php |
| 2 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 3 |
|
| 4 |
if (!class_exists('WPRProtectRequest_V547')) : |
| 5 |
class WPRProtectRequest_V547 { |
| 6 |
public $ip; |
| 7 |
public $host = ''; |
| 8 |
public $uri; |
| 9 |
public $method = ''; |
| 10 |
public $path = ''; |
| 11 |
public $timestamp; |
| 12 |
public $get_params; |
| 13 |
public $post_params; |
| 14 |
public $cookies; |
| 15 |
public $headers = array(); |
| 16 |
public $file_names = array(); |
| 17 |
public $files; |
| 18 |
public $respcode; |
| 19 |
public $status = WPRProtectRequest_V547::STATUS_ALLOWED; |
| 20 |
public $category = WPRProtectRequest_V547::CATEGORY_NORMAL; |
| 21 |
|
| 22 |
public $wp_user; |
| 23 |
|
| 24 |
#XNOTE: SHould be part of Protect. |
| 25 |
const STATUS_ALLOWED = 1; |
| 26 |
const STATUS_BLOCKED = 2; |
| 27 |
const STATUS_BYPASSED = 3; |
| 28 |
|
| 29 |
const CATEGORY_BLACKLISTED = 1; |
| 30 |
const CATEGORY_NORMAL = 10; |
| 31 |
const CATEGORY_WHITELISTED = 20; |
| 32 |
const CATEGORY_BOT_BLOCKED = 30; |
| 33 |
const CATEGORY_COUNTRY_BLOCKED = 40; |
| 34 |
const CATEGORY_USER_BLACKLISTED = 50; |
| 35 |
const CATEGORY_RULE_BLOCKED = 60; |
| 36 |
const CATEGORY_RULE_ALLOWED = 70; |
| 37 |
const CATEGORY_PRIVATEIP = 80; |
| 38 |
const CATEGORY_GLOBAL_BOT_BLOCKED = 90; |
| 39 |
|
| 40 |
public function __construct($ip_header) { |
| 41 |
$this->ip = WPRProtectUtils_V547::getIP($ip_header); |
| 42 |
$this->timestamp = time(); |
| 43 |
$this->get_params = $_GET; |
| 44 |
$this->cookies = $_COOKIE; |
| 45 |
$this->post_params = $_POST; |
| 46 |
$this->files = $_FILES; |
| 47 |
if (!empty($_FILES)) { |
| 48 |
foreach ($_FILES as $input => $file) { |
| 49 |
$this->file_names[$input] = $file['name']; |
| 50 |
} |
| 51 |
} |
| 52 |
if (is_array($_SERVER)) { |
| 53 |
foreach ($_SERVER as $key => $value) { |
| 54 |
if (strpos($key, 'HTTP_') === 0) { |
| 55 |
$header = substr($key, 5); |
| 56 |
$header = str_replace(array(' ', '_'), array('', ' '), $header); |
| 57 |
$header = ucwords(strtolower($header)); |
| 58 |
$header = str_replace(' ', '-', $header); |
| 59 |
$this->headers[$header] = $value; |
| 60 |
} |
| 61 |
} |
| 62 |
if (array_key_exists('CONTENT_TYPE', $_SERVER)) { |
| 63 |
$this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE']; |
| 64 |
} |
| 65 |
if (array_key_exists('CONTENT_LENGTH', $_SERVER)) { |
| 66 |
$this->headers['Content-Length'] = $_SERVER['CONTENT_LENGTH']; |
| 67 |
} |
| 68 |
if (array_key_exists('REFERER', $_SERVER)) { |
| 69 |
$this->headers['Referer'] = $_SERVER['REFERER']; |
| 70 |
} |
| 71 |
if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { |
| 72 |
$this->headers['User-Agent'] = $_SERVER['HTTP_USER_AGENT']; |
| 73 |
} |
| 74 |
|
| 75 |
if (array_key_exists('Host', $this->headers)) { |
| 76 |
$this->host = $this->headers['Host']; |
| 77 |
} elseif (array_key_exists('SERVER_NAME', $_SERVER)) { |
| 78 |
$this->host = $_SERVER['SERVER_NAME']; |
| 79 |
} |
| 80 |
|
| 81 |
$this->method = array_key_exists('REQUEST_METHOD', $_SERVER) |
| 82 |
? $_SERVER['REQUEST_METHOD'] : 'GET'; |
| 83 |
$this->uri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : ''; |
| 84 |
$_uri = parse_url($this->uri); |
| 85 |
$this->path = (is_array($_uri) && array_key_exists('path', $_uri)) ? $_uri['path'] : $this->uri; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
public static function blacklistedCategories() { |
| 90 |
return array( |
| 91 |
WPRProtectRequest_V547::CATEGORY_BOT_BLOCKED, |
| 92 |
WPRProtectRequest_V547::CATEGORY_COUNTRY_BLOCKED, |
| 93 |
WPRProtectRequest_V547::CATEGORY_USER_BLACKLISTED, |
| 94 |
WPRProtectRequest_V547::CATEGORY_GLOBAL_BOT_BLOCKED |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
public static function whitelistedCategories() { |
| 99 |
return array(WPRProtectRequest_V547::CATEGORY_WHITELISTED); |
| 100 |
} |
| 101 |
|
| 102 |
public function setRespCode($code) { |
| 103 |
$this->respcode = $code; |
| 104 |
} |
| 105 |
|
| 106 |
public function getRespCode() { |
| 107 |
if (!isset($this->respcode) && function_exists('http_response_code')) { |
| 108 |
$this->respcode = http_response_code(); |
| 109 |
} |
| 110 |
|
| 111 |
return $this->respcode; |
| 112 |
} |
| 113 |
|
| 114 |
public function getStatus() { |
| 115 |
return $this->status; |
| 116 |
} |
| 117 |
|
| 118 |
public function getCategory() { |
| 119 |
return $this->category; |
| 120 |
} |
| 121 |
|
| 122 |
private function getKeyVal($array, $key) { |
| 123 |
if (is_array($array)) { |
| 124 |
if (is_array($key)) { |
| 125 |
$_key = array_shift($key); |
| 126 |
if (array_key_exists($_key, $array)) { |
| 127 |
if (count($key) > 0) { |
| 128 |
return $this->getKeyVal($array[$_key], $key); |
| 129 |
} else { |
| 130 |
return $array[$_key]; |
| 131 |
} |
| 132 |
} |
| 133 |
} else { |
| 134 |
return array_key_exists($key, $array) ? $array[$key] : null; |
| 135 |
} |
| 136 |
} |
| 137 |
return null; |
| 138 |
} |
| 139 |
|
| 140 |
public function getPostParams() { |
| 141 |
if (func_num_args() > 0) { |
| 142 |
$args = func_get_args(); |
| 143 |
return $this->getKeyVal($this->post_params, $args); |
| 144 |
} |
| 145 |
return $this->post_params; |
| 146 |
} |
| 147 |
|
| 148 |
public function getCookies() { |
| 149 |
if (func_num_args() > 0) { |
| 150 |
$args = func_get_args(); |
| 151 |
return $this->getKeyVal($this->cookies, $args); |
| 152 |
} |
| 153 |
return $this->cookies; |
| 154 |
} |
| 155 |
|
| 156 |
public function getGetParams() { |
| 157 |
if (func_num_args() > 0) { |
| 158 |
$args = func_get_args(); |
| 159 |
return $this->getKeyVal($this->get_params, $args); |
| 160 |
} |
| 161 |
return $this->get_params; |
| 162 |
} |
| 163 |
|
| 164 |
public function getAllParams() { |
| 165 |
return array("getParams" => $this->get_params, "postParams" => $this->post_params); |
| 166 |
} |
| 167 |
|
| 168 |
public function getHeader($key) { |
| 169 |
if (array_key_exists($key, $this->headers)) { |
| 170 |
return $this->headers[$key]; |
| 171 |
} |
| 172 |
return null; |
| 173 |
} |
| 174 |
|
| 175 |
public function getHeaders() { |
| 176 |
if (func_num_args() > 0) { |
| 177 |
$args = func_get_args(); |
| 178 |
return $this->getKeyVal($this->headers, $args); |
| 179 |
} |
| 180 |
return $this->headers; |
| 181 |
} |
| 182 |
|
| 183 |
public function getFiles() { |
| 184 |
if (func_num_args() > 0) { |
| 185 |
$args = func_get_args(); |
| 186 |
return $this->getKeyVal($this->files, $args); |
| 187 |
} |
| 188 |
return $this->files; |
| 189 |
} |
| 190 |
|
| 191 |
public function getFileNames() { |
| 192 |
if (func_num_args() > 0) { |
| 193 |
$args = func_get_args(); |
| 194 |
return $this->getKeyVal($this->file_names, $args); |
| 195 |
} |
| 196 |
return $this->file_names; |
| 197 |
} |
| 198 |
|
| 199 |
public function getHost() { |
| 200 |
return $this->host; |
| 201 |
} |
| 202 |
|
| 203 |
public function getURI() { |
| 204 |
return $this->uri; |
| 205 |
} |
| 206 |
|
| 207 |
public function getAction() { |
| 208 |
$post_action = $this->getPostParams('action'); |
| 209 |
if (isset($post_action)) { |
| 210 |
return $post_action; |
| 211 |
} else { |
| 212 |
return $this->getGetParams('action'); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
public function getPath() { |
| 217 |
return $this->path; |
| 218 |
} |
| 219 |
|
| 220 |
public function getIP() { |
| 221 |
return $this->ip; |
| 222 |
} |
| 223 |
|
| 224 |
public function getMethod() { |
| 225 |
return $this->method; |
| 226 |
} |
| 227 |
|
| 228 |
public function getTimestamp() { |
| 229 |
return $this->timestamp; |
| 230 |
} |
| 231 |
|
| 232 |
public function getRequestID() { |
| 233 |
if (!defined("BV_REQUEST_ID")) { |
| 234 |
define("BV_REQUEST_ID", uniqid(mt_rand())); |
| 235 |
} |
| 236 |
|
| 237 |
return BV_REQUEST_ID; |
| 238 |
} |
| 239 |
|
| 240 |
public function getServerValue($key) { |
| 241 |
if (isset($_SERVER) && array_key_exists($key, $_SERVER)) { |
| 242 |
return $_SERVER[$key]; |
| 243 |
} |
| 244 |
return false; |
| 245 |
} |
| 246 |
|
| 247 |
public function getHeadersV2() { |
| 248 |
return $this->headers; |
| 249 |
} |
| 250 |
|
| 251 |
public function getFilesV2() { |
| 252 |
return $this->files; |
| 253 |
} |
| 254 |
|
| 255 |
public function getFileNamesV2() { |
| 256 |
return $this->file_names; |
| 257 |
} |
| 258 |
|
| 259 |
public function getPostParamsV2() { |
| 260 |
return $this->post_params; |
| 261 |
} |
| 262 |
|
| 263 |
public function getGetParamsV2() { |
| 264 |
return $this->get_params; |
| 265 |
} |
| 266 |
|
| 267 |
public function getCookiesV2() { |
| 268 |
return $this->cookies; |
| 269 |
} |
| 270 |
} |
| 271 |
endif; |