PluginProbe
The WP Remote WordPress Plugin / 4.86
The WP Remote WordPress Plugin v4.86
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 | callback/wings/fs.php +11 -155 6.694.86 View file →
@@ -1,15 +1,16 @@
1 1 <?php
2 +
2 3 if (!defined('ABSPATH')) exit;
3 -if (!class_exists('WPRFSCallback')) :
4 +if (!class_exists('BVFSCallback')) :
4 5 require_once dirname( __FILE__ ) . '/../streams.php';
5 6
6 -class WPRFSCallback extends WPRCallbackBase {
7 +class BVFSCallback extends BVCallbackBase {
7 8 public $stream;
8 9 public $account;
9 10
10 11 public static $cwAllowedFiles = array(".htaccess", ".user.ini", "malcare-waf.php");
11 - const FS_WING_VERSION = 1.4;
12 + const FS_WING_VERSION = 1.2;
12 13
13 14 public function __construct($callback_handler) {
14 15 $this->account = $callback_handler->account;
15 16 }
@@ -17,15 +18,8 @@
17 18 function fileStat($relfile, $md5 = false) {
18 19 $absfile = ABSPATH.$relfile;
19 20 $fdata = array();
20 21 $fdata["filename"] = $relfile;
21 -
22 - if (@is_readable($absfile) === false) {
23 - $fdata["failed"] = true;
24 - $fdata["error"] = "NOT_READABLE";
25 - return $fdata;
26 - }
27 -
28 22 $stats = @stat($absfile);
29 23 if ($stats) {
30 24 foreach (preg_grep('#size|uid|gid|mode|mtime#i', array_keys($stats)) as $key ) {
31 25 $fdata[$key] = $stats[$key];
@@ -139,105 +133,8 @@
139 133
140 134 return $links;
141 135 }
142 136
143 - function getDirectoryPath($dir, $traversal_stack) {
144 - $base_path = rtrim($dir, '/');
145 - $sub_path = empty($traversal_stack) ? '' : '/' . implode('/', array_column($traversal_stack, 0));
146 - return $base_path . $sub_path . '/';
147 - }
148 -
149 - function seekDirectoryHandle($directory_handle, $offset) {
150 - while ($offset > 0 && ($file = @readdir($directory_handle)) !== false) {
151 - if ($file === "." || $file === "..") continue;
152 - $offset--;
153 - }
154 - }
155 -
156 - function scanFilesDfs($dir = "/", $traversal_stack = array(), $folder_offset = 0, $limit = 0, $traversal_stack_max_size = 100,
157 - $batch_size = 512, $is_recursive = true, $include_md5 = false) {
158 - $links = [];
159 - $batch_count = 0;
160 - $batch_files = [];
161 - $count = 0;
162 - $traversal_stack_max_size_reached_count = 0;
163 -
164 - $base_path = $this->getDirectoryPath($dir, $traversal_stack);
165 - $directory_handle = @opendir(ABSPATH . $base_path);
166 -
167 - $this->seekDirectoryHandle($directory_handle, $folder_offset);
168 -
169 - while ($limit == 0 || ($limit > 0 && $count < $limit)) {
170 - if (($file = @readdir($directory_handle)) !== false) {
171 - if ($file === "." || $file === "..") continue;
172 -
173 - $relative_path = $base_path . $file;
174 - $absolute_path = ABSPATH . $relative_path;
175 -
176 - $count++;
177 - $folder_offset++;
178 -
179 - $batch_files[] = $this->fileStat($relative_path, $include_md5);
180 - $batch_count++;
181 -
182 - if ($batch_count >= $batch_size) {
183 - $this->stream->writeStream(serialize($batch_files));
184 - $batch_count = 0;
185 - $batch_files = [];
186 - }
187 -
188 - if (is_link($absolute_path)) {
189 - $links[] = $relative_path;
190 - } elseif ($is_recursive && is_dir($absolute_path)) {
191 - if (count($traversal_stack) >= $traversal_stack_max_size) {
192 - $traversal_stack_max_size_reached_count += 1;
193 - continue;
194 - }
195 -
196 - closedir($directory_handle);
197 -
198 - array_push($traversal_stack, [$file, $folder_offset]);
199 - $base_path = $this->getDirectoryPath($dir, $traversal_stack);
200 -
201 - $directory_handle = @opendir(ABSPATH . $base_path);
202 - $folder_offset = 0;
203 - }
204 -
205 - continue;
206 - }
207 -
208 - if ($directory_handle !== false) {
209 - closedir($directory_handle);
210 - }
211 -
212 - if (empty($traversal_stack)) {
213 - break;
214 - }
215 - $current_info = array_pop($traversal_stack);
216 -
217 - $base_path = $this->getDirectoryPath($dir, $traversal_stack);
218 - $directory_handle = @opendir(ABSPATH . $base_path);
219 -
220 - if ($directory_handle === false) {
221 - continue;
222 - }
223 -
224 - $this->seekDirectoryHandle($directory_handle, $current_info[1]);
225 - $folder_offset = $current_info[1];
226 - }
227 -
228 - if ($batch_count > 0) {
229 - $this->stream->writeStream(serialize($batch_files));
230 - }
231 -
232 - return [
233 - 'links' => $links,
234 - 'traversal_stack' => $traversal_stack,
235 - 'folder_offset' => $folder_offset,
236 - 'traversal_stack_max_size_reached_count' => $traversal_stack_max_size_reached_count
237 - ];
238 - }
239 -
240 137 function calculateMd5($absfile, $fdata, $offset, $limit, $bsize) {
241 138 if ($offset == 0 && $limit == 0) {
242 139 $md5 = md5_file($absfile);
243 140 } else {
@@ -244,9 +141,8 @@
244 141 if ($limit == 0)
245 142 $limit = $fdata["size"];
246 143 if ($offset + $limit < $fdata["size"])
247 144 $limit = $fdata["size"] - $offset;
248 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
249 145 $handle = fopen($absfile, "rb");
250 146 $ctx = hash_init('md5');
251 147 fseek($handle, $offset, SEEK_SET);
252 148 $dlen = 1;
@@ -252,15 +148,13 @@
252 148 $dlen = 1;
253 149 while (($limit > 0) && ($dlen > 0)) {
254 150 if ($bsize > $limit)
255 151 $bsize = $limit;
256 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread -- Required for handling partial file reads with offset and limit
257 152 $d = fread($handle, $bsize);
258 153 $dlen = strlen($d);
259 154 hash_update($ctx, $d);
260 155 $limit -= $dlen;
261 156 }
262 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
263 157 fclose($handle);
264 158 $md5 = hash_final($ctx);
265 159 }
266 160 return $md5;
@@ -267,22 +161,20 @@
267 161 }
268 162
269 163 function getFilesContent($files, $withContent = true) {
270 164 $result = array();
271 -
272 165 foreach ($files as $file) {
273 166 $fdata = $this->fileStat($file);
274 - $absfile = ABSPATH . $file;
167 + $absfile = ABSPATH.$file;
275 168
276 - if ((WPRWPFileSystem::getInstance()->isDir($absfile) === true) && !is_link($absfile)) {
169 + if (is_dir($absfile) && !is_link($absfile)) {
277 170 $fdata['is_dir'] = true;
278 171 } else {
279 - if (isset($fdata["error"]) && $fdata["error"] === "NOT_READABLE") {
172 + if (!is_readable($absfile)) {
280 173 $fdata['error'] = 'file not readable';
281 174 } else {
282 175 if ($withContent === true) {
283 - $content = WPRWPFileSystem::getInstance()->getContents($absfile);
284 - if ($content !== false) {
176 + if ($content = file_get_contents($absfile)) {
285 177 $fdata['content'] = $content;
286 178 } else {
287 179 $fdata['error'] = 'unable to read file';
288 180 }
@@ -289,12 +181,8 @@
289 181 }
290 182 }
291 183 }
292 184
293 - $fs_error = WPRWPFileSystem::getInstance()->checkForErrors();
294 - if (isset($fs_error)) {
295 - $fdata['fs_error'] = $fs_error;
296 - }
297 185 $result[$file] = $fdata;
298 186 }
299 187
300 188 return $result;
@@ -304,9 +192,9 @@
304 192 $result = array();
305 193 foreach ($files as $file) {
306 194 $fdata = $this->fileStat($file);
307 195 $absfile = ABSPATH.$file;
308 - if (isset($fdata["error"]) && $fdata["error"] === "NOT_READABLE") {
196 + if (!is_readable($absfile)) {
309 197 $result["missingfiles"][] = $file;
310 198 continue;
311 199 }
312 200 if ($md5 === true && !is_dir($absfile)) {
@@ -319,13 +207,12 @@
319 207
320 208 function uploadFiles($files, $offset = 0, $limit = 0, $bsize = 102400) {
321 209 $result = array();
322 210 foreach ($files as $file) {
323 - if (WPRWPFileSystem::getInstance()->isReadable(ABSPATH.$file) === false) {
211 + if (!is_readable(ABSPATH.$file)) {
324 212 $result["missingfiles"][] = $file;
325 213 continue;
326 214 }
327 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Required for binary-safe chunked reading
328 215 $handle = fopen(ABSPATH.$file, "rb");
329 216 if (($handle != null) && is_resource($handle)) {
330 217 $fdata = $this->fileStat($file);
331 218 $_limit = $limit;
@@ -341,15 +228,13 @@
341 228 $dlen = 1;
342 229 while (($_limit > 0) && ($dlen > 0)) {
343 230 if ($_bsize > $_limit)
344 231 $_bsize = $_limit;
345 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread -- Required for binary-safe chunked reading
346 232 $d = fread($handle, $_bsize);
347 233 $dlen = strlen($d);
348 234 $this->stream->writeStream($d);
349 235 $_limit -= $dlen;
350 236 }
351 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Required for cleanup
352 237 fclose($handle);
353 238 } else {
354 239 $result["unreadablefiles"][] = $file;
355 240 }
@@ -359,9 +244,9 @@
359 244 }
360 245
361 246 function process($request) {
362 247 $params = $request->params;
363 - $stream_init_info = WPRStream::startStream($this->account, $request);
248 + $stream_init_info = BVStream::startStream($this->account, $request);
364 249
365 250 if (array_key_exists('stream', $stream_init_info)) {
366 251 $this->stream = $stream_init_info['stream'];
367 252 switch ($request->method) {
@@ -400,37 +285,8 @@
400 285 $_links = $this->scanFiles($dir, $offset, $limit, $bsize, $recurse, $md5);
401 286 $links = array_merge($links, $_links);
402 287 }
403 288 $resp = array("status" => "done", "links" => $links);
404 - break;
405 - case "scanfilesdfs":
406 - $resp = array();
407 - $dir_options = array();
408 - if (array_key_exists('dir_options', $params)) {
409 - $dir_options = $params['dir_options'];
410 - }
411 - $bsize = intval($params['bsize']);
412 - $traversal_stack_max_size = intval($params['traversal_stack_max_size']);
413 - foreach($dir_options as $option) {
414 - $dir = $option['dir'];
415 - $traversal_stack = $option['traversal_stack'];
416 - $folder_offset = intval($option['folder_offset']);
417 - $limit = intval($option['limit']);
418 -
419 - $recurse = true;
420 - if (array_key_exists('recurse', $option) && $option["recurse"] == "false") {
421 - $recurse = false;
422 - }
423 -
424 - $md5 = true;
425 - if (array_key_exists('md5', $option) && $option["md5"] == "false") {
426 - $md5 = false;
427 - }
428 -
429 - $resp[$dir] = $this->scanFilesDfs($dir, $traversal_stack, $folder_offset, $limit,
430 - $traversal_stack_max_size, $bsize, $recurse, $md5);
431 - }
432 - $resp["status"] = "done";
433 289 break;
434 290 case "getfilesstats":
435 291 $files = $params['files'];
436 292 $offset = intval($params['offset']);