PluginProbe
WPIDE – File Manager & Code Editor / 3.5.10
WPIDE – File Manager & Code Editor v3.5.10
3.5.10 3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 All 56 releases
← All changes | App/Controllers/FileManager/DownloadController.php +39 -1 3.5.7 → 3.5.10 View file →
@@ -81,11 +81,34 @@
81 81 } catch (\Exception $e) {
82 82 return $response->redirect('/');
83 83 }
84 84
85 - $this->downloadFile($file, $request, $response, $streamedResponse);
85 + return $this->downloadFile($file, $request, $response, $streamedResponse);
86 86 }
87 87
88 + public function readContent(Request $request, Response $response)
89 + {
90 + $encodedPath = $request->input('path');
91 + $path = is_string($encodedPath) ? base64_decode($encodedPath, true) : false;
92 +
93 + if ($path === false || !$this->storage->fileExists($path)) {
94 + return $response->json(__('Requested file does not exist', 'wpide'), 404);
95 + }
96 +
97 + try {
98 + $file = $this->storage->read($path);
99 + } catch (\Exception $error) {
100 + return $response->json(__('Cannot read file, please check file permissions!', 'wpide'), 422);
101 + }
102 +
103 + $content = $file['contents'];
104 + if (!is_string($content) || strlen($content) !== (int) $file['filesize'] || preg_match('//u', $content) !== 1) {
105 + return $response->json(__('Cannot read file, please check file permissions!', 'wpide'), 422);
106 + }
107 +
108 + return $response->json($content);
109 + }
110 +
88 111 /**
89 112 * @param $file array
90 113 * @param Request $request
91 114 * @param StreamedResponse $streamedResponse
@@ -95,8 +118,23 @@
95 118 {
96 119
97 120 if($file['stream'] === false) {
98 121 return $response->json('Cannot read file, please check file permissions!', 422);
122 + }
123 +
124 + // Output produced before this response would be prepended to the file. With
125 + // Content-Length set below, clients can then lose the same number of bytes
126 + // from the end of the file.
127 + if (headers_sent()) {
128 + fclose($file['stream']);
129 + return $response->json('Cannot safely stream file!', 500);
130 + }
131 +
132 + while (ob_get_level() > 0) {
133 + if (!@ob_end_clean()) {
134 + fclose($file['stream']);
135 + return $response->json('Cannot safely stream file!', 500);
136 + }
99 137 }
100 138
101 139 $streamedResponse->setCallback(function () use ($file) {
102 140 // @codeCoverageIgnoreStart