PluginProbe
The WP Remote WordPress Plugin / 5.42
The WP Remote WordPress Plugin v5.42
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 / rule / functions / string.php

string.php in The WP Remote WordPress Plugin 5.42, at protect/fw/rule/functions/string.php

334 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit;
3
4 if (!trait_exists('WPRProtectFWRuleStringFunc_V542')) :
5 trait WPRProtectFWRuleStringFunc_V542 {
6 private function _rf_isNumeric() {
7 $args = $this->processRuleFunctionParams(
8 'isNumeric',
9 func_num_args(),
10 func_get_args(),
11 1
12 );
13 $value = $args[0];
14
15 return (WPRHelper::safePregMatch('/^\d+$/', $value));
16 }
17
18 private function _rf_isRegularWord() {
19 $args = $this->processRuleFunctionParams(
20 'isRegularWord',
21 func_num_args(),
22 func_get_args(),
23 1
24 );
25 $value = $args[0];
26
27 return (WPRHelper::safePregMatch('/^\w+$/', $value));
28 }
29
30 private function _rf_isSpecialWord() {
31 $args = $this->processRuleFunctionParams(
32 'isSpecialWord',
33 func_num_args(),
34 func_get_args(),
35 1
36 );
37 $value = $args[0];
38
39 return (WPRHelper::safePregMatch('/^\S+$/', $value));
40 }
41
42 private function _rf_isRegularSentence() {
43 $args = $this->processRuleFunctionParams(
44 'isRegularSentence',
45 func_num_args(),
46 func_get_args(),
47 1
48 );
49 $value = $args[0];
50
51 return (WPRHelper::safePregMatch('/^[\w\s]+$/', $value));
52 }
53
54 private function _rf_isSpecialCharsSentence() {
55 $args = $this->processRuleFunctionParams(
56 'isSpecialCharsSentence',
57 func_num_args(),
58 func_get_args(),
59 1
60 );
61 $value = $args[0];
62
63 return (WPRHelper::safePregMatch('/^[\w\W]+$/', $value));
64 }
65
66 private function _rf_isLink() {
67 $args = $this->processRuleFunctionParams(
68 'isLink',
69 func_num_args(),
70 func_get_args(),
71 1
72 );
73 $value = $args[0];
74
75 return (WPRHelper::safePregMatch('/^(http|ftp)s?:\/\/\S+$/i', $value));
76 }
77
78 private function _rf_isIpv4() {
79 $args = $this->processRuleFunctionParams(
80 'isIpv4',
81 func_num_args(),
82 func_get_args(),
83 1
84 );
85 $value = $args[0];
86
87 return (WPRHelper::safePregMatch('/^\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b$/x', $value));
88 }
89
90 private function _rf_isEmbededIpv4() {
91 $args = $this->processRuleFunctionParams(
92 'isEmbededIpv4',
93 func_num_args(),
94 func_get_args(),
95 1
96 );
97 $value = $args[0];
98
99 return (WPRHelper::safePregMatch('/\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/x', $value));
100 }
101
102 private function _rf_isIpv6() {
103 $args = $this->processRuleFunctionParams(
104 'isIpv6',
105 func_num_args(),
106 func_get_args(),
107 1
108 );
109 $value = $args[0];
110
111 return (WPRHelper::safePregMatch('/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/x', $value));
112 }
113
114 private function _rf_isEmbededIpv6() {
115 $args = $this->processRuleFunctionParams(
116 'isEmbededIpv6',
117 func_num_args(),
118 func_get_args(),
119 1
120 );
121 $value = $args[0];
122
123 return (WPRHelper::safePregMatch('/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/x', $value));
124 }
125
126 private function _rf_isEmail() {
127 $args = $this->processRuleFunctionParams(
128 'isEmail',
129 func_num_args(),
130 func_get_args(),
131 1
132 );
133 $value = $args[0];
134
135 return (WPRHelper::safePregMatch('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/', $value));
136 }
137
138 private function _rf_isEmbededEmail($value) {
139 $args = $this->processRuleFunctionParams(
140 'isEmbededEmail',
141 func_num_args(),
142 func_get_args(),
143 1
144 );
145 $value = $args[0];
146
147 return (WPRHelper::safePregMatch('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/', $value));
148 }
149
150 private function _rf_isEmbededLink() {
151 $args = $this->processRuleFunctionParams(
152 'isEmbededLink',
153 func_num_args(),
154 func_get_args(),
155 1
156 );
157 $value = $args[0];
158
159 return (WPRHelper::safePregMatch('/(http|ftp)s?:\/\/\S+$/i', $value));
160 }
161
162 private function _rf_isEmbededHtml() {
163 $args = $this->processRuleFunctionParams(
164 'isEmbededHtml',
165 func_num_args(),
166 func_get_args(),
167 1
168 );
169 $value = $args[0];
170
171 return (WPRHelper::safePregMatch('/<(html|head|title|base|link|meta|style|picture|source|img|iframe|embed|object|param|video|audio|track|map|area|form|label|input|button|select|datalist|optgroup|option|textarea|output|progress|meter|fieldset|legend|script|noscript|template|slot|canvas)/ix', $value));
172 }
173
174 private function _rf_isFile() {
175 $args = $this->processRuleFunctionParams(
176 'isFile',
177 func_num_args(),
178 func_get_args(),
179 1
180 );
181 $value = $args[0];
182
183 return (WPRHelper::safePregMatch('/\.(jpg|jpeg|png|gif|ico|pdf|doc|docx|ppt|pptx|pps|ppsx|odt|xls|zip|gzip|xlsx|psd|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2|php|html|phtml|js|css)/ix', $value));
184 }
185
186 private function _rf_isPathTraversal() {
187 $args = $this->processRuleFunctionParams(
188 'isPathTraversal',
189 func_num_args(),
190 func_get_args(),
191 1
192 );
193 $value = $args[0];
194
195 return (WPRHelper::safePregMatch('/(?:\.{2}[\/]+)/', $value));
196 }
197
198 private function _rf_isPhpEval() {
199 $args = $this->processRuleFunctionParams(
200 'isPhpEval',
201 func_num_args(),
202 func_get_args(),
203 1
204 );
205 $value = $args[0];
206
207 return (WPRHelper::safePregMatch('/\\b(?i:eval)\\s*\\(\\s*(?i:base64_decode|exec|file_get_contents|gzinflate|passthru|shell_exec|stripslashes|system)\\s*\\(/', $value));
208 }
209
210 private function _rf_isSubstring() {
211 $args = $this->processRuleFunctionParams(
212 'isSubstring',
213 func_num_args(),
214 func_get_args(),
215 2
216 );
217 $string = $args[0];
218 $substring = $args[1];
219
220 return strpos((string) $string, (string) $substring) !== false;
221 }
222
223 private function _rf_containsAnySubstring() {
224 $args = $this->processRuleFunctionParams(
225 'containsAnySubstring',
226 func_num_args(),
227 func_get_args(),
228 2
229 );
230 $string = $args[0];
231 $array_of_substrings = $args[1];
232
233 if (is_array($array_of_substrings)) {
234 foreach ($array_of_substrings as $i => $substring) {
235 if ($this->_rf_isSubstring($string, $substring)) {
236 return true;
237 }
238 }
239 } else {
240 throw new WPRProtectRuleError_V542(
241 $this->addExState("containsAnySubstring: Expects an array of substrings.")
242 );
243 }
244
245 return false;
246 }
247
248 private function _rf_concatString() {
249 $args = $this->processRuleFunctionParams(
250 'concatString',
251 func_num_args(),
252 func_get_args(),
253 2,
254 ['string', 'string']
255 );
256 $source_str = $args[0];
257 $str = $args[1];
258
259 return $source_str . $str;
260 }
261
262 private function _rf_strPos() {
263 $args = $this->processRuleFunctionParams(
264 'strPos',
265 func_num_args(),
266 func_get_args(),
267 2,
268 ['string', 'string']
269 );
270 $haystack = $args[0];
271 $needle = $args[1];
272 $offset = isset($args[2]) ? $args[2] : 0;
273
274 if (!is_int($offset)) {
275 throw new WPRProtectRuleError_V542(
276 $this->addExState("strPos: Offset should be an integer")
277 );
278 }
279
280 return strpos($haystack, $needle, $offset);
281 }
282
283 private function _rf_checkStringsForSubstringsPos() {
284 $args = $this->processRuleFunctionParams(
285 'checkStringsForSubstringsPos',
286 func_num_args(),
287 func_get_args(),
288 3,
289 ['array', 'array', 'integer']
290 );
291 $strings = $args[0];
292 $sub_strings = $args[1];
293 $pos = $args[2];
294
295 foreach ($strings as $string) {
296 foreach ($sub_strings as $sub_string) {
297 $position = $this->_rf_strPos($string, $sub_string);
298 if ($position === $pos) {
299 return true;
300 }
301 }
302 }
303
304 return false;
305 }
306
307 private function _rf_splitString() {
308 $args = $this->processRuleFunctionParams(
309 'splitString',
310 func_num_args(),
311 func_get_args(),
312 2,
313 ['string', 'string']
314 );
315 $separator = $args[0];
316 $str = $args[1];
317 $limit = isset($args[2]) ? $args[2] : PHP_INT_MAX;
318
319 if (empty($separator)) {
320 throw new WPRProtectRuleError_V542(
321 $this->addExState("splitString: Separator cannot be empty")
322 );
323 }
324
325 if (!is_int($limit)) {
326 throw new WPRProtectRuleError_V542(
327 $this->addExState("splitString: Limit should be an integer")
328 );
329 }
330
331 return explode($separator, $str, $limit);
332 }
333 }
334 endif;