@@ -30,10 +30,10 @@ |
||
30 | 30 | */ |
31 | 31 | interface IBackendProvider { |
32 | 32 | |
33 | - /** |
|
34 | - * @since 9.1.0 |
|
35 | - * @return Backend[] |
|
36 | - */ |
|
37 | - public function getBackends(); |
|
33 | + /** |
|
34 | + * @since 9.1.0 |
|
35 | + * @return Backend[] |
|
36 | + */ |
|
37 | + public function getBackends(); |
|
38 | 38 | |
39 | 39 | } |
@@ -30,10 +30,10 @@ |
||
30 | 30 | */ |
31 | 31 | interface IAuthMechanismProvider { |
32 | 32 | |
33 | - /** |
|
34 | - * @since 9.1.0 |
|
35 | - * @return AuthMechanism[] |
|
36 | - */ |
|
37 | - public function getAuthMechanisms(); |
|
33 | + /** |
|
34 | + * @since 9.1.0 |
|
35 | + * @return AuthMechanism[] |
|
36 | + */ |
|
37 | + public function getAuthMechanisms(); |
|
38 | 38 | |
39 | 39 | } |
@@ -31,14 +31,14 @@ |
||
31 | 31 | */ |
32 | 32 | class SessionStorageWrapper extends PermissionsMask { |
33 | 33 | |
34 | - /** |
|
35 | - * @param array $arguments ['storage' => $storage] |
|
36 | - */ |
|
37 | - public function __construct($arguments) { |
|
38 | - // disable sharing permission |
|
39 | - $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE; |
|
40 | - parent::__construct($arguments); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param array $arguments ['storage' => $storage] |
|
36 | + */ |
|
37 | + public function __construct($arguments) { |
|
38 | + // disable sharing permission |
|
39 | + $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE; |
|
40 | + parent::__construct($arguments); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
44 | 44 |
@@ -29,15 +29,15 @@ |
||
29 | 29 | * Authentication mechanism or backend has insufficient data |
30 | 30 | */ |
31 | 31 | class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException { |
32 | - /** |
|
33 | - * StorageNotAvailableException constructor. |
|
34 | - * |
|
35 | - * @param string $message |
|
36 | - * @param int $code |
|
37 | - * @param \Exception $previous |
|
38 | - * @since 6.0.0 |
|
39 | - */ |
|
40 | - public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { |
|
41 | - parent::__construct($message, $code, $previous); |
|
42 | - } |
|
32 | + /** |
|
33 | + * StorageNotAvailableException constructor. |
|
34 | + * |
|
35 | + * @param string $message |
|
36 | + * @param int $code |
|
37 | + * @param \Exception $previous |
|
38 | + * @since 6.0.0 |
|
39 | + */ |
|
40 | + public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { |
|
41 | + parent::__construct($message, $code, $previous); |
|
42 | + } |
|
43 | 43 | } |
@@ -42,428 +42,428 @@ |
||
42 | 42 | * provide access to SFTP servers. |
43 | 43 | */ |
44 | 44 | class SFTP extends \OC\Files\Storage\Common { |
45 | - private $host; |
|
46 | - private $user; |
|
47 | - private $root; |
|
48 | - private $port = 22; |
|
49 | - |
|
50 | - private $auth; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \phpseclib\Net\SFTP |
|
54 | - */ |
|
55 | - protected $client; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $host protocol://server:port |
|
59 | - * @return array [$server, $port] |
|
60 | - */ |
|
61 | - private function splitHost($host) { |
|
62 | - $input = $host; |
|
63 | - if (strpos($host, '://') === false) { |
|
64 | - // add a protocol to fix parse_url behavior with ipv6 |
|
65 | - $host = 'http://' . $host; |
|
66 | - } |
|
67 | - |
|
68 | - $parsed = parse_url($host); |
|
69 | - if(is_array($parsed) && isset($parsed['port'])) { |
|
70 | - return [$parsed['host'], $parsed['port']]; |
|
71 | - } else if (is_array($parsed)) { |
|
72 | - return [$parsed['host'], 22]; |
|
73 | - } else { |
|
74 | - return [$input, 22]; |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritdoc} |
|
80 | - */ |
|
81 | - public function __construct($params) { |
|
82 | - // Register sftp:// |
|
83 | - Stream::register(); |
|
84 | - |
|
85 | - $parsedHost = $this->splitHost($params['host']); |
|
86 | - |
|
87 | - $this->host = $parsedHost[0]; |
|
88 | - $this->port = $parsedHost[1]; |
|
89 | - |
|
90 | - if (!isset($params['user'])) { |
|
91 | - throw new \UnexpectedValueException('no authentication parameters specified'); |
|
92 | - } |
|
93 | - $this->user = $params['user']; |
|
94 | - |
|
95 | - if (isset($params['public_key_auth'])) { |
|
96 | - $this->auth = $params['public_key_auth']; |
|
97 | - } elseif (isset($params['password'])) { |
|
98 | - $this->auth = $params['password']; |
|
99 | - } else { |
|
100 | - throw new \UnexpectedValueException('no authentication parameters specified'); |
|
101 | - } |
|
102 | - |
|
103 | - $this->root |
|
104 | - = isset($params['root']) ? $this->cleanPath($params['root']) : '/'; |
|
105 | - |
|
106 | - if ($this->root[0] != '/') { |
|
107 | - $this->root = '/' . $this->root; |
|
108 | - } |
|
109 | - |
|
110 | - if (substr($this->root, -1, 1) != '/') { |
|
111 | - $this->root .= '/'; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Returns the connection. |
|
117 | - * |
|
118 | - * @return \phpseclib\Net\SFTP connected client instance |
|
119 | - * @throws \Exception when the connection failed |
|
120 | - */ |
|
121 | - public function getConnection() { |
|
122 | - if (!is_null($this->client)) { |
|
123 | - return $this->client; |
|
124 | - } |
|
125 | - |
|
126 | - $hostKeys = $this->readHostKeys(); |
|
127 | - $this->client = new \phpseclib\Net\SFTP($this->host, $this->port); |
|
128 | - |
|
129 | - // The SSH Host Key MUST be verified before login(). |
|
130 | - $currentHostKey = $this->client->getServerPublicHostKey(); |
|
131 | - if (array_key_exists($this->host, $hostKeys)) { |
|
132 | - if ($hostKeys[$this->host] != $currentHostKey) { |
|
133 | - throw new \Exception('Host public key does not match known key'); |
|
134 | - } |
|
135 | - } else { |
|
136 | - $hostKeys[$this->host] = $currentHostKey; |
|
137 | - $this->writeHostKeys($hostKeys); |
|
138 | - } |
|
139 | - |
|
140 | - if (!$this->client->login($this->user, $this->auth)) { |
|
141 | - throw new \Exception('Login failed'); |
|
142 | - } |
|
143 | - return $this->client; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * {@inheritdoc} |
|
148 | - */ |
|
149 | - public function test() { |
|
150 | - if ( |
|
151 | - !isset($this->host) |
|
152 | - || !isset($this->user) |
|
153 | - ) { |
|
154 | - return false; |
|
155 | - } |
|
156 | - return $this->getConnection()->nlist() !== false; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * {@inheritdoc} |
|
161 | - */ |
|
162 | - public function getId(){ |
|
163 | - $id = 'sftp::' . $this->user . '@' . $this->host; |
|
164 | - if ($this->port !== 22) { |
|
165 | - $id .= ':' . $this->port; |
|
166 | - } |
|
167 | - // note: this will double the root slash, |
|
168 | - // we should not change it to keep compatible with |
|
169 | - // old storage ids |
|
170 | - $id .= '/' . $this->root; |
|
171 | - return $id; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function getHost() { |
|
178 | - return $this->host; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getRoot() { |
|
185 | - return $this->root; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return mixed |
|
190 | - */ |
|
191 | - public function getUser() { |
|
192 | - return $this->user; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $path |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - private function absPath($path) { |
|
200 | - return $this->root . $this->cleanPath($path); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string|false |
|
205 | - */ |
|
206 | - private function hostKeysPath() { |
|
207 | - try { |
|
208 | - $storage_view = \OCP\Files::getStorage('files_external'); |
|
209 | - if ($storage_view) { |
|
210 | - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . |
|
211 | - $storage_view->getAbsolutePath('') . |
|
212 | - 'ssh_hostKeys'; |
|
213 | - } |
|
214 | - } catch (\Exception $e) { |
|
215 | - } |
|
216 | - return false; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param $keys |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - protected function writeHostKeys($keys) { |
|
224 | - try { |
|
225 | - $keyPath = $this->hostKeysPath(); |
|
226 | - if ($keyPath && file_exists($keyPath)) { |
|
227 | - $fp = fopen($keyPath, 'w'); |
|
228 | - foreach ($keys as $host => $key) { |
|
229 | - fwrite($fp, $host . '::' . $key . "\n"); |
|
230 | - } |
|
231 | - fclose($fp); |
|
232 | - return true; |
|
233 | - } |
|
234 | - } catch (\Exception $e) { |
|
235 | - } |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - protected function readHostKeys() { |
|
243 | - try { |
|
244 | - $keyPath = $this->hostKeysPath(); |
|
245 | - if (file_exists($keyPath)) { |
|
246 | - $hosts = array(); |
|
247 | - $keys = array(); |
|
248 | - $lines = file($keyPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
249 | - if ($lines) { |
|
250 | - foreach ($lines as $line) { |
|
251 | - $hostKeyArray = explode("::", $line, 2); |
|
252 | - if (count($hostKeyArray) == 2) { |
|
253 | - $hosts[] = $hostKeyArray[0]; |
|
254 | - $keys[] = $hostKeyArray[1]; |
|
255 | - } |
|
256 | - } |
|
257 | - return array_combine($hosts, $keys); |
|
258 | - } |
|
259 | - } |
|
260 | - } catch (\Exception $e) { |
|
261 | - } |
|
262 | - return array(); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * {@inheritdoc} |
|
267 | - */ |
|
268 | - public function mkdir($path) { |
|
269 | - try { |
|
270 | - return $this->getConnection()->mkdir($this->absPath($path)); |
|
271 | - } catch (\Exception $e) { |
|
272 | - return false; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * {@inheritdoc} |
|
278 | - */ |
|
279 | - public function rmdir($path) { |
|
280 | - try { |
|
281 | - $result = $this->getConnection()->delete($this->absPath($path), true); |
|
282 | - // workaround: stray stat cache entry when deleting empty folders |
|
283 | - // see https://github.com/phpseclib/phpseclib/issues/706 |
|
284 | - $this->getConnection()->clearStatCache(); |
|
285 | - return $result; |
|
286 | - } catch (\Exception $e) { |
|
287 | - return false; |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * {@inheritdoc} |
|
293 | - */ |
|
294 | - public function opendir($path) { |
|
295 | - try { |
|
296 | - $list = $this->getConnection()->nlist($this->absPath($path)); |
|
297 | - if ($list === false) { |
|
298 | - return false; |
|
299 | - } |
|
300 | - |
|
301 | - $id = md5('sftp:' . $path); |
|
302 | - $dirStream = array(); |
|
303 | - foreach($list as $file) { |
|
304 | - if ($file != '.' && $file != '..') { |
|
305 | - $dirStream[] = $file; |
|
306 | - } |
|
307 | - } |
|
308 | - return IteratorDirectory::wrap($dirStream); |
|
309 | - } catch(\Exception $e) { |
|
310 | - return false; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * {@inheritdoc} |
|
316 | - */ |
|
317 | - public function filetype($path) { |
|
318 | - try { |
|
319 | - $stat = $this->getConnection()->stat($this->absPath($path)); |
|
320 | - if ($stat['type'] == NET_SFTP_TYPE_REGULAR) { |
|
321 | - return 'file'; |
|
322 | - } |
|
323 | - |
|
324 | - if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) { |
|
325 | - return 'dir'; |
|
326 | - } |
|
327 | - } catch (\Exception $e) { |
|
328 | - |
|
329 | - } |
|
330 | - return false; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * {@inheritdoc} |
|
335 | - */ |
|
336 | - public function file_exists($path) { |
|
337 | - try { |
|
338 | - return $this->getConnection()->stat($this->absPath($path)) !== false; |
|
339 | - } catch (\Exception $e) { |
|
340 | - return false; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * {@inheritdoc} |
|
346 | - */ |
|
347 | - public function unlink($path) { |
|
348 | - try { |
|
349 | - return $this->getConnection()->delete($this->absPath($path), true); |
|
350 | - } catch (\Exception $e) { |
|
351 | - return false; |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * {@inheritdoc} |
|
357 | - */ |
|
358 | - public function fopen($path, $mode) { |
|
359 | - try { |
|
360 | - $absPath = $this->absPath($path); |
|
361 | - switch($mode) { |
|
362 | - case 'r': |
|
363 | - case 'rb': |
|
364 | - if ( !$this->file_exists($path)) { |
|
365 | - return false; |
|
366 | - } |
|
367 | - case 'w': |
|
368 | - case 'wb': |
|
369 | - case 'a': |
|
370 | - case 'ab': |
|
371 | - case 'r+': |
|
372 | - case 'w+': |
|
373 | - case 'wb+': |
|
374 | - case 'a+': |
|
375 | - case 'x': |
|
376 | - case 'x+': |
|
377 | - case 'c': |
|
378 | - case 'c+': |
|
379 | - $context = stream_context_create(array('sftp' => array('session' => $this->getConnection()))); |
|
380 | - $handle = fopen($this->constructUrl($path), $mode, false, $context); |
|
381 | - return RetryWrapper::wrap($handle); |
|
382 | - } |
|
383 | - } catch (\Exception $e) { |
|
384 | - } |
|
385 | - return false; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * {@inheritdoc} |
|
390 | - */ |
|
391 | - public function touch($path, $mtime=null) { |
|
392 | - try { |
|
393 | - if (!is_null($mtime)) { |
|
394 | - return false; |
|
395 | - } |
|
396 | - if (!$this->file_exists($path)) { |
|
397 | - $this->getConnection()->put($this->absPath($path), ''); |
|
398 | - } else { |
|
399 | - return false; |
|
400 | - } |
|
401 | - } catch (\Exception $e) { |
|
402 | - return false; |
|
403 | - } |
|
404 | - return true; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * @param string $path |
|
409 | - * @param string $target |
|
410 | - * @throws \Exception |
|
411 | - */ |
|
412 | - public function getFile($path, $target) { |
|
413 | - $this->getConnection()->get($path, $target); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $path |
|
418 | - * @param string $target |
|
419 | - * @throws \Exception |
|
420 | - */ |
|
421 | - public function uploadFile($path, $target) { |
|
422 | - $this->getConnection()->put($target, $path, NET_SFTP_LOCAL_FILE); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * {@inheritdoc} |
|
427 | - */ |
|
428 | - public function rename($source, $target) { |
|
429 | - try { |
|
430 | - if ($this->file_exists($target)) { |
|
431 | - $this->unlink($target); |
|
432 | - } |
|
433 | - return $this->getConnection()->rename( |
|
434 | - $this->absPath($source), |
|
435 | - $this->absPath($target) |
|
436 | - ); |
|
437 | - } catch (\Exception $e) { |
|
438 | - return false; |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * {@inheritdoc} |
|
444 | - */ |
|
445 | - public function stat($path) { |
|
446 | - try { |
|
447 | - $stat = $this->getConnection()->stat($this->absPath($path)); |
|
448 | - |
|
449 | - $mtime = $stat ? $stat['mtime'] : -1; |
|
450 | - $size = $stat ? $stat['size'] : 0; |
|
451 | - |
|
452 | - return array('mtime' => $mtime, 'size' => $size, 'ctime' => -1); |
|
453 | - } catch (\Exception $e) { |
|
454 | - return false; |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $path |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public function constructUrl($path) { |
|
463 | - // Do not pass the password here. We want to use the Net_SFTP object |
|
464 | - // supplied via stream context or fail. We only supply username and |
|
465 | - // hostname because this might show up in logs (they are not used). |
|
466 | - $url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path; |
|
467 | - return $url; |
|
468 | - } |
|
45 | + private $host; |
|
46 | + private $user; |
|
47 | + private $root; |
|
48 | + private $port = 22; |
|
49 | + |
|
50 | + private $auth; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \phpseclib\Net\SFTP |
|
54 | + */ |
|
55 | + protected $client; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $host protocol://server:port |
|
59 | + * @return array [$server, $port] |
|
60 | + */ |
|
61 | + private function splitHost($host) { |
|
62 | + $input = $host; |
|
63 | + if (strpos($host, '://') === false) { |
|
64 | + // add a protocol to fix parse_url behavior with ipv6 |
|
65 | + $host = 'http://' . $host; |
|
66 | + } |
|
67 | + |
|
68 | + $parsed = parse_url($host); |
|
69 | + if(is_array($parsed) && isset($parsed['port'])) { |
|
70 | + return [$parsed['host'], $parsed['port']]; |
|
71 | + } else if (is_array($parsed)) { |
|
72 | + return [$parsed['host'], 22]; |
|
73 | + } else { |
|
74 | + return [$input, 22]; |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritdoc} |
|
80 | + */ |
|
81 | + public function __construct($params) { |
|
82 | + // Register sftp:// |
|
83 | + Stream::register(); |
|
84 | + |
|
85 | + $parsedHost = $this->splitHost($params['host']); |
|
86 | + |
|
87 | + $this->host = $parsedHost[0]; |
|
88 | + $this->port = $parsedHost[1]; |
|
89 | + |
|
90 | + if (!isset($params['user'])) { |
|
91 | + throw new \UnexpectedValueException('no authentication parameters specified'); |
|
92 | + } |
|
93 | + $this->user = $params['user']; |
|
94 | + |
|
95 | + if (isset($params['public_key_auth'])) { |
|
96 | + $this->auth = $params['public_key_auth']; |
|
97 | + } elseif (isset($params['password'])) { |
|
98 | + $this->auth = $params['password']; |
|
99 | + } else { |
|
100 | + throw new \UnexpectedValueException('no authentication parameters specified'); |
|
101 | + } |
|
102 | + |
|
103 | + $this->root |
|
104 | + = isset($params['root']) ? $this->cleanPath($params['root']) : '/'; |
|
105 | + |
|
106 | + if ($this->root[0] != '/') { |
|
107 | + $this->root = '/' . $this->root; |
|
108 | + } |
|
109 | + |
|
110 | + if (substr($this->root, -1, 1) != '/') { |
|
111 | + $this->root .= '/'; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Returns the connection. |
|
117 | + * |
|
118 | + * @return \phpseclib\Net\SFTP connected client instance |
|
119 | + * @throws \Exception when the connection failed |
|
120 | + */ |
|
121 | + public function getConnection() { |
|
122 | + if (!is_null($this->client)) { |
|
123 | + return $this->client; |
|
124 | + } |
|
125 | + |
|
126 | + $hostKeys = $this->readHostKeys(); |
|
127 | + $this->client = new \phpseclib\Net\SFTP($this->host, $this->port); |
|
128 | + |
|
129 | + // The SSH Host Key MUST be verified before login(). |
|
130 | + $currentHostKey = $this->client->getServerPublicHostKey(); |
|
131 | + if (array_key_exists($this->host, $hostKeys)) { |
|
132 | + if ($hostKeys[$this->host] != $currentHostKey) { |
|
133 | + throw new \Exception('Host public key does not match known key'); |
|
134 | + } |
|
135 | + } else { |
|
136 | + $hostKeys[$this->host] = $currentHostKey; |
|
137 | + $this->writeHostKeys($hostKeys); |
|
138 | + } |
|
139 | + |
|
140 | + if (!$this->client->login($this->user, $this->auth)) { |
|
141 | + throw new \Exception('Login failed'); |
|
142 | + } |
|
143 | + return $this->client; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * {@inheritdoc} |
|
148 | + */ |
|
149 | + public function test() { |
|
150 | + if ( |
|
151 | + !isset($this->host) |
|
152 | + || !isset($this->user) |
|
153 | + ) { |
|
154 | + return false; |
|
155 | + } |
|
156 | + return $this->getConnection()->nlist() !== false; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * {@inheritdoc} |
|
161 | + */ |
|
162 | + public function getId(){ |
|
163 | + $id = 'sftp::' . $this->user . '@' . $this->host; |
|
164 | + if ($this->port !== 22) { |
|
165 | + $id .= ':' . $this->port; |
|
166 | + } |
|
167 | + // note: this will double the root slash, |
|
168 | + // we should not change it to keep compatible with |
|
169 | + // old storage ids |
|
170 | + $id .= '/' . $this->root; |
|
171 | + return $id; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function getHost() { |
|
178 | + return $this->host; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getRoot() { |
|
185 | + return $this->root; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return mixed |
|
190 | + */ |
|
191 | + public function getUser() { |
|
192 | + return $this->user; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $path |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + private function absPath($path) { |
|
200 | + return $this->root . $this->cleanPath($path); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string|false |
|
205 | + */ |
|
206 | + private function hostKeysPath() { |
|
207 | + try { |
|
208 | + $storage_view = \OCP\Files::getStorage('files_external'); |
|
209 | + if ($storage_view) { |
|
210 | + return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . |
|
211 | + $storage_view->getAbsolutePath('') . |
|
212 | + 'ssh_hostKeys'; |
|
213 | + } |
|
214 | + } catch (\Exception $e) { |
|
215 | + } |
|
216 | + return false; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @param $keys |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + protected function writeHostKeys($keys) { |
|
224 | + try { |
|
225 | + $keyPath = $this->hostKeysPath(); |
|
226 | + if ($keyPath && file_exists($keyPath)) { |
|
227 | + $fp = fopen($keyPath, 'w'); |
|
228 | + foreach ($keys as $host => $key) { |
|
229 | + fwrite($fp, $host . '::' . $key . "\n"); |
|
230 | + } |
|
231 | + fclose($fp); |
|
232 | + return true; |
|
233 | + } |
|
234 | + } catch (\Exception $e) { |
|
235 | + } |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + protected function readHostKeys() { |
|
243 | + try { |
|
244 | + $keyPath = $this->hostKeysPath(); |
|
245 | + if (file_exists($keyPath)) { |
|
246 | + $hosts = array(); |
|
247 | + $keys = array(); |
|
248 | + $lines = file($keyPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
249 | + if ($lines) { |
|
250 | + foreach ($lines as $line) { |
|
251 | + $hostKeyArray = explode("::", $line, 2); |
|
252 | + if (count($hostKeyArray) == 2) { |
|
253 | + $hosts[] = $hostKeyArray[0]; |
|
254 | + $keys[] = $hostKeyArray[1]; |
|
255 | + } |
|
256 | + } |
|
257 | + return array_combine($hosts, $keys); |
|
258 | + } |
|
259 | + } |
|
260 | + } catch (\Exception $e) { |
|
261 | + } |
|
262 | + return array(); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * {@inheritdoc} |
|
267 | + */ |
|
268 | + public function mkdir($path) { |
|
269 | + try { |
|
270 | + return $this->getConnection()->mkdir($this->absPath($path)); |
|
271 | + } catch (\Exception $e) { |
|
272 | + return false; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * {@inheritdoc} |
|
278 | + */ |
|
279 | + public function rmdir($path) { |
|
280 | + try { |
|
281 | + $result = $this->getConnection()->delete($this->absPath($path), true); |
|
282 | + // workaround: stray stat cache entry when deleting empty folders |
|
283 | + // see https://github.com/phpseclib/phpseclib/issues/706 |
|
284 | + $this->getConnection()->clearStatCache(); |
|
285 | + return $result; |
|
286 | + } catch (\Exception $e) { |
|
287 | + return false; |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * {@inheritdoc} |
|
293 | + */ |
|
294 | + public function opendir($path) { |
|
295 | + try { |
|
296 | + $list = $this->getConnection()->nlist($this->absPath($path)); |
|
297 | + if ($list === false) { |
|
298 | + return false; |
|
299 | + } |
|
300 | + |
|
301 | + $id = md5('sftp:' . $path); |
|
302 | + $dirStream = array(); |
|
303 | + foreach($list as $file) { |
|
304 | + if ($file != '.' && $file != '..') { |
|
305 | + $dirStream[] = $file; |
|
306 | + } |
|
307 | + } |
|
308 | + return IteratorDirectory::wrap($dirStream); |
|
309 | + } catch(\Exception $e) { |
|
310 | + return false; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * {@inheritdoc} |
|
316 | + */ |
|
317 | + public function filetype($path) { |
|
318 | + try { |
|
319 | + $stat = $this->getConnection()->stat($this->absPath($path)); |
|
320 | + if ($stat['type'] == NET_SFTP_TYPE_REGULAR) { |
|
321 | + return 'file'; |
|
322 | + } |
|
323 | + |
|
324 | + if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) { |
|
325 | + return 'dir'; |
|
326 | + } |
|
327 | + } catch (\Exception $e) { |
|
328 | + |
|
329 | + } |
|
330 | + return false; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * {@inheritdoc} |
|
335 | + */ |
|
336 | + public function file_exists($path) { |
|
337 | + try { |
|
338 | + return $this->getConnection()->stat($this->absPath($path)) !== false; |
|
339 | + } catch (\Exception $e) { |
|
340 | + return false; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * {@inheritdoc} |
|
346 | + */ |
|
347 | + public function unlink($path) { |
|
348 | + try { |
|
349 | + return $this->getConnection()->delete($this->absPath($path), true); |
|
350 | + } catch (\Exception $e) { |
|
351 | + return false; |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * {@inheritdoc} |
|
357 | + */ |
|
358 | + public function fopen($path, $mode) { |
|
359 | + try { |
|
360 | + $absPath = $this->absPath($path); |
|
361 | + switch($mode) { |
|
362 | + case 'r': |
|
363 | + case 'rb': |
|
364 | + if ( !$this->file_exists($path)) { |
|
365 | + return false; |
|
366 | + } |
|
367 | + case 'w': |
|
368 | + case 'wb': |
|
369 | + case 'a': |
|
370 | + case 'ab': |
|
371 | + case 'r+': |
|
372 | + case 'w+': |
|
373 | + case 'wb+': |
|
374 | + case 'a+': |
|
375 | + case 'x': |
|
376 | + case 'x+': |
|
377 | + case 'c': |
|
378 | + case 'c+': |
|
379 | + $context = stream_context_create(array('sftp' => array('session' => $this->getConnection()))); |
|
380 | + $handle = fopen($this->constructUrl($path), $mode, false, $context); |
|
381 | + return RetryWrapper::wrap($handle); |
|
382 | + } |
|
383 | + } catch (\Exception $e) { |
|
384 | + } |
|
385 | + return false; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * {@inheritdoc} |
|
390 | + */ |
|
391 | + public function touch($path, $mtime=null) { |
|
392 | + try { |
|
393 | + if (!is_null($mtime)) { |
|
394 | + return false; |
|
395 | + } |
|
396 | + if (!$this->file_exists($path)) { |
|
397 | + $this->getConnection()->put($this->absPath($path), ''); |
|
398 | + } else { |
|
399 | + return false; |
|
400 | + } |
|
401 | + } catch (\Exception $e) { |
|
402 | + return false; |
|
403 | + } |
|
404 | + return true; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * @param string $path |
|
409 | + * @param string $target |
|
410 | + * @throws \Exception |
|
411 | + */ |
|
412 | + public function getFile($path, $target) { |
|
413 | + $this->getConnection()->get($path, $target); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $path |
|
418 | + * @param string $target |
|
419 | + * @throws \Exception |
|
420 | + */ |
|
421 | + public function uploadFile($path, $target) { |
|
422 | + $this->getConnection()->put($target, $path, NET_SFTP_LOCAL_FILE); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * {@inheritdoc} |
|
427 | + */ |
|
428 | + public function rename($source, $target) { |
|
429 | + try { |
|
430 | + if ($this->file_exists($target)) { |
|
431 | + $this->unlink($target); |
|
432 | + } |
|
433 | + return $this->getConnection()->rename( |
|
434 | + $this->absPath($source), |
|
435 | + $this->absPath($target) |
|
436 | + ); |
|
437 | + } catch (\Exception $e) { |
|
438 | + return false; |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * {@inheritdoc} |
|
444 | + */ |
|
445 | + public function stat($path) { |
|
446 | + try { |
|
447 | + $stat = $this->getConnection()->stat($this->absPath($path)); |
|
448 | + |
|
449 | + $mtime = $stat ? $stat['mtime'] : -1; |
|
450 | + $size = $stat ? $stat['size'] : 0; |
|
451 | + |
|
452 | + return array('mtime' => $mtime, 'size' => $size, 'ctime' => -1); |
|
453 | + } catch (\Exception $e) { |
|
454 | + return false; |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $path |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public function constructUrl($path) { |
|
463 | + // Do not pass the password here. We want to use the Net_SFTP object |
|
464 | + // supplied via stream context or fail. We only supply username and |
|
465 | + // hostname because this might show up in logs (they are not used). |
|
466 | + $url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path; |
|
467 | + return $url; |
|
468 | + } |
|
469 | 469 | } |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | $input = $host; |
63 | 63 | if (strpos($host, '://') === false) { |
64 | 64 | // add a protocol to fix parse_url behavior with ipv6 |
65 | - $host = 'http://' . $host; |
|
65 | + $host = 'http://'.$host; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $parsed = parse_url($host); |
69 | - if(is_array($parsed) && isset($parsed['port'])) { |
|
69 | + if (is_array($parsed) && isset($parsed['port'])) { |
|
70 | 70 | return [$parsed['host'], $parsed['port']]; |
71 | 71 | } else if (is_array($parsed)) { |
72 | 72 | return [$parsed['host'], 22]; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | // Register sftp:// |
83 | 83 | Stream::register(); |
84 | 84 | |
85 | - $parsedHost = $this->splitHost($params['host']); |
|
85 | + $parsedHost = $this->splitHost($params['host']); |
|
86 | 86 | |
87 | 87 | $this->host = $parsedHost[0]; |
88 | 88 | $this->port = $parsedHost[1]; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | = isset($params['root']) ? $this->cleanPath($params['root']) : '/'; |
105 | 105 | |
106 | 106 | if ($this->root[0] != '/') { |
107 | - $this->root = '/' . $this->root; |
|
107 | + $this->root = '/'.$this->root; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | if (substr($this->root, -1, 1) != '/') { |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | /** |
160 | 160 | * {@inheritdoc} |
161 | 161 | */ |
162 | - public function getId(){ |
|
163 | - $id = 'sftp::' . $this->user . '@' . $this->host; |
|
162 | + public function getId() { |
|
163 | + $id = 'sftp::'.$this->user.'@'.$this->host; |
|
164 | 164 | if ($this->port !== 22) { |
165 | - $id .= ':' . $this->port; |
|
165 | + $id .= ':'.$this->port; |
|
166 | 166 | } |
167 | 167 | // note: this will double the root slash, |
168 | 168 | // we should not change it to keep compatible with |
169 | 169 | // old storage ids |
170 | - $id .= '/' . $this->root; |
|
170 | + $id .= '/'.$this->root; |
|
171 | 171 | return $id; |
172 | 172 | } |
173 | 173 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @return string |
198 | 198 | */ |
199 | 199 | private function absPath($path) { |
200 | - return $this->root . $this->cleanPath($path); |
|
200 | + return $this->root.$this->cleanPath($path); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | try { |
208 | 208 | $storage_view = \OCP\Files::getStorage('files_external'); |
209 | 209 | if ($storage_view) { |
210 | - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . |
|
211 | - $storage_view->getAbsolutePath('') . |
|
210 | + return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'). |
|
211 | + $storage_view->getAbsolutePath(''). |
|
212 | 212 | 'ssh_hostKeys'; |
213 | 213 | } |
214 | 214 | } catch (\Exception $e) { |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | if ($keyPath && file_exists($keyPath)) { |
227 | 227 | $fp = fopen($keyPath, 'w'); |
228 | 228 | foreach ($keys as $host => $key) { |
229 | - fwrite($fp, $host . '::' . $key . "\n"); |
|
229 | + fwrite($fp, $host.'::'.$key."\n"); |
|
230 | 230 | } |
231 | 231 | fclose($fp); |
232 | 232 | return true; |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | return false; |
299 | 299 | } |
300 | 300 | |
301 | - $id = md5('sftp:' . $path); |
|
301 | + $id = md5('sftp:'.$path); |
|
302 | 302 | $dirStream = array(); |
303 | - foreach($list as $file) { |
|
303 | + foreach ($list as $file) { |
|
304 | 304 | if ($file != '.' && $file != '..') { |
305 | 305 | $dirStream[] = $file; |
306 | 306 | } |
307 | 307 | } |
308 | 308 | return IteratorDirectory::wrap($dirStream); |
309 | - } catch(\Exception $e) { |
|
309 | + } catch (\Exception $e) { |
|
310 | 310 | return false; |
311 | 311 | } |
312 | 312 | } |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | public function fopen($path, $mode) { |
359 | 359 | try { |
360 | 360 | $absPath = $this->absPath($path); |
361 | - switch($mode) { |
|
361 | + switch ($mode) { |
|
362 | 362 | case 'r': |
363 | 363 | case 'rb': |
364 | - if ( !$this->file_exists($path)) { |
|
364 | + if (!$this->file_exists($path)) { |
|
365 | 365 | return false; |
366 | 366 | } |
367 | 367 | case 'w': |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | /** |
389 | 389 | * {@inheritdoc} |
390 | 390 | */ |
391 | - public function touch($path, $mtime=null) { |
|
391 | + public function touch($path, $mtime = null) { |
|
392 | 392 | try { |
393 | 393 | if (!is_null($mtime)) { |
394 | 394 | return false; |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | // Do not pass the password here. We want to use the Net_SFTP object |
464 | 464 | // supplied via stream context or fail. We only supply username and |
465 | 465 | // hostname because this might show up in logs (they are not used). |
466 | - $url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path; |
|
466 | + $url = 'sftp://'.urlencode($this->user).'@'.$this->host.':'.$this->port.$this->root.$path; |
|
467 | 467 | return $url; |
468 | 468 | } |
469 | 469 | } |
@@ -30,101 +30,101 @@ |
||
30 | 30 | |
31 | 31 | abstract class StreamWrapper extends \OC\Files\Storage\Common { |
32 | 32 | |
33 | - /** |
|
34 | - * @param string $path |
|
35 | - * @return string|null |
|
36 | - */ |
|
37 | - abstract public function constructUrl($path); |
|
38 | - |
|
39 | - public function mkdir($path) { |
|
40 | - return mkdir($this->constructUrl($path)); |
|
41 | - } |
|
42 | - |
|
43 | - public function rmdir($path) { |
|
44 | - if ($this->is_dir($path) && $this->isDeletable($path)) { |
|
45 | - $dh = $this->opendir($path); |
|
46 | - if (!is_resource($dh)) { |
|
47 | - return false; |
|
48 | - } |
|
49 | - while (($file = readdir($dh)) !== false) { |
|
50 | - if ($this->is_dir($path . '/' . $file)) { |
|
51 | - $this->rmdir($path . '/' . $file); |
|
52 | - } else { |
|
53 | - $this->unlink($path . '/' . $file); |
|
54 | - } |
|
55 | - } |
|
56 | - $url = $this->constructUrl($path); |
|
57 | - $success = rmdir($url); |
|
58 | - clearstatcache(false, $url); |
|
59 | - return $success; |
|
60 | - } else { |
|
61 | - return false; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public function opendir($path) { |
|
66 | - return opendir($this->constructUrl($path)); |
|
67 | - } |
|
68 | - |
|
69 | - public function filetype($path) { |
|
70 | - return @filetype($this->constructUrl($path)); |
|
71 | - } |
|
72 | - |
|
73 | - public function file_exists($path) { |
|
74 | - return file_exists($this->constructUrl($path)); |
|
75 | - } |
|
76 | - |
|
77 | - public function unlink($path) { |
|
78 | - $url = $this->constructUrl($path); |
|
79 | - $success = unlink($url); |
|
80 | - // normally unlink() is supposed to do this implicitly, |
|
81 | - // but doing it anyway just to be sure |
|
82 | - clearstatcache(false, $url); |
|
83 | - return $success; |
|
84 | - } |
|
85 | - |
|
86 | - public function fopen($path, $mode) { |
|
87 | - return fopen($this->constructUrl($path), $mode); |
|
88 | - } |
|
89 | - |
|
90 | - public function touch($path, $mtime = null) { |
|
91 | - if ($this->file_exists($path)) { |
|
92 | - if (is_null($mtime)) { |
|
93 | - $fh = $this->fopen($path, 'a'); |
|
94 | - fwrite($fh, ''); |
|
95 | - fclose($fh); |
|
96 | - |
|
97 | - return true; |
|
98 | - } else { |
|
99 | - return false; //not supported |
|
100 | - } |
|
101 | - } else { |
|
102 | - $this->file_put_contents($path, ''); |
|
103 | - return true; |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $path |
|
109 | - * @param string $target |
|
110 | - */ |
|
111 | - public function getFile($path, $target) { |
|
112 | - return copy($this->constructUrl($path), $target); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $target |
|
117 | - */ |
|
118 | - public function uploadFile($path, $target) { |
|
119 | - return copy($path, $this->constructUrl($target)); |
|
120 | - } |
|
121 | - |
|
122 | - public function rename($path1, $path2) { |
|
123 | - return rename($this->constructUrl($path1), $this->constructUrl($path2)); |
|
124 | - } |
|
125 | - |
|
126 | - public function stat($path) { |
|
127 | - return stat($this->constructUrl($path)); |
|
128 | - } |
|
33 | + /** |
|
34 | + * @param string $path |
|
35 | + * @return string|null |
|
36 | + */ |
|
37 | + abstract public function constructUrl($path); |
|
38 | + |
|
39 | + public function mkdir($path) { |
|
40 | + return mkdir($this->constructUrl($path)); |
|
41 | + } |
|
42 | + |
|
43 | + public function rmdir($path) { |
|
44 | + if ($this->is_dir($path) && $this->isDeletable($path)) { |
|
45 | + $dh = $this->opendir($path); |
|
46 | + if (!is_resource($dh)) { |
|
47 | + return false; |
|
48 | + } |
|
49 | + while (($file = readdir($dh)) !== false) { |
|
50 | + if ($this->is_dir($path . '/' . $file)) { |
|
51 | + $this->rmdir($path . '/' . $file); |
|
52 | + } else { |
|
53 | + $this->unlink($path . '/' . $file); |
|
54 | + } |
|
55 | + } |
|
56 | + $url = $this->constructUrl($path); |
|
57 | + $success = rmdir($url); |
|
58 | + clearstatcache(false, $url); |
|
59 | + return $success; |
|
60 | + } else { |
|
61 | + return false; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public function opendir($path) { |
|
66 | + return opendir($this->constructUrl($path)); |
|
67 | + } |
|
68 | + |
|
69 | + public function filetype($path) { |
|
70 | + return @filetype($this->constructUrl($path)); |
|
71 | + } |
|
72 | + |
|
73 | + public function file_exists($path) { |
|
74 | + return file_exists($this->constructUrl($path)); |
|
75 | + } |
|
76 | + |
|
77 | + public function unlink($path) { |
|
78 | + $url = $this->constructUrl($path); |
|
79 | + $success = unlink($url); |
|
80 | + // normally unlink() is supposed to do this implicitly, |
|
81 | + // but doing it anyway just to be sure |
|
82 | + clearstatcache(false, $url); |
|
83 | + return $success; |
|
84 | + } |
|
85 | + |
|
86 | + public function fopen($path, $mode) { |
|
87 | + return fopen($this->constructUrl($path), $mode); |
|
88 | + } |
|
89 | + |
|
90 | + public function touch($path, $mtime = null) { |
|
91 | + if ($this->file_exists($path)) { |
|
92 | + if (is_null($mtime)) { |
|
93 | + $fh = $this->fopen($path, 'a'); |
|
94 | + fwrite($fh, ''); |
|
95 | + fclose($fh); |
|
96 | + |
|
97 | + return true; |
|
98 | + } else { |
|
99 | + return false; //not supported |
|
100 | + } |
|
101 | + } else { |
|
102 | + $this->file_put_contents($path, ''); |
|
103 | + return true; |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $path |
|
109 | + * @param string $target |
|
110 | + */ |
|
111 | + public function getFile($path, $target) { |
|
112 | + return copy($this->constructUrl($path), $target); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $target |
|
117 | + */ |
|
118 | + public function uploadFile($path, $target) { |
|
119 | + return copy($path, $this->constructUrl($target)); |
|
120 | + } |
|
121 | + |
|
122 | + public function rename($path1, $path2) { |
|
123 | + return rename($this->constructUrl($path1), $this->constructUrl($path2)); |
|
124 | + } |
|
125 | + |
|
126 | + public function stat($path) { |
|
127 | + return stat($this->constructUrl($path)); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
@@ -47,10 +47,10 @@ |
||
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | while (($file = readdir($dh)) !== false) { |
50 | - if ($this->is_dir($path . '/' . $file)) { |
|
51 | - $this->rmdir($path . '/' . $file); |
|
50 | + if ($this->is_dir($path.'/'.$file)) { |
|
51 | + $this->rmdir($path.'/'.$file); |
|
52 | 52 | } else { |
53 | - $this->unlink($path . '/' . $file); |
|
53 | + $this->unlink($path.'/'.$file); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | $url = $this->constructUrl($path); |
@@ -62,8 +62,7 @@ |
||
62 | 62 | if (substr($root, 0, 1) !== '/'){ |
63 | 63 | $root = '/' . $root; |
64 | 64 | } |
65 | - } |
|
66 | - else{ |
|
65 | + } else{ |
|
67 | 66 | $root = '/'; |
68 | 67 | } |
69 | 68 |
@@ -33,45 +33,45 @@ |
||
33 | 33 | * |
34 | 34 | */ |
35 | 35 | class OwnCloud extends \OC\Files\Storage\DAV{ |
36 | - const OC_URL_SUFFIX = 'remote.php/webdav'; |
|
36 | + const OC_URL_SUFFIX = 'remote.php/webdav'; |
|
37 | 37 | |
38 | - public function __construct($params) { |
|
39 | - // extract context path from host if specified |
|
40 | - // (owncloud install path on host) |
|
41 | - $host = $params['host']; |
|
42 | - // strip protocol |
|
43 | - if (substr($host, 0, 8) == "https://") { |
|
44 | - $host = substr($host, 8); |
|
45 | - $params['secure'] = true; |
|
46 | - } else if (substr($host, 0, 7) == "http://") { |
|
47 | - $host = substr($host, 7); |
|
48 | - $params['secure'] = false; |
|
49 | - } |
|
50 | - $contextPath = ''; |
|
51 | - $hostSlashPos = strpos($host, '/'); |
|
52 | - if ($hostSlashPos !== false){ |
|
53 | - $contextPath = substr($host, $hostSlashPos); |
|
54 | - $host = substr($host, 0, $hostSlashPos); |
|
55 | - } |
|
38 | + public function __construct($params) { |
|
39 | + // extract context path from host if specified |
|
40 | + // (owncloud install path on host) |
|
41 | + $host = $params['host']; |
|
42 | + // strip protocol |
|
43 | + if (substr($host, 0, 8) == "https://") { |
|
44 | + $host = substr($host, 8); |
|
45 | + $params['secure'] = true; |
|
46 | + } else if (substr($host, 0, 7) == "http://") { |
|
47 | + $host = substr($host, 7); |
|
48 | + $params['secure'] = false; |
|
49 | + } |
|
50 | + $contextPath = ''; |
|
51 | + $hostSlashPos = strpos($host, '/'); |
|
52 | + if ($hostSlashPos !== false){ |
|
53 | + $contextPath = substr($host, $hostSlashPos); |
|
54 | + $host = substr($host, 0, $hostSlashPos); |
|
55 | + } |
|
56 | 56 | |
57 | - if (substr($contextPath, -1) !== '/'){ |
|
58 | - $contextPath .= '/'; |
|
59 | - } |
|
57 | + if (substr($contextPath, -1) !== '/'){ |
|
58 | + $contextPath .= '/'; |
|
59 | + } |
|
60 | 60 | |
61 | - if (isset($params['root'])){ |
|
62 | - $root = $params['root']; |
|
63 | - if (substr($root, 0, 1) !== '/'){ |
|
64 | - $root = '/' . $root; |
|
65 | - } |
|
66 | - } |
|
67 | - else{ |
|
68 | - $root = '/'; |
|
69 | - } |
|
61 | + if (isset($params['root'])){ |
|
62 | + $root = $params['root']; |
|
63 | + if (substr($root, 0, 1) !== '/'){ |
|
64 | + $root = '/' . $root; |
|
65 | + } |
|
66 | + } |
|
67 | + else{ |
|
68 | + $root = '/'; |
|
69 | + } |
|
70 | 70 | |
71 | - $params['host'] = $host; |
|
72 | - $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root; |
|
73 | - $params['authType'] = Client::AUTH_BASIC; |
|
71 | + $params['host'] = $host; |
|
72 | + $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root; |
|
73 | + $params['authType'] = Client::AUTH_BASIC; |
|
74 | 74 | |
75 | - parent::__construct($params); |
|
76 | - } |
|
75 | + parent::__construct($params); |
|
76 | + } |
|
77 | 77 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * http://%host/%context/remote.php/webdav/%root |
33 | 33 | * |
34 | 34 | */ |
35 | -class OwnCloud extends \OC\Files\Storage\DAV{ |
|
35 | +class OwnCloud extends \OC\Files\Storage\DAV { |
|
36 | 36 | const OC_URL_SUFFIX = 'remote.php/webdav'; |
37 | 37 | |
38 | 38 | public function __construct($params) { |
@@ -49,27 +49,27 @@ discard block |
||
49 | 49 | } |
50 | 50 | $contextPath = ''; |
51 | 51 | $hostSlashPos = strpos($host, '/'); |
52 | - if ($hostSlashPos !== false){ |
|
52 | + if ($hostSlashPos !== false) { |
|
53 | 53 | $contextPath = substr($host, $hostSlashPos); |
54 | 54 | $host = substr($host, 0, $hostSlashPos); |
55 | 55 | } |
56 | 56 | |
57 | - if (substr($contextPath, -1) !== '/'){ |
|
57 | + if (substr($contextPath, -1) !== '/') { |
|
58 | 58 | $contextPath .= '/'; |
59 | 59 | } |
60 | 60 | |
61 | - if (isset($params['root'])){ |
|
61 | + if (isset($params['root'])) { |
|
62 | 62 | $root = $params['root']; |
63 | - if (substr($root, 0, 1) !== '/'){ |
|
64 | - $root = '/' . $root; |
|
63 | + if (substr($root, 0, 1) !== '/') { |
|
64 | + $root = '/'.$root; |
|
65 | 65 | } |
66 | 66 | } |
67 | - else{ |
|
67 | + else { |
|
68 | 68 | $root = '/'; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $params['host'] = $host; |
72 | - $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root; |
|
72 | + $params['root'] = $contextPath.self::OC_URL_SUFFIX.$root; |
|
73 | 73 | $params['authType'] = Client::AUTH_BASIC; |
74 | 74 | |
75 | 75 | parent::__construct($params); |
@@ -43,28 +43,28 @@ |
||
43 | 43 | */ |
44 | 44 | trait StorageModifierTrait { |
45 | 45 | |
46 | - /** |
|
47 | - * Modify a StorageConfig parameters |
|
48 | - * |
|
49 | - * @param StorageConfig $storage |
|
50 | - * @param IUser $user User the storage is being used as |
|
51 | - * @throws InsufficientDataForMeaningfulAnswerException |
|
52 | - * @throws StorageNotAvailableException |
|
53 | - */ |
|
54 | - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
55 | - } |
|
46 | + /** |
|
47 | + * Modify a StorageConfig parameters |
|
48 | + * |
|
49 | + * @param StorageConfig $storage |
|
50 | + * @param IUser $user User the storage is being used as |
|
51 | + * @throws InsufficientDataForMeaningfulAnswerException |
|
52 | + * @throws StorageNotAvailableException |
|
53 | + */ |
|
54 | + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Wrap a Storage if necessary |
|
59 | - * |
|
60 | - * @param Storage $storage |
|
61 | - * @return Storage |
|
62 | - * @throws InsufficientDataForMeaningfulAnswerException |
|
63 | - * @throws StorageNotAvailableException |
|
64 | - */ |
|
65 | - public function wrapStorage(Storage $storage) { |
|
66 | - return $storage; |
|
67 | - } |
|
57 | + /** |
|
58 | + * Wrap a Storage if necessary |
|
59 | + * |
|
60 | + * @param Storage $storage |
|
61 | + * @return Storage |
|
62 | + * @throws InsufficientDataForMeaningfulAnswerException |
|
63 | + * @throws StorageNotAvailableException |
|
64 | + */ |
|
65 | + public function wrapStorage(Storage $storage) { |
|
66 | + return $storage; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -51,7 +51,7 @@ |
||
51 | 51 | * @throws InsufficientDataForMeaningfulAnswerException |
52 | 52 | * @throws StorageNotAvailableException |
53 | 53 | */ |
54 | - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
54 | + public function manipulateStorageConfig(StorageConfig & $storage, IUser $user = null) { |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -32,58 +32,58 @@ |
||
32 | 32 | * Person mount points can be moved by the user |
33 | 33 | */ |
34 | 34 | class PersonalMount extends MountPoint implements MoveableMount { |
35 | - /** @var UserStoragesService */ |
|
36 | - protected $storagesService; |
|
35 | + /** @var UserStoragesService */ |
|
36 | + protected $storagesService; |
|
37 | 37 | |
38 | - /** @var int */ |
|
39 | - protected $numericStorageId; |
|
38 | + /** @var int */ |
|
39 | + protected $numericStorageId; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param UserStoragesService $storagesService |
|
43 | - * @param int $storageId |
|
44 | - * @param \OCP\Files\Storage $storage |
|
45 | - * @param string $mountpoint |
|
46 | - * @param array $arguments (optional) configuration for the storage backend |
|
47 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
48 | - * @param array $mountOptions mount specific options |
|
49 | - */ |
|
50 | - public function __construct( |
|
51 | - UserStoragesService $storagesService, |
|
52 | - $storageId, |
|
53 | - $storage, |
|
54 | - $mountpoint, |
|
55 | - $arguments = null, |
|
56 | - $loader = null, |
|
57 | - $mountOptions = null |
|
58 | - ) { |
|
59 | - parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions); |
|
60 | - $this->storagesService = $storagesService; |
|
61 | - $this->numericStorageId = $storageId; |
|
62 | - } |
|
41 | + /** |
|
42 | + * @param UserStoragesService $storagesService |
|
43 | + * @param int $storageId |
|
44 | + * @param \OCP\Files\Storage $storage |
|
45 | + * @param string $mountpoint |
|
46 | + * @param array $arguments (optional) configuration for the storage backend |
|
47 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
48 | + * @param array $mountOptions mount specific options |
|
49 | + */ |
|
50 | + public function __construct( |
|
51 | + UserStoragesService $storagesService, |
|
52 | + $storageId, |
|
53 | + $storage, |
|
54 | + $mountpoint, |
|
55 | + $arguments = null, |
|
56 | + $loader = null, |
|
57 | + $mountOptions = null |
|
58 | + ) { |
|
59 | + parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions); |
|
60 | + $this->storagesService = $storagesService; |
|
61 | + $this->numericStorageId = $storageId; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Move the mount point to $target |
|
66 | - * |
|
67 | - * @param string $target the target mount point |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function moveMount($target) { |
|
71 | - $storage = $this->storagesService->getStorage($this->numericStorageId); |
|
72 | - // remove "/$user/files" prefix |
|
73 | - $targetParts = explode('/', trim($target, '/'), 3); |
|
74 | - $storage->setMountPoint($targetParts[2]); |
|
75 | - $this->storagesService->updateStorage($storage); |
|
76 | - $this->setMountPoint($target); |
|
77 | - return true; |
|
78 | - } |
|
64 | + /** |
|
65 | + * Move the mount point to $target |
|
66 | + * |
|
67 | + * @param string $target the target mount point |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function moveMount($target) { |
|
71 | + $storage = $this->storagesService->getStorage($this->numericStorageId); |
|
72 | + // remove "/$user/files" prefix |
|
73 | + $targetParts = explode('/', trim($target, '/'), 3); |
|
74 | + $storage->setMountPoint($targetParts[2]); |
|
75 | + $this->storagesService->updateStorage($storage); |
|
76 | + $this->setMountPoint($target); |
|
77 | + return true; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Remove the mount points |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function removeMount() { |
|
86 | - $this->storagesService->removeStorage($this->numericStorageId); |
|
87 | - return true; |
|
88 | - } |
|
80 | + /** |
|
81 | + * Remove the mount points |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function removeMount() { |
|
86 | + $this->storagesService->removeStorage($this->numericStorageId); |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | } |