|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Björn Schießle <[email protected]> |
|
6
|
|
|
* @author Lukas Reschke <[email protected]> |
|
7
|
|
|
* @author Thomas Müller <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace OCA\Federation; |
|
25
|
|
|
|
|
26
|
|
|
use OC\OCS\DiscoveryService; |
|
27
|
|
|
use OCA\DAV\CardDAV\SyncService; |
|
28
|
|
|
use OCP\AppFramework\Http; |
|
29
|
|
|
use OCP\OCS\IDiscoveryService; |
|
30
|
|
|
|
|
31
|
|
|
class SyncFederationAddressBooks { |
|
32
|
|
|
|
|
33
|
|
|
/** @var DbHandler */ |
|
34
|
|
|
protected $dbHandler; |
|
35
|
|
|
|
|
36
|
|
|
/** @var SyncService */ |
|
37
|
|
|
private $syncService; |
|
38
|
|
|
|
|
39
|
|
|
/** @var DiscoveryService */ |
|
40
|
|
|
private $ocsDiscoveryService; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param DbHandler $dbHandler |
|
44
|
|
|
* @param SyncService $syncService |
|
45
|
|
|
* @param IDiscoveryService $ocsDiscoveryService |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(DbHandler $dbHandler, |
|
48
|
|
|
SyncService $syncService, |
|
49
|
|
|
IDiscoveryService $ocsDiscoveryService |
|
50
|
|
|
) { |
|
51
|
|
|
$this->syncService = $syncService; |
|
52
|
|
|
$this->dbHandler = $dbHandler; |
|
53
|
|
|
$this->ocsDiscoveryService = $ocsDiscoveryService; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \Closure $callback |
|
58
|
|
|
*/ |
|
59
|
|
|
public function syncThemAll(\Closure $callback) { |
|
60
|
|
|
|
|
61
|
|
|
$trustedServers = $this->dbHandler->getAllServer(); |
|
62
|
|
|
foreach ($trustedServers as $trustedServer) { |
|
63
|
|
|
$url = $trustedServer['url']; |
|
64
|
|
|
$callback($url, null); |
|
65
|
|
|
$sharedSecret = $trustedServer['shared_secret']; |
|
66
|
|
|
$syncToken = $trustedServer['sync_token']; |
|
67
|
|
|
|
|
68
|
|
|
$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING'); |
|
69
|
|
|
$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system'; |
|
70
|
|
|
$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system'; |
|
71
|
|
|
|
|
72
|
|
|
if (is_null($sharedSecret)) { |
|
73
|
|
|
continue; |
|
74
|
|
|
} |
|
75
|
|
|
$targetBookId = $trustedServer['url_hash']; |
|
76
|
|
|
$targetPrincipal = "principals/system/system"; |
|
77
|
|
|
$targetBookProperties = [ |
|
78
|
|
|
'{DAV:}displayname' => $url |
|
79
|
|
|
]; |
|
80
|
|
|
try { |
|
81
|
|
|
$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); |
|
82
|
|
|
if ($newToken !== $syncToken) { |
|
83
|
|
|
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); |
|
84
|
|
|
} |
|
85
|
|
|
} catch (\Exception $ex) { |
|
86
|
|
|
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
87
|
|
|
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); |
|
88
|
|
|
} |
|
89
|
|
|
$callback($url, $ex); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.