@@ -27,101 +27,101 @@ |
||
27 | 27 | use OCP\Files\Search\ISearchQuery; |
28 | 28 | |
29 | 29 | class NullCache implements ICache { |
30 | - public function getNumericStorageId() { |
|
31 | - return -1; |
|
32 | - } |
|
33 | - |
|
34 | - public function get($file) { |
|
35 | - return $file !== '' ? null : |
|
36 | - new CacheEntry([ |
|
37 | - 'fileid' => -1, |
|
38 | - 'parent' => -1, |
|
39 | - 'name' => '', |
|
40 | - 'path' => '', |
|
41 | - 'size' => '0', |
|
42 | - 'mtime' => time(), |
|
43 | - 'storage_mtime' => time(), |
|
44 | - 'etag' => '', |
|
45 | - 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
46 | - 'mimepart' => 'httpd', |
|
47 | - 'permissions' => Constants::PERMISSION_READ |
|
48 | - ]); |
|
49 | - } |
|
50 | - |
|
51 | - public function getFolderContents($folder) { |
|
52 | - return []; |
|
53 | - } |
|
54 | - |
|
55 | - public function getFolderContentsById($fileId) { |
|
56 | - return []; |
|
57 | - } |
|
58 | - |
|
59 | - public function put($file, array $data) { |
|
60 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
61 | - } |
|
62 | - |
|
63 | - public function insert($file, array $data) { |
|
64 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
65 | - } |
|
66 | - |
|
67 | - public function update($id, array $data) { |
|
68 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
69 | - } |
|
70 | - |
|
71 | - public function getId($file) { |
|
72 | - return -1; |
|
73 | - } |
|
74 | - |
|
75 | - public function getParentId($file) { |
|
76 | - return -1; |
|
77 | - } |
|
78 | - |
|
79 | - public function inCache($file) { |
|
80 | - return $file === ''; |
|
81 | - } |
|
82 | - |
|
83 | - public function remove($file) { |
|
84 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
85 | - } |
|
86 | - |
|
87 | - public function move($source, $target) { |
|
88 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
89 | - } |
|
90 | - |
|
91 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
92 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
93 | - } |
|
94 | - |
|
95 | - public function getStatus($file) { |
|
96 | - return ICache::COMPLETE; |
|
97 | - } |
|
98 | - |
|
99 | - public function search($pattern) { |
|
100 | - return []; |
|
101 | - } |
|
102 | - |
|
103 | - public function searchByMime($mimetype) { |
|
104 | - return []; |
|
105 | - } |
|
106 | - |
|
107 | - public function searchQuery(ISearchQuery $query) { |
|
108 | - return []; |
|
109 | - } |
|
110 | - |
|
111 | - public function searchByTag($tag, $userId) { |
|
112 | - return []; |
|
113 | - } |
|
114 | - |
|
115 | - public function getIncomplete() { |
|
116 | - return []; |
|
117 | - } |
|
118 | - |
|
119 | - public function getPathById($id) { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - |
|
123 | - public function normalize($path) { |
|
124 | - return $path; |
|
125 | - } |
|
30 | + public function getNumericStorageId() { |
|
31 | + return -1; |
|
32 | + } |
|
33 | + |
|
34 | + public function get($file) { |
|
35 | + return $file !== '' ? null : |
|
36 | + new CacheEntry([ |
|
37 | + 'fileid' => -1, |
|
38 | + 'parent' => -1, |
|
39 | + 'name' => '', |
|
40 | + 'path' => '', |
|
41 | + 'size' => '0', |
|
42 | + 'mtime' => time(), |
|
43 | + 'storage_mtime' => time(), |
|
44 | + 'etag' => '', |
|
45 | + 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
46 | + 'mimepart' => 'httpd', |
|
47 | + 'permissions' => Constants::PERMISSION_READ |
|
48 | + ]); |
|
49 | + } |
|
50 | + |
|
51 | + public function getFolderContents($folder) { |
|
52 | + return []; |
|
53 | + } |
|
54 | + |
|
55 | + public function getFolderContentsById($fileId) { |
|
56 | + return []; |
|
57 | + } |
|
58 | + |
|
59 | + public function put($file, array $data) { |
|
60 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
61 | + } |
|
62 | + |
|
63 | + public function insert($file, array $data) { |
|
64 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
65 | + } |
|
66 | + |
|
67 | + public function update($id, array $data) { |
|
68 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
69 | + } |
|
70 | + |
|
71 | + public function getId($file) { |
|
72 | + return -1; |
|
73 | + } |
|
74 | + |
|
75 | + public function getParentId($file) { |
|
76 | + return -1; |
|
77 | + } |
|
78 | + |
|
79 | + public function inCache($file) { |
|
80 | + return $file === ''; |
|
81 | + } |
|
82 | + |
|
83 | + public function remove($file) { |
|
84 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
85 | + } |
|
86 | + |
|
87 | + public function move($source, $target) { |
|
88 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
89 | + } |
|
90 | + |
|
91 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
92 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
93 | + } |
|
94 | + |
|
95 | + public function getStatus($file) { |
|
96 | + return ICache::COMPLETE; |
|
97 | + } |
|
98 | + |
|
99 | + public function search($pattern) { |
|
100 | + return []; |
|
101 | + } |
|
102 | + |
|
103 | + public function searchByMime($mimetype) { |
|
104 | + return []; |
|
105 | + } |
|
106 | + |
|
107 | + public function searchQuery(ISearchQuery $query) { |
|
108 | + return []; |
|
109 | + } |
|
110 | + |
|
111 | + public function searchByTag($tag, $userId) { |
|
112 | + return []; |
|
113 | + } |
|
114 | + |
|
115 | + public function getIncomplete() { |
|
116 | + return []; |
|
117 | + } |
|
118 | + |
|
119 | + public function getPathById($id) { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + |
|
123 | + public function normalize($path) { |
|
124 | + return $path; |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php /** @var $l OC_L10N */ ?> |
2 | 2 | <?php |
3 | 3 | script('core', [ |
4 | - 'jquery-showpassword', |
|
4 | + 'jquery-showpassword', |
|
5 | 5 | ]); |
6 | 6 | script('user_ldap', [ |
7 | - 'renewPassword', |
|
7 | + 'renewPassword', |
|
8 | 8 | ]); |
9 | 9 | style('user_ldap', 'renewPassword'); |
10 | 10 | \OC_Util::addVendorScript('strengthify/jquery.strengthify'); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | <div class="warning title"> |
19 | 19 | <?php p($l->t('Please renew your password.')); ?><br> |
20 | 20 | </div> |
21 | - <?php foreach($_['messages'] as $message): ?> |
|
21 | + <?php foreach ($_['messages'] as $message): ?> |
|
22 | 22 | <div class="warning"> |
23 | 23 | <?php p($message); ?><br> |
24 | 24 | </div> |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | <?php endif; ?> |
32 | 32 | <div id="message" class="hidden"> |
33 | 33 | <img class="float-spinner" alt="" |
34 | - src="<?php p(image_path('core', 'loading-dark.gif'));?>"> |
|
34 | + src="<?php p(image_path('core', 'loading-dark.gif')); ?>"> |
|
35 | 35 | <span id="messageText"></span> |
36 | 36 | <!-- the following div ensures that the spinner is always inside the #message div --> |
37 | 37 | <div style="clear: both;"></div> |
38 | 38 | </div> |
39 | 39 | <p class="grouptop"> |
40 | 40 | <input type="password" id="oldPassword" name="oldPassword" |
41 | - placeholder="<?php echo $l->t('Current password');?>" |
|
41 | + placeholder="<?php echo $l->t('Current password'); ?>" |
|
42 | 42 | autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
43 | 43 | <label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label> |
44 | 44 | </p> |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | <input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label> |
48 | 48 | <label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label> |
49 | 49 | <input type="password" id="newPassword" name="newPassword" |
50 | - placeholder="<?php echo $l->t('New password');?>" |
|
50 | + placeholder="<?php echo $l->t('New password'); ?>" |
|
51 | 51 | data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
52 | 52 | </p> |
53 | 53 |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | $updatedEntries = $builder->execute(); |
73 | 73 | if ($updatedEntries > 0) { |
74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
74 | + $out->info('Fixed file share permissions for '.$updatedEntries.' shares'); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if ($deletedEntries) { |
110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
110 | + $out->info('Removed '.$deletedEntries.' shares where the parent did not exist'); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 |
@@ -33,90 +33,90 @@ |
||
33 | 33 | */ |
34 | 34 | class RepairInvalidShares implements IRepairStep { |
35 | 35 | |
36 | - const CHUNK_SIZE = 200; |
|
37 | - |
|
38 | - /** @var \OCP\IConfig */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** @var \OCP\IDBConnection */ |
|
42 | - protected $connection; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param \OCP\IConfig $config |
|
46 | - * @param \OCP\IDBConnection $connection |
|
47 | - */ |
|
48 | - public function __construct($config, $connection) { |
|
49 | - $this->connection = $connection; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
52 | - |
|
53 | - public function getName() { |
|
54 | - return 'Repair invalid shares'; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Adjust file share permissions |
|
59 | - * @suppress SqlInjectionChecker |
|
60 | - */ |
|
61 | - private function adjustFileSharePermissions(IOutput $out) { |
|
62 | - $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | - $builder = $this->connection->getQueryBuilder(); |
|
64 | - |
|
65 | - $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | - $builder |
|
67 | - ->update('share') |
|
68 | - ->set('permissions', $permsFunc) |
|
69 | - ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | - ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | - |
|
72 | - $updatedEntries = $builder->execute(); |
|
73 | - if ($updatedEntries > 0) { |
|
74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Remove shares where the parent share does not exist anymore |
|
80 | - */ |
|
81 | - private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | - $deletedEntries = 0; |
|
83 | - |
|
84 | - $query = $this->connection->getQueryBuilder(); |
|
85 | - $query->select('s1.parent') |
|
86 | - ->from('share', 's1') |
|
87 | - ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | - ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | - ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | - ->groupBy('s1.parent') |
|
91 | - ->setMaxResults(self::CHUNK_SIZE); |
|
92 | - |
|
93 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | - $deleteQuery->delete('share') |
|
95 | - ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | - |
|
97 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | - $deletedInLastChunk = 0; |
|
100 | - $result = $query->execute(); |
|
101 | - while ($row = $result->fetch()) { |
|
102 | - $deletedInLastChunk++; |
|
103 | - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | - ->execute(); |
|
105 | - } |
|
106 | - $result->closeCursor(); |
|
107 | - } |
|
108 | - |
|
109 | - if ($deletedEntries) { |
|
110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - public function run(IOutput $out) { |
|
115 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | - $this->adjustFileSharePermissions($out); |
|
118 | - } |
|
119 | - |
|
120 | - $this->removeSharesNonExistingParent($out); |
|
121 | - } |
|
36 | + const CHUNK_SIZE = 200; |
|
37 | + |
|
38 | + /** @var \OCP\IConfig */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** @var \OCP\IDBConnection */ |
|
42 | + protected $connection; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param \OCP\IConfig $config |
|
46 | + * @param \OCP\IDBConnection $connection |
|
47 | + */ |
|
48 | + public function __construct($config, $connection) { |
|
49 | + $this->connection = $connection; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | + |
|
53 | + public function getName() { |
|
54 | + return 'Repair invalid shares'; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Adjust file share permissions |
|
59 | + * @suppress SqlInjectionChecker |
|
60 | + */ |
|
61 | + private function adjustFileSharePermissions(IOutput $out) { |
|
62 | + $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
63 | + $builder = $this->connection->getQueryBuilder(); |
|
64 | + |
|
65 | + $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
66 | + $builder |
|
67 | + ->update('share') |
|
68 | + ->set('permissions', $permsFunc) |
|
69 | + ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
70 | + ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
71 | + |
|
72 | + $updatedEntries = $builder->execute(); |
|
73 | + if ($updatedEntries > 0) { |
|
74 | + $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Remove shares where the parent share does not exist anymore |
|
80 | + */ |
|
81 | + private function removeSharesNonExistingParent(IOutput $out) { |
|
82 | + $deletedEntries = 0; |
|
83 | + |
|
84 | + $query = $this->connection->getQueryBuilder(); |
|
85 | + $query->select('s1.parent') |
|
86 | + ->from('share', 's1') |
|
87 | + ->where($query->expr()->isNotNull('s1.parent')) |
|
88 | + ->andWhere($query->expr()->isNull('s2.id')) |
|
89 | + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
90 | + ->groupBy('s1.parent') |
|
91 | + ->setMaxResults(self::CHUNK_SIZE); |
|
92 | + |
|
93 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
94 | + $deleteQuery->delete('share') |
|
95 | + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
96 | + |
|
97 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
98 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
99 | + $deletedInLastChunk = 0; |
|
100 | + $result = $query->execute(); |
|
101 | + while ($row = $result->fetch()) { |
|
102 | + $deletedInLastChunk++; |
|
103 | + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
104 | + ->execute(); |
|
105 | + } |
|
106 | + $result->closeCursor(); |
|
107 | + } |
|
108 | + |
|
109 | + if ($deletedEntries) { |
|
110 | + $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + public function run(IOutput $out) { |
|
115 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
116 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
117 | + $this->adjustFileSharePermissions($out); |
|
118 | + } |
|
119 | + |
|
120 | + $this->removeSharesNonExistingParent($out); |
|
121 | + } |
|
122 | 122 | } |
@@ -194,6 +194,9 @@ |
||
194 | 194 | parent::propPatch($propPatch); |
195 | 195 | } |
196 | 196 | |
197 | + /** |
|
198 | + * @return string |
|
199 | + */ |
|
197 | 200 | public function getContactsGroups() { |
198 | 201 | return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
199 | 202 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | public function getACL() { |
102 | - $acl = [ |
|
102 | + $acl = [ |
|
103 | 103 | [ |
104 | 104 | 'privilege' => '{DAV:}read', |
105 | 105 | 'principal' => $this->getOwner(), |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | 'protected' => true, |
112 | 112 | ]; |
113 | 113 | if ($this->getOwner() !== parent::getOwner()) { |
114 | - $acl[] = [ |
|
114 | + $acl[] = [ |
|
115 | 115 | 'privilege' => '{DAV:}read', |
116 | 116 | 'principal' => parent::getOwner(), |
117 | 117 | 'protected' => true, |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | public function delete() { |
172 | 172 | if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
173 | - $principal = 'principal:' . parent::getOwner(); |
|
173 | + $principal = 'principal:'.parent::getOwner(); |
|
174 | 174 | $shares = $this->carddavBackend->getShares($this->getResourceId()); |
175 | 175 | $shares = array_filter($shares, function($share) use ($principal){ |
176 | 176 | return $share['href'] === $principal; |
@@ -38,179 +38,179 @@ |
||
38 | 38 | */ |
39 | 39 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
40 | 40 | |
41 | - /** |
|
42 | - * AddressBook constructor. |
|
43 | - * |
|
44 | - * @param BackendInterface $carddavBackend |
|
45 | - * @param array $addressBookInfo |
|
46 | - * @param IL10N $l10n |
|
47 | - */ |
|
48 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
49 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
50 | - |
|
51 | - if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
52 | - $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
53 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Updates the list of shares. |
|
59 | - * |
|
60 | - * The first array is a list of people that are to be added to the |
|
61 | - * addressbook. |
|
62 | - * |
|
63 | - * Every element in the add array has the following properties: |
|
64 | - * * href - A url. Usually a mailto: address |
|
65 | - * * commonName - Usually a first and last name, or false |
|
66 | - * * summary - A description of the share, can also be false |
|
67 | - * * readOnly - A boolean value |
|
68 | - * |
|
69 | - * Every element in the remove array is just the address string. |
|
70 | - * |
|
71 | - * @param array $add |
|
72 | - * @param array $remove |
|
73 | - * @return void |
|
74 | - * @throws Forbidden |
|
75 | - */ |
|
76 | - public function updateShares(array $add, array $remove) { |
|
77 | - if ($this->isShared()) { |
|
78 | - throw new Forbidden(); |
|
79 | - } |
|
80 | - $this->carddavBackend->updateShares($this, $add, $remove); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns the list of people whom this addressbook is shared with. |
|
85 | - * |
|
86 | - * Every element in this array should have the following properties: |
|
87 | - * * href - Often a mailto: address |
|
88 | - * * commonName - Optional, for example a first + last name |
|
89 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
90 | - * * readOnly - boolean |
|
91 | - * * summary - Optional, a description for the share |
|
92 | - * |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public function getShares() { |
|
96 | - if ($this->isShared()) { |
|
97 | - return []; |
|
98 | - } |
|
99 | - return $this->carddavBackend->getShares($this->getResourceId()); |
|
100 | - } |
|
101 | - |
|
102 | - public function getACL() { |
|
103 | - $acl = [ |
|
104 | - [ |
|
105 | - 'privilege' => '{DAV:}read', |
|
106 | - 'principal' => $this->getOwner(), |
|
107 | - 'protected' => true, |
|
108 | - ]]; |
|
109 | - $acl[] = [ |
|
110 | - 'privilege' => '{DAV:}write', |
|
111 | - 'principal' => $this->getOwner(), |
|
112 | - 'protected' => true, |
|
113 | - ]; |
|
114 | - if ($this->getOwner() !== parent::getOwner()) { |
|
115 | - $acl[] = [ |
|
116 | - 'privilege' => '{DAV:}read', |
|
117 | - 'principal' => parent::getOwner(), |
|
118 | - 'protected' => true, |
|
119 | - ]; |
|
120 | - if ($this->canWrite()) { |
|
121 | - $acl[] = [ |
|
122 | - 'privilege' => '{DAV:}write', |
|
123 | - 'principal' => parent::getOwner(), |
|
124 | - 'protected' => true, |
|
125 | - ]; |
|
126 | - } |
|
127 | - } |
|
128 | - if ($this->getOwner() === 'principals/system/system') { |
|
129 | - $acl[] = [ |
|
130 | - 'privilege' => '{DAV:}read', |
|
131 | - 'principal' => '{DAV:}authenticated', |
|
132 | - 'protected' => true, |
|
133 | - ]; |
|
134 | - } |
|
135 | - |
|
136 | - if ($this->isShared()) { |
|
137 | - return $acl; |
|
138 | - } |
|
139 | - |
|
140 | - return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
141 | - } |
|
142 | - |
|
143 | - public function getChildACL() { |
|
144 | - return $this->getACL(); |
|
145 | - } |
|
146 | - |
|
147 | - public function getChild($name) { |
|
148 | - |
|
149 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
150 | - if (!$obj) { |
|
151 | - throw new NotFound('Card not found'); |
|
152 | - } |
|
153 | - $obj['acl'] = $this->getChildACL(); |
|
154 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int |
|
160 | - */ |
|
161 | - public function getResourceId() { |
|
162 | - return $this->addressBookInfo['id']; |
|
163 | - } |
|
164 | - |
|
165 | - public function getOwner() { |
|
166 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
167 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
168 | - } |
|
169 | - return parent::getOwner(); |
|
170 | - } |
|
171 | - |
|
172 | - public function delete() { |
|
173 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
174 | - $principal = 'principal:' . parent::getOwner(); |
|
175 | - $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
176 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
177 | - return $share['href'] === $principal; |
|
178 | - }); |
|
179 | - if (empty($shares)) { |
|
180 | - throw new Forbidden(); |
|
181 | - } |
|
182 | - |
|
183 | - $this->carddavBackend->updateShares($this, [], [ |
|
184 | - $principal |
|
185 | - ]); |
|
186 | - return; |
|
187 | - } |
|
188 | - parent::delete(); |
|
189 | - } |
|
190 | - |
|
191 | - public function propPatch(PropPatch $propPatch) { |
|
192 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
193 | - throw new Forbidden(); |
|
194 | - } |
|
195 | - parent::propPatch($propPatch); |
|
196 | - } |
|
197 | - |
|
198 | - public function getContactsGroups() { |
|
199 | - return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
200 | - } |
|
201 | - |
|
202 | - private function isShared() { |
|
203 | - if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
208 | - } |
|
209 | - |
|
210 | - private function canWrite() { |
|
211 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
212 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
213 | - } |
|
214 | - return true; |
|
215 | - } |
|
41 | + /** |
|
42 | + * AddressBook constructor. |
|
43 | + * |
|
44 | + * @param BackendInterface $carddavBackend |
|
45 | + * @param array $addressBookInfo |
|
46 | + * @param IL10N $l10n |
|
47 | + */ |
|
48 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
49 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
50 | + |
|
51 | + if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
52 | + $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
53 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Updates the list of shares. |
|
59 | + * |
|
60 | + * The first array is a list of people that are to be added to the |
|
61 | + * addressbook. |
|
62 | + * |
|
63 | + * Every element in the add array has the following properties: |
|
64 | + * * href - A url. Usually a mailto: address |
|
65 | + * * commonName - Usually a first and last name, or false |
|
66 | + * * summary - A description of the share, can also be false |
|
67 | + * * readOnly - A boolean value |
|
68 | + * |
|
69 | + * Every element in the remove array is just the address string. |
|
70 | + * |
|
71 | + * @param array $add |
|
72 | + * @param array $remove |
|
73 | + * @return void |
|
74 | + * @throws Forbidden |
|
75 | + */ |
|
76 | + public function updateShares(array $add, array $remove) { |
|
77 | + if ($this->isShared()) { |
|
78 | + throw new Forbidden(); |
|
79 | + } |
|
80 | + $this->carddavBackend->updateShares($this, $add, $remove); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns the list of people whom this addressbook is shared with. |
|
85 | + * |
|
86 | + * Every element in this array should have the following properties: |
|
87 | + * * href - Often a mailto: address |
|
88 | + * * commonName - Optional, for example a first + last name |
|
89 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
90 | + * * readOnly - boolean |
|
91 | + * * summary - Optional, a description for the share |
|
92 | + * |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public function getShares() { |
|
96 | + if ($this->isShared()) { |
|
97 | + return []; |
|
98 | + } |
|
99 | + return $this->carddavBackend->getShares($this->getResourceId()); |
|
100 | + } |
|
101 | + |
|
102 | + public function getACL() { |
|
103 | + $acl = [ |
|
104 | + [ |
|
105 | + 'privilege' => '{DAV:}read', |
|
106 | + 'principal' => $this->getOwner(), |
|
107 | + 'protected' => true, |
|
108 | + ]]; |
|
109 | + $acl[] = [ |
|
110 | + 'privilege' => '{DAV:}write', |
|
111 | + 'principal' => $this->getOwner(), |
|
112 | + 'protected' => true, |
|
113 | + ]; |
|
114 | + if ($this->getOwner() !== parent::getOwner()) { |
|
115 | + $acl[] = [ |
|
116 | + 'privilege' => '{DAV:}read', |
|
117 | + 'principal' => parent::getOwner(), |
|
118 | + 'protected' => true, |
|
119 | + ]; |
|
120 | + if ($this->canWrite()) { |
|
121 | + $acl[] = [ |
|
122 | + 'privilege' => '{DAV:}write', |
|
123 | + 'principal' => parent::getOwner(), |
|
124 | + 'protected' => true, |
|
125 | + ]; |
|
126 | + } |
|
127 | + } |
|
128 | + if ($this->getOwner() === 'principals/system/system') { |
|
129 | + $acl[] = [ |
|
130 | + 'privilege' => '{DAV:}read', |
|
131 | + 'principal' => '{DAV:}authenticated', |
|
132 | + 'protected' => true, |
|
133 | + ]; |
|
134 | + } |
|
135 | + |
|
136 | + if ($this->isShared()) { |
|
137 | + return $acl; |
|
138 | + } |
|
139 | + |
|
140 | + return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
141 | + } |
|
142 | + |
|
143 | + public function getChildACL() { |
|
144 | + return $this->getACL(); |
|
145 | + } |
|
146 | + |
|
147 | + public function getChild($name) { |
|
148 | + |
|
149 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
150 | + if (!$obj) { |
|
151 | + throw new NotFound('Card not found'); |
|
152 | + } |
|
153 | + $obj['acl'] = $this->getChildACL(); |
|
154 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int |
|
160 | + */ |
|
161 | + public function getResourceId() { |
|
162 | + return $this->addressBookInfo['id']; |
|
163 | + } |
|
164 | + |
|
165 | + public function getOwner() { |
|
166 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
167 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
168 | + } |
|
169 | + return parent::getOwner(); |
|
170 | + } |
|
171 | + |
|
172 | + public function delete() { |
|
173 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
174 | + $principal = 'principal:' . parent::getOwner(); |
|
175 | + $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
176 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
177 | + return $share['href'] === $principal; |
|
178 | + }); |
|
179 | + if (empty($shares)) { |
|
180 | + throw new Forbidden(); |
|
181 | + } |
|
182 | + |
|
183 | + $this->carddavBackend->updateShares($this, [], [ |
|
184 | + $principal |
|
185 | + ]); |
|
186 | + return; |
|
187 | + } |
|
188 | + parent::delete(); |
|
189 | + } |
|
190 | + |
|
191 | + public function propPatch(PropPatch $propPatch) { |
|
192 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
193 | + throw new Forbidden(); |
|
194 | + } |
|
195 | + parent::propPatch($propPatch); |
|
196 | + } |
|
197 | + |
|
198 | + public function getContactsGroups() { |
|
199 | + return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
200 | + } |
|
201 | + |
|
202 | + private function isShared() { |
|
203 | + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
208 | + } |
|
209 | + |
|
210 | + private function canWrite() { |
|
211 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
212 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
213 | + } |
|
214 | + return true; |
|
215 | + } |
|
216 | 216 | } |
@@ -38,139 +38,139 @@ |
||
38 | 38 | |
39 | 39 | class DecryptAll extends Command { |
40 | 40 | |
41 | - /** @var IManager */ |
|
42 | - protected $encryptionManager; |
|
43 | - |
|
44 | - /** @var IAppManager */ |
|
45 | - protected $appManager; |
|
46 | - |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - |
|
50 | - /** @var QuestionHelper */ |
|
51 | - protected $questionHelper; |
|
52 | - |
|
53 | - /** @var bool */ |
|
54 | - protected $wasTrashbinEnabled; |
|
55 | - |
|
56 | - /** @var bool */ |
|
57 | - protected $wasMaintenanceModeEnabled; |
|
58 | - |
|
59 | - /** @var \OC\Encryption\DecryptAll */ |
|
60 | - protected $decryptAll; |
|
61 | - |
|
62 | - /** |
|
63 | - * @param IManager $encryptionManager |
|
64 | - * @param IAppManager $appManager |
|
65 | - * @param IConfig $config |
|
66 | - * @param \OC\Encryption\DecryptAll $decryptAll |
|
67 | - * @param QuestionHelper $questionHelper |
|
68 | - */ |
|
69 | - public function __construct( |
|
70 | - IManager $encryptionManager, |
|
71 | - IAppManager $appManager, |
|
72 | - IConfig $config, |
|
73 | - \OC\Encryption\DecryptAll $decryptAll, |
|
74 | - QuestionHelper $questionHelper |
|
75 | - ) { |
|
76 | - parent::__construct(); |
|
77 | - |
|
78 | - $this->appManager = $appManager; |
|
79 | - $this->encryptionManager = $encryptionManager; |
|
80 | - $this->config = $config; |
|
81 | - $this->decryptAll = $decryptAll; |
|
82 | - $this->questionHelper = $questionHelper; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Set maintenance mode and disable the trashbin app |
|
87 | - */ |
|
88 | - protected function forceMaintenanceAndTrashbin() { |
|
89 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
90 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
91 | - $this->config->setSystemValue('maintenance', true); |
|
92 | - $this->appManager->disableApp('files_trashbin'); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Reset the maintenance mode and re-enable the trashbin app |
|
97 | - */ |
|
98 | - protected function resetMaintenanceAndTrashbin() { |
|
99 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
100 | - if ($this->wasTrashbinEnabled) { |
|
101 | - $this->appManager->enableApp('files_trashbin'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - protected function configure() { |
|
106 | - parent::configure(); |
|
107 | - |
|
108 | - $this->setName('encryption:decrypt-all'); |
|
109 | - $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
110 | - $this->setHelp( |
|
111 | - 'This will disable server-side encryption and decrypt all files for ' |
|
112 | - . 'all users if it is supported by your encryption module. ' |
|
113 | - . 'Please make sure that no user access his files during this process!' |
|
114 | - ); |
|
115 | - $this->addArgument( |
|
116 | - 'user', |
|
117 | - InputArgument::OPTIONAL, |
|
118 | - 'user for which you want to decrypt all files (optional)', |
|
119 | - '' |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
124 | - |
|
125 | - try { |
|
126 | - if ($this->encryptionManager->isEnabled() === true) { |
|
127 | - $output->write('Disable server side encryption... '); |
|
128 | - $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
129 | - $output->writeln('done.'); |
|
130 | - } else { |
|
131 | - $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - $uid = $input->getArgument('user'); |
|
136 | - if ($uid === '') { |
|
137 | - $message = 'your Nextcloud'; |
|
138 | - } else { |
|
139 | - $message = "$uid's account"; |
|
140 | - } |
|
141 | - |
|
142 | - $output->writeln("\n"); |
|
143 | - $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
144 | - $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
145 | - $output->writeln('Depending on the number and size of your files this can take some time'); |
|
146 | - $output->writeln('Please make sure that no user access his files during this process!'); |
|
147 | - $output->writeln(''); |
|
148 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
149 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
150 | - $this->forceMaintenanceAndTrashbin(); |
|
151 | - $user = $input->getArgument('user'); |
|
152 | - $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
153 | - if ($result === false) { |
|
154 | - $output->writeln(' aborted.'); |
|
155 | - $output->writeln('Server side encryption remains enabled'); |
|
156 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
157 | - } else if ($uid !== '') { |
|
158 | - $output->writeln('Server side encryption remains enabled'); |
|
159 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
160 | - } |
|
161 | - $this->resetMaintenanceAndTrashbin(); |
|
162 | - } else { |
|
163 | - $output->write('Enable server side encryption... '); |
|
164 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
165 | - $output->writeln('done.'); |
|
166 | - $output->writeln('aborted'); |
|
167 | - } |
|
168 | - } catch (\Exception $e) { |
|
169 | - // enable server side encryption again if something went wrong |
|
170 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
171 | - $this->resetMaintenanceAndTrashbin(); |
|
172 | - throw $e; |
|
173 | - } |
|
174 | - |
|
175 | - } |
|
41 | + /** @var IManager */ |
|
42 | + protected $encryptionManager; |
|
43 | + |
|
44 | + /** @var IAppManager */ |
|
45 | + protected $appManager; |
|
46 | + |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + |
|
50 | + /** @var QuestionHelper */ |
|
51 | + protected $questionHelper; |
|
52 | + |
|
53 | + /** @var bool */ |
|
54 | + protected $wasTrashbinEnabled; |
|
55 | + |
|
56 | + /** @var bool */ |
|
57 | + protected $wasMaintenanceModeEnabled; |
|
58 | + |
|
59 | + /** @var \OC\Encryption\DecryptAll */ |
|
60 | + protected $decryptAll; |
|
61 | + |
|
62 | + /** |
|
63 | + * @param IManager $encryptionManager |
|
64 | + * @param IAppManager $appManager |
|
65 | + * @param IConfig $config |
|
66 | + * @param \OC\Encryption\DecryptAll $decryptAll |
|
67 | + * @param QuestionHelper $questionHelper |
|
68 | + */ |
|
69 | + public function __construct( |
|
70 | + IManager $encryptionManager, |
|
71 | + IAppManager $appManager, |
|
72 | + IConfig $config, |
|
73 | + \OC\Encryption\DecryptAll $decryptAll, |
|
74 | + QuestionHelper $questionHelper |
|
75 | + ) { |
|
76 | + parent::__construct(); |
|
77 | + |
|
78 | + $this->appManager = $appManager; |
|
79 | + $this->encryptionManager = $encryptionManager; |
|
80 | + $this->config = $config; |
|
81 | + $this->decryptAll = $decryptAll; |
|
82 | + $this->questionHelper = $questionHelper; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Set maintenance mode and disable the trashbin app |
|
87 | + */ |
|
88 | + protected function forceMaintenanceAndTrashbin() { |
|
89 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
90 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
91 | + $this->config->setSystemValue('maintenance', true); |
|
92 | + $this->appManager->disableApp('files_trashbin'); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Reset the maintenance mode and re-enable the trashbin app |
|
97 | + */ |
|
98 | + protected function resetMaintenanceAndTrashbin() { |
|
99 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
100 | + if ($this->wasTrashbinEnabled) { |
|
101 | + $this->appManager->enableApp('files_trashbin'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + protected function configure() { |
|
106 | + parent::configure(); |
|
107 | + |
|
108 | + $this->setName('encryption:decrypt-all'); |
|
109 | + $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
110 | + $this->setHelp( |
|
111 | + 'This will disable server-side encryption and decrypt all files for ' |
|
112 | + . 'all users if it is supported by your encryption module. ' |
|
113 | + . 'Please make sure that no user access his files during this process!' |
|
114 | + ); |
|
115 | + $this->addArgument( |
|
116 | + 'user', |
|
117 | + InputArgument::OPTIONAL, |
|
118 | + 'user for which you want to decrypt all files (optional)', |
|
119 | + '' |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
124 | + |
|
125 | + try { |
|
126 | + if ($this->encryptionManager->isEnabled() === true) { |
|
127 | + $output->write('Disable server side encryption... '); |
|
128 | + $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
129 | + $output->writeln('done.'); |
|
130 | + } else { |
|
131 | + $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + $uid = $input->getArgument('user'); |
|
136 | + if ($uid === '') { |
|
137 | + $message = 'your Nextcloud'; |
|
138 | + } else { |
|
139 | + $message = "$uid's account"; |
|
140 | + } |
|
141 | + |
|
142 | + $output->writeln("\n"); |
|
143 | + $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
144 | + $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
145 | + $output->writeln('Depending on the number and size of your files this can take some time'); |
|
146 | + $output->writeln('Please make sure that no user access his files during this process!'); |
|
147 | + $output->writeln(''); |
|
148 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
149 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
150 | + $this->forceMaintenanceAndTrashbin(); |
|
151 | + $user = $input->getArgument('user'); |
|
152 | + $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
153 | + if ($result === false) { |
|
154 | + $output->writeln(' aborted.'); |
|
155 | + $output->writeln('Server side encryption remains enabled'); |
|
156 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
157 | + } else if ($uid !== '') { |
|
158 | + $output->writeln('Server side encryption remains enabled'); |
|
159 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
160 | + } |
|
161 | + $this->resetMaintenanceAndTrashbin(); |
|
162 | + } else { |
|
163 | + $output->write('Enable server side encryption... '); |
|
164 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
165 | + $output->writeln('done.'); |
|
166 | + $output->writeln('aborted'); |
|
167 | + } |
|
168 | + } catch (\Exception $e) { |
|
169 | + // enable server side encryption again if something went wrong |
|
170 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
171 | + $this->resetMaintenanceAndTrashbin(); |
|
172 | + throw $e; |
|
173 | + } |
|
174 | + |
|
175 | + } |
|
176 | 176 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ], |
55 | 55 | ]; |
56 | 56 | |
57 | - if($this->appManager->isEnabledForUser('files_sharing')) { |
|
57 | + if ($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | 58 | $services['SHARING'] = [ |
59 | 59 | 'version' => 1, |
60 | 60 | 'endpoints' => [ |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if($this->appManager->isEnabledForUser('activity')) { |
|
88 | + if ($this->appManager->isEnabledForUser('activity')) { |
|
89 | 89 | $services['ACTIVITY'] = [ |
90 | 90 | 'version' => 1, |
91 | 91 | 'endpoints' => [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ]; |
95 | 95 | } |
96 | 96 | |
97 | - if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
97 | + if ($this->appManager->isEnabledForUser('provisioning_api')) { |
|
98 | 98 | $services['PROVISIONING'] = [ |
99 | 99 | 'version' => 1, |
100 | 100 | 'endpoints' => [ |
@@ -24,92 +24,92 @@ |
||
24 | 24 | namespace OC\OCS; |
25 | 25 | |
26 | 26 | class Provider extends \OCP\AppFramework\Controller { |
27 | - /** @var \OCP\App\IAppManager */ |
|
28 | - private $appManager; |
|
27 | + /** @var \OCP\App\IAppManager */ |
|
28 | + private $appManager; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $appName |
|
32 | - * @param \OCP\IRequest $request |
|
33 | - * @param \OCP\App\IAppManager $appManager |
|
34 | - */ |
|
35 | - public function __construct($appName, |
|
36 | - \OCP\IRequest $request, |
|
37 | - \OCP\App\IAppManager $appManager) { |
|
38 | - parent::__construct($appName, $request); |
|
39 | - $this->appManager = $appManager; |
|
40 | - } |
|
30 | + /** |
|
31 | + * @param string $appName |
|
32 | + * @param \OCP\IRequest $request |
|
33 | + * @param \OCP\App\IAppManager $appManager |
|
34 | + */ |
|
35 | + public function __construct($appName, |
|
36 | + \OCP\IRequest $request, |
|
37 | + \OCP\App\IAppManager $appManager) { |
|
38 | + parent::__construct($appName, $request); |
|
39 | + $this->appManager = $appManager; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return \OCP\AppFramework\Http\JSONResponse |
|
44 | - */ |
|
45 | - public function buildProviderList() { |
|
46 | - $services = [ |
|
47 | - 'PRIVATE_DATA' => [ |
|
48 | - 'version' => 1, |
|
49 | - 'endpoints' => [ |
|
50 | - 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
51 | - 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
52 | - 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
53 | - ], |
|
54 | - ], |
|
55 | - ]; |
|
42 | + /** |
|
43 | + * @return \OCP\AppFramework\Http\JSONResponse |
|
44 | + */ |
|
45 | + public function buildProviderList() { |
|
46 | + $services = [ |
|
47 | + 'PRIVATE_DATA' => [ |
|
48 | + 'version' => 1, |
|
49 | + 'endpoints' => [ |
|
50 | + 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
51 | + 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
52 | + 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
53 | + ], |
|
54 | + ], |
|
55 | + ]; |
|
56 | 56 | |
57 | - if($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | - $services['SHARING'] = [ |
|
59 | - 'version' => 1, |
|
60 | - 'endpoints' => [ |
|
61 | - 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
62 | - ], |
|
63 | - ]; |
|
64 | - $services['FEDERATED_SHARING'] = [ |
|
65 | - 'version' => 1, |
|
66 | - 'endpoints' => [ |
|
67 | - 'share' => '/ocs/v2.php/cloud/shares', |
|
68 | - 'webdav' => '/public.php/webdav/', |
|
69 | - ], |
|
70 | - ]; |
|
71 | - } |
|
57 | + if($this->appManager->isEnabledForUser('files_sharing')) { |
|
58 | + $services['SHARING'] = [ |
|
59 | + 'version' => 1, |
|
60 | + 'endpoints' => [ |
|
61 | + 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
62 | + ], |
|
63 | + ]; |
|
64 | + $services['FEDERATED_SHARING'] = [ |
|
65 | + 'version' => 1, |
|
66 | + 'endpoints' => [ |
|
67 | + 'share' => '/ocs/v2.php/cloud/shares', |
|
68 | + 'webdav' => '/public.php/webdav/', |
|
69 | + ], |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | - if ($this->appManager->isEnabledForUser('federation')) { |
|
74 | - if (isset($services['FEDERATED_SHARING'])) { |
|
75 | - $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
76 | - $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
77 | - $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
78 | - } else { |
|
79 | - $services['FEDERATED_SHARING'] = [ |
|
80 | - 'version' => 1, |
|
81 | - 'endpoints' => [ |
|
82 | - 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
83 | - 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
84 | - 'carddav-user' => 'system' |
|
85 | - ], |
|
86 | - ]; |
|
87 | - } |
|
88 | - } |
|
73 | + if ($this->appManager->isEnabledForUser('federation')) { |
|
74 | + if (isset($services['FEDERATED_SHARING'])) { |
|
75 | + $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
76 | + $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
77 | + $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
78 | + } else { |
|
79 | + $services['FEDERATED_SHARING'] = [ |
|
80 | + 'version' => 1, |
|
81 | + 'endpoints' => [ |
|
82 | + 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
83 | + 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
84 | + 'carddav-user' => 'system' |
|
85 | + ], |
|
86 | + ]; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - if($this->appManager->isEnabledForUser('activity')) { |
|
91 | - $services['ACTIVITY'] = [ |
|
92 | - 'version' => 1, |
|
93 | - 'endpoints' => [ |
|
94 | - 'list' => '/ocs/v2.php/cloud/activity', |
|
95 | - ], |
|
96 | - ]; |
|
97 | - } |
|
90 | + if($this->appManager->isEnabledForUser('activity')) { |
|
91 | + $services['ACTIVITY'] = [ |
|
92 | + 'version' => 1, |
|
93 | + 'endpoints' => [ |
|
94 | + 'list' => '/ocs/v2.php/cloud/activity', |
|
95 | + ], |
|
96 | + ]; |
|
97 | + } |
|
98 | 98 | |
99 | - if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
100 | - $services['PROVISIONING'] = [ |
|
101 | - 'version' => 1, |
|
102 | - 'endpoints' => [ |
|
103 | - 'user' => '/ocs/v2.php/cloud/users', |
|
104 | - 'groups' => '/ocs/v2.php/cloud/groups', |
|
105 | - 'apps' => '/ocs/v2.php/cloud/apps', |
|
106 | - ], |
|
107 | - ]; |
|
108 | - } |
|
99 | + if($this->appManager->isEnabledForUser('provisioning_api')) { |
|
100 | + $services['PROVISIONING'] = [ |
|
101 | + 'version' => 1, |
|
102 | + 'endpoints' => [ |
|
103 | + 'user' => '/ocs/v2.php/cloud/users', |
|
104 | + 'groups' => '/ocs/v2.php/cloud/groups', |
|
105 | + 'apps' => '/ocs/v2.php/cloud/apps', |
|
106 | + ], |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | |
110 | - return new \OCP\AppFramework\Http\JSONResponse([ |
|
111 | - 'version' => 2, |
|
112 | - 'services' => $services, |
|
113 | - ]); |
|
114 | - } |
|
110 | + return new \OCP\AppFramework\Http\JSONResponse([ |
|
111 | + 'version' => 2, |
|
112 | + 'services' => $services, |
|
113 | + ]); |
|
114 | + } |
|
115 | 115 | } |
@@ -30,172 +30,172 @@ |
||
30 | 30 | |
31 | 31 | class GroupPrincipalBackend implements BackendInterface { |
32 | 32 | |
33 | - const PRINCIPAL_PREFIX = 'principals/groups'; |
|
34 | - |
|
35 | - /** @var IGroupManager */ |
|
36 | - private $groupManager; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param IGroupManager $IGroupManager |
|
40 | - */ |
|
41 | - public function __construct(IGroupManager $IGroupManager) { |
|
42 | - $this->groupManager = $IGroupManager; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns a list of principals based on a prefix. |
|
47 | - * |
|
48 | - * This prefix will often contain something like 'principals'. You are only |
|
49 | - * expected to return principals that are in this base path. |
|
50 | - * |
|
51 | - * You are expected to return at least a 'uri' for every user, you can |
|
52 | - * return any additional properties if you wish so. Common properties are: |
|
53 | - * {DAV:}displayname |
|
54 | - * |
|
55 | - * @param string $prefixPath |
|
56 | - * @return string[] |
|
57 | - */ |
|
58 | - public function getPrincipalsByPrefix($prefixPath) { |
|
59 | - $principals = []; |
|
60 | - |
|
61 | - if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
62 | - foreach($this->groupManager->search('') as $user) { |
|
63 | - $principals[] = $this->groupToPrincipal($user); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $principals; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns a specific principal, specified by it's path. |
|
72 | - * The returned structure should be the exact same as from |
|
73 | - * getPrincipalsByPrefix. |
|
74 | - * |
|
75 | - * @param string $path |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getPrincipalByPath($path) { |
|
79 | - $elements = explode('/', $path, 3); |
|
80 | - if ($elements[0] !== 'principals') { |
|
81 | - return null; |
|
82 | - } |
|
83 | - if ($elements[1] !== 'groups') { |
|
84 | - return null; |
|
85 | - } |
|
86 | - $name = urldecode($elements[2]); |
|
87 | - $group = $this->groupManager->get($name); |
|
88 | - |
|
89 | - if (!is_null($group)) { |
|
90 | - return $this->groupToPrincipal($group); |
|
91 | - } |
|
92 | - |
|
93 | - return null; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Returns the list of members for a group-principal |
|
98 | - * |
|
99 | - * @param string $principal |
|
100 | - * @return string[] |
|
101 | - * @throws Exception |
|
102 | - */ |
|
103 | - public function getGroupMemberSet($principal) { |
|
104 | - $elements = explode('/', $principal); |
|
105 | - if ($elements[0] !== 'principals') { |
|
106 | - return []; |
|
107 | - } |
|
108 | - if ($elements[1] !== 'groups') { |
|
109 | - return []; |
|
110 | - } |
|
111 | - $name = $elements[2]; |
|
112 | - $group = $this->groupManager->get($name); |
|
113 | - |
|
114 | - if (is_null($group)) { |
|
115 | - return []; |
|
116 | - } |
|
117 | - |
|
118 | - return array_map(function($user) { |
|
119 | - return $this->userToPrincipal($user); |
|
120 | - }, $group->getUsers()); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns the list of groups a principal is a member of |
|
125 | - * |
|
126 | - * @param string $principal |
|
127 | - * @return array |
|
128 | - * @throws Exception |
|
129 | - */ |
|
130 | - public function getGroupMembership($principal) { |
|
131 | - return []; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Updates the list of group members for a group principal. |
|
136 | - * |
|
137 | - * The principals should be passed as a list of uri's. |
|
138 | - * |
|
139 | - * @param string $principal |
|
140 | - * @param string[] $members |
|
141 | - * @throws Exception |
|
142 | - */ |
|
143 | - public function setGroupMemberSet($principal, array $members) { |
|
144 | - throw new Exception('Setting members of the group is not supported yet'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $path |
|
149 | - * @param PropPatch $propPatch |
|
150 | - * @return int |
|
151 | - */ |
|
152 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
153 | - return 0; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $prefixPath |
|
158 | - * @param array $searchProperties |
|
159 | - * @param string $test |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
163 | - return []; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $uri |
|
168 | - * @param string $principalPrefix |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - function findByUri($uri, $principalPrefix) { |
|
172 | - return ''; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param IGroup $group |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - protected function groupToPrincipal($group) { |
|
180 | - $groupId = $group->getGID(); |
|
181 | - $principal = [ |
|
182 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
183 | - '{DAV:}displayname' => $groupId, |
|
184 | - ]; |
|
185 | - |
|
186 | - return $principal; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param IUser $user |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function userToPrincipal($user) { |
|
194 | - $principal = [ |
|
195 | - 'uri' => 'principals/users/' . $user->getUID(), |
|
196 | - '{DAV:}displayname' => $user->getDisplayName(), |
|
197 | - ]; |
|
198 | - |
|
199 | - return $principal; |
|
200 | - } |
|
33 | + const PRINCIPAL_PREFIX = 'principals/groups'; |
|
34 | + |
|
35 | + /** @var IGroupManager */ |
|
36 | + private $groupManager; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param IGroupManager $IGroupManager |
|
40 | + */ |
|
41 | + public function __construct(IGroupManager $IGroupManager) { |
|
42 | + $this->groupManager = $IGroupManager; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns a list of principals based on a prefix. |
|
47 | + * |
|
48 | + * This prefix will often contain something like 'principals'. You are only |
|
49 | + * expected to return principals that are in this base path. |
|
50 | + * |
|
51 | + * You are expected to return at least a 'uri' for every user, you can |
|
52 | + * return any additional properties if you wish so. Common properties are: |
|
53 | + * {DAV:}displayname |
|
54 | + * |
|
55 | + * @param string $prefixPath |
|
56 | + * @return string[] |
|
57 | + */ |
|
58 | + public function getPrincipalsByPrefix($prefixPath) { |
|
59 | + $principals = []; |
|
60 | + |
|
61 | + if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
62 | + foreach($this->groupManager->search('') as $user) { |
|
63 | + $principals[] = $this->groupToPrincipal($user); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $principals; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns a specific principal, specified by it's path. |
|
72 | + * The returned structure should be the exact same as from |
|
73 | + * getPrincipalsByPrefix. |
|
74 | + * |
|
75 | + * @param string $path |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getPrincipalByPath($path) { |
|
79 | + $elements = explode('/', $path, 3); |
|
80 | + if ($elements[0] !== 'principals') { |
|
81 | + return null; |
|
82 | + } |
|
83 | + if ($elements[1] !== 'groups') { |
|
84 | + return null; |
|
85 | + } |
|
86 | + $name = urldecode($elements[2]); |
|
87 | + $group = $this->groupManager->get($name); |
|
88 | + |
|
89 | + if (!is_null($group)) { |
|
90 | + return $this->groupToPrincipal($group); |
|
91 | + } |
|
92 | + |
|
93 | + return null; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Returns the list of members for a group-principal |
|
98 | + * |
|
99 | + * @param string $principal |
|
100 | + * @return string[] |
|
101 | + * @throws Exception |
|
102 | + */ |
|
103 | + public function getGroupMemberSet($principal) { |
|
104 | + $elements = explode('/', $principal); |
|
105 | + if ($elements[0] !== 'principals') { |
|
106 | + return []; |
|
107 | + } |
|
108 | + if ($elements[1] !== 'groups') { |
|
109 | + return []; |
|
110 | + } |
|
111 | + $name = $elements[2]; |
|
112 | + $group = $this->groupManager->get($name); |
|
113 | + |
|
114 | + if (is_null($group)) { |
|
115 | + return []; |
|
116 | + } |
|
117 | + |
|
118 | + return array_map(function($user) { |
|
119 | + return $this->userToPrincipal($user); |
|
120 | + }, $group->getUsers()); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns the list of groups a principal is a member of |
|
125 | + * |
|
126 | + * @param string $principal |
|
127 | + * @return array |
|
128 | + * @throws Exception |
|
129 | + */ |
|
130 | + public function getGroupMembership($principal) { |
|
131 | + return []; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Updates the list of group members for a group principal. |
|
136 | + * |
|
137 | + * The principals should be passed as a list of uri's. |
|
138 | + * |
|
139 | + * @param string $principal |
|
140 | + * @param string[] $members |
|
141 | + * @throws Exception |
|
142 | + */ |
|
143 | + public function setGroupMemberSet($principal, array $members) { |
|
144 | + throw new Exception('Setting members of the group is not supported yet'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $path |
|
149 | + * @param PropPatch $propPatch |
|
150 | + * @return int |
|
151 | + */ |
|
152 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
153 | + return 0; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $prefixPath |
|
158 | + * @param array $searchProperties |
|
159 | + * @param string $test |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
163 | + return []; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $uri |
|
168 | + * @param string $principalPrefix |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + function findByUri($uri, $principalPrefix) { |
|
172 | + return ''; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param IGroup $group |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + protected function groupToPrincipal($group) { |
|
180 | + $groupId = $group->getGID(); |
|
181 | + $principal = [ |
|
182 | + 'uri' => 'principals/groups/' . urlencode($groupId), |
|
183 | + '{DAV:}displayname' => $groupId, |
|
184 | + ]; |
|
185 | + |
|
186 | + return $principal; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param IUser $user |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function userToPrincipal($user) { |
|
194 | + $principal = [ |
|
195 | + 'uri' => 'principals/users/' . $user->getUID(), |
|
196 | + '{DAV:}displayname' => $user->getDisplayName(), |
|
197 | + ]; |
|
198 | + |
|
199 | + return $principal; |
|
200 | + } |
|
201 | 201 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $principals = []; |
60 | 60 | |
61 | 61 | if ($prefixPath === self::PRINCIPAL_PREFIX) { |
62 | - foreach($this->groupManager->search('') as $user) { |
|
62 | + foreach ($this->groupManager->search('') as $user) { |
|
63 | 63 | $principals[] = $this->groupToPrincipal($user); |
64 | 64 | } |
65 | 65 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return array |
77 | 77 | */ |
78 | 78 | public function getPrincipalByPath($path) { |
79 | - $elements = explode('/', $path, 3); |
|
79 | + $elements = explode('/', $path, 3); |
|
80 | 80 | if ($elements[0] !== 'principals') { |
81 | 81 | return null; |
82 | 82 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | protected function groupToPrincipal($group) { |
180 | 180 | $groupId = $group->getGID(); |
181 | 181 | $principal = [ |
182 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
182 | + 'uri' => 'principals/groups/'.urlencode($groupId), |
|
183 | 183 | '{DAV:}displayname' => $groupId, |
184 | 184 | ]; |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | protected function userToPrincipal($user) { |
194 | 194 | $principal = [ |
195 | - 'uri' => 'principals/users/' . $user->getUID(), |
|
195 | + 'uri' => 'principals/users/'.$user->getUID(), |
|
196 | 196 | '{DAV:}displayname' => $user->getDisplayName(), |
197 | 197 | ]; |
198 | 198 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | <div class="warning"> |
15 | 15 | <h2 class="two-factor-header"><?php p($provider->getDisplayName()); ?></h2> |
16 | 16 | <?php if ($error): ?> |
17 | - <?php if($error_message): ?> |
|
17 | + <?php if ($error_message): ?> |
|
18 | 18 | <p><strong><?php p($error_message); ?></strong></p> |
19 | 19 | <?php else: ?> |
20 | 20 | <p><strong><?php p($l->t('Error while validating your second factor')); ?></strong></p> |
@@ -16,8 +16,11 @@ |
||
16 | 16 | <?php if ($error): ?> |
17 | 17 | <?php if($error_message): ?> |
18 | 18 | <p><strong><?php p($error_message); ?></strong></p> |
19 | - <?php else: ?> |
|
20 | - <p><strong><?php p($l->t('Error while validating your second factor')); ?></strong></p> |
|
19 | + <?php else { |
|
20 | + : ?> |
|
21 | + <p><strong><?php p($l->t('Error while validating your second factor')); |
|
22 | +} |
|
23 | +?></strong></p> |
|
21 | 24 | <?php endif; ?> |
22 | 25 | <?php endif; ?> |
23 | 26 | <?php print_unescaped($template); ?> |
@@ -25,11 +25,11 @@ |
||
25 | 25 | <a class="button" href="<?php print_unescaped($_['logout_url']); ?>"><?php p($l->t('Cancel log in')) ?></a> |
26 | 26 | <?php if (!is_null($_['backupProvider'])): ?> |
27 | 27 | <a class="button" href="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.showChallenge', |
28 | - [ |
|
29 | - 'challengeProviderId' => $_['backupProvider']->getId(), |
|
30 | - 'redirect_url' => $_['redirect_url'], |
|
31 | - ] |
|
32 | - )) ?>"><?php p($l->t('Use backup code')) ?></a> |
|
28 | + [ |
|
29 | + 'challengeProviderId' => $_['backupProvider']->getId(), |
|
30 | + 'redirect_url' => $_['redirect_url'], |
|
31 | + ] |
|
32 | + )) ?>"><?php p($l->t('Use backup code')) ?></a> |
|
33 | 33 | <?php endif; ?> |
34 | 34 | </p> |
35 | 35 | </div> |
@@ -88,7 +88,7 @@ |
||
88 | 88 | if (strpos($path, '/webdav/') === 0) { |
89 | 89 | $path = substr($path, strlen('/webdav')); |
90 | 90 | } |
91 | - $path = $this->path . $path; |
|
91 | + $path = $this->path.$path; |
|
92 | 92 | $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
93 | 93 | return $this->mimeType[$this->storage->getId()][$path]; |
94 | 94 | } |
@@ -29,159 +29,159 @@ |
||
29 | 29 | |
30 | 30 | class FileMimeType extends AbstractStringCheck { |
31 | 31 | |
32 | - /** @var array */ |
|
33 | - protected $mimeType; |
|
34 | - |
|
35 | - /** @var IRequest */ |
|
36 | - protected $request; |
|
37 | - |
|
38 | - /** @var IMimeTypeDetector */ |
|
39 | - protected $mimeTypeDetector; |
|
40 | - |
|
41 | - /** @var IStorage */ |
|
42 | - protected $storage; |
|
43 | - |
|
44 | - /** @var string */ |
|
45 | - protected $path; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param IL10N $l |
|
49 | - * @param IRequest $request |
|
50 | - * @param IMimeTypeDetector $mimeTypeDetector |
|
51 | - */ |
|
52 | - public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) { |
|
53 | - parent::__construct($l); |
|
54 | - $this->request = $request; |
|
55 | - $this->mimeTypeDetector = $mimeTypeDetector; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IStorage $storage |
|
60 | - * @param string $path |
|
61 | - */ |
|
62 | - public function setFileInfo(IStorage $storage, $path) { |
|
63 | - $this->storage = $storage; |
|
64 | - $this->path = $path; |
|
65 | - if (!isset($this->mimeType[$this->storage->getId()][$this->path]) |
|
66 | - || $this->mimeType[$this->storage->getId()][$this->path] === '') { |
|
67 | - $this->mimeType[$this->storage->getId()][$this->path] = null; |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - protected function getActualValue() { |
|
75 | - if ($this->mimeType[$this->storage->getId()][$this->path] !== null) { |
|
76 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
77 | - } |
|
78 | - |
|
79 | - if ($this->isWebDAVRequest()) { |
|
80 | - // Creating a folder |
|
81 | - if ($this->request->getMethod() === 'MKCOL') { |
|
82 | - $this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory'; |
|
83 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
84 | - } |
|
85 | - |
|
86 | - if ($this->request->getMethod() === 'PUT') { |
|
87 | - $path = $this->request->getPathInfo(); |
|
88 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path); |
|
89 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
90 | - } |
|
91 | - } else if ($this->isPublicWebDAVRequest()) { |
|
92 | - if ($this->request->getMethod() === 'PUT') { |
|
93 | - $path = $this->request->getPathInfo(); |
|
94 | - if (strpos($path, '/webdav/') === 0) { |
|
95 | - $path = substr($path, strlen('/webdav')); |
|
96 | - } |
|
97 | - $path = $this->path . $path; |
|
98 | - $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
|
99 | - return $this->mimeType[$this->storage->getId()][$path]; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - if (in_array($this->request->getMethod(), ['POST', 'PUT'])) { |
|
104 | - $files = $this->request->getUploadedFile('files'); |
|
105 | - if (isset($files['type'][0])) { |
|
106 | - $mimeType = $files['type'][0]; |
|
107 | - if ($this->mimeType === 'application/octet-stream') { |
|
108 | - // Maybe not... |
|
109 | - $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]); |
|
110 | - if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
111 | - $mimeType = $mimeTypeTest; |
|
112 | - } else { |
|
113 | - $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]); |
|
114 | - if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
115 | - $mimeType = $mimeTypeTest; |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - $this->mimeType[$this->storage->getId()][$this->path] = $mimeType; |
|
120 | - return $mimeType; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path); |
|
125 | - if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') { |
|
126 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath(); |
|
127 | - } |
|
128 | - |
|
129 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function detectMimetypeFromPath() { |
|
136 | - $mimeType = $this->mimeTypeDetector->detectPath($this->path); |
|
137 | - if ($mimeType !== 'application/octet-stream' && $mimeType !== false) { |
|
138 | - return $mimeType; |
|
139 | - } |
|
140 | - |
|
141 | - if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local') |
|
142 | - || $this->storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
143 | - || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) { |
|
144 | - $localFile = $this->storage->getLocalFile($this->path); |
|
145 | - if ($localFile !== false) { |
|
146 | - $mimeType = $this->mimeTypeDetector->detect($localFile); |
|
147 | - if ($mimeType !== false) { |
|
148 | - return $mimeType; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - return 'application/octet-stream'; |
|
153 | - } else { |
|
154 | - $handle = $this->storage->fopen($this->path, 'r'); |
|
155 | - $data = fread($handle, 8024); |
|
156 | - fclose($handle); |
|
157 | - $mimeType = $this->mimeTypeDetector->detectString($data); |
|
158 | - if ($mimeType !== false) { |
|
159 | - return $mimeType; |
|
160 | - } |
|
161 | - |
|
162 | - return 'application/octet-stream'; |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - protected function isWebDAVRequest() { |
|
170 | - return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
171 | - $this->request->getPathInfo() === '/webdav' || |
|
172 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
173 | - $this->request->getPathInfo() === '/dav/files' || |
|
174 | - strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - protected function isPublicWebDAVRequest() { |
|
182 | - return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && ( |
|
183 | - $this->request->getPathInfo() === '/webdav' || |
|
184 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 |
|
185 | - ); |
|
186 | - } |
|
32 | + /** @var array */ |
|
33 | + protected $mimeType; |
|
34 | + |
|
35 | + /** @var IRequest */ |
|
36 | + protected $request; |
|
37 | + |
|
38 | + /** @var IMimeTypeDetector */ |
|
39 | + protected $mimeTypeDetector; |
|
40 | + |
|
41 | + /** @var IStorage */ |
|
42 | + protected $storage; |
|
43 | + |
|
44 | + /** @var string */ |
|
45 | + protected $path; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param IL10N $l |
|
49 | + * @param IRequest $request |
|
50 | + * @param IMimeTypeDetector $mimeTypeDetector |
|
51 | + */ |
|
52 | + public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) { |
|
53 | + parent::__construct($l); |
|
54 | + $this->request = $request; |
|
55 | + $this->mimeTypeDetector = $mimeTypeDetector; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IStorage $storage |
|
60 | + * @param string $path |
|
61 | + */ |
|
62 | + public function setFileInfo(IStorage $storage, $path) { |
|
63 | + $this->storage = $storage; |
|
64 | + $this->path = $path; |
|
65 | + if (!isset($this->mimeType[$this->storage->getId()][$this->path]) |
|
66 | + || $this->mimeType[$this->storage->getId()][$this->path] === '') { |
|
67 | + $this->mimeType[$this->storage->getId()][$this->path] = null; |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + protected function getActualValue() { |
|
75 | + if ($this->mimeType[$this->storage->getId()][$this->path] !== null) { |
|
76 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
77 | + } |
|
78 | + |
|
79 | + if ($this->isWebDAVRequest()) { |
|
80 | + // Creating a folder |
|
81 | + if ($this->request->getMethod() === 'MKCOL') { |
|
82 | + $this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory'; |
|
83 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
84 | + } |
|
85 | + |
|
86 | + if ($this->request->getMethod() === 'PUT') { |
|
87 | + $path = $this->request->getPathInfo(); |
|
88 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path); |
|
89 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
90 | + } |
|
91 | + } else if ($this->isPublicWebDAVRequest()) { |
|
92 | + if ($this->request->getMethod() === 'PUT') { |
|
93 | + $path = $this->request->getPathInfo(); |
|
94 | + if (strpos($path, '/webdav/') === 0) { |
|
95 | + $path = substr($path, strlen('/webdav')); |
|
96 | + } |
|
97 | + $path = $this->path . $path; |
|
98 | + $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
|
99 | + return $this->mimeType[$this->storage->getId()][$path]; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + if (in_array($this->request->getMethod(), ['POST', 'PUT'])) { |
|
104 | + $files = $this->request->getUploadedFile('files'); |
|
105 | + if (isset($files['type'][0])) { |
|
106 | + $mimeType = $files['type'][0]; |
|
107 | + if ($this->mimeType === 'application/octet-stream') { |
|
108 | + // Maybe not... |
|
109 | + $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]); |
|
110 | + if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
111 | + $mimeType = $mimeTypeTest; |
|
112 | + } else { |
|
113 | + $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]); |
|
114 | + if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
115 | + $mimeType = $mimeTypeTest; |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + $this->mimeType[$this->storage->getId()][$this->path] = $mimeType; |
|
120 | + return $mimeType; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path); |
|
125 | + if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') { |
|
126 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath(); |
|
127 | + } |
|
128 | + |
|
129 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function detectMimetypeFromPath() { |
|
136 | + $mimeType = $this->mimeTypeDetector->detectPath($this->path); |
|
137 | + if ($mimeType !== 'application/octet-stream' && $mimeType !== false) { |
|
138 | + return $mimeType; |
|
139 | + } |
|
140 | + |
|
141 | + if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local') |
|
142 | + || $this->storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
143 | + || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) { |
|
144 | + $localFile = $this->storage->getLocalFile($this->path); |
|
145 | + if ($localFile !== false) { |
|
146 | + $mimeType = $this->mimeTypeDetector->detect($localFile); |
|
147 | + if ($mimeType !== false) { |
|
148 | + return $mimeType; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + return 'application/octet-stream'; |
|
153 | + } else { |
|
154 | + $handle = $this->storage->fopen($this->path, 'r'); |
|
155 | + $data = fread($handle, 8024); |
|
156 | + fclose($handle); |
|
157 | + $mimeType = $this->mimeTypeDetector->detectString($data); |
|
158 | + if ($mimeType !== false) { |
|
159 | + return $mimeType; |
|
160 | + } |
|
161 | + |
|
162 | + return 'application/octet-stream'; |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + protected function isWebDAVRequest() { |
|
170 | + return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
171 | + $this->request->getPathInfo() === '/webdav' || |
|
172 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
173 | + $this->request->getPathInfo() === '/dav/files' || |
|
174 | + strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + protected function isPublicWebDAVRequest() { |
|
182 | + return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && ( |
|
183 | + $this->request->getPathInfo() === '/webdav' || |
|
184 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | } |