PluginProbe
The WP Remote WordPress Plugin / 4.76
The WP Remote WordPress Plugin v4.76
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / protect / fw / request.php

request.php in The WP Remote WordPress Plugin 4.76, at protect/fw/request.php

357 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (! (defined('ABSPATH') || defined('MCDATAPATH')) ) exit;
4 if (!class_exists('BVWPRequest')) :
5
6 class BVWPRequest {
7 private $fileNames;
8 private $files;
9 private $headers;
10 private $host;
11 private $ip;
12 private $method;
13 private $path;
14 private $getParams;
15 private $timestamp;
16 private $uri;
17 private $postParams;
18 private $cookies;
19 private $respcode;
20 private $status;
21 private $rulesInfo;
22 private $reqInfo;
23 private $matchedRules;
24
25 #status
26 const ALLOWED = 1;
27 const BLOCKED = 2;
28 const BYPASSED = 3;
29
30 #category
31 const BLACKLISTED = 1;
32 const NORMAL = 10;
33 const WHITELISTED = 20;
34 const BOT_BLOCKED = 30;
35 const COUNTRY_BLOCKED = 40;
36 const USER_BLACKLISTED = 50;
37 const RULE_BLOCKED = 60;
38 const RULE_ALLOWED = 70;
39
40 public function __construct($ip) {
41 $fileNames = array();
42 $headers = array();
43 $host = '';
44 $method = '';
45 $path = '';
46 $this->ip = $ip;
47 $this->rulesInfo = array();
48 $this->matchedRules = array();
49 $this->reqInfo = array();
50 $this->setRespCode(0);
51 $this->setCategory(BVWPRequest::NORMAL);
52 $this->setStatus(BVWpRequest::ALLOWED);
53 $this->setTimestamp(time());
54 $this->setGetParams($_GET);
55 $this->setCookies($_COOKIE);
56 $this->setPostParams($_POST);
57 $this->setFiles($_FILES);
58 if (!empty($_FILES)) {
59 foreach ($_FILES as $input => $file) {
60 $fileNames[$input] = $file['name'];
61 }
62 }
63 $this->setFileNames($fileNames);
64 if (is_array($_SERVER)) {
65 foreach ($_SERVER as $key => $value) {
66 if (strpos($key, 'HTTP_') === 0) {
67 $header = substr($key, 5);
68 $header = str_replace(array(' ', '_'), array('', ' '), $header);
69 $header = ucwords(strtolower($header));
70 $header = str_replace(' ', '-', $header);
71 $headers[$header] = $value;
72 }
73 }
74 if (array_key_exists('CONTENT_TYPE', $_SERVER)) {
75 $headers['Content-Type'] = $_SERVER['CONTENT_TYPE'];
76 }
77 if (array_key_exists('CONTENT_LENGTH', $_SERVER)) {
78 $headers['Content-Length'] = $_SERVER['CONTENT_LENGTH'];
79 }
80 if (array_key_exists('REFERER', $_SERVER)) {
81 $headers['Referer'] = $_SERVER['REFERER'];
82 }
83 if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
84 $headers['User-Agent'] = $_SERVER['HTTP_USER_AGENT'];
85 }
86
87 if (array_key_exists('Host', $headers)) {
88 $host = $headers['Host'];
89 } else if (array_key_exists('SERVER_NAME', $_SERVER)) {
90 $host = $_SERVER['SERVER_NAME'];
91 }
92
93 $method = array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET';
94 $uri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : '';
95 $_uri = parse_url($uri);
96 $path = (is_array($_uri) && array_key_exists('path', $_uri)) ? $_uri['path'] : $uri;
97 }
98 $this->setHeaders($headers);
99 $this->setHost($host);
100 $this->setMethod($method);
101 $this->setUri($uri);
102 $this->setPath($path);
103 }
104
105 public function setStatus($status) {
106 $this->status = $status;
107 }
108
109 public function setCategory($category) {
110 $this->category = $category;
111 }
112
113 public function setPostParams($postParams) {
114 $this->postParams = $postParams;
115 }
116
117 public function setCookies($cookies) {
118 $this->cookies = $cookies;
119 }
120
121 public function setFileNames($fileNames) {
122 $this->fileNames = $fileNames;
123 }
124
125 public function setFiles($files) {
126 $this->files = $files;
127 }
128
129 public function setHeaders($headers) {
130 $this->headers = $headers;
131 }
132
133 public function setRespCode($code) {
134 $this->respcode = $code;
135 }
136
137 public function getRespCode() {
138 return $this->respcode;
139 }
140
141 public function setHost($host) {
142 $this->host = $host;
143 }
144
145 public function setMethod($method) {
146 $this->method = $method;
147 }
148
149 public function setPath($path) {
150 $this->path = $path;
151 }
152
153 public function setGetParams($getParams) {
154 $this->getParams = $getParams;
155 }
156
157 public function setTimestamp($timestamp) {
158 $this->timestamp = $timestamp;
159 }
160
161 public function setUri($uri) {
162 $this->uri = $uri;
163 }
164
165 public function updateMatchedRules($matched_rule_id) {
166 $this->matchedRules[] = $matched_rule_id;
167 }
168
169 public function updateRulesInfo($category, $sub_category, $value) {
170 $rule_info = (array_key_exists($category, $this->rulesInfo)) ? $this->rulesInfo[$category] : array();
171 $rule_info[$sub_category] = $value;
172 $this->rulesInfo[$category] = $rule_info;
173 }
174
175 public function getRulesInfo() {
176 return $this->rulesInfo;
177 }
178
179 public function getMatchedRules() {
180 return $this->matchedRules;
181 }
182
183 public function updateReqInfo($info) {
184 if (is_array($info)) {
185 $this->reqInfo = $this->reqInfo + $info;
186 }
187 }
188
189 public function getReqInfo() {
190 return $this->reqInfo;
191 }
192
193 public function getStatus() {
194 return $this->status;
195 }
196
197 public function getCategory() {
198 return $this->category;
199 }
200
201 public function getDataToLog() {
202 $referer = $this->getHeader('Referer') ? $this->getHeader('Referer') : '';
203 $user_agent = $this->getHeader('User-Agent') ? $this->getHeader('User-Agent') : '';
204 $rules_info = serialize($this->getRulesInfo());
205 $req_info = serialize($this->getReqInfo());
206 if (strlen($req_info) > 16000) {
207 $req_info = serialize(array("keys" => array_keys($this->getReqInfo())));
208 if (strlen($req_info) > 16000) {
209 $req_info = serialize(array("bv_over_size" => true));
210 }
211 }
212 $data = array(
213 "path" => $this->getPath(),
214 "filenames" => serialize($this->getFileNames()),
215 "host" => $this->getHost(),
216 "time" => $this->getTimeStamp(),
217 "ip" => $this->getIP(),
218 "method" => $this->getMethod(),
219 "query_string" => $req_info,
220 "user_agent" => $user_agent,
221 "resp_code" => $this->getRespCode(),
222 "referer" => $referer,
223 "status" => $this->getStatus(),
224 "category" => $this->getCategory(),
225 "rules_info" => $rules_info,
226 "request_id" => $this->getRequestID(),
227 "matched_rules"=> serialize($this->getMatchedRules())
228 );
229 return $data;
230 }
231
232 protected function getKeyVal($array, $key) {
233 if (is_array($array)) {
234 if (is_array($key)) {
235 $_key = array_shift($key);
236 if (array_key_exists($_key, $array)) {
237 if (count($key) > 0) {
238 return $this->getKeyVal($array[$_key], $key);
239 } else {
240 return $array[$_key];
241 }
242 }
243 } else {
244 return array_key_exists($key, $array) ? $array[$key] : null;
245 }
246 }
247 return null;
248 }
249
250 public function getPostParams() {
251 if (func_num_args() > 0) {
252 $args = func_get_args();
253 return $this->getKeyVal($this->postParams, $args);
254 }
255 return $this->postParams;
256 }
257
258 public function getCookies() {
259 if (func_num_args() > 0) {
260 $args = func_get_args();
261 return $this->getKeyVal($this->cookies, $args);
262 }
263 return $this->cookies;
264 }
265
266 public function getGetParams() {
267 if (func_num_args() > 0) {
268 $args = func_get_args();
269 return $this->getKeyVal($this->getParams, $args);
270 }
271 return $this->getParams;
272 }
273
274 public function getAllParams() {
275 return array("getParams" => $this->getParams, "postParams" => $this->postParams);
276 }
277
278 public function getHeader($key) {
279 if (array_key_exists($key, $this->headers)) {
280 return $this->headers[$key];
281 }
282 return null;
283 }
284
285 public function getHeaders() {
286 if (func_num_args() > 0) {
287 $args = func_get_args();
288 return $this->getKeyVal($this->headers, $args);
289 }
290 return $this->headers;
291 }
292
293 public function getFiles() {
294 if (func_num_args() > 0) {
295 $args = func_get_args();
296 return $this->getKeyVal($this->files, $args);
297 }
298 return $this->files;
299 }
300
301 public function getFileNames() {
302 if (func_num_args() > 0) {
303 $args = func_get_args();
304 return $this->getKeyVal($this->fileNames, $args);
305 }
306 return $this->fileNames;
307 }
308
309 public function getHost() {
310 return $this->host;
311 }
312
313 public function getURI() {
314 return $this->uri;
315 }
316
317 public function getPath() {
318 return $this->path;
319 }
320
321 public function getIP() {
322 return $this->ip;
323 }
324
325 public function getMethod() {
326 return $this->method;
327 }
328
329 public function getTimestamp() {
330 return $this->timestamp;
331 }
332
333 public function getRequestID() {
334 if (!defined("BV_REQUEST_ID")) {
335 define("BV_REQUEST_ID", uniqid(mt_rand()));
336 }
337 return BV_REQUEST_ID;
338 }
339
340 public function getServerValue($key) {
341 if (isset($_SERVER) && array_key_exists($key, $_SERVER)) {
342 return $_SERVER[$key];
343 }
344 return false;
345 }
346
347 public function getUserRoleLevel() {
348 // TODO
349 // Handle prepend level using custom cookies.
350 return 0;
351 }
352
353 public function isUserRoleLevel($level) {
354 return ($level === $this->getUserRoleLevel());
355 }
356 }
357 endif;