This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Björn Schießle <[email protected]> |
||
4 | * |
||
5 | * @copyright Copyright (c) 2018, ownCloud GmbH |
||
6 | * @license AGPL-3.0 |
||
7 | * |
||
8 | * This code is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Affero General Public License, version 3, |
||
10 | * as published by the Free Software Foundation. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | * GNU Affero General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU Affero General Public License, version 3, |
||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
||
19 | * |
||
20 | */ |
||
21 | |||
22 | |||
23 | namespace OCA\Files_Texteditor\Controller; |
||
24 | |||
25 | |||
26 | use OC\Files\View; |
||
27 | use OC\HintException; |
||
28 | use OCP\AppFramework\Controller; |
||
29 | use OCP\AppFramework\Http; |
||
30 | use OCP\AppFramework\Http\DataResponse; |
||
31 | use OCP\Files\ForbiddenException; |
||
32 | use OCP\IL10N; |
||
33 | use OCP\ILogger; |
||
34 | use OCP\IRequest; |
||
35 | use OCP\Lock\LockedException; |
||
36 | |||
37 | class FileHandlingController extends Controller{ |
||
38 | |||
39 | /** @var IL10N */ |
||
40 | private $l; |
||
41 | |||
42 | /** @var View */ |
||
43 | private $view; |
||
44 | |||
45 | /** @var ILogger */ |
||
46 | private $logger; |
||
47 | |||
48 | /** |
||
49 | * @NoAdminRequired |
||
50 | * |
||
51 | * @param string $AppName |
||
52 | * @param IRequest $request |
||
53 | * @param IL10N $l10n |
||
54 | * @param View $view |
||
55 | * @param ILogger $logger |
||
56 | */ |
||
57 | 20 | public function __construct($AppName, |
|
58 | IRequest $request, |
||
59 | IL10N $l10n, |
||
60 | View $view, |
||
61 | ILogger $logger) { |
||
62 | 20 | parent::__construct($AppName, $request); |
|
63 | 20 | $this->l = $l10n; |
|
64 | 20 | $this->view = $view; |
|
65 | 20 | $this->logger = $logger; |
|
66 | 20 | } |
|
67 | |||
68 | /** |
||
69 | * load text file |
||
70 | * |
||
71 | * @NoAdminRequired |
||
72 | * |
||
73 | * @param string $dir |
||
74 | * @param string $filename |
||
75 | * @return DataResponse |
||
76 | */ |
||
77 | 10 | public function load($dir, $filename) { |
|
78 | try { |
||
79 | 10 | if (!empty($filename)) { |
|
80 | 9 | $path = $dir . '/' . $filename; |
|
81 | // default of 4MB |
||
82 | 9 | $maxSize = 4194304; |
|
83 | 9 | if ($this->view->filesize($path) > $maxSize) { |
|
84 | 1 | return new DataResponse(['message' => (string)$this->l->t('This file is too big to be opened. Please download the file instead.')], Http::STATUS_BAD_REQUEST); |
|
85 | } |
||
86 | 8 | $fileContents = $this->view->file_get_contents($path); |
|
87 | 4 | if ($fileContents !== false) { |
|
88 | 3 | $writable = $this->view->isUpdatable($path); |
|
89 | 3 | $mime = $this->view->getMimeType($path); |
|
90 | 3 | $mTime = $this->view->filemtime($path); |
|
91 | 3 | $encoding = mb_detect_encoding($fileContents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true); |
|
92 | 3 | if ($encoding == "") { |
|
93 | // set default encoding if it couldn't be detected |
||
94 | $encoding = 'ISO-8859-15'; |
||
95 | } |
||
96 | 3 | $fileContents = iconv($encoding, "UTF-8", $fileContents); |
|
97 | 3 | return new DataResponse( |
|
98 | [ |
||
99 | 3 | 'filecontents' => $fileContents, |
|
100 | 3 | 'writeable' => $writable, |
|
101 | 3 | 'mime' => $mime, |
|
102 | 3 | 'mtime' => $mTime |
|
103 | ], |
||
104 | 3 | Http::STATUS_OK |
|
105 | ); |
||
106 | } else { |
||
107 | 1 | return new DataResponse(['message' => (string)$this->l->t('Cannot read the file.')], Http::STATUS_BAD_REQUEST); |
|
108 | } |
||
109 | } else { |
||
110 | 1 | return new DataResponse(['message' => (string)$this->l->t('Invalid file path supplied.')], Http::STATUS_BAD_REQUEST); |
|
111 | } |
||
112 | |||
113 | 4 | } catch (LockedException $e) { |
|
0 ignored issues
–
show
|
|||
114 | 1 | $message = (string) $this->l->t('The file is locked.'); |
|
115 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
116 | 3 | } catch (ForbiddenException $e) { |
|
0 ignored issues
–
show
The class
OCP\Files\ForbiddenException does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. ![]() |
|||
117 | 1 | return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
118 | 2 | } catch (HintException $e) { |
|
0 ignored issues
–
show
The class
OC\HintException does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. ![]() |
|||
119 | 1 | $message = (string)$e->getHint(); |
|
120 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
121 | 1 | } catch (\Exception $e) { |
|
122 | 1 | $message = (string)$this->l->t('An internal server error occurred.'); |
|
123 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
124 | } |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * save text file |
||
129 | * |
||
130 | * @NoAdminRequired |
||
131 | * |
||
132 | * @param string $path |
||
133 | * @param string $filecontents |
||
134 | * @param integer $mtime |
||
135 | * @return DataResponse |
||
136 | */ |
||
137 | 10 | public function save($path, $filecontents, $mtime) { |
|
138 | try { |
||
139 | 10 | if($path !== '' && (is_integer($mtime) && $mtime > 0)) { |
|
140 | // Get file mtime |
||
141 | 7 | $filemtime = $this->view->filemtime($path); |
|
142 | 7 | if($mtime !== $filemtime) { |
|
143 | // Then the file has changed since opening |
||
144 | 1 | $this->logger->error('File: ' . $path . ' modified since opening.', |
|
145 | 1 | ['app' => 'files_texteditor']); |
|
146 | 1 | return new DataResponse( |
|
147 | 1 | ['message' => $this->l->t('Cannot save file as it has been modified since opening')], |
|
148 | 1 | Http::STATUS_BAD_REQUEST); |
|
149 | } else { |
||
150 | // File same as when opened, save file |
||
151 | 6 | if($this->view->isUpdatable($path)) { |
|
152 | 5 | $filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents); |
|
153 | try { |
||
154 | 5 | $this->view->file_put_contents($path, $filecontents); |
|
155 | 4 | } catch (LockedException $e) { |
|
0 ignored issues
–
show
The class
OCP\Lock\LockedException does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. ![]() |
|||
156 | 1 | $message = (string) $this->l->t('The file is locked.'); |
|
157 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
158 | 3 | } catch (ForbiddenException $e) { |
|
0 ignored issues
–
show
The class
OCP\Files\ForbiddenException does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. ![]() |
|||
159 | 1 | return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
160 | } |
||
161 | // Clear statcache |
||
162 | 1 | clearstatcache(); |
|
163 | // Get new mtime |
||
164 | 1 | $newmtime = $this->view->filemtime($path); |
|
165 | 1 | $newsize = $this->view->filesize($path); |
|
166 | 1 | return new DataResponse(['mtime' => $newmtime, 'size' => $newsize], Http::STATUS_OK); |
|
167 | View Code Duplication | } else { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
168 | // Not writeable! |
||
169 | 1 | $this->logger->error('User does not have permission to write to file: ' . $path, |
|
170 | 1 | ['app' => 'files_texteditor']); |
|
171 | 1 | return new DataResponse([ 'message' => $this->l->t('Insufficient permissions')], |
|
172 | 1 | Http::STATUS_BAD_REQUEST); |
|
173 | } |
||
174 | } |
||
175 | 3 | } else if ($path === '') { |
|
176 | 1 | $this->logger->error('No file path supplied'); |
|
177 | 1 | return new DataResponse(['message' => $this->l->t('File path not supplied')], Http::STATUS_BAD_REQUEST); |
|
178 | View Code Duplication | } else { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
179 | 2 | $this->logger->error('No file mtime supplied', ['app' => 'files_texteditor']); |
|
180 | 2 | return new DataResponse(['message' => $this->l->t('File mtime not supplied')], Http::STATUS_BAD_REQUEST); |
|
181 | } |
||
182 | |||
183 | 2 | } catch (HintException $e) { |
|
0 ignored issues
–
show
The class
OC\HintException does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. ![]() |
|||
184 | 1 | $message = (string)$e->getHint(); |
|
185 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
186 | 1 | } catch (\Exception $e) { |
|
187 | 1 | $message = (string)$this->l->t('An internal server error occurred.'); |
|
188 | 1 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
189 | } |
||
190 | } |
||
191 | |||
192 | } |
||
193 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.