@@ -29,8 +29,8 @@ |
||
29 | 29 | */ |
30 | 30 | interface IDeleteGroupBackend { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 14.0.0 |
|
34 | - */ |
|
35 | - public function deleteGroup(string $gid): bool; |
|
32 | + /** |
|
33 | + * @since 14.0.0 |
|
34 | + */ |
|
35 | + public function deleteGroup(string $gid): bool; |
|
36 | 36 | } |
@@ -32,79 +32,79 @@ |
||
32 | 32 | use Sabre\DAV\IFile; |
33 | 33 | |
34 | 34 | class DirectFile implements IFile { |
35 | - /** @var Direct */ |
|
36 | - private $direct; |
|
35 | + /** @var Direct */ |
|
36 | + private $direct; |
|
37 | 37 | |
38 | - /** @var IRootFolder */ |
|
39 | - private $rootFolder; |
|
38 | + /** @var IRootFolder */ |
|
39 | + private $rootFolder; |
|
40 | 40 | |
41 | - /** @var File */ |
|
42 | - private $file; |
|
41 | + /** @var File */ |
|
42 | + private $file; |
|
43 | 43 | |
44 | - public function __construct(Direct $direct, IRootFolder $rootFolder) { |
|
45 | - $this->direct = $direct; |
|
46 | - $this->rootFolder = $rootFolder; |
|
47 | - } |
|
44 | + public function __construct(Direct $direct, IRootFolder $rootFolder) { |
|
45 | + $this->direct = $direct; |
|
46 | + $this->rootFolder = $rootFolder; |
|
47 | + } |
|
48 | 48 | |
49 | - public function put($data) { |
|
50 | - throw new Forbidden(); |
|
51 | - } |
|
49 | + public function put($data) { |
|
50 | + throw new Forbidden(); |
|
51 | + } |
|
52 | 52 | |
53 | - public function get() { |
|
54 | - $this->getFile(); |
|
53 | + public function get() { |
|
54 | + $this->getFile(); |
|
55 | 55 | |
56 | - return $this->file->fopen('rb'); |
|
57 | - } |
|
56 | + return $this->file->fopen('rb'); |
|
57 | + } |
|
58 | 58 | |
59 | - public function getContentType() { |
|
60 | - $this->getFile(); |
|
59 | + public function getContentType() { |
|
60 | + $this->getFile(); |
|
61 | 61 | |
62 | - return $this->file->getMimeType(); |
|
63 | - } |
|
62 | + return $this->file->getMimeType(); |
|
63 | + } |
|
64 | 64 | |
65 | - public function getETag() { |
|
66 | - $this->getFile(); |
|
65 | + public function getETag() { |
|
66 | + $this->getFile(); |
|
67 | 67 | |
68 | - return $this->file->getEtag(); |
|
69 | - } |
|
68 | + return $this->file->getEtag(); |
|
69 | + } |
|
70 | 70 | |
71 | - public function getSize() { |
|
72 | - $this->getFile(); |
|
71 | + public function getSize() { |
|
72 | + $this->getFile(); |
|
73 | 73 | |
74 | - return $this->file->getSize(); |
|
75 | - } |
|
74 | + return $this->file->getSize(); |
|
75 | + } |
|
76 | 76 | |
77 | - public function delete() { |
|
78 | - throw new Forbidden(); |
|
79 | - } |
|
77 | + public function delete() { |
|
78 | + throw new Forbidden(); |
|
79 | + } |
|
80 | 80 | |
81 | - public function getName() { |
|
82 | - return $this->direct->getToken(); |
|
83 | - } |
|
81 | + public function getName() { |
|
82 | + return $this->direct->getToken(); |
|
83 | + } |
|
84 | 84 | |
85 | - public function setName($name) { |
|
86 | - throw new Forbidden(); |
|
87 | - } |
|
85 | + public function setName($name) { |
|
86 | + throw new Forbidden(); |
|
87 | + } |
|
88 | 88 | |
89 | - public function getLastModified() { |
|
90 | - $this->getFile(); |
|
89 | + public function getLastModified() { |
|
90 | + $this->getFile(); |
|
91 | 91 | |
92 | - return $this->file->getMTime(); |
|
93 | - } |
|
92 | + return $this->file->getMTime(); |
|
93 | + } |
|
94 | 94 | |
95 | - private function getFile() { |
|
96 | - if ($this->file === null) { |
|
97 | - $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
98 | - $files = $userFolder->getById($this->direct->getFileId()); |
|
95 | + private function getFile() { |
|
96 | + if ($this->file === null) { |
|
97 | + $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); |
|
98 | + $files = $userFolder->getById($this->direct->getFileId()); |
|
99 | 99 | |
100 | - if ($files === []) { |
|
101 | - throw new NotFound(); |
|
102 | - } |
|
100 | + if ($files === []) { |
|
101 | + throw new NotFound(); |
|
102 | + } |
|
103 | 103 | |
104 | - $this->file = array_shift($files); |
|
105 | - } |
|
104 | + $this->file = array_shift($files); |
|
105 | + } |
|
106 | 106 | |
107 | - return $this->file; |
|
108 | - } |
|
107 | + return $this->file; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
@@ -29,22 +29,22 @@ |
||
29 | 29 | use OCP\AppFramework\Utility\ITimeFactory; |
30 | 30 | |
31 | 31 | class CleanupDirectLinksJob extends TimedJob { |
32 | - /** @var ITimeFactory */ |
|
33 | - private $timeFactory; |
|
32 | + /** @var ITimeFactory */ |
|
33 | + private $timeFactory; |
|
34 | 34 | |
35 | - /** @var DirectMapper */ |
|
36 | - private $mapper; |
|
35 | + /** @var DirectMapper */ |
|
36 | + private $mapper; |
|
37 | 37 | |
38 | - public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) { |
|
39 | - $this->setInterval(60*60*24); |
|
38 | + public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) { |
|
39 | + $this->setInterval(60*60*24); |
|
40 | 40 | |
41 | - $this->timeFactory = $timeFactory; |
|
42 | - $this->mapper = $mapper; |
|
43 | - } |
|
41 | + $this->timeFactory = $timeFactory; |
|
42 | + $this->mapper = $mapper; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function run($argument) { |
|
46 | - // Delete all shares expired 24 hours ago |
|
47 | - $this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24); |
|
48 | - } |
|
45 | + protected function run($argument) { |
|
46 | + // Delete all shares expired 24 hours ago |
|
47 | + $this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | } |
@@ -29,14 +29,14 @@ |
||
29 | 29 | |
30 | 30 | class Errorlog implements IWriter { |
31 | 31 | |
32 | - /** |
|
33 | - * write a message in the log |
|
34 | - * @param string $app |
|
35 | - * @param string $message |
|
36 | - * @param int $level |
|
37 | - */ |
|
38 | - public function write(string $app, $message, int $level) { |
|
39 | - error_log('[owncloud]['.$app.']['.$level.'] '.$message); |
|
40 | - } |
|
32 | + /** |
|
33 | + * write a message in the log |
|
34 | + * @param string $app |
|
35 | + * @param string $message |
|
36 | + * @param int $level |
|
37 | + */ |
|
38 | + public function write(string $app, $message, int $level) { |
|
39 | + error_log('[owncloud]['.$app.']['.$level.'] '.$message); |
|
40 | + } |
|
41 | 41 | } |
42 | 42 |
@@ -30,8 +30,8 @@ |
||
30 | 30 | * @since 14.0.0 |
31 | 31 | */ |
32 | 32 | interface IWriter { |
33 | - /** |
|
34 | - * @since 14.0.0 |
|
35 | - */ |
|
36 | - public function write(string $app, $message, int $level); |
|
33 | + /** |
|
34 | + * @since 14.0.0 |
|
35 | + */ |
|
36 | + public function write(string $app, $message, int $level); |
|
37 | 37 | } |
@@ -31,13 +31,13 @@ |
||
31 | 31 | * @since 14.0.0 |
32 | 32 | */ |
33 | 33 | interface IFileBased { |
34 | - /** |
|
35 | - * @since 14.0.0 |
|
36 | - */ |
|
37 | - public function getLogFilePath():string; |
|
34 | + /** |
|
35 | + * @since 14.0.0 |
|
36 | + */ |
|
37 | + public function getLogFilePath():string; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @since 14.0.0 |
|
41 | - */ |
|
42 | - public function getEntries(int $limit=50, int $offset=0): array; |
|
39 | + /** |
|
40 | + * @since 14.0.0 |
|
41 | + */ |
|
42 | + public function getEntries(int $limit=50, int $offset=0): array; |
|
43 | 43 | } |
@@ -32,40 +32,40 @@ |
||
32 | 32 | */ |
33 | 33 | trait RotationTrait { |
34 | 34 | |
35 | - /** |
|
36 | - * @var string |
|
37 | - * @since 14.0.0 |
|
38 | - */ |
|
39 | - protected $filePath; |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + * @since 14.0.0 |
|
38 | + */ |
|
39 | + protected $filePath; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var int |
|
43 | - * @since 14.0.0 |
|
44 | - */ |
|
45 | - protected $maxSize; |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + * @since 14.0.0 |
|
44 | + */ |
|
45 | + protected $maxSize; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string the resulting new filepath |
|
49 | - * @since 14.0.0 |
|
50 | - */ |
|
51 | - protected function rotate():string { |
|
52 | - $rotatedFile = $this->filePath.'.1'; |
|
53 | - rename($this->filePath, $rotatedFile); |
|
54 | - return $rotatedFile; |
|
55 | - } |
|
47 | + /** |
|
48 | + * @return string the resulting new filepath |
|
49 | + * @since 14.0.0 |
|
50 | + */ |
|
51 | + protected function rotate():string { |
|
52 | + $rotatedFile = $this->filePath.'.1'; |
|
53 | + rename($this->filePath, $rotatedFile); |
|
54 | + return $rotatedFile; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return bool |
|
59 | - * @since 14.0.0 |
|
60 | - */ |
|
61 | - protected function shouldRotateBySize():bool { |
|
62 | - if ((int)$this->maxSize > 0) { |
|
63 | - $filesize = @filesize($this->filePath); |
|
64 | - if ($filesize >= (int)$this->maxSize) { |
|
65 | - return true; |
|
66 | - } |
|
67 | - } |
|
68 | - return false; |
|
69 | - } |
|
57 | + /** |
|
58 | + * @return bool |
|
59 | + * @since 14.0.0 |
|
60 | + */ |
|
61 | + protected function shouldRotateBySize():bool { |
|
62 | + if ((int)$this->maxSize > 0) { |
|
63 | + $filesize = @filesize($this->filePath); |
|
64 | + if ($filesize >= (int)$this->maxSize) { |
|
65 | + return true; |
|
66 | + } |
|
67 | + } |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
@@ -39,75 +39,75 @@ |
||
39 | 39 | |
40 | 40 | class DirectController extends OCSController { |
41 | 41 | |
42 | - /** @var IRootFolder */ |
|
43 | - private $rootFolder; |
|
42 | + /** @var IRootFolder */ |
|
43 | + private $rootFolder; |
|
44 | 44 | |
45 | - /** @var string */ |
|
46 | - private $userId; |
|
45 | + /** @var string */ |
|
46 | + private $userId; |
|
47 | 47 | |
48 | - /** @var DirectMapper */ |
|
49 | - private $mapper; |
|
48 | + /** @var DirectMapper */ |
|
49 | + private $mapper; |
|
50 | 50 | |
51 | - /** @var ISecureRandom */ |
|
52 | - private $random; |
|
51 | + /** @var ISecureRandom */ |
|
52 | + private $random; |
|
53 | 53 | |
54 | - /** @var ITimeFactory */ |
|
55 | - private $timeFactory; |
|
54 | + /** @var ITimeFactory */ |
|
55 | + private $timeFactory; |
|
56 | 56 | |
57 | - /** @var IURLGenerator */ |
|
58 | - private $urlGenerator; |
|
57 | + /** @var IURLGenerator */ |
|
58 | + private $urlGenerator; |
|
59 | 59 | |
60 | 60 | |
61 | - public function __construct(string $appName, |
|
62 | - IRequest $request, |
|
63 | - IRootFolder $rootFolder, |
|
64 | - string $userId, |
|
65 | - DirectMapper $mapper, |
|
66 | - ISecureRandom $random, |
|
67 | - ITimeFactory $timeFactory, |
|
68 | - IURLGenerator $urlGenerator) { |
|
69 | - parent::__construct($appName, $request); |
|
61 | + public function __construct(string $appName, |
|
62 | + IRequest $request, |
|
63 | + IRootFolder $rootFolder, |
|
64 | + string $userId, |
|
65 | + DirectMapper $mapper, |
|
66 | + ISecureRandom $random, |
|
67 | + ITimeFactory $timeFactory, |
|
68 | + IURLGenerator $urlGenerator) { |
|
69 | + parent::__construct($appName, $request); |
|
70 | 70 | |
71 | - $this->rootFolder = $rootFolder; |
|
72 | - $this->userId = $userId; |
|
73 | - $this->mapper = $mapper; |
|
74 | - $this->random = $random; |
|
75 | - $this->timeFactory = $timeFactory; |
|
76 | - $this->urlGenerator = $urlGenerator; |
|
77 | - } |
|
71 | + $this->rootFolder = $rootFolder; |
|
72 | + $this->userId = $userId; |
|
73 | + $this->mapper = $mapper; |
|
74 | + $this->random = $random; |
|
75 | + $this->timeFactory = $timeFactory; |
|
76 | + $this->urlGenerator = $urlGenerator; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @NoAdminRequired |
|
81 | - */ |
|
82 | - public function getUrl(int $fileId): DataResponse { |
|
83 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
79 | + /** |
|
80 | + * @NoAdminRequired |
|
81 | + */ |
|
82 | + public function getUrl(int $fileId): DataResponse { |
|
83 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
84 | 84 | |
85 | - $files = $userFolder->getById($fileId); |
|
85 | + $files = $userFolder->getById($fileId); |
|
86 | 86 | |
87 | - if ($files === []) { |
|
88 | - throw new OCSNotFoundException(); |
|
89 | - } |
|
87 | + if ($files === []) { |
|
88 | + throw new OCSNotFoundException(); |
|
89 | + } |
|
90 | 90 | |
91 | - $file = array_shift($files); |
|
92 | - if (!($file instanceof File)) { |
|
93 | - throw new OCSBadRequestException('Direct download only works for files'); |
|
94 | - } |
|
91 | + $file = array_shift($files); |
|
92 | + if (!($file instanceof File)) { |
|
93 | + throw new OCSBadRequestException('Direct download only works for files'); |
|
94 | + } |
|
95 | 95 | |
96 | - //TODO: at some point we should use the directdownlaod function of storages |
|
97 | - $direct = new Direct(); |
|
98 | - $direct->setUserId($this->userId); |
|
99 | - $direct->setFileId($fileId); |
|
96 | + //TODO: at some point we should use the directdownlaod function of storages |
|
97 | + $direct = new Direct(); |
|
98 | + $direct->setUserId($this->userId); |
|
99 | + $direct->setFileId($fileId); |
|
100 | 100 | |
101 | - $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
102 | - $direct->setToken($token); |
|
103 | - $direct->setExpiration($this->timeFactory->getTime() + 60 * 60 * 8); |
|
101 | + $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
102 | + $direct->setToken($token); |
|
103 | + $direct->setExpiration($this->timeFactory->getTime() + 60 * 60 * 8); |
|
104 | 104 | |
105 | - $this->mapper->insert($direct); |
|
105 | + $this->mapper->insert($direct); |
|
106 | 106 | |
107 | - $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token); |
|
107 | + $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token); |
|
108 | 108 | |
109 | - return new DataResponse([ |
|
110 | - 'url' => $url, |
|
111 | - ]); |
|
112 | - } |
|
109 | + return new DataResponse([ |
|
110 | + 'url' => $url, |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | } |
@@ -37,82 +37,82 @@ |
||
37 | 37 | |
38 | 38 | class DirectHome implements ICollection { |
39 | 39 | |
40 | - /** @var IRootFolder */ |
|
41 | - private $rootFolder; |
|
42 | - |
|
43 | - /** @var DirectMapper */ |
|
44 | - private $mapper; |
|
45 | - |
|
46 | - /** @var ITimeFactory */ |
|
47 | - private $timeFactory; |
|
48 | - |
|
49 | - /** @var Throttler */ |
|
50 | - private $throttler; |
|
51 | - |
|
52 | - /** @var IRequest */ |
|
53 | - private $request; |
|
54 | - |
|
55 | - public function __construct(IRootFolder $rootFolder, |
|
56 | - DirectMapper $mapper, |
|
57 | - ITimeFactory $timeFactory, |
|
58 | - Throttler $throttler, |
|
59 | - IRequest $request) { |
|
60 | - $this->rootFolder = $rootFolder; |
|
61 | - $this->mapper = $mapper; |
|
62 | - $this->timeFactory = $timeFactory; |
|
63 | - $this->throttler = $throttler; |
|
64 | - $this->request = $request; |
|
65 | - } |
|
66 | - |
|
67 | - public function createFile($name, $data = null) { |
|
68 | - throw new Forbidden(); |
|
69 | - } |
|
70 | - |
|
71 | - public function createDirectory($name) { |
|
72 | - throw new Forbidden(); |
|
73 | - } |
|
74 | - |
|
75 | - public function getChild($name): DirectFile { |
|
76 | - try { |
|
77 | - $direct = $this->mapper->getByToken($name); |
|
78 | - |
|
79 | - // Expired |
|
80 | - if ($direct->getExpiration() < $this->timeFactory->getTime()) { |
|
81 | - throw new NotFound(); |
|
82 | - } |
|
83 | - |
|
84 | - return new DirectFile($direct, $this->rootFolder); |
|
85 | - } catch (DoesNotExistException $e) { |
|
86 | - // Since the token space is so huge only throttle on non exsisting token |
|
87 | - $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress()); |
|
88 | - $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink'); |
|
89 | - |
|
90 | - throw new NotFound(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - public function getChildren() { |
|
95 | - throw new MethodNotAllowed('Listing members of this collection is disabled'); |
|
96 | - } |
|
97 | - |
|
98 | - public function childExists($name): bool { |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - public function delete() { |
|
103 | - throw new Forbidden(); |
|
104 | - } |
|
105 | - |
|
106 | - public function getName(): string { |
|
107 | - return 'direct'; |
|
108 | - } |
|
109 | - |
|
110 | - public function setName($name) { |
|
111 | - throw new Forbidden(); |
|
112 | - } |
|
113 | - |
|
114 | - public function getLastModified(): int { |
|
115 | - return 0; |
|
116 | - } |
|
40 | + /** @var IRootFolder */ |
|
41 | + private $rootFolder; |
|
42 | + |
|
43 | + /** @var DirectMapper */ |
|
44 | + private $mapper; |
|
45 | + |
|
46 | + /** @var ITimeFactory */ |
|
47 | + private $timeFactory; |
|
48 | + |
|
49 | + /** @var Throttler */ |
|
50 | + private $throttler; |
|
51 | + |
|
52 | + /** @var IRequest */ |
|
53 | + private $request; |
|
54 | + |
|
55 | + public function __construct(IRootFolder $rootFolder, |
|
56 | + DirectMapper $mapper, |
|
57 | + ITimeFactory $timeFactory, |
|
58 | + Throttler $throttler, |
|
59 | + IRequest $request) { |
|
60 | + $this->rootFolder = $rootFolder; |
|
61 | + $this->mapper = $mapper; |
|
62 | + $this->timeFactory = $timeFactory; |
|
63 | + $this->throttler = $throttler; |
|
64 | + $this->request = $request; |
|
65 | + } |
|
66 | + |
|
67 | + public function createFile($name, $data = null) { |
|
68 | + throw new Forbidden(); |
|
69 | + } |
|
70 | + |
|
71 | + public function createDirectory($name) { |
|
72 | + throw new Forbidden(); |
|
73 | + } |
|
74 | + |
|
75 | + public function getChild($name): DirectFile { |
|
76 | + try { |
|
77 | + $direct = $this->mapper->getByToken($name); |
|
78 | + |
|
79 | + // Expired |
|
80 | + if ($direct->getExpiration() < $this->timeFactory->getTime()) { |
|
81 | + throw new NotFound(); |
|
82 | + } |
|
83 | + |
|
84 | + return new DirectFile($direct, $this->rootFolder); |
|
85 | + } catch (DoesNotExistException $e) { |
|
86 | + // Since the token space is so huge only throttle on non exsisting token |
|
87 | + $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress()); |
|
88 | + $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink'); |
|
89 | + |
|
90 | + throw new NotFound(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + public function getChildren() { |
|
95 | + throw new MethodNotAllowed('Listing members of this collection is disabled'); |
|
96 | + } |
|
97 | + |
|
98 | + public function childExists($name): bool { |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + public function delete() { |
|
103 | + throw new Forbidden(); |
|
104 | + } |
|
105 | + |
|
106 | + public function getName(): string { |
|
107 | + return 'direct'; |
|
108 | + } |
|
109 | + |
|
110 | + public function setName($name) { |
|
111 | + throw new Forbidden(); |
|
112 | + } |
|
113 | + |
|
114 | + public function getLastModified(): int { |
|
115 | + return 0; |
|
116 | + } |
|
117 | 117 | |
118 | 118 | } |