PluginProbe
The WP Remote WordPress Plugin / trunk
The WP Remote WordPress Plugin vtrunk
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
← All changes | protect/lib/utils.php +24 -25 5.38trunk View file →
@@ -1,18 +1,17 @@
1 1 <?php
2 2 if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit;
3 3
4 -if (!class_exists('MCProtectUtils')) :
5 -class MCProtectUtils {
4 +if (!class_exists('WPRProtectUtils_V672')) :
5 +class WPRProtectUtils_V672 {
6 6 public static function getIP($ip_header) {
7 7 $ip = null;
8 -
9 8 if (is_array($ip_header)) {
10 9 if ((array_key_exists('hdr', $ip_header) && is_string($ip_header['hdr'])) &&
11 10 (array_key_exists('pos', $ip_header) && is_int($ip_header['pos']))) {
12 11
13 12 if (array_key_exists($ip_header['hdr'], $_SERVER) && is_string($_SERVER[$ip_header['hdr']])) {
14 - $_ips = preg_split("/(,| |\t)/", $_SERVER[$ip_header['hdr']]);
13 + $_ips = preg_split("/(,| |\t)/", WPRHelper::getRawParam('SERVER', $ip_header['hdr']));
15 14
16 15 if (array_key_exists($ip_header['pos'], $_ips)) {
17 16 $ip = $_ips[$ip_header['pos']];
18 17 }
@@ -18,9 +17,9 @@
18 17 }
19 18 }
20 19 }
21 20 } elseif (array_key_exists('REMOTE_ADDR', $_SERVER)) {
22 - $ip = $_SERVER['REMOTE_ADDR'];
21 + $ip = WPRHelper::getRawParam('SERVER', 'REMOTE_ADDR');
23 22 }
24 23
25 24 if (is_string($ip)) {
26 25 $ip = trim($ip);
@@ -120,20 +119,10 @@
120 119 return $result;
121 120 }
122 121
123 122 public static function rrmdir($dir) {
124 - if (is_dir($dir)) {
125 - $objects = scandir($dir);
126 - foreach ($objects as $object) {
127 - if ($object != "." && $object != "..") {
128 - if (is_dir($dir . "/" . $object) && !is_link($dir . "/" . $object)) {
129 - MCProtectUtils::rrmdir($dir . "/" . $object);
130 - } else {
131 - unlink($dir . "/" . $object);
132 - }
133 - }
134 - }
135 - rmdir($dir);
123 + if (WPRWPFileSystem::getInstance()->isDir($dir) === true) {
124 + WPRWPFileSystem::getInstance()->rmdir($dir, true);
136 125 }
137 126 }
138 127
139 128 public static function getLength($val) {
@@ -140,9 +129,9 @@
140 129 $length = 0;
141 130
142 131 if (is_array($val)) {
143 132 foreach ($val as $e) {
144 - $length += MCProtectUtils::getLength($e);
133 + $length += WPRProtectUtils_V672::getLength($e);
145 134 }
146 135
147 136 return $length;
148 137 } else {
@@ -153,9 +142,9 @@
153 142 public static function parseFile($fname) {
154 143 $result = array();
155 144
156 145 if (file_exists($fname)) {
157 - $content = file_get_contents($fname);
146 + $content = file_get_contents($fname); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
158 147 if (($content !== false) && is_string($content)) {
159 148 $result = json_decode($content, true);
160 149
161 150 if (!is_array($result)) {
@@ -167,12 +156,14 @@
167 156 return $result;
168 157 }
169 158
170 159 public static function fileRemovePattern($fname, $pattern, $regex_pattern = false) {
171 - if (!file_exists($fname)) return;
160 + if (WPRWPFileSystem::getInstance()->exists($fname) === false) {
161 + return;
162 + }
172 163
173 - $content = file_get_contents($fname);
174 - if ($content) {
164 + $content = WPRWPFileSystem::getInstance()->getContents($fname);
165 + if ($content !== false) {
175 166 if ($regex_pattern) {
176 167 $modified_content = preg_replace($pattern, "", $content);
177 168 } else {
178 169 $modified_content = str_replace($pattern, "", $content);
@@ -178,9 +169,10 @@
178 169 $modified_content = str_replace($pattern, "", $content);
179 170 }
180 171
181 172 if ($content !== $modified_content) {
182 - file_put_contents($fname, $modified_content);
173 + WPRWPFileSystem::getInstance()->putContents($fname, $modified_content,
174 + WPRWPFileSystem::getInstance()->getchmodOctal($fname));
183 175 }
184 176 }
185 177 }
186 178
@@ -226,9 +218,9 @@
226 218 );
227 219 }
228 220
229 221 public static function signMessage($message, $key, $algorithm = 'sha256') {
230 - if (!is_string($message) && !is_string($key)) {
222 + if (!is_string($message) || !is_string($key)) {
231 223 return false;
232 224 }
233 225
234 226 return hash_hmac($algorithm, $message, $key);
@@ -234,9 +226,9 @@
234 226 return hash_hmac($algorithm, $message, $key);
235 227 }
236 228
237 229 public static function verifyMessage($message, $signature, $key, $algorithm = 'sha256') {
238 - if (!is_string($message) && !is_string($signature) && !is_string($key)) {
230 + if (!is_string($message) || !is_string($signature) || !is_string($key)) {
239 231 return false;
240 232 }
241 233
242 234 $calc_signature = self::signMessage($message, $key, $algorithm);
@@ -241,7 +233,14 @@
241 233
242 234 $calc_signature = self::signMessage($message, $key, $algorithm);
243 235
244 236 return hash_equals($calc_signature, $signature);
237 + }
238 +
239 + public static function safeDecodeJSON($str, $associative = true, $depth = 512) {
240 + $decoded_data = @json_decode($str, $associative, $depth);
241 + if (isset($decoded_data)) {
242 + return $decoded_data;
243 + }
245 244 }
246 245 }
247 246 endif;