@@ -33,122 +33,122 @@ |
||
33 | 33 | */ |
34 | 34 | class AddressHandler { |
35 | 35 | |
36 | - /** @var IL10N */ |
|
37 | - private $l; |
|
38 | - |
|
39 | - /** @var IURLGenerator */ |
|
40 | - private $urlGenerator; |
|
41 | - |
|
42 | - /** @var ICloudIdManager */ |
|
43 | - private $cloudIdManager; |
|
44 | - |
|
45 | - /** |
|
46 | - * AddressHandler constructor. |
|
47 | - * |
|
48 | - * @param IURLGenerator $urlGenerator |
|
49 | - * @param IL10N $il10n |
|
50 | - * @param ICloudIdManager $cloudIdManager |
|
51 | - */ |
|
52 | - public function __construct( |
|
53 | - IURLGenerator $urlGenerator, |
|
54 | - IL10N $il10n, |
|
55 | - ICloudIdManager $cloudIdManager |
|
56 | - ) { |
|
57 | - $this->l = $il10n; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - $this->cloudIdManager = $cloudIdManager; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * split user and remote from federated cloud id |
|
64 | - * |
|
65 | - * @param string $address federated share address |
|
66 | - * @return array [user, remoteURL] |
|
67 | - * @throws HintException |
|
68 | - */ |
|
69 | - public function splitUserRemote($address) { |
|
70 | - try { |
|
71 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
72 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
73 | - } catch (\InvalidArgumentException $e) { |
|
74 | - $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
75 | - throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * generate remote URL part of federated ID |
|
81 | - * |
|
82 | - * @return string url of the current server |
|
83 | - */ |
|
84 | - public function generateRemoteURL() { |
|
85 | - $url = $this->urlGenerator->getAbsoluteURL('/'); |
|
86 | - return $url; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * check if two federated cloud IDs refer to the same user |
|
91 | - * |
|
92 | - * @param string $user1 |
|
93 | - * @param string $server1 |
|
94 | - * @param string $user2 |
|
95 | - * @param string $server2 |
|
96 | - * @return bool true if both users and servers are the same |
|
97 | - */ |
|
98 | - public function compareAddresses($user1, $server1, $user2, $server2) { |
|
99 | - $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
100 | - $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
101 | - |
|
102 | - if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
103 | - // FIXME this should be a method in the user management instead |
|
104 | - \OCP\Util::emitHook( |
|
105 | - '\OCA\Files_Sharing\API\Server2Server', |
|
106 | - 'preLoginNameUsedAsUserName', |
|
107 | - array('uid' => &$user1) |
|
108 | - ); |
|
109 | - \OCP\Util::emitHook( |
|
110 | - '\OCA\Files_Sharing\API\Server2Server', |
|
111 | - 'preLoginNameUsedAsUserName', |
|
112 | - array('uid' => &$user2) |
|
113 | - ); |
|
114 | - |
|
115 | - if ($user1 === $user2) { |
|
116 | - return true; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * remove protocol from URL |
|
125 | - * |
|
126 | - * @param string $url |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function removeProtocolFromUrl($url) { |
|
130 | - if (strpos($url, 'https://') === 0) { |
|
131 | - return substr($url, strlen('https://')); |
|
132 | - } else if (strpos($url, 'http://') === 0) { |
|
133 | - return substr($url, strlen('http://')); |
|
134 | - } |
|
135 | - |
|
136 | - return $url; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * check if the url contain the protocol (http or https) |
|
141 | - * |
|
142 | - * @param string $url |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function urlContainProtocol($url) { |
|
146 | - if (strpos($url, 'https://') === 0 || |
|
147 | - strpos($url, 'http://') === 0) { |
|
148 | - |
|
149 | - return true; |
|
150 | - } |
|
151 | - |
|
152 | - return false; |
|
153 | - } |
|
36 | + /** @var IL10N */ |
|
37 | + private $l; |
|
38 | + |
|
39 | + /** @var IURLGenerator */ |
|
40 | + private $urlGenerator; |
|
41 | + |
|
42 | + /** @var ICloudIdManager */ |
|
43 | + private $cloudIdManager; |
|
44 | + |
|
45 | + /** |
|
46 | + * AddressHandler constructor. |
|
47 | + * |
|
48 | + * @param IURLGenerator $urlGenerator |
|
49 | + * @param IL10N $il10n |
|
50 | + * @param ICloudIdManager $cloudIdManager |
|
51 | + */ |
|
52 | + public function __construct( |
|
53 | + IURLGenerator $urlGenerator, |
|
54 | + IL10N $il10n, |
|
55 | + ICloudIdManager $cloudIdManager |
|
56 | + ) { |
|
57 | + $this->l = $il10n; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + $this->cloudIdManager = $cloudIdManager; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * split user and remote from federated cloud id |
|
64 | + * |
|
65 | + * @param string $address federated share address |
|
66 | + * @return array [user, remoteURL] |
|
67 | + * @throws HintException |
|
68 | + */ |
|
69 | + public function splitUserRemote($address) { |
|
70 | + try { |
|
71 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
72 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
73 | + } catch (\InvalidArgumentException $e) { |
|
74 | + $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
75 | + throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * generate remote URL part of federated ID |
|
81 | + * |
|
82 | + * @return string url of the current server |
|
83 | + */ |
|
84 | + public function generateRemoteURL() { |
|
85 | + $url = $this->urlGenerator->getAbsoluteURL('/'); |
|
86 | + return $url; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * check if two federated cloud IDs refer to the same user |
|
91 | + * |
|
92 | + * @param string $user1 |
|
93 | + * @param string $server1 |
|
94 | + * @param string $user2 |
|
95 | + * @param string $server2 |
|
96 | + * @return bool true if both users and servers are the same |
|
97 | + */ |
|
98 | + public function compareAddresses($user1, $server1, $user2, $server2) { |
|
99 | + $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
100 | + $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
101 | + |
|
102 | + if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
103 | + // FIXME this should be a method in the user management instead |
|
104 | + \OCP\Util::emitHook( |
|
105 | + '\OCA\Files_Sharing\API\Server2Server', |
|
106 | + 'preLoginNameUsedAsUserName', |
|
107 | + array('uid' => &$user1) |
|
108 | + ); |
|
109 | + \OCP\Util::emitHook( |
|
110 | + '\OCA\Files_Sharing\API\Server2Server', |
|
111 | + 'preLoginNameUsedAsUserName', |
|
112 | + array('uid' => &$user2) |
|
113 | + ); |
|
114 | + |
|
115 | + if ($user1 === $user2) { |
|
116 | + return true; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * remove protocol from URL |
|
125 | + * |
|
126 | + * @param string $url |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function removeProtocolFromUrl($url) { |
|
130 | + if (strpos($url, 'https://') === 0) { |
|
131 | + return substr($url, strlen('https://')); |
|
132 | + } else if (strpos($url, 'http://') === 0) { |
|
133 | + return substr($url, strlen('http://')); |
|
134 | + } |
|
135 | + |
|
136 | + return $url; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * check if the url contain the protocol (http or https) |
|
141 | + * |
|
142 | + * @param string $url |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function urlContainProtocol($url) { |
|
146 | + if (strpos($url, 'https://') === 0 || |
|
147 | + strpos($url, 'http://') === 0) { |
|
148 | + |
|
149 | + return true; |
|
150 | + } |
|
151 | + |
|
152 | + return false; |
|
153 | + } |
|
154 | 154 | } |
@@ -28,10 +28,10 @@ |
||
28 | 28 | <?php if((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
29 | 29 | <span class="status success"></span> |
30 | 30 | <?php |
31 | - } elseif( |
|
32 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
33 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
34 | - ) { ?> |
|
31 | + } elseif( |
|
32 | + (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
33 | + (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
34 | + ) { ?> |
|
35 | 35 | <span class="status indeterminate"></span> |
36 | 36 | <?php } else {?> |
37 | 37 | <span class="status error"></span> |
@@ -11,19 +11,19 @@ |
||
11 | 11 | <p class="settings-hint"><?php p($l->t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></p> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="autoAddServers" type="checkbox" class="checkbox" <?php if($_['autoAddServers']) p('checked'); ?> /> |
|
14 | + <input id="autoAddServers" type="checkbox" class="checkbox" <?php if ($_['autoAddServers']) p('checked'); ?> /> |
|
15 | 15 | <label for="autoAddServers"><?php p($l->t('Add server automatically once a federated share was created successfully')); ?></label> |
16 | 16 | </p> |
17 | 17 | |
18 | 18 | <ul id="listOfTrustedServers"> |
19 | - <?php foreach($_['trustedServers'] as $trustedServer) { ?> |
|
19 | + <?php foreach ($_['trustedServers'] as $trustedServer) { ?> |
|
20 | 20 | <li id="<?php p($trustedServer['id']); ?>"> |
21 | - <?php if((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
|
21 | + <?php if ((int) $trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
|
22 | 22 | <span class="status success"></span> |
23 | 23 | <?php |
24 | - } elseif( |
|
25 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
26 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
24 | + } elseif ( |
|
25 | + (int) $trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
26 | + (int) $trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
27 | 27 | ) { ?> |
28 | 28 | <span class="status indeterminate"></span> |
29 | 29 | <?php } else {?> |
@@ -11,7 +11,10 @@ |
||
11 | 11 | <p class="settings-hint"><?php p($l->t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></p> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="autoAddServers" type="checkbox" class="checkbox" <?php if($_['autoAddServers']) p('checked'); ?> /> |
|
14 | + <input id="autoAddServers" type="checkbox" class="checkbox" <?php if($_['autoAddServers']) { |
|
15 | + p('checked'); |
|
16 | +} |
|
17 | +?> /> |
|
15 | 18 | <label for="autoAddServers"><?php p($l->t('Add server automatically once a federated share was created successfully')); ?></label> |
16 | 19 | </p> |
17 | 20 |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $progress->start(); |
61 | 61 | $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
62 | 62 | if ($ex instanceof \Exception) { |
63 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
63 | + $output->writeln("Error while syncing $url : ".$ex->getMessage()); |
|
64 | 64 | |
65 | 65 | } else { |
66 | 66 | $progress->advance(); |
@@ -30,45 +30,45 @@ |
||
30 | 30 | |
31 | 31 | class SyncFederationAddressBooks extends Command { |
32 | 32 | |
33 | - /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
34 | - private $syncService; |
|
33 | + /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
34 | + private $syncService; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
38 | - */ |
|
39 | - public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
40 | - parent::__construct(); |
|
36 | + /** |
|
37 | + * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
38 | + */ |
|
39 | + public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
40 | + parent::__construct(); |
|
41 | 41 | |
42 | - $this->syncService = $syncService; |
|
43 | - } |
|
42 | + $this->syncService = $syncService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('federation:sync-addressbooks') |
|
48 | - ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
49 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('federation:sync-addressbooks') |
|
48 | + ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param InputInterface $input |
|
53 | - * @param OutputInterface $output |
|
54 | - * @return int |
|
55 | - */ |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
51 | + /** |
|
52 | + * @param InputInterface $input |
|
53 | + * @param OutputInterface $output |
|
54 | + * @return int |
|
55 | + */ |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | 57 | |
58 | - $progress = new ProgressBar($output); |
|
59 | - $progress->start(); |
|
60 | - $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
61 | - if ($ex instanceof \Exception) { |
|
62 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
58 | + $progress = new ProgressBar($output); |
|
59 | + $progress->start(); |
|
60 | + $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
61 | + if ($ex instanceof \Exception) { |
|
62 | + $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
63 | 63 | |
64 | - } else { |
|
65 | - $progress->advance(); |
|
66 | - } |
|
67 | - }); |
|
64 | + } else { |
|
65 | + $progress->advance(); |
|
66 | + } |
|
67 | + }); |
|
68 | 68 | |
69 | - $progress->finish(); |
|
70 | - $output->writeln(''); |
|
69 | + $progress->finish(); |
|
70 | + $output->writeln(''); |
|
71 | 71 | |
72 | - return 0; |
|
73 | - } |
|
72 | + return 0; |
|
73 | + } |
|
74 | 74 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $client = $this->httpClientService->newClient(); |
222 | 222 | try { |
223 | 223 | $result = $client->get( |
224 | - $url . '/status.php', |
|
224 | + $url.'/status.php', |
|
225 | 225 | [ |
226 | 226 | 'timeout' => 3, |
227 | 227 | 'connect_timeout' => 3, |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | } |
234 | 234 | } catch (\Exception $e) { |
235 | - $this->logger->debug('No Nextcloud server: ' . $e->getMessage()); |
|
235 | + $this->logger->debug('No Nextcloud server: '.$e->getMessage()); |
|
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | |
@@ -273,6 +273,6 @@ discard block |
||
273 | 273 | |
274 | 274 | } |
275 | 275 | |
276 | - return 'https://' . $url; |
|
276 | + return 'https://'.$url; |
|
277 | 277 | } |
278 | 278 | } |
@@ -39,248 +39,248 @@ |
||
39 | 39 | |
40 | 40 | class TrustedServers { |
41 | 41 | |
42 | - /** after a user list was exchanged at least once successfully */ |
|
43 | - const STATUS_OK = 1; |
|
44 | - /** waiting for shared secret or initial user list exchange */ |
|
45 | - const STATUS_PENDING = 2; |
|
46 | - /** something went wrong, misconfigured server, software bug,... user interaction needed */ |
|
47 | - const STATUS_FAILURE = 3; |
|
48 | - /** remote server revoked access */ |
|
49 | - const STATUS_ACCESS_REVOKED = 4; |
|
50 | - |
|
51 | - /** @var dbHandler */ |
|
52 | - private $dbHandler; |
|
53 | - |
|
54 | - /** @var IClientService */ |
|
55 | - private $httpClientService; |
|
56 | - |
|
57 | - /** @var ILogger */ |
|
58 | - private $logger; |
|
59 | - |
|
60 | - /** @var IJobList */ |
|
61 | - private $jobList; |
|
62 | - |
|
63 | - /** @var ISecureRandom */ |
|
64 | - private $secureRandom; |
|
65 | - |
|
66 | - /** @var IConfig */ |
|
67 | - private $config; |
|
68 | - |
|
69 | - /** @var EventDispatcherInterface */ |
|
70 | - private $dispatcher; |
|
71 | - |
|
72 | - /** @var ITimeFactory */ |
|
73 | - private $timeFactory; |
|
74 | - |
|
75 | - /** |
|
76 | - * @param DbHandler $dbHandler |
|
77 | - * @param IClientService $httpClientService |
|
78 | - * @param ILogger $logger |
|
79 | - * @param IJobList $jobList |
|
80 | - * @param ISecureRandom $secureRandom |
|
81 | - * @param IConfig $config |
|
82 | - * @param EventDispatcherInterface $dispatcher |
|
83 | - * @param ITimeFactory $timeFactory |
|
84 | - */ |
|
85 | - public function __construct( |
|
86 | - DbHandler $dbHandler, |
|
87 | - IClientService $httpClientService, |
|
88 | - ILogger $logger, |
|
89 | - IJobList $jobList, |
|
90 | - ISecureRandom $secureRandom, |
|
91 | - IConfig $config, |
|
92 | - EventDispatcherInterface $dispatcher, |
|
93 | - ITimeFactory $timeFactory |
|
94 | - ) { |
|
95 | - $this->dbHandler = $dbHandler; |
|
96 | - $this->httpClientService = $httpClientService; |
|
97 | - $this->logger = $logger; |
|
98 | - $this->jobList = $jobList; |
|
99 | - $this->secureRandom = $secureRandom; |
|
100 | - $this->config = $config; |
|
101 | - $this->dispatcher = $dispatcher; |
|
102 | - $this->timeFactory = $timeFactory; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * add server to the list of trusted servers |
|
107 | - * |
|
108 | - * @param $url |
|
109 | - * @return int server id |
|
110 | - */ |
|
111 | - public function addServer($url) { |
|
112 | - $url = $this->updateProtocol($url); |
|
113 | - $result = $this->dbHandler->addServer($url); |
|
114 | - if ($result) { |
|
115 | - $token = $this->secureRandom->generate(16); |
|
116 | - $this->dbHandler->addToken($url, $token); |
|
117 | - $this->jobList->add( |
|
118 | - 'OCA\Federation\BackgroundJob\RequestSharedSecret', |
|
119 | - [ |
|
120 | - 'url' => $url, |
|
121 | - 'token' => $token, |
|
122 | - 'created' => $this->timeFactory->getTime() |
|
123 | - ] |
|
124 | - ); |
|
125 | - } |
|
126 | - |
|
127 | - return $result; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * enable/disable to automatically add servers to the list of trusted servers |
|
132 | - * once a federated share was created and accepted successfully |
|
133 | - * |
|
134 | - * @param bool $status |
|
135 | - */ |
|
136 | - public function setAutoAddServers($status) { |
|
137 | - $value = $status ? '1' : '0'; |
|
138 | - $this->config->setAppValue('federation', 'autoAddServers', $value); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * return if we automatically add servers to the list of trusted servers |
|
143 | - * once a federated share was created and accepted successfully |
|
144 | - * |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function getAutoAddServers() { |
|
148 | - $value = $this->config->getAppValue('federation', 'autoAddServers', '0'); |
|
149 | - return $value === '1'; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * get shared secret for the given server |
|
154 | - * |
|
155 | - * @param string $url |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function getSharedSecret($url) { |
|
159 | - return $this->dbHandler->getSharedSecret($url); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * add shared secret for the given server |
|
164 | - * |
|
165 | - * @param string $url |
|
166 | - * @param $sharedSecret |
|
167 | - */ |
|
168 | - public function addSharedSecret($url, $sharedSecret) { |
|
169 | - $this->dbHandler->addSharedSecret($url, $sharedSecret); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * remove server from the list of trusted servers |
|
174 | - * |
|
175 | - * @param int $id |
|
176 | - */ |
|
177 | - public function removeServer($id) { |
|
178 | - $server = $this->dbHandler->getServerById($id); |
|
179 | - $this->dbHandler->removeServer($id); |
|
180 | - $event = new GenericEvent($server['url_hash']); |
|
181 | - $this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * get all trusted servers |
|
186 | - * |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - public function getServers() { |
|
190 | - return $this->dbHandler->getAllServer(); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * check if given server is a trusted Nextcloud server |
|
195 | - * |
|
196 | - * @param string $url |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function isTrustedServer($url) { |
|
200 | - return $this->dbHandler->serverExists($url); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * set server status |
|
205 | - * |
|
206 | - * @param string $url |
|
207 | - * @param int $status |
|
208 | - */ |
|
209 | - public function setServerStatus($url, $status) { |
|
210 | - $this->dbHandler->setServerStatus($url, $status); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @param string $url |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function getServerStatus($url) { |
|
218 | - return $this->dbHandler->getServerStatus($url); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * check if URL point to a ownCloud/Nextcloud server |
|
223 | - * |
|
224 | - * @param string $url |
|
225 | - * @return bool |
|
226 | - */ |
|
227 | - public function isOwnCloudServer($url) { |
|
228 | - $isValidOwnCloud = false; |
|
229 | - $client = $this->httpClientService->newClient(); |
|
230 | - try { |
|
231 | - $result = $client->get( |
|
232 | - $url . '/status.php', |
|
233 | - [ |
|
234 | - 'timeout' => 3, |
|
235 | - 'connect_timeout' => 3, |
|
236 | - ] |
|
237 | - ); |
|
238 | - if ($result->getStatusCode() === Http::STATUS_OK) { |
|
239 | - $isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody()); |
|
240 | - |
|
241 | - } |
|
242 | - } catch (\Exception $e) { |
|
243 | - $this->logger->debug('No Nextcloud server: ' . $e->getMessage()); |
|
244 | - return false; |
|
245 | - } |
|
246 | - |
|
247 | - return $isValidOwnCloud; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * check if ownCloud version is >= 9.0 |
|
252 | - * |
|
253 | - * @param $status |
|
254 | - * @return bool |
|
255 | - * @throws HintException |
|
256 | - */ |
|
257 | - protected function checkOwnCloudVersion($status) { |
|
258 | - $decoded = json_decode($status, true); |
|
259 | - if (!empty($decoded) && isset($decoded['version'])) { |
|
260 | - if (!version_compare($decoded['version'], '9.0.0', '>=')) { |
|
261 | - throw new HintException('Remote server version is too low. 9.0 is required.'); |
|
262 | - } |
|
263 | - return true; |
|
264 | - } |
|
265 | - return false; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * check if the URL contain a protocol, if not add https |
|
270 | - * |
|
271 | - * @param string $url |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - protected function updateProtocol($url) { |
|
275 | - if ( |
|
276 | - strpos($url, 'https://') === 0 |
|
277 | - || strpos($url, 'http://') === 0 |
|
278 | - ) { |
|
279 | - |
|
280 | - return $url; |
|
281 | - |
|
282 | - } |
|
283 | - |
|
284 | - return 'https://' . $url; |
|
285 | - } |
|
42 | + /** after a user list was exchanged at least once successfully */ |
|
43 | + const STATUS_OK = 1; |
|
44 | + /** waiting for shared secret or initial user list exchange */ |
|
45 | + const STATUS_PENDING = 2; |
|
46 | + /** something went wrong, misconfigured server, software bug,... user interaction needed */ |
|
47 | + const STATUS_FAILURE = 3; |
|
48 | + /** remote server revoked access */ |
|
49 | + const STATUS_ACCESS_REVOKED = 4; |
|
50 | + |
|
51 | + /** @var dbHandler */ |
|
52 | + private $dbHandler; |
|
53 | + |
|
54 | + /** @var IClientService */ |
|
55 | + private $httpClientService; |
|
56 | + |
|
57 | + /** @var ILogger */ |
|
58 | + private $logger; |
|
59 | + |
|
60 | + /** @var IJobList */ |
|
61 | + private $jobList; |
|
62 | + |
|
63 | + /** @var ISecureRandom */ |
|
64 | + private $secureRandom; |
|
65 | + |
|
66 | + /** @var IConfig */ |
|
67 | + private $config; |
|
68 | + |
|
69 | + /** @var EventDispatcherInterface */ |
|
70 | + private $dispatcher; |
|
71 | + |
|
72 | + /** @var ITimeFactory */ |
|
73 | + private $timeFactory; |
|
74 | + |
|
75 | + /** |
|
76 | + * @param DbHandler $dbHandler |
|
77 | + * @param IClientService $httpClientService |
|
78 | + * @param ILogger $logger |
|
79 | + * @param IJobList $jobList |
|
80 | + * @param ISecureRandom $secureRandom |
|
81 | + * @param IConfig $config |
|
82 | + * @param EventDispatcherInterface $dispatcher |
|
83 | + * @param ITimeFactory $timeFactory |
|
84 | + */ |
|
85 | + public function __construct( |
|
86 | + DbHandler $dbHandler, |
|
87 | + IClientService $httpClientService, |
|
88 | + ILogger $logger, |
|
89 | + IJobList $jobList, |
|
90 | + ISecureRandom $secureRandom, |
|
91 | + IConfig $config, |
|
92 | + EventDispatcherInterface $dispatcher, |
|
93 | + ITimeFactory $timeFactory |
|
94 | + ) { |
|
95 | + $this->dbHandler = $dbHandler; |
|
96 | + $this->httpClientService = $httpClientService; |
|
97 | + $this->logger = $logger; |
|
98 | + $this->jobList = $jobList; |
|
99 | + $this->secureRandom = $secureRandom; |
|
100 | + $this->config = $config; |
|
101 | + $this->dispatcher = $dispatcher; |
|
102 | + $this->timeFactory = $timeFactory; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * add server to the list of trusted servers |
|
107 | + * |
|
108 | + * @param $url |
|
109 | + * @return int server id |
|
110 | + */ |
|
111 | + public function addServer($url) { |
|
112 | + $url = $this->updateProtocol($url); |
|
113 | + $result = $this->dbHandler->addServer($url); |
|
114 | + if ($result) { |
|
115 | + $token = $this->secureRandom->generate(16); |
|
116 | + $this->dbHandler->addToken($url, $token); |
|
117 | + $this->jobList->add( |
|
118 | + 'OCA\Federation\BackgroundJob\RequestSharedSecret', |
|
119 | + [ |
|
120 | + 'url' => $url, |
|
121 | + 'token' => $token, |
|
122 | + 'created' => $this->timeFactory->getTime() |
|
123 | + ] |
|
124 | + ); |
|
125 | + } |
|
126 | + |
|
127 | + return $result; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * enable/disable to automatically add servers to the list of trusted servers |
|
132 | + * once a federated share was created and accepted successfully |
|
133 | + * |
|
134 | + * @param bool $status |
|
135 | + */ |
|
136 | + public function setAutoAddServers($status) { |
|
137 | + $value = $status ? '1' : '0'; |
|
138 | + $this->config->setAppValue('federation', 'autoAddServers', $value); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * return if we automatically add servers to the list of trusted servers |
|
143 | + * once a federated share was created and accepted successfully |
|
144 | + * |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function getAutoAddServers() { |
|
148 | + $value = $this->config->getAppValue('federation', 'autoAddServers', '0'); |
|
149 | + return $value === '1'; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * get shared secret for the given server |
|
154 | + * |
|
155 | + * @param string $url |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function getSharedSecret($url) { |
|
159 | + return $this->dbHandler->getSharedSecret($url); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * add shared secret for the given server |
|
164 | + * |
|
165 | + * @param string $url |
|
166 | + * @param $sharedSecret |
|
167 | + */ |
|
168 | + public function addSharedSecret($url, $sharedSecret) { |
|
169 | + $this->dbHandler->addSharedSecret($url, $sharedSecret); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * remove server from the list of trusted servers |
|
174 | + * |
|
175 | + * @param int $id |
|
176 | + */ |
|
177 | + public function removeServer($id) { |
|
178 | + $server = $this->dbHandler->getServerById($id); |
|
179 | + $this->dbHandler->removeServer($id); |
|
180 | + $event = new GenericEvent($server['url_hash']); |
|
181 | + $this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * get all trusted servers |
|
186 | + * |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + public function getServers() { |
|
190 | + return $this->dbHandler->getAllServer(); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * check if given server is a trusted Nextcloud server |
|
195 | + * |
|
196 | + * @param string $url |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function isTrustedServer($url) { |
|
200 | + return $this->dbHandler->serverExists($url); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * set server status |
|
205 | + * |
|
206 | + * @param string $url |
|
207 | + * @param int $status |
|
208 | + */ |
|
209 | + public function setServerStatus($url, $status) { |
|
210 | + $this->dbHandler->setServerStatus($url, $status); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @param string $url |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function getServerStatus($url) { |
|
218 | + return $this->dbHandler->getServerStatus($url); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * check if URL point to a ownCloud/Nextcloud server |
|
223 | + * |
|
224 | + * @param string $url |
|
225 | + * @return bool |
|
226 | + */ |
|
227 | + public function isOwnCloudServer($url) { |
|
228 | + $isValidOwnCloud = false; |
|
229 | + $client = $this->httpClientService->newClient(); |
|
230 | + try { |
|
231 | + $result = $client->get( |
|
232 | + $url . '/status.php', |
|
233 | + [ |
|
234 | + 'timeout' => 3, |
|
235 | + 'connect_timeout' => 3, |
|
236 | + ] |
|
237 | + ); |
|
238 | + if ($result->getStatusCode() === Http::STATUS_OK) { |
|
239 | + $isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody()); |
|
240 | + |
|
241 | + } |
|
242 | + } catch (\Exception $e) { |
|
243 | + $this->logger->debug('No Nextcloud server: ' . $e->getMessage()); |
|
244 | + return false; |
|
245 | + } |
|
246 | + |
|
247 | + return $isValidOwnCloud; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * check if ownCloud version is >= 9.0 |
|
252 | + * |
|
253 | + * @param $status |
|
254 | + * @return bool |
|
255 | + * @throws HintException |
|
256 | + */ |
|
257 | + protected function checkOwnCloudVersion($status) { |
|
258 | + $decoded = json_decode($status, true); |
|
259 | + if (!empty($decoded) && isset($decoded['version'])) { |
|
260 | + if (!version_compare($decoded['version'], '9.0.0', '>=')) { |
|
261 | + throw new HintException('Remote server version is too low. 9.0 is required.'); |
|
262 | + } |
|
263 | + return true; |
|
264 | + } |
|
265 | + return false; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * check if the URL contain a protocol, if not add https |
|
270 | + * |
|
271 | + * @param string $url |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + protected function updateProtocol($url) { |
|
275 | + if ( |
|
276 | + strpos($url, 'https://') === 0 |
|
277 | + || strpos($url, 'http://') === 0 |
|
278 | + ) { |
|
279 | + |
|
280 | + return $url; |
|
281 | + |
|
282 | + } |
|
283 | + |
|
284 | + return 'https://' . $url; |
|
285 | + } |
|
286 | 286 | } |
@@ -29,41 +29,41 @@ |
||
29 | 29 | |
30 | 30 | class Admin implements ISettings { |
31 | 31 | |
32 | - /** @var TrustedServers */ |
|
33 | - private $trustedServers; |
|
32 | + /** @var TrustedServers */ |
|
33 | + private $trustedServers; |
|
34 | 34 | |
35 | - public function __construct(TrustedServers $trustedServers) { |
|
36 | - $this->trustedServers = $trustedServers; |
|
37 | - } |
|
35 | + public function __construct(TrustedServers $trustedServers) { |
|
36 | + $this->trustedServers = $trustedServers; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return TemplateResponse |
|
41 | - */ |
|
42 | - public function getForm() { |
|
43 | - $parameters = [ |
|
44 | - 'trustedServers' => $this->trustedServers->getServers(), |
|
45 | - 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
46 | - ]; |
|
39 | + /** |
|
40 | + * @return TemplateResponse |
|
41 | + */ |
|
42 | + public function getForm() { |
|
43 | + $parameters = [ |
|
44 | + 'trustedServers' => $this->trustedServers->getServers(), |
|
45 | + 'autoAddServers' => $this->trustedServers->getAutoAddServers(), |
|
46 | + ]; |
|
47 | 47 | |
48 | - return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
49 | - } |
|
48 | + return new TemplateResponse('federation', 'settings-admin', $parameters, ''); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string the section ID, e.g. 'sharing' |
|
53 | - */ |
|
54 | - public function getSection() { |
|
55 | - return 'sharing'; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string the section ID, e.g. 'sharing' |
|
53 | + */ |
|
54 | + public function getSection() { |
|
55 | + return 'sharing'; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return int whether the form should be rather on the top or bottom of |
|
60 | - * the admin section. The forms are arranged in ascending order of the |
|
61 | - * priority values. It is required to return a value between 0 and 100. |
|
62 | - * |
|
63 | - * E.g.: 70 |
|
64 | - */ |
|
65 | - public function getPriority() { |
|
66 | - return 30; |
|
67 | - } |
|
58 | + /** |
|
59 | + * @return int whether the form should be rather on the top or bottom of |
|
60 | + * the admin section. The forms are arranged in ascending order of the |
|
61 | + * priority values. It is required to return a value between 0 and 100. |
|
62 | + * |
|
63 | + * E.g.: 70 |
|
64 | + */ |
|
65 | + public function getPriority() { |
|
66 | + return 30; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -27,25 +27,25 @@ |
||
27 | 27 | |
28 | 28 | class Hooks { |
29 | 29 | |
30 | - /** @var TrustedServers */ |
|
31 | - private $trustedServers; |
|
32 | - |
|
33 | - public function __construct(TrustedServers $trustedServers) { |
|
34 | - $this->trustedServers = $trustedServers; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * add servers to the list of trusted servers once a federated share was established |
|
39 | - * |
|
40 | - * @param array $params |
|
41 | - */ |
|
42 | - public function addServerHook($params) { |
|
43 | - if ( |
|
44 | - $this->trustedServers->getAutoAddServers() === true && |
|
45 | - $this->trustedServers->isTrustedServer($params['server']) === false |
|
46 | - ) { |
|
47 | - $this->trustedServers->addServer($params['server']); |
|
48 | - } |
|
49 | - } |
|
30 | + /** @var TrustedServers */ |
|
31 | + private $trustedServers; |
|
32 | + |
|
33 | + public function __construct(TrustedServers $trustedServers) { |
|
34 | + $this->trustedServers = $trustedServers; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * add servers to the list of trusted servers once a federated share was established |
|
39 | + * |
|
40 | + * @param array $params |
|
41 | + */ |
|
42 | + public function addServerHook($params) { |
|
43 | + if ( |
|
44 | + $this->trustedServers->getAutoAddServers() === true && |
|
45 | + $this->trustedServers->isTrustedServer($params['server']) === false |
|
46 | + ) { |
|
47 | + $this->trustedServers->addServer($params['server']); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -26,67 +26,67 @@ |
||
26 | 26 | |
27 | 27 | class PublicAuth implements BackendInterface { |
28 | 28 | |
29 | - /** @var string[] */ |
|
30 | - private $publicURLs; |
|
29 | + /** @var string[] */ |
|
30 | + private $publicURLs; |
|
31 | 31 | |
32 | - public function __construct() { |
|
33 | - $this->publicURLs = [ |
|
34 | - 'public-calendars', |
|
35 | - 'principals/system/public' |
|
36 | - ]; |
|
37 | - } |
|
32 | + public function __construct() { |
|
33 | + $this->publicURLs = [ |
|
34 | + 'public-calendars', |
|
35 | + 'principals/system/public' |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * When this method is called, the backend must check if authentication was |
|
41 | - * successful. |
|
42 | - * |
|
43 | - * The returned value must be one of the following |
|
44 | - * |
|
45 | - * [true, "principals/username"] |
|
46 | - * [false, "reason for failure"] |
|
47 | - * |
|
48 | - * If authentication was successful, it's expected that the authentication |
|
49 | - * backend returns a so-called principal url. |
|
50 | - * |
|
51 | - * Examples of a principal url: |
|
52 | - * |
|
53 | - * principals/admin |
|
54 | - * principals/user1 |
|
55 | - * principals/users/joe |
|
56 | - * principals/uid/123457 |
|
57 | - * |
|
58 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | - * return a string such as: |
|
60 | - * |
|
61 | - * principals/users/[username] |
|
62 | - * |
|
63 | - * @param RequestInterface $request |
|
64 | - * @param ResponseInterface $response |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - function check(RequestInterface $request, ResponseInterface $response) { |
|
39 | + /** |
|
40 | + * When this method is called, the backend must check if authentication was |
|
41 | + * successful. |
|
42 | + * |
|
43 | + * The returned value must be one of the following |
|
44 | + * |
|
45 | + * [true, "principals/username"] |
|
46 | + * [false, "reason for failure"] |
|
47 | + * |
|
48 | + * If authentication was successful, it's expected that the authentication |
|
49 | + * backend returns a so-called principal url. |
|
50 | + * |
|
51 | + * Examples of a principal url: |
|
52 | + * |
|
53 | + * principals/admin |
|
54 | + * principals/user1 |
|
55 | + * principals/users/joe |
|
56 | + * principals/uid/123457 |
|
57 | + * |
|
58 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | + * return a string such as: |
|
60 | + * |
|
61 | + * principals/users/[username] |
|
62 | + * |
|
63 | + * @param RequestInterface $request |
|
64 | + * @param ResponseInterface $response |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + function check(RequestInterface $request, ResponseInterface $response) { |
|
68 | 68 | |
69 | - if ($this->isRequestPublic($request)) { |
|
70 | - return [true, "principals/system/public"]; |
|
71 | - } |
|
72 | - return [false, "No public access to this resource."]; |
|
73 | - } |
|
69 | + if ($this->isRequestPublic($request)) { |
|
70 | + return [true, "principals/system/public"]; |
|
71 | + } |
|
72 | + return [false, "No public access to this resource."]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @inheritdoc |
|
77 | - */ |
|
78 | - function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | - } |
|
75 | + /** |
|
76 | + * @inheritdoc |
|
77 | + */ |
|
78 | + function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param RequestInterface $request |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - private function isRequestPublic(RequestInterface $request) { |
|
86 | - $url = $request->getPath(); |
|
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | - return strpos($url, $publicUrl, 0) === 0; |
|
89 | - }); |
|
90 | - return !empty($matchingUrls); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @param RequestInterface $request |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + private function isRequestPublic(RequestInterface $request) { |
|
86 | + $url = $request->getPath(); |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | + return strpos($url, $publicUrl, 0) === 0; |
|
89 | + }); |
|
90 | + return !empty($matchingUrls); |
|
91 | + } |
|
92 | 92 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | */ |
85 | 85 | private function isRequestPublic(RequestInterface $request) { |
86 | 86 | $url = $request->getPath(); |
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function($publicUrl) use ($url) { |
|
88 | 88 | return strpos($url, $publicUrl, 0) === 0; |
89 | 89 | }); |
90 | 90 | return !empty($matchingUrls); |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | static function xmlDeserialize(Reader $reader) { |
48 | 48 | |
49 | 49 | $elements = $reader->parseInnerTree([ |
50 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
51 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
50 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
51 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
52 | 52 | ]); |
53 | 53 | |
54 | 54 | $set = []; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | foreach ($elements as $elem) { |
58 | 58 | switch ($elem['name']) { |
59 | 59 | |
60 | - case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
60 | + case '{'.Plugin::NS_OWNCLOUD.'}set' : |
|
61 | 61 | $sharee = $elem['value']; |
62 | 62 | |
63 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
64 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
63 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
64 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
65 | 65 | |
66 | 66 | $set[] = [ |
67 | 67 | 'href' => $sharee['{DAV:}href'], |
68 | 68 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
69 | 69 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
70 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
70 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
71 | 71 | ]; |
72 | 72 | break; |
73 | 73 | |
74 | - case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
74 | + case '{'.Plugin::NS_OWNCLOUD.'}remove' : |
|
75 | 75 | $remove[] = $elem['value']['{DAV:}href']; |
76 | 76 | break; |
77 | 77 |
@@ -41,130 +41,130 @@ |
||
41 | 41 | */ |
42 | 42 | class Invite implements XmlSerializable { |
43 | 43 | |
44 | - /** |
|
45 | - * The list of users a calendar has been shared to. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $users; |
|
50 | - |
|
51 | - /** |
|
52 | - * The organizer contains information about the person who shared the |
|
53 | - * object. |
|
54 | - * |
|
55 | - * @var array|null |
|
56 | - */ |
|
57 | - protected $organizer; |
|
58 | - |
|
59 | - /** |
|
60 | - * Creates the property. |
|
61 | - * |
|
62 | - * Users is an array. Each element of the array has the following |
|
63 | - * properties: |
|
64 | - * |
|
65 | - * * href - Often a mailto: address |
|
66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | - * * readOnly - true or false |
|
69 | - * * summary - Optional, description of the share |
|
70 | - * |
|
71 | - * The organizer key is optional to specify. It's only useful when a |
|
72 | - * 'sharee' requests the sharing information. |
|
73 | - * |
|
74 | - * The organizer may have the following properties: |
|
75 | - * * href - Often a mailto: address. |
|
76 | - * * commonName - Optional human-readable name. |
|
77 | - * * firstName - Optional first name. |
|
78 | - * * lastName - Optional last name. |
|
79 | - * |
|
80 | - * If you wonder why these two structures are so different, I guess a |
|
81 | - * valid answer is that the current spec is still a draft. |
|
82 | - * |
|
83 | - * @param array $users |
|
84 | - */ |
|
85 | - function __construct(array $users, array $organizer = null) { |
|
86 | - |
|
87 | - $this->users = $users; |
|
88 | - $this->organizer = $organizer; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns the list of users, as it was passed to the constructor. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - function getValue() { |
|
98 | - |
|
99 | - return $this->users; |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * The xmlSerialize metod is called during xml writing. |
|
105 | - * |
|
106 | - * Use the $writer argument to write its own xml serialization. |
|
107 | - * |
|
108 | - * An important note: do _not_ create a parent element. Any element |
|
109 | - * implementing XmlSerializble should only ever write what's considered |
|
110 | - * its 'inner xml'. |
|
111 | - * |
|
112 | - * The parent of the current element is responsible for writing a |
|
113 | - * containing element. |
|
114 | - * |
|
115 | - * This allows serializers to be re-used for different element names. |
|
116 | - * |
|
117 | - * If you are opening new elements, you must also close them again. |
|
118 | - * |
|
119 | - * @param Writer $writer |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - function xmlSerialize(Writer $writer) { |
|
123 | - |
|
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | - |
|
126 | - if (!is_null($this->organizer)) { |
|
127 | - |
|
128 | - $writer->startElement($cs . 'organizer'); |
|
129 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | - |
|
131 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | - } |
|
134 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | - } |
|
137 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | - } |
|
140 | - $writer->endElement(); // organizer |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - foreach ($this->users as $user) { |
|
145 | - |
|
146 | - $writer->startElement($cs . 'user'); |
|
147 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | - if (isset($user['commonName']) && $user['commonName']) { |
|
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | - } |
|
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
152 | - |
|
153 | - $writer->startElement($cs . 'access'); |
|
154 | - if ($user['readOnly']) { |
|
155 | - $writer->writeElement($cs . 'read'); |
|
156 | - } else { |
|
157 | - $writer->writeElement($cs . 'read-write'); |
|
158 | - } |
|
159 | - $writer->endElement(); // access |
|
160 | - |
|
161 | - if (isset($user['summary']) && $user['summary']) { |
|
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | - } |
|
164 | - |
|
165 | - $writer->endElement(); //user |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - } |
|
44 | + /** |
|
45 | + * The list of users a calendar has been shared to. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $users; |
|
50 | + |
|
51 | + /** |
|
52 | + * The organizer contains information about the person who shared the |
|
53 | + * object. |
|
54 | + * |
|
55 | + * @var array|null |
|
56 | + */ |
|
57 | + protected $organizer; |
|
58 | + |
|
59 | + /** |
|
60 | + * Creates the property. |
|
61 | + * |
|
62 | + * Users is an array. Each element of the array has the following |
|
63 | + * properties: |
|
64 | + * |
|
65 | + * * href - Often a mailto: address |
|
66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | + * * readOnly - true or false |
|
69 | + * * summary - Optional, description of the share |
|
70 | + * |
|
71 | + * The organizer key is optional to specify. It's only useful when a |
|
72 | + * 'sharee' requests the sharing information. |
|
73 | + * |
|
74 | + * The organizer may have the following properties: |
|
75 | + * * href - Often a mailto: address. |
|
76 | + * * commonName - Optional human-readable name. |
|
77 | + * * firstName - Optional first name. |
|
78 | + * * lastName - Optional last name. |
|
79 | + * |
|
80 | + * If you wonder why these two structures are so different, I guess a |
|
81 | + * valid answer is that the current spec is still a draft. |
|
82 | + * |
|
83 | + * @param array $users |
|
84 | + */ |
|
85 | + function __construct(array $users, array $organizer = null) { |
|
86 | + |
|
87 | + $this->users = $users; |
|
88 | + $this->organizer = $organizer; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns the list of users, as it was passed to the constructor. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + function getValue() { |
|
98 | + |
|
99 | + return $this->users; |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * The xmlSerialize metod is called during xml writing. |
|
105 | + * |
|
106 | + * Use the $writer argument to write its own xml serialization. |
|
107 | + * |
|
108 | + * An important note: do _not_ create a parent element. Any element |
|
109 | + * implementing XmlSerializble should only ever write what's considered |
|
110 | + * its 'inner xml'. |
|
111 | + * |
|
112 | + * The parent of the current element is responsible for writing a |
|
113 | + * containing element. |
|
114 | + * |
|
115 | + * This allows serializers to be re-used for different element names. |
|
116 | + * |
|
117 | + * If you are opening new elements, you must also close them again. |
|
118 | + * |
|
119 | + * @param Writer $writer |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + function xmlSerialize(Writer $writer) { |
|
123 | + |
|
124 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | + |
|
126 | + if (!is_null($this->organizer)) { |
|
127 | + |
|
128 | + $writer->startElement($cs . 'organizer'); |
|
129 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | + |
|
131 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | + } |
|
134 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | + } |
|
137 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | + } |
|
140 | + $writer->endElement(); // organizer |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + foreach ($this->users as $user) { |
|
145 | + |
|
146 | + $writer->startElement($cs . 'user'); |
|
147 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | + if (isset($user['commonName']) && $user['commonName']) { |
|
149 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | + } |
|
151 | + $writer->writeElement($cs . 'invite-accepted'); |
|
152 | + |
|
153 | + $writer->startElement($cs . 'access'); |
|
154 | + if ($user['readOnly']) { |
|
155 | + $writer->writeElement($cs . 'read'); |
|
156 | + } else { |
|
157 | + $writer->writeElement($cs . 'read-write'); |
|
158 | + } |
|
159 | + $writer->endElement(); // access |
|
160 | + |
|
161 | + if (isset($user['summary']) && $user['summary']) { |
|
162 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | + } |
|
164 | + |
|
165 | + $writer->endElement(); //user |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + } |
|
170 | 170 | } |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | */ |
122 | 122 | function xmlSerialize(Writer $writer) { |
123 | 123 | |
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
124 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
125 | 125 | |
126 | 126 | if (!is_null($this->organizer)) { |
127 | 127 | |
128 | - $writer->startElement($cs . 'organizer'); |
|
128 | + $writer->startElement($cs.'organizer'); |
|
129 | 129 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
130 | 130 | |
131 | 131 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
132 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
133 | 133 | } |
134 | 134 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
135 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
136 | 136 | } |
137 | 137 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
138 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
139 | 139 | } |
140 | 140 | $writer->endElement(); // organizer |
141 | 141 | |
@@ -143,23 +143,23 @@ discard block |
||
143 | 143 | |
144 | 144 | foreach ($this->users as $user) { |
145 | 145 | |
146 | - $writer->startElement($cs . 'user'); |
|
146 | + $writer->startElement($cs.'user'); |
|
147 | 147 | $writer->writeElement('{DAV:}href', $user['href']); |
148 | 148 | if (isset($user['commonName']) && $user['commonName']) { |
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
149 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
150 | 150 | } |
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
151 | + $writer->writeElement($cs.'invite-accepted'); |
|
152 | 152 | |
153 | - $writer->startElement($cs . 'access'); |
|
153 | + $writer->startElement($cs.'access'); |
|
154 | 154 | if ($user['readOnly']) { |
155 | - $writer->writeElement($cs . 'read'); |
|
155 | + $writer->writeElement($cs.'read'); |
|
156 | 156 | } else { |
157 | - $writer->writeElement($cs . 'read-write'); |
|
157 | + $writer->writeElement($cs.'read-write'); |
|
158 | 158 | } |
159 | 159 | $writer->endElement(); // access |
160 | 160 | |
161 | 161 | if (isset($user['summary']) && $user['summary']) { |
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
162 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $writer->endElement(); //user |