@@ -39,105 +39,105 @@ |
||
39 | 39 | * @package OCA\FederatedFileSharing |
40 | 40 | */ |
41 | 41 | class DiscoveryManager { |
42 | - /** @var ICache */ |
|
43 | - private $cache; |
|
44 | - /** @var IClient */ |
|
45 | - private $client; |
|
42 | + /** @var ICache */ |
|
43 | + private $cache; |
|
44 | + /** @var IClient */ |
|
45 | + private $client; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param ICacheFactory $cacheFactory |
|
49 | - * @param IClientService $clientService |
|
50 | - */ |
|
51 | - public function __construct(ICacheFactory $cacheFactory, |
|
52 | - IClientService $clientService) { |
|
53 | - $this->cache = $cacheFactory->create('ocs-discovery'); |
|
54 | - $this->client = $clientService->newClient(); |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param ICacheFactory $cacheFactory |
|
49 | + * @param IClientService $clientService |
|
50 | + */ |
|
51 | + public function __construct(ICacheFactory $cacheFactory, |
|
52 | + IClientService $clientService) { |
|
53 | + $this->cache = $cacheFactory->create('ocs-discovery'); |
|
54 | + $this->client = $clientService->newClient(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns whether the specified URL includes only safe characters, if not |
|
59 | - * returns false |
|
60 | - * |
|
61 | - * @param string $url |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - private function isSafeUrl($url) { |
|
65 | - return (bool)preg_match('/^[\/\.A-Za-z0-9]+$/', $url); |
|
66 | - } |
|
57 | + /** |
|
58 | + * Returns whether the specified URL includes only safe characters, if not |
|
59 | + * returns false |
|
60 | + * |
|
61 | + * @param string $url |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + private function isSafeUrl($url) { |
|
65 | + return (bool)preg_match('/^[\/\.A-Za-z0-9]+$/', $url); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Discover the actual data and do some naive caching to ensure that the data |
|
70 | - * is not requested multiple times. |
|
71 | - * |
|
72 | - * If no valid discovery data is found the Nextcloud defaults are returned. |
|
73 | - * |
|
74 | - * @param string $remote |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - private function discover($remote) { |
|
78 | - // Check if something is in the cache |
|
79 | - if($cacheData = $this->cache->get($remote)) { |
|
80 | - return json_decode($cacheData, true); |
|
81 | - } |
|
68 | + /** |
|
69 | + * Discover the actual data and do some naive caching to ensure that the data |
|
70 | + * is not requested multiple times. |
|
71 | + * |
|
72 | + * If no valid discovery data is found the Nextcloud defaults are returned. |
|
73 | + * |
|
74 | + * @param string $remote |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + private function discover($remote) { |
|
78 | + // Check if something is in the cache |
|
79 | + if($cacheData = $this->cache->get($remote)) { |
|
80 | + return json_decode($cacheData, true); |
|
81 | + } |
|
82 | 82 | |
83 | - // Default response body |
|
84 | - $discoveredServices = [ |
|
85 | - 'webdav' => '/public.php/webdav', |
|
86 | - 'share' => '/ocs/v1.php/cloud/shares', |
|
87 | - ]; |
|
83 | + // Default response body |
|
84 | + $discoveredServices = [ |
|
85 | + 'webdav' => '/public.php/webdav', |
|
86 | + 'share' => '/ocs/v1.php/cloud/shares', |
|
87 | + ]; |
|
88 | 88 | |
89 | - // Read the data from the response body |
|
90 | - try { |
|
91 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
92 | - 'timeout' => 10, |
|
93 | - 'connect_timeout' => 10, |
|
94 | - ]); |
|
95 | - if($response->getStatusCode() === 200) { |
|
96 | - $decodedService = json_decode($response->getBody(), true); |
|
97 | - if(is_array($decodedService)) { |
|
98 | - $endpoints = [ |
|
99 | - 'webdav', |
|
100 | - 'share', |
|
101 | - ]; |
|
89 | + // Read the data from the response body |
|
90 | + try { |
|
91 | + $response = $this->client->get($remote . '/ocs-provider/', [ |
|
92 | + 'timeout' => 10, |
|
93 | + 'connect_timeout' => 10, |
|
94 | + ]); |
|
95 | + if($response->getStatusCode() === 200) { |
|
96 | + $decodedService = json_decode($response->getBody(), true); |
|
97 | + if(is_array($decodedService)) { |
|
98 | + $endpoints = [ |
|
99 | + 'webdav', |
|
100 | + 'share', |
|
101 | + ]; |
|
102 | 102 | |
103 | - foreach($endpoints as $endpoint) { |
|
104 | - if(isset($decodedService['services']['FEDERATED_SHARING']['endpoints'][$endpoint])) { |
|
105 | - $endpointUrl = (string)$decodedService['services']['FEDERATED_SHARING']['endpoints'][$endpoint]; |
|
106 | - if($this->isSafeUrl($endpointUrl)) { |
|
107 | - $discoveredServices[$endpoint] = $endpointUrl; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - } catch (ClientException $e) { |
|
114 | - // Don't throw any exception since exceptions are handled before |
|
115 | - } catch (ConnectException $e) { |
|
116 | - // Don't throw any exception since exceptions are handled before |
|
117 | - } |
|
103 | + foreach($endpoints as $endpoint) { |
|
104 | + if(isset($decodedService['services']['FEDERATED_SHARING']['endpoints'][$endpoint])) { |
|
105 | + $endpointUrl = (string)$decodedService['services']['FEDERATED_SHARING']['endpoints'][$endpoint]; |
|
106 | + if($this->isSafeUrl($endpointUrl)) { |
|
107 | + $discoveredServices[$endpoint] = $endpointUrl; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + } catch (ClientException $e) { |
|
114 | + // Don't throw any exception since exceptions are handled before |
|
115 | + } catch (ConnectException $e) { |
|
116 | + // Don't throw any exception since exceptions are handled before |
|
117 | + } |
|
118 | 118 | |
119 | - // Write into cache |
|
120 | - $this->cache->set($remote, json_encode($discoveredServices)); |
|
121 | - return $discoveredServices; |
|
122 | - } |
|
119 | + // Write into cache |
|
120 | + $this->cache->set($remote, json_encode($discoveredServices)); |
|
121 | + return $discoveredServices; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Return the public WebDAV endpoint used by the specified remote |
|
126 | - * |
|
127 | - * @param string $host |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function getWebDavEndpoint($host) { |
|
131 | - return $this->discover($host)['webdav']; |
|
132 | - } |
|
124 | + /** |
|
125 | + * Return the public WebDAV endpoint used by the specified remote |
|
126 | + * |
|
127 | + * @param string $host |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function getWebDavEndpoint($host) { |
|
131 | + return $this->discover($host)['webdav']; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Return the sharing endpoint used by the specified remote |
|
136 | - * |
|
137 | - * @param string $host |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function getShareEndpoint($host) { |
|
141 | - return $this->discover($host)['share']; |
|
142 | - } |
|
134 | + /** |
|
135 | + * Return the sharing endpoint used by the specified remote |
|
136 | + * |
|
137 | + * @param string $host |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function getShareEndpoint($host) { |
|
141 | + return $this->discover($host)['share']; |
|
142 | + } |
|
143 | 143 | } |
@@ -33,30 +33,30 @@ |
||
33 | 33 | */ |
34 | 34 | class TokenHandler { |
35 | 35 | |
36 | - const TOKEN_LENGTH = 15; |
|
37 | - |
|
38 | - /** @var ISecureRandom */ |
|
39 | - private $secureRandom; |
|
40 | - |
|
41 | - /** |
|
42 | - * TokenHandler constructor. |
|
43 | - * |
|
44 | - * @param ISecureRandom $secureRandom |
|
45 | - */ |
|
46 | - public function __construct(ISecureRandom $secureRandom) { |
|
47 | - $this->secureRandom = $secureRandom; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * generate to token used to authenticate federated shares |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function generateToken() { |
|
56 | - $token = $this->secureRandom->generate( |
|
57 | - self::TOKEN_LENGTH, |
|
58 | - ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
59 | - return $token; |
|
60 | - } |
|
36 | + const TOKEN_LENGTH = 15; |
|
37 | + |
|
38 | + /** @var ISecureRandom */ |
|
39 | + private $secureRandom; |
|
40 | + |
|
41 | + /** |
|
42 | + * TokenHandler constructor. |
|
43 | + * |
|
44 | + * @param ISecureRandom $secureRandom |
|
45 | + */ |
|
46 | + public function __construct(ISecureRandom $secureRandom) { |
|
47 | + $this->secureRandom = $secureRandom; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * generate to token used to authenticate federated shares |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function generateToken() { |
|
56 | + $token = $this->secureRandom->generate( |
|
57 | + self::TOKEN_LENGTH, |
|
58 | + ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
59 | + return $token; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -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> |
@@ -34,91 +34,91 @@ |
||
34 | 34 | |
35 | 35 | class SettingsController extends Controller { |
36 | 36 | |
37 | - /** @var IL10N */ |
|
38 | - private $l; |
|
39 | - |
|
40 | - /** @var TrustedServers */ |
|
41 | - private $trustedServers; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $AppName |
|
45 | - * @param IRequest $request |
|
46 | - * @param IL10N $l10n |
|
47 | - * @param TrustedServers $trustedServers |
|
48 | - */ |
|
49 | - public function __construct($AppName, |
|
50 | - IRequest $request, |
|
51 | - IL10N $l10n, |
|
52 | - TrustedServers $trustedServers |
|
53 | - ) { |
|
54 | - parent::__construct($AppName, $request); |
|
55 | - $this->l = $l10n; |
|
56 | - $this->trustedServers = $trustedServers; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * add server to the list of trusted ownClouds |
|
62 | - * |
|
63 | - * @param string $url |
|
64 | - * @return DataResponse |
|
65 | - * @throws HintException |
|
66 | - */ |
|
67 | - public function addServer($url) { |
|
68 | - $this->checkServer($url); |
|
69 | - $id = $this->trustedServers->addServer($url); |
|
70 | - |
|
71 | - return new DataResponse( |
|
72 | - [ |
|
73 | - 'url' => $url, |
|
74 | - 'id' => $id, |
|
75 | - 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
76 | - ] |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * add server to the list of trusted ownClouds |
|
82 | - * |
|
83 | - * @param int $id |
|
84 | - * @return DataResponse |
|
85 | - */ |
|
86 | - public function removeServer($id) { |
|
87 | - $this->trustedServers->removeServer($id); |
|
88 | - return new DataResponse(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * enable/disable to automatically add servers to the list of trusted servers |
|
93 | - * once a federated share was created and accepted successfully |
|
94 | - * |
|
95 | - * @param bool $autoAddServers |
|
96 | - */ |
|
97 | - public function autoAddServers($autoAddServers) { |
|
98 | - $this->trustedServers->setAutoAddServers($autoAddServers); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * check if the server should be added to the list of trusted servers or not |
|
103 | - * |
|
104 | - * @param string $url |
|
105 | - * @return bool |
|
106 | - * @throws HintException |
|
107 | - */ |
|
108 | - protected function checkServer($url) { |
|
109 | - if ($this->trustedServers->isTrustedServer($url) === true) { |
|
110 | - $message = 'Server is already in the list of trusted servers.'; |
|
111 | - $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
112 | - throw new HintException($message, $hint); |
|
113 | - } |
|
114 | - |
|
115 | - if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
116 | - $message = 'No server to federate with found'; |
|
117 | - $hint = $this->l->t('No server to federate with found'); |
|
118 | - throw new HintException($message, $hint); |
|
119 | - } |
|
120 | - |
|
121 | - return true; |
|
122 | - } |
|
37 | + /** @var IL10N */ |
|
38 | + private $l; |
|
39 | + |
|
40 | + /** @var TrustedServers */ |
|
41 | + private $trustedServers; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $AppName |
|
45 | + * @param IRequest $request |
|
46 | + * @param IL10N $l10n |
|
47 | + * @param TrustedServers $trustedServers |
|
48 | + */ |
|
49 | + public function __construct($AppName, |
|
50 | + IRequest $request, |
|
51 | + IL10N $l10n, |
|
52 | + TrustedServers $trustedServers |
|
53 | + ) { |
|
54 | + parent::__construct($AppName, $request); |
|
55 | + $this->l = $l10n; |
|
56 | + $this->trustedServers = $trustedServers; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * add server to the list of trusted ownClouds |
|
62 | + * |
|
63 | + * @param string $url |
|
64 | + * @return DataResponse |
|
65 | + * @throws HintException |
|
66 | + */ |
|
67 | + public function addServer($url) { |
|
68 | + $this->checkServer($url); |
|
69 | + $id = $this->trustedServers->addServer($url); |
|
70 | + |
|
71 | + return new DataResponse( |
|
72 | + [ |
|
73 | + 'url' => $url, |
|
74 | + 'id' => $id, |
|
75 | + 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
76 | + ] |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * add server to the list of trusted ownClouds |
|
82 | + * |
|
83 | + * @param int $id |
|
84 | + * @return DataResponse |
|
85 | + */ |
|
86 | + public function removeServer($id) { |
|
87 | + $this->trustedServers->removeServer($id); |
|
88 | + return new DataResponse(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * enable/disable to automatically add servers to the list of trusted servers |
|
93 | + * once a federated share was created and accepted successfully |
|
94 | + * |
|
95 | + * @param bool $autoAddServers |
|
96 | + */ |
|
97 | + public function autoAddServers($autoAddServers) { |
|
98 | + $this->trustedServers->setAutoAddServers($autoAddServers); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * check if the server should be added to the list of trusted servers or not |
|
103 | + * |
|
104 | + * @param string $url |
|
105 | + * @return bool |
|
106 | + * @throws HintException |
|
107 | + */ |
|
108 | + protected function checkServer($url) { |
|
109 | + if ($this->trustedServers->isTrustedServer($url) === true) { |
|
110 | + $message = 'Server is already in the list of trusted servers.'; |
|
111 | + $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
112 | + throw new HintException($message, $hint); |
|
113 | + } |
|
114 | + |
|
115 | + if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
116 | + $message = 'No server to federate with found'; |
|
117 | + $hint = $this->l->t('No server to federate with found'); |
|
118 | + throw new HintException($message, $hint); |
|
119 | + } |
|
120 | + |
|
121 | + return true; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | } |
@@ -31,45 +31,45 @@ |
||
31 | 31 | |
32 | 32 | class SyncFederationAddressBooks extends Command { |
33 | 33 | |
34 | - /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
35 | - private $syncService; |
|
34 | + /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
35 | + private $syncService; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
39 | - */ |
|
40 | - function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
41 | - parent::__construct(); |
|
37 | + /** |
|
38 | + * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
39 | + */ |
|
40 | + function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
41 | + parent::__construct(); |
|
42 | 42 | |
43 | - $this->syncService = $syncService; |
|
44 | - } |
|
43 | + $this->syncService = $syncService; |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('federation:sync-addressbooks') |
|
49 | - ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
50 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('federation:sync-addressbooks') |
|
49 | + ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param InputInterface $input |
|
54 | - * @param OutputInterface $output |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
52 | + /** |
|
53 | + * @param InputInterface $input |
|
54 | + * @param OutputInterface $output |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
58 | 58 | |
59 | - $progress = new ProgressBar($output); |
|
60 | - $progress->start(); |
|
61 | - $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
62 | - if ($ex instanceof \Exception) { |
|
63 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
59 | + $progress = new ProgressBar($output); |
|
60 | + $progress->start(); |
|
61 | + $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
62 | + if ($ex instanceof \Exception) { |
|
63 | + $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
64 | 64 | |
65 | - } else { |
|
66 | - $progress->advance(); |
|
67 | - } |
|
68 | - }); |
|
65 | + } else { |
|
66 | + $progress->advance(); |
|
67 | + } |
|
68 | + }); |
|
69 | 69 | |
70 | - $progress->finish(); |
|
71 | - $output->writeln(''); |
|
70 | + $progress->finish(); |
|
71 | + $output->writeln(''); |
|
72 | 72 | |
73 | - return 0; |
|
74 | - } |
|
73 | + return 0; |
|
74 | + } |
|
75 | 75 | } |
@@ -32,52 +32,52 @@ |
||
32 | 32 | |
33 | 33 | class SyncFederationAddressBooks { |
34 | 34 | |
35 | - /** @var DbHandler */ |
|
36 | - protected $dbHandler; |
|
35 | + /** @var DbHandler */ |
|
36 | + protected $dbHandler; |
|
37 | 37 | |
38 | - /** @var SyncService */ |
|
39 | - private $syncService; |
|
38 | + /** @var SyncService */ |
|
39 | + private $syncService; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param DbHandler $dbHandler |
|
43 | - * @param SyncService $syncService |
|
44 | - */ |
|
45 | - function __construct(DbHandler $dbHandler, SyncService $syncService) { |
|
46 | - $this->syncService = $syncService; |
|
47 | - $this->dbHandler = $dbHandler; |
|
48 | - } |
|
41 | + /** |
|
42 | + * @param DbHandler $dbHandler |
|
43 | + * @param SyncService $syncService |
|
44 | + */ |
|
45 | + function __construct(DbHandler $dbHandler, SyncService $syncService) { |
|
46 | + $this->syncService = $syncService; |
|
47 | + $this->dbHandler = $dbHandler; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param \Closure $callback |
|
52 | - */ |
|
53 | - public function syncThemAll(\Closure $callback) { |
|
50 | + /** |
|
51 | + * @param \Closure $callback |
|
52 | + */ |
|
53 | + public function syncThemAll(\Closure $callback) { |
|
54 | 54 | |
55 | - $trustedServers = $this->dbHandler->getAllServer(); |
|
56 | - foreach ($trustedServers as $trustedServer) { |
|
57 | - $url = $trustedServer['url']; |
|
58 | - $callback($url, null); |
|
59 | - $sharedSecret = $trustedServer['shared_secret']; |
|
60 | - $syncToken = $trustedServer['sync_token']; |
|
55 | + $trustedServers = $this->dbHandler->getAllServer(); |
|
56 | + foreach ($trustedServers as $trustedServer) { |
|
57 | + $url = $trustedServer['url']; |
|
58 | + $callback($url, null); |
|
59 | + $sharedSecret = $trustedServer['shared_secret']; |
|
60 | + $syncToken = $trustedServer['sync_token']; |
|
61 | 61 | |
62 | - if (is_null($sharedSecret)) { |
|
63 | - continue; |
|
64 | - } |
|
65 | - $targetBookId = $trustedServer['url_hash']; |
|
66 | - $targetPrincipal = "principals/system/system"; |
|
67 | - $targetBookProperties = [ |
|
68 | - '{DAV:}displayname' => $url |
|
69 | - ]; |
|
70 | - try { |
|
71 | - $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); |
|
72 | - if ($newToken !== $syncToken) { |
|
73 | - $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); |
|
74 | - } |
|
75 | - } catch (\Exception $ex) { |
|
76 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
77 | - $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); |
|
78 | - } |
|
79 | - $callback($url, $ex); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
62 | + if (is_null($sharedSecret)) { |
|
63 | + continue; |
|
64 | + } |
|
65 | + $targetBookId = $trustedServer['url_hash']; |
|
66 | + $targetPrincipal = "principals/system/system"; |
|
67 | + $targetBookProperties = [ |
|
68 | + '{DAV:}displayname' => $url |
|
69 | + ]; |
|
70 | + try { |
|
71 | + $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); |
|
72 | + if ($newToken !== $syncToken) { |
|
73 | + $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); |
|
74 | + } |
|
75 | + } catch (\Exception $ex) { |
|
76 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
77 | + $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); |
|
78 | + } |
|
79 | + $callback($url, $ex); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | 83 | } |
@@ -47,157 +47,157 @@ |
||
47 | 47 | */ |
48 | 48 | class GetSharedSecret extends Job{ |
49 | 49 | |
50 | - /** @var IClient */ |
|
51 | - private $httpClient; |
|
52 | - |
|
53 | - /** @var IJobList */ |
|
54 | - private $jobList; |
|
55 | - |
|
56 | - /** @var IURLGenerator */ |
|
57 | - private $urlGenerator; |
|
58 | - |
|
59 | - /** @var TrustedServers */ |
|
60 | - private $trustedServers; |
|
61 | - |
|
62 | - /** @var DbHandler */ |
|
63 | - private $dbHandler; |
|
64 | - |
|
65 | - /** @var ILogger */ |
|
66 | - private $logger; |
|
67 | - |
|
68 | - /** @var bool */ |
|
69 | - protected $retainJob = false; |
|
70 | - |
|
71 | - private $endPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json'; |
|
72 | - |
|
73 | - /** |
|
74 | - * RequestSharedSecret constructor. |
|
75 | - * |
|
76 | - * @param IClient $httpClient |
|
77 | - * @param IURLGenerator $urlGenerator |
|
78 | - * @param IJobList $jobList |
|
79 | - * @param TrustedServers $trustedServers |
|
80 | - * @param ILogger $logger |
|
81 | - * @param DbHandler $dbHandler |
|
82 | - */ |
|
83 | - public function __construct( |
|
84 | - IClient $httpClient = null, |
|
85 | - IURLGenerator $urlGenerator = null, |
|
86 | - IJobList $jobList = null, |
|
87 | - TrustedServers $trustedServers = null, |
|
88 | - ILogger $logger = null, |
|
89 | - DbHandler $dbHandler = null |
|
90 | - ) { |
|
91 | - $this->logger = $logger ? $logger : \OC::$server->getLogger(); |
|
92 | - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
93 | - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
94 | - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
95 | - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
96 | - if ($trustedServers) { |
|
97 | - $this->trustedServers = $trustedServers; |
|
98 | - } else { |
|
99 | - $this->trustedServers = new TrustedServers( |
|
100 | - $this->dbHandler, |
|
101 | - \OC::$server->getHTTPClientService(), |
|
102 | - $this->logger, |
|
103 | - $this->jobList, |
|
104 | - \OC::$server->getSecureRandom(), |
|
105 | - \OC::$server->getConfig(), |
|
106 | - \OC::$server->getEventDispatcher() |
|
107 | - ); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * run the job, then remove it from the joblist |
|
113 | - * |
|
114 | - * @param JobList $jobList |
|
115 | - * @param ILogger $logger |
|
116 | - */ |
|
117 | - public function execute($jobList, ILogger $logger = null) { |
|
118 | - $target = $this->argument['url']; |
|
119 | - // only execute if target is still in the list of trusted domains |
|
120 | - if ($this->trustedServers->isTrustedServer($target)) { |
|
121 | - $this->parentExecute($jobList, $logger); |
|
122 | - } |
|
123 | - |
|
124 | - if (!$this->retainJob) { |
|
125 | - $jobList->remove($this, $this->argument); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * call execute() method of parent |
|
131 | - * |
|
132 | - * @param JobList $jobList |
|
133 | - * @param ILogger $logger |
|
134 | - */ |
|
135 | - protected function parentExecute($jobList, $logger = null) { |
|
136 | - parent::execute($jobList, $logger); |
|
137 | - } |
|
138 | - |
|
139 | - protected function run($argument) { |
|
140 | - $target = $argument['url']; |
|
141 | - $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
142 | - $source = rtrim($source, '/'); |
|
143 | - $token = $argument['token']; |
|
144 | - |
|
145 | - $result = null; |
|
146 | - try { |
|
147 | - $result = $this->httpClient->get( |
|
148 | - $target . $this->endPoint, |
|
149 | - [ |
|
150 | - 'query' => |
|
151 | - [ |
|
152 | - 'url' => $source, |
|
153 | - 'token' => $token |
|
154 | - ], |
|
155 | - 'timeout' => 3, |
|
156 | - 'connect_timeout' => 3, |
|
157 | - ] |
|
158 | - ); |
|
159 | - |
|
160 | - $status = $result->getStatusCode(); |
|
161 | - |
|
162 | - } catch (ClientException $e) { |
|
163 | - $status = $e->getCode(); |
|
164 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
165 | - $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
166 | - } else { |
|
167 | - $this->logger->logException($e, ['app' => 'federation']); |
|
168 | - } |
|
169 | - } catch (\Exception $e) { |
|
170 | - $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
171 | - $this->logger->logException($e, ['app' => 'federation']); |
|
172 | - } |
|
173 | - |
|
174 | - // if we received a unexpected response we try again later |
|
175 | - if ( |
|
176 | - $status !== Http::STATUS_OK |
|
177 | - && $status !== Http::STATUS_FORBIDDEN |
|
178 | - ) { |
|
179 | - $this->retainJob = true; |
|
180 | - } else { |
|
181 | - // reset token if we received a valid response |
|
182 | - $this->dbHandler->addToken($target, ''); |
|
183 | - } |
|
184 | - |
|
185 | - if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
186 | - $body = $result->getBody(); |
|
187 | - $result = json_decode($body, true); |
|
188 | - if (isset($result['ocs']['data']['sharedSecret'])) { |
|
189 | - $this->trustedServers->addSharedSecret( |
|
190 | - $target, |
|
191 | - $result['ocs']['data']['sharedSecret'] |
|
192 | - ); |
|
193 | - } else { |
|
194 | - $this->logger->error( |
|
195 | - 'remote server "' . $target . '"" does not return a valid shared secret', |
|
196 | - ['app' => 'federation'] |
|
197 | - ); |
|
198 | - $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - } |
|
50 | + /** @var IClient */ |
|
51 | + private $httpClient; |
|
52 | + |
|
53 | + /** @var IJobList */ |
|
54 | + private $jobList; |
|
55 | + |
|
56 | + /** @var IURLGenerator */ |
|
57 | + private $urlGenerator; |
|
58 | + |
|
59 | + /** @var TrustedServers */ |
|
60 | + private $trustedServers; |
|
61 | + |
|
62 | + /** @var DbHandler */ |
|
63 | + private $dbHandler; |
|
64 | + |
|
65 | + /** @var ILogger */ |
|
66 | + private $logger; |
|
67 | + |
|
68 | + /** @var bool */ |
|
69 | + protected $retainJob = false; |
|
70 | + |
|
71 | + private $endPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json'; |
|
72 | + |
|
73 | + /** |
|
74 | + * RequestSharedSecret constructor. |
|
75 | + * |
|
76 | + * @param IClient $httpClient |
|
77 | + * @param IURLGenerator $urlGenerator |
|
78 | + * @param IJobList $jobList |
|
79 | + * @param TrustedServers $trustedServers |
|
80 | + * @param ILogger $logger |
|
81 | + * @param DbHandler $dbHandler |
|
82 | + */ |
|
83 | + public function __construct( |
|
84 | + IClient $httpClient = null, |
|
85 | + IURLGenerator $urlGenerator = null, |
|
86 | + IJobList $jobList = null, |
|
87 | + TrustedServers $trustedServers = null, |
|
88 | + ILogger $logger = null, |
|
89 | + DbHandler $dbHandler = null |
|
90 | + ) { |
|
91 | + $this->logger = $logger ? $logger : \OC::$server->getLogger(); |
|
92 | + $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
93 | + $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
94 | + $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
95 | + $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
96 | + if ($trustedServers) { |
|
97 | + $this->trustedServers = $trustedServers; |
|
98 | + } else { |
|
99 | + $this->trustedServers = new TrustedServers( |
|
100 | + $this->dbHandler, |
|
101 | + \OC::$server->getHTTPClientService(), |
|
102 | + $this->logger, |
|
103 | + $this->jobList, |
|
104 | + \OC::$server->getSecureRandom(), |
|
105 | + \OC::$server->getConfig(), |
|
106 | + \OC::$server->getEventDispatcher() |
|
107 | + ); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * run the job, then remove it from the joblist |
|
113 | + * |
|
114 | + * @param JobList $jobList |
|
115 | + * @param ILogger $logger |
|
116 | + */ |
|
117 | + public function execute($jobList, ILogger $logger = null) { |
|
118 | + $target = $this->argument['url']; |
|
119 | + // only execute if target is still in the list of trusted domains |
|
120 | + if ($this->trustedServers->isTrustedServer($target)) { |
|
121 | + $this->parentExecute($jobList, $logger); |
|
122 | + } |
|
123 | + |
|
124 | + if (!$this->retainJob) { |
|
125 | + $jobList->remove($this, $this->argument); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * call execute() method of parent |
|
131 | + * |
|
132 | + * @param JobList $jobList |
|
133 | + * @param ILogger $logger |
|
134 | + */ |
|
135 | + protected function parentExecute($jobList, $logger = null) { |
|
136 | + parent::execute($jobList, $logger); |
|
137 | + } |
|
138 | + |
|
139 | + protected function run($argument) { |
|
140 | + $target = $argument['url']; |
|
141 | + $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
142 | + $source = rtrim($source, '/'); |
|
143 | + $token = $argument['token']; |
|
144 | + |
|
145 | + $result = null; |
|
146 | + try { |
|
147 | + $result = $this->httpClient->get( |
|
148 | + $target . $this->endPoint, |
|
149 | + [ |
|
150 | + 'query' => |
|
151 | + [ |
|
152 | + 'url' => $source, |
|
153 | + 'token' => $token |
|
154 | + ], |
|
155 | + 'timeout' => 3, |
|
156 | + 'connect_timeout' => 3, |
|
157 | + ] |
|
158 | + ); |
|
159 | + |
|
160 | + $status = $result->getStatusCode(); |
|
161 | + |
|
162 | + } catch (ClientException $e) { |
|
163 | + $status = $e->getCode(); |
|
164 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
165 | + $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']); |
|
166 | + } else { |
|
167 | + $this->logger->logException($e, ['app' => 'federation']); |
|
168 | + } |
|
169 | + } catch (\Exception $e) { |
|
170 | + $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
171 | + $this->logger->logException($e, ['app' => 'federation']); |
|
172 | + } |
|
173 | + |
|
174 | + // if we received a unexpected response we try again later |
|
175 | + if ( |
|
176 | + $status !== Http::STATUS_OK |
|
177 | + && $status !== Http::STATUS_FORBIDDEN |
|
178 | + ) { |
|
179 | + $this->retainJob = true; |
|
180 | + } else { |
|
181 | + // reset token if we received a valid response |
|
182 | + $this->dbHandler->addToken($target, ''); |
|
183 | + } |
|
184 | + |
|
185 | + if ($status === Http::STATUS_OK && $result instanceof IResponse) { |
|
186 | + $body = $result->getBody(); |
|
187 | + $result = json_decode($body, true); |
|
188 | + if (isset($result['ocs']['data']['sharedSecret'])) { |
|
189 | + $this->trustedServers->addSharedSecret( |
|
190 | + $target, |
|
191 | + $result['ocs']['data']['sharedSecret'] |
|
192 | + ); |
|
193 | + } else { |
|
194 | + $this->logger->error( |
|
195 | + 'remote server "' . $target . '"" does not return a valid shared secret', |
|
196 | + ['app' => 'federation'] |
|
197 | + ); |
|
198 | + $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + } |
|
203 | 203 | } |
@@ -47,140 +47,140 @@ |
||
47 | 47 | */ |
48 | 48 | class RequestSharedSecret extends Job { |
49 | 49 | |
50 | - /** @var IClient */ |
|
51 | - private $httpClient; |
|
52 | - |
|
53 | - /** @var IJobList */ |
|
54 | - private $jobList; |
|
55 | - |
|
56 | - /** @var IURLGenerator */ |
|
57 | - private $urlGenerator; |
|
58 | - |
|
59 | - /** @var DbHandler */ |
|
60 | - private $dbHandler; |
|
61 | - |
|
62 | - /** @var TrustedServers */ |
|
63 | - private $trustedServers; |
|
64 | - |
|
65 | - private $endPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json'; |
|
66 | - |
|
67 | - /** @var ILogger */ |
|
68 | - private $logger; |
|
69 | - |
|
70 | - /** @var bool */ |
|
71 | - protected $retainJob = false; |
|
72 | - |
|
73 | - /** |
|
74 | - * RequestSharedSecret constructor. |
|
75 | - * |
|
76 | - * @param IClient $httpClient |
|
77 | - * @param IURLGenerator $urlGenerator |
|
78 | - * @param IJobList $jobList |
|
79 | - * @param TrustedServers $trustedServers |
|
80 | - * @param DbHandler $dbHandler |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - IClient $httpClient = null, |
|
84 | - IURLGenerator $urlGenerator = null, |
|
85 | - IJobList $jobList = null, |
|
86 | - TrustedServers $trustedServers = null, |
|
87 | - DbHandler $dbHandler = null |
|
88 | - ) { |
|
89 | - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
90 | - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
91 | - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
92 | - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
93 | - $this->logger = \OC::$server->getLogger(); |
|
94 | - if ($trustedServers) { |
|
95 | - $this->trustedServers = $trustedServers; |
|
96 | - } else { |
|
97 | - $this->trustedServers = new TrustedServers( |
|
98 | - $this->dbHandler, |
|
99 | - \OC::$server->getHTTPClientService(), |
|
100 | - $this->logger, |
|
101 | - $this->jobList, |
|
102 | - \OC::$server->getSecureRandom(), |
|
103 | - \OC::$server->getConfig(), |
|
104 | - \OC::$server->getEventDispatcher() |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * run the job, then remove it from the joblist |
|
112 | - * |
|
113 | - * @param JobList $jobList |
|
114 | - * @param ILogger $logger |
|
115 | - */ |
|
116 | - public function execute($jobList, ILogger $logger = null) { |
|
117 | - $target = $this->argument['url']; |
|
118 | - // only execute if target is still in the list of trusted domains |
|
119 | - if ($this->trustedServers->isTrustedServer($target)) { |
|
120 | - $this->parentExecute($jobList, $logger); |
|
121 | - } |
|
122 | - |
|
123 | - if (!$this->retainJob) { |
|
124 | - $jobList->remove($this, $this->argument); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * call execute() method of parent |
|
130 | - * |
|
131 | - * @param JobList $jobList |
|
132 | - * @param ILogger $logger |
|
133 | - */ |
|
134 | - protected function parentExecute($jobList, $logger) { |
|
135 | - parent::execute($jobList, $logger); |
|
136 | - } |
|
137 | - |
|
138 | - protected function run($argument) { |
|
139 | - |
|
140 | - $target = $argument['url']; |
|
141 | - $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
142 | - $source = rtrim($source, '/'); |
|
143 | - $token = $argument['token']; |
|
144 | - |
|
145 | - try { |
|
146 | - $result = $this->httpClient->post( |
|
147 | - $target . $this->endPoint, |
|
148 | - [ |
|
149 | - 'body' => [ |
|
150 | - 'url' => $source, |
|
151 | - 'token' => $token, |
|
152 | - ], |
|
153 | - 'timeout' => 3, |
|
154 | - 'connect_timeout' => 3, |
|
155 | - ] |
|
156 | - ); |
|
157 | - |
|
158 | - $status = $result->getStatusCode(); |
|
159 | - |
|
160 | - } catch (ClientException $e) { |
|
161 | - $status = $e->getCode(); |
|
162 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
163 | - $this->logger->info($target . ' refused to ask for a shared secret.', ['app' => 'federation']); |
|
164 | - } else { |
|
165 | - $this->logger->logException($e, ['app' => 'federation']); |
|
166 | - } |
|
167 | - } catch (\Exception $e) { |
|
168 | - $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
169 | - $this->logger->logException($e, ['app' => 'federation']); |
|
170 | - } |
|
171 | - |
|
172 | - // if we received a unexpected response we try again later |
|
173 | - if ( |
|
174 | - $status !== Http::STATUS_OK |
|
175 | - && $status !== Http::STATUS_FORBIDDEN |
|
176 | - ) { |
|
177 | - $this->retainJob = true; |
|
178 | - } |
|
179 | - |
|
180 | - if ($status === Http::STATUS_FORBIDDEN) { |
|
181 | - // clear token if remote server refuses to ask for shared secret |
|
182 | - $this->dbHandler->addToken($target, ''); |
|
183 | - } |
|
184 | - |
|
185 | - } |
|
50 | + /** @var IClient */ |
|
51 | + private $httpClient; |
|
52 | + |
|
53 | + /** @var IJobList */ |
|
54 | + private $jobList; |
|
55 | + |
|
56 | + /** @var IURLGenerator */ |
|
57 | + private $urlGenerator; |
|
58 | + |
|
59 | + /** @var DbHandler */ |
|
60 | + private $dbHandler; |
|
61 | + |
|
62 | + /** @var TrustedServers */ |
|
63 | + private $trustedServers; |
|
64 | + |
|
65 | + private $endPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json'; |
|
66 | + |
|
67 | + /** @var ILogger */ |
|
68 | + private $logger; |
|
69 | + |
|
70 | + /** @var bool */ |
|
71 | + protected $retainJob = false; |
|
72 | + |
|
73 | + /** |
|
74 | + * RequestSharedSecret constructor. |
|
75 | + * |
|
76 | + * @param IClient $httpClient |
|
77 | + * @param IURLGenerator $urlGenerator |
|
78 | + * @param IJobList $jobList |
|
79 | + * @param TrustedServers $trustedServers |
|
80 | + * @param DbHandler $dbHandler |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + IClient $httpClient = null, |
|
84 | + IURLGenerator $urlGenerator = null, |
|
85 | + IJobList $jobList = null, |
|
86 | + TrustedServers $trustedServers = null, |
|
87 | + DbHandler $dbHandler = null |
|
88 | + ) { |
|
89 | + $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); |
|
90 | + $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); |
|
91 | + $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); |
|
92 | + $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); |
|
93 | + $this->logger = \OC::$server->getLogger(); |
|
94 | + if ($trustedServers) { |
|
95 | + $this->trustedServers = $trustedServers; |
|
96 | + } else { |
|
97 | + $this->trustedServers = new TrustedServers( |
|
98 | + $this->dbHandler, |
|
99 | + \OC::$server->getHTTPClientService(), |
|
100 | + $this->logger, |
|
101 | + $this->jobList, |
|
102 | + \OC::$server->getSecureRandom(), |
|
103 | + \OC::$server->getConfig(), |
|
104 | + \OC::$server->getEventDispatcher() |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * run the job, then remove it from the joblist |
|
112 | + * |
|
113 | + * @param JobList $jobList |
|
114 | + * @param ILogger $logger |
|
115 | + */ |
|
116 | + public function execute($jobList, ILogger $logger = null) { |
|
117 | + $target = $this->argument['url']; |
|
118 | + // only execute if target is still in the list of trusted domains |
|
119 | + if ($this->trustedServers->isTrustedServer($target)) { |
|
120 | + $this->parentExecute($jobList, $logger); |
|
121 | + } |
|
122 | + |
|
123 | + if (!$this->retainJob) { |
|
124 | + $jobList->remove($this, $this->argument); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * call execute() method of parent |
|
130 | + * |
|
131 | + * @param JobList $jobList |
|
132 | + * @param ILogger $logger |
|
133 | + */ |
|
134 | + protected function parentExecute($jobList, $logger) { |
|
135 | + parent::execute($jobList, $logger); |
|
136 | + } |
|
137 | + |
|
138 | + protected function run($argument) { |
|
139 | + |
|
140 | + $target = $argument['url']; |
|
141 | + $source = $this->urlGenerator->getAbsoluteURL('/'); |
|
142 | + $source = rtrim($source, '/'); |
|
143 | + $token = $argument['token']; |
|
144 | + |
|
145 | + try { |
|
146 | + $result = $this->httpClient->post( |
|
147 | + $target . $this->endPoint, |
|
148 | + [ |
|
149 | + 'body' => [ |
|
150 | + 'url' => $source, |
|
151 | + 'token' => $token, |
|
152 | + ], |
|
153 | + 'timeout' => 3, |
|
154 | + 'connect_timeout' => 3, |
|
155 | + ] |
|
156 | + ); |
|
157 | + |
|
158 | + $status = $result->getStatusCode(); |
|
159 | + |
|
160 | + } catch (ClientException $e) { |
|
161 | + $status = $e->getCode(); |
|
162 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
163 | + $this->logger->info($target . ' refused to ask for a shared secret.', ['app' => 'federation']); |
|
164 | + } else { |
|
165 | + $this->logger->logException($e, ['app' => 'federation']); |
|
166 | + } |
|
167 | + } catch (\Exception $e) { |
|
168 | + $status = Http::STATUS_INTERNAL_SERVER_ERROR; |
|
169 | + $this->logger->logException($e, ['app' => 'federation']); |
|
170 | + } |
|
171 | + |
|
172 | + // if we received a unexpected response we try again later |
|
173 | + if ( |
|
174 | + $status !== Http::STATUS_OK |
|
175 | + && $status !== Http::STATUS_FORBIDDEN |
|
176 | + ) { |
|
177 | + $this->retainJob = true; |
|
178 | + } |
|
179 | + |
|
180 | + if ($status === Http::STATUS_FORBIDDEN) { |
|
181 | + // clear token if remote server refuses to ask for shared secret |
|
182 | + $this->dbHandler->addToken($target, ''); |
|
183 | + } |
|
184 | + |
|
185 | + } |
|
186 | 186 | } |
@@ -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 | } |