@@ -39,20 +39,20 @@ |
||
39 | 39 | |
40 | 40 | class Application extends App implements IBootstrap { |
41 | 41 | |
42 | - /** |
|
43 | - * @param array $urlParams |
|
44 | - */ |
|
45 | - public function __construct($urlParams = []) { |
|
46 | - parent::__construct('federation', $urlParams); |
|
47 | - } |
|
42 | + /** |
|
43 | + * @param array $urlParams |
|
44 | + */ |
|
45 | + public function __construct($urlParams = []) { |
|
46 | + parent::__construct('federation', $urlParams); |
|
47 | + } |
|
48 | 48 | |
49 | - public function register(IRegistrationContext $context): void { |
|
50 | - $context->registerMiddleware(AddServerMiddleware::class); |
|
49 | + public function register(IRegistrationContext $context): void { |
|
50 | + $context->registerMiddleware(AddServerMiddleware::class); |
|
51 | 51 | |
52 | - $context->registerEventListener(FederatedShareAddedEvent::class, FederatedShareAddedListener::class); |
|
53 | - $context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class); |
|
54 | - } |
|
52 | + $context->registerEventListener(FederatedShareAddedEvent::class, FederatedShareAddedListener::class); |
|
53 | + $context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class); |
|
54 | + } |
|
55 | 55 | |
56 | - public function boot(IBootContext $context): void { |
|
57 | - } |
|
56 | + public function boot(IBootContext $context): void { |
|
57 | + } |
|
58 | 58 | } |
@@ -36,22 +36,22 @@ |
||
36 | 36 | * @since 20.0.0 |
37 | 37 | */ |
38 | 38 | class SabrePluginAuthInitListener implements IEventListener { |
39 | - /** @var FedAuth */ |
|
40 | - private $fedAuth; |
|
41 | - |
|
42 | - public function __construct(FedAuth $fedAuth) { |
|
43 | - $this->fedAuth = $fedAuth; |
|
44 | - } |
|
45 | - |
|
46 | - public function handle(Event $event): void { |
|
47 | - if (!($event instanceof SabrePluginAuthInitEvent)) { |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - $server = $event->getServer(); |
|
52 | - $authPlugin = $server->getPlugin('auth'); |
|
53 | - if ($authPlugin instanceof Plugin) { |
|
54 | - $authPlugin->addBackend($this->fedAuth); |
|
55 | - } |
|
56 | - } |
|
39 | + /** @var FedAuth */ |
|
40 | + private $fedAuth; |
|
41 | + |
|
42 | + public function __construct(FedAuth $fedAuth) { |
|
43 | + $this->fedAuth = $fedAuth; |
|
44 | + } |
|
45 | + |
|
46 | + public function handle(Event $event): void { |
|
47 | + if (!($event instanceof SabrePluginAuthInitEvent)) { |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + $server = $event->getServer(); |
|
52 | + $authPlugin = $server->getPlugin('auth'); |
|
53 | + if ($authPlugin instanceof Plugin) { |
|
54 | + $authPlugin->addBackend($this->fedAuth); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |
@@ -37,24 +37,24 @@ |
||
37 | 37 | * @since 20.0.0 |
38 | 38 | */ |
39 | 39 | class FederatedShareAddedListener implements IEventListener { |
40 | - /** @var TrustedServers */ |
|
41 | - private $trustedServers; |
|
42 | - |
|
43 | - public function __construct(TrustedServers $trustedServers) { |
|
44 | - $this->trustedServers = $trustedServers; |
|
45 | - } |
|
46 | - |
|
47 | - public function handle(Event $event): void { |
|
48 | - if (!($event instanceof FederatedShareAddedEvent)) { |
|
49 | - return; |
|
50 | - } |
|
51 | - |
|
52 | - $server = $event->getRemote(); |
|
53 | - if ( |
|
54 | - $this->trustedServers->getAutoAddServers() === true && |
|
55 | - $this->trustedServers->isTrustedServer($server) === false |
|
56 | - ) { |
|
57 | - $this->trustedServers->addServer($server); |
|
58 | - } |
|
59 | - } |
|
40 | + /** @var TrustedServers */ |
|
41 | + private $trustedServers; |
|
42 | + |
|
43 | + public function __construct(TrustedServers $trustedServers) { |
|
44 | + $this->trustedServers = $trustedServers; |
|
45 | + } |
|
46 | + |
|
47 | + public function handle(Event $event): void { |
|
48 | + if (!($event instanceof FederatedShareAddedEvent)) { |
|
49 | + return; |
|
50 | + } |
|
51 | + |
|
52 | + $server = $event->getRemote(); |
|
53 | + if ( |
|
54 | + $this->trustedServers->getAutoAddServers() === true && |
|
55 | + $this->trustedServers->isTrustedServer($server) === false |
|
56 | + ) { |
|
57 | + $this->trustedServers->addServer($server); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | } |
@@ -6,43 +6,43 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitFederation |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\Federation\\' => 15, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\Federation\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\Federation\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
25 | - 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/GetSharedSecret.php', |
|
26 | - 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php', |
|
27 | - 'OCA\\Federation\\Command\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/Command/SyncFederationAddressBooks.php', |
|
28 | - 'OCA\\Federation\\Controller\\OCSAuthAPIController' => __DIR__ . '/..' . '/../lib/Controller/OCSAuthAPIController.php', |
|
29 | - 'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', |
|
30 | - 'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php', |
|
31 | - 'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php', |
|
32 | - 'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', |
|
33 | - 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => __DIR__ . '/..' . '/../lib/Listeners/FederatedShareAddedListener.php', |
|
34 | - 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => __DIR__ . '/..' . '/../lib/Listeners/SabrePluginAuthInitListener.php', |
|
35 | - 'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php', |
|
36 | - 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191302.php', |
|
37 | - 'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
38 | - 'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php', |
|
39 | - 'OCA\\Federation\\SyncJob' => __DIR__ . '/..' . '/../lib/SyncJob.php', |
|
40 | - 'OCA\\Federation\\TrustedServers' => __DIR__ . '/..' . '/../lib/TrustedServers.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\Federation\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
25 | + 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__.'/..'.'/../lib/BackgroundJob/GetSharedSecret.php', |
|
26 | + 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__.'/..'.'/../lib/BackgroundJob/RequestSharedSecret.php', |
|
27 | + 'OCA\\Federation\\Command\\SyncFederationAddressBooks' => __DIR__.'/..'.'/../lib/Command/SyncFederationAddressBooks.php', |
|
28 | + 'OCA\\Federation\\Controller\\OCSAuthAPIController' => __DIR__.'/..'.'/../lib/Controller/OCSAuthAPIController.php', |
|
29 | + 'OCA\\Federation\\Controller\\SettingsController' => __DIR__.'/..'.'/../lib/Controller/SettingsController.php', |
|
30 | + 'OCA\\Federation\\DAV\\FedAuth' => __DIR__.'/..'.'/../lib/DAV/FedAuth.php', |
|
31 | + 'OCA\\Federation\\DbHandler' => __DIR__.'/..'.'/../lib/DbHandler.php', |
|
32 | + 'OCA\\Federation\\Hooks' => __DIR__.'/..'.'/../lib/Hooks.php', |
|
33 | + 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => __DIR__.'/..'.'/../lib/Listeners/FederatedShareAddedListener.php', |
|
34 | + 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => __DIR__.'/..'.'/../lib/Listeners/SabrePluginAuthInitListener.php', |
|
35 | + 'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__.'/..'.'/../lib/Middleware/AddServerMiddleware.php', |
|
36 | + 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => __DIR__.'/..'.'/../lib/Migration/Version1010Date20200630191302.php', |
|
37 | + 'OCA\\Federation\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
38 | + 'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__.'/..'.'/../lib/SyncFederationAddressBooks.php', |
|
39 | + 'OCA\\Federation\\SyncJob' => __DIR__.'/..'.'/../lib/SyncJob.php', |
|
40 | + 'OCA\\Federation\\TrustedServers' => __DIR__.'/..'.'/../lib/TrustedServers.php', |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | public static function getInitializer(ClassLoader $loader) |
44 | 44 | { |
45 | - return \Closure::bind(function () use ($loader) { |
|
45 | + return \Closure::bind(function() use ($loader) { |
|
46 | 46 | $loader->prefixLengthsPsr4 = ComposerStaticInitFederation::$prefixLengthsPsr4; |
47 | 47 | $loader->prefixDirsPsr4 = ComposerStaticInitFederation::$prefixDirsPsr4; |
48 | 48 | $loader->classMap = ComposerStaticInitFederation::$classMap; |
@@ -6,21 +6,21 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Federation\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
10 | - 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir . '/../lib/BackgroundJob/GetSharedSecret.php', |
|
11 | - 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php', |
|
12 | - 'OCA\\Federation\\Command\\SyncFederationAddressBooks' => $baseDir . '/../lib/Command/SyncFederationAddressBooks.php', |
|
13 | - 'OCA\\Federation\\Controller\\OCSAuthAPIController' => $baseDir . '/../lib/Controller/OCSAuthAPIController.php', |
|
14 | - 'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', |
|
15 | - 'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php', |
|
16 | - 'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php', |
|
17 | - 'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php', |
|
18 | - 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => $baseDir . '/../lib/Listeners/FederatedShareAddedListener.php', |
|
19 | - 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => $baseDir . '/../lib/Listeners/SabrePluginAuthInitListener.php', |
|
20 | - 'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php', |
|
21 | - 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => $baseDir . '/../lib/Migration/Version1010Date20200630191302.php', |
|
22 | - 'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
|
23 | - 'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php', |
|
24 | - 'OCA\\Federation\\SyncJob' => $baseDir . '/../lib/SyncJob.php', |
|
25 | - 'OCA\\Federation\\TrustedServers' => $baseDir . '/../lib/TrustedServers.php', |
|
9 | + 'OCA\\Federation\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
10 | + 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir.'/../lib/BackgroundJob/GetSharedSecret.php', |
|
11 | + 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir.'/../lib/BackgroundJob/RequestSharedSecret.php', |
|
12 | + 'OCA\\Federation\\Command\\SyncFederationAddressBooks' => $baseDir.'/../lib/Command/SyncFederationAddressBooks.php', |
|
13 | + 'OCA\\Federation\\Controller\\OCSAuthAPIController' => $baseDir.'/../lib/Controller/OCSAuthAPIController.php', |
|
14 | + 'OCA\\Federation\\Controller\\SettingsController' => $baseDir.'/../lib/Controller/SettingsController.php', |
|
15 | + 'OCA\\Federation\\DAV\\FedAuth' => $baseDir.'/../lib/DAV/FedAuth.php', |
|
16 | + 'OCA\\Federation\\DbHandler' => $baseDir.'/../lib/DbHandler.php', |
|
17 | + 'OCA\\Federation\\Hooks' => $baseDir.'/../lib/Hooks.php', |
|
18 | + 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => $baseDir.'/../lib/Listeners/FederatedShareAddedListener.php', |
|
19 | + 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => $baseDir.'/../lib/Listeners/SabrePluginAuthInitListener.php', |
|
20 | + 'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir.'/../lib/Middleware/AddServerMiddleware.php', |
|
21 | + 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => $baseDir.'/../lib/Migration/Version1010Date20200630191302.php', |
|
22 | + 'OCA\\Federation\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php', |
|
23 | + 'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir.'/../lib/SyncFederationAddressBooks.php', |
|
24 | + 'OCA\\Federation\\SyncJob' => $baseDir.'/../lib/SyncJob.php', |
|
25 | + 'OCA\\Federation\\TrustedServers' => $baseDir.'/../lib/TrustedServers.php', |
|
26 | 26 | ); |
@@ -50,579 +50,579 @@ |
||
50 | 50 | use OCP\Share\IShare; |
51 | 51 | |
52 | 52 | class Manager { |
53 | - public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
54 | - |
|
55 | - /** @var string */ |
|
56 | - private $uid; |
|
57 | - |
|
58 | - /** @var IDBConnection */ |
|
59 | - private $connection; |
|
60 | - |
|
61 | - /** @var \OC\Files\Mount\Manager */ |
|
62 | - private $mountManager; |
|
63 | - |
|
64 | - /** @var IStorageFactory */ |
|
65 | - private $storageLoader; |
|
66 | - |
|
67 | - /** @var IClientService */ |
|
68 | - private $clientService; |
|
69 | - |
|
70 | - /** @var IManager */ |
|
71 | - private $notificationManager; |
|
72 | - |
|
73 | - /** @var IDiscoveryService */ |
|
74 | - private $discoveryService; |
|
75 | - |
|
76 | - /** @var ICloudFederationProviderManager */ |
|
77 | - private $cloudFederationProviderManager; |
|
78 | - |
|
79 | - /** @var ICloudFederationFactory */ |
|
80 | - private $cloudFederationFactory; |
|
81 | - |
|
82 | - /** @var IGroupManager */ |
|
83 | - private $groupManager; |
|
84 | - |
|
85 | - /** @var IUserManager */ |
|
86 | - private $userManager; |
|
87 | - |
|
88 | - /** @var IEventDispatcher */ |
|
89 | - private $eventDispatcher; |
|
90 | - |
|
91 | - public function __construct(IDBConnection $connection, |
|
92 | - \OC\Files\Mount\Manager $mountManager, |
|
93 | - IStorageFactory $storageLoader, |
|
94 | - IClientService $clientService, |
|
95 | - IManager $notificationManager, |
|
96 | - IDiscoveryService $discoveryService, |
|
97 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
98 | - ICloudFederationFactory $cloudFederationFactory, |
|
99 | - IGroupManager $groupManager, |
|
100 | - IUserManager $userManager, |
|
101 | - string $uid, |
|
102 | - IEventDispatcher $eventDispatcher) { |
|
103 | - $this->connection = $connection; |
|
104 | - $this->mountManager = $mountManager; |
|
105 | - $this->storageLoader = $storageLoader; |
|
106 | - $this->clientService = $clientService; |
|
107 | - $this->uid = $uid; |
|
108 | - $this->notificationManager = $notificationManager; |
|
109 | - $this->discoveryService = $discoveryService; |
|
110 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
111 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
112 | - $this->groupManager = $groupManager; |
|
113 | - $this->userManager = $userManager; |
|
114 | - $this->eventDispatcher = $eventDispatcher; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * add new server-to-server share |
|
119 | - * |
|
120 | - * @param string $remote |
|
121 | - * @param string $token |
|
122 | - * @param string $password |
|
123 | - * @param string $name |
|
124 | - * @param string $owner |
|
125 | - * @param int $shareType |
|
126 | - * @param boolean $accepted |
|
127 | - * @param string $user |
|
128 | - * @param int $remoteId |
|
129 | - * @param int $parent |
|
130 | - * @return Mount|null |
|
131 | - * @throws \Doctrine\DBAL\DBALException |
|
132 | - */ |
|
133 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
134 | - $user = $user ? $user : $this->uid; |
|
135 | - $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; |
|
136 | - $name = Filesystem::normalizePath('/' . $name); |
|
137 | - |
|
138 | - if ($accepted !== IShare::STATUS_ACCEPTED) { |
|
139 | - // To avoid conflicts with the mount point generation later, |
|
140 | - // we only use a temporary mount point name here. The real |
|
141 | - // mount point name will be generated when accepting the share, |
|
142 | - // using the original share item name. |
|
143 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
144 | - $mountPoint = $tmpMountPointName; |
|
145 | - $hash = md5($tmpMountPointName); |
|
146 | - $data = [ |
|
147 | - 'remote' => $remote, |
|
148 | - 'share_token' => $token, |
|
149 | - 'password' => $password, |
|
150 | - 'name' => $name, |
|
151 | - 'owner' => $owner, |
|
152 | - 'user' => $user, |
|
153 | - 'mountpoint' => $mountPoint, |
|
154 | - 'mountpoint_hash' => $hash, |
|
155 | - 'accepted' => $accepted, |
|
156 | - 'remote_id' => $remoteId, |
|
157 | - 'share_type' => $shareType, |
|
158 | - ]; |
|
159 | - |
|
160 | - $i = 1; |
|
161 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
162 | - // The external share already exists for the user |
|
163 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
164 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
165 | - $i++; |
|
166 | - } |
|
167 | - return null; |
|
168 | - } |
|
169 | - |
|
170 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
171 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
172 | - $hash = md5($mountPoint); |
|
173 | - |
|
174 | - $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); |
|
175 | - |
|
176 | - $options = [ |
|
177 | - 'remote' => $remote, |
|
178 | - 'token' => $token, |
|
179 | - 'password' => $password, |
|
180 | - 'mountpoint' => $mountPoint, |
|
181 | - 'owner' => $owner |
|
182 | - ]; |
|
183 | - return $this->mountShare($options); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * write remote share to the database |
|
188 | - * |
|
189 | - * @param $remote |
|
190 | - * @param $token |
|
191 | - * @param $password |
|
192 | - * @param $name |
|
193 | - * @param $owner |
|
194 | - * @param $user |
|
195 | - * @param $mountPoint |
|
196 | - * @param $hash |
|
197 | - * @param $accepted |
|
198 | - * @param $remoteId |
|
199 | - * @param $parent |
|
200 | - * @param $shareType |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) { |
|
204 | - $query = $this->connection->prepare(' |
|
53 | + public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
54 | + |
|
55 | + /** @var string */ |
|
56 | + private $uid; |
|
57 | + |
|
58 | + /** @var IDBConnection */ |
|
59 | + private $connection; |
|
60 | + |
|
61 | + /** @var \OC\Files\Mount\Manager */ |
|
62 | + private $mountManager; |
|
63 | + |
|
64 | + /** @var IStorageFactory */ |
|
65 | + private $storageLoader; |
|
66 | + |
|
67 | + /** @var IClientService */ |
|
68 | + private $clientService; |
|
69 | + |
|
70 | + /** @var IManager */ |
|
71 | + private $notificationManager; |
|
72 | + |
|
73 | + /** @var IDiscoveryService */ |
|
74 | + private $discoveryService; |
|
75 | + |
|
76 | + /** @var ICloudFederationProviderManager */ |
|
77 | + private $cloudFederationProviderManager; |
|
78 | + |
|
79 | + /** @var ICloudFederationFactory */ |
|
80 | + private $cloudFederationFactory; |
|
81 | + |
|
82 | + /** @var IGroupManager */ |
|
83 | + private $groupManager; |
|
84 | + |
|
85 | + /** @var IUserManager */ |
|
86 | + private $userManager; |
|
87 | + |
|
88 | + /** @var IEventDispatcher */ |
|
89 | + private $eventDispatcher; |
|
90 | + |
|
91 | + public function __construct(IDBConnection $connection, |
|
92 | + \OC\Files\Mount\Manager $mountManager, |
|
93 | + IStorageFactory $storageLoader, |
|
94 | + IClientService $clientService, |
|
95 | + IManager $notificationManager, |
|
96 | + IDiscoveryService $discoveryService, |
|
97 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
98 | + ICloudFederationFactory $cloudFederationFactory, |
|
99 | + IGroupManager $groupManager, |
|
100 | + IUserManager $userManager, |
|
101 | + string $uid, |
|
102 | + IEventDispatcher $eventDispatcher) { |
|
103 | + $this->connection = $connection; |
|
104 | + $this->mountManager = $mountManager; |
|
105 | + $this->storageLoader = $storageLoader; |
|
106 | + $this->clientService = $clientService; |
|
107 | + $this->uid = $uid; |
|
108 | + $this->notificationManager = $notificationManager; |
|
109 | + $this->discoveryService = $discoveryService; |
|
110 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
111 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
112 | + $this->groupManager = $groupManager; |
|
113 | + $this->userManager = $userManager; |
|
114 | + $this->eventDispatcher = $eventDispatcher; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * add new server-to-server share |
|
119 | + * |
|
120 | + * @param string $remote |
|
121 | + * @param string $token |
|
122 | + * @param string $password |
|
123 | + * @param string $name |
|
124 | + * @param string $owner |
|
125 | + * @param int $shareType |
|
126 | + * @param boolean $accepted |
|
127 | + * @param string $user |
|
128 | + * @param int $remoteId |
|
129 | + * @param int $parent |
|
130 | + * @return Mount|null |
|
131 | + * @throws \Doctrine\DBAL\DBALException |
|
132 | + */ |
|
133 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
134 | + $user = $user ? $user : $this->uid; |
|
135 | + $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; |
|
136 | + $name = Filesystem::normalizePath('/' . $name); |
|
137 | + |
|
138 | + if ($accepted !== IShare::STATUS_ACCEPTED) { |
|
139 | + // To avoid conflicts with the mount point generation later, |
|
140 | + // we only use a temporary mount point name here. The real |
|
141 | + // mount point name will be generated when accepting the share, |
|
142 | + // using the original share item name. |
|
143 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
144 | + $mountPoint = $tmpMountPointName; |
|
145 | + $hash = md5($tmpMountPointName); |
|
146 | + $data = [ |
|
147 | + 'remote' => $remote, |
|
148 | + 'share_token' => $token, |
|
149 | + 'password' => $password, |
|
150 | + 'name' => $name, |
|
151 | + 'owner' => $owner, |
|
152 | + 'user' => $user, |
|
153 | + 'mountpoint' => $mountPoint, |
|
154 | + 'mountpoint_hash' => $hash, |
|
155 | + 'accepted' => $accepted, |
|
156 | + 'remote_id' => $remoteId, |
|
157 | + 'share_type' => $shareType, |
|
158 | + ]; |
|
159 | + |
|
160 | + $i = 1; |
|
161 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
162 | + // The external share already exists for the user |
|
163 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
164 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
165 | + $i++; |
|
166 | + } |
|
167 | + return null; |
|
168 | + } |
|
169 | + |
|
170 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
171 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
172 | + $hash = md5($mountPoint); |
|
173 | + |
|
174 | + $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); |
|
175 | + |
|
176 | + $options = [ |
|
177 | + 'remote' => $remote, |
|
178 | + 'token' => $token, |
|
179 | + 'password' => $password, |
|
180 | + 'mountpoint' => $mountPoint, |
|
181 | + 'owner' => $owner |
|
182 | + ]; |
|
183 | + return $this->mountShare($options); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * write remote share to the database |
|
188 | + * |
|
189 | + * @param $remote |
|
190 | + * @param $token |
|
191 | + * @param $password |
|
192 | + * @param $name |
|
193 | + * @param $owner |
|
194 | + * @param $user |
|
195 | + * @param $mountPoint |
|
196 | + * @param $hash |
|
197 | + * @param $accepted |
|
198 | + * @param $remoteId |
|
199 | + * @param $parent |
|
200 | + * @param $shareType |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) { |
|
204 | + $query = $this->connection->prepare(' |
|
205 | 205 | INSERT INTO `*PREFIX*share_external` |
206 | 206 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) |
207 | 207 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
208 | 208 | '); |
209 | - return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * get share |
|
214 | - * |
|
215 | - * @param int $id share id |
|
216 | - * @return mixed share of false |
|
217 | - */ |
|
218 | - public function getShare($id) { |
|
219 | - $getShare = $this->connection->prepare(' |
|
209 | + return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * get share |
|
214 | + * |
|
215 | + * @param int $id share id |
|
216 | + * @return mixed share of false |
|
217 | + */ |
|
218 | + public function getShare($id) { |
|
219 | + $getShare = $this->connection->prepare(' |
|
220 | 220 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`, `parent`, `share_type`, `password`, `mountpoint_hash` |
221 | 221 | FROM `*PREFIX*share_external` |
222 | 222 | WHERE `id` = ?'); |
223 | - $result = $getShare->execute([$id]); |
|
224 | - |
|
225 | - $share = $result ? $getShare->fetch() : []; |
|
226 | - |
|
227 | - $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); |
|
228 | - |
|
229 | - // check if the user is allowed to access it |
|
230 | - if ($validShare && (int)$share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
231 | - return $share; |
|
232 | - } elseif ($validShare && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
233 | - $user = $this->userManager->get($this->uid); |
|
234 | - if ($this->groupManager->get($share['user'])->inGroup($user)) { |
|
235 | - return $share; |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - return false; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * accept server-to-server share |
|
244 | - * |
|
245 | - * @param int $id |
|
246 | - * @return bool True if the share could be accepted, false otherwise |
|
247 | - */ |
|
248 | - public function acceptShare($id) { |
|
249 | - $share = $this->getShare($id); |
|
250 | - $result = false; |
|
251 | - |
|
252 | - if ($share) { |
|
253 | - \OC_Util::setupFS($this->uid); |
|
254 | - $shareFolder = Helper::getShareFolder(); |
|
255 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
256 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
257 | - $hash = md5($mountPoint); |
|
258 | - $userShareAccepted = false; |
|
259 | - |
|
260 | - if ((int)$share['share_type'] === IShare::TYPE_USER) { |
|
261 | - $acceptShare = $this->connection->prepare(' |
|
223 | + $result = $getShare->execute([$id]); |
|
224 | + |
|
225 | + $share = $result ? $getShare->fetch() : []; |
|
226 | + |
|
227 | + $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); |
|
228 | + |
|
229 | + // check if the user is allowed to access it |
|
230 | + if ($validShare && (int)$share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
231 | + return $share; |
|
232 | + } elseif ($validShare && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
233 | + $user = $this->userManager->get($this->uid); |
|
234 | + if ($this->groupManager->get($share['user'])->inGroup($user)) { |
|
235 | + return $share; |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + return false; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * accept server-to-server share |
|
244 | + * |
|
245 | + * @param int $id |
|
246 | + * @return bool True if the share could be accepted, false otherwise |
|
247 | + */ |
|
248 | + public function acceptShare($id) { |
|
249 | + $share = $this->getShare($id); |
|
250 | + $result = false; |
|
251 | + |
|
252 | + if ($share) { |
|
253 | + \OC_Util::setupFS($this->uid); |
|
254 | + $shareFolder = Helper::getShareFolder(); |
|
255 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
256 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
257 | + $hash = md5($mountPoint); |
|
258 | + $userShareAccepted = false; |
|
259 | + |
|
260 | + if ((int)$share['share_type'] === IShare::TYPE_USER) { |
|
261 | + $acceptShare = $this->connection->prepare(' |
|
262 | 262 | UPDATE `*PREFIX*share_external` |
263 | 263 | SET `accepted` = ?, |
264 | 264 | `mountpoint` = ?, |
265 | 265 | `mountpoint_hash` = ? |
266 | 266 | WHERE `id` = ? AND `user` = ?'); |
267 | - $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); |
|
268 | - } else { |
|
269 | - $result = $this->writeShareToDb( |
|
270 | - $share['remote'], |
|
271 | - $share['share_token'], |
|
272 | - $share['password'], |
|
273 | - $share['name'], |
|
274 | - $share['owner'], |
|
275 | - $this->uid, |
|
276 | - $mountPoint, $hash, 1, |
|
277 | - $share['remote_id'], |
|
278 | - $id, |
|
279 | - $share['share_type']); |
|
280 | - } |
|
281 | - if ($userShareAccepted === true) { |
|
282 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
283 | - $event = new FederatedShareAddedEvent($share['remote']); |
|
284 | - $this->eventDispatcher->dispatchTyped($event); |
|
285 | - $result = true; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - // Make sure the user has no notification for something that does not exist anymore. |
|
290 | - $this->processNotification($id); |
|
291 | - |
|
292 | - return $result; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * decline server-to-server share |
|
297 | - * |
|
298 | - * @param int $id |
|
299 | - * @return bool True if the share could be declined, false otherwise |
|
300 | - */ |
|
301 | - public function declineShare($id) { |
|
302 | - $share = $this->getShare($id); |
|
303 | - $result = false; |
|
304 | - |
|
305 | - if ($share && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
306 | - $removeShare = $this->connection->prepare(' |
|
267 | + $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); |
|
268 | + } else { |
|
269 | + $result = $this->writeShareToDb( |
|
270 | + $share['remote'], |
|
271 | + $share['share_token'], |
|
272 | + $share['password'], |
|
273 | + $share['name'], |
|
274 | + $share['owner'], |
|
275 | + $this->uid, |
|
276 | + $mountPoint, $hash, 1, |
|
277 | + $share['remote_id'], |
|
278 | + $id, |
|
279 | + $share['share_type']); |
|
280 | + } |
|
281 | + if ($userShareAccepted === true) { |
|
282 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
283 | + $event = new FederatedShareAddedEvent($share['remote']); |
|
284 | + $this->eventDispatcher->dispatchTyped($event); |
|
285 | + $result = true; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + // Make sure the user has no notification for something that does not exist anymore. |
|
290 | + $this->processNotification($id); |
|
291 | + |
|
292 | + return $result; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * decline server-to-server share |
|
297 | + * |
|
298 | + * @param int $id |
|
299 | + * @return bool True if the share could be declined, false otherwise |
|
300 | + */ |
|
301 | + public function declineShare($id) { |
|
302 | + $share = $this->getShare($id); |
|
303 | + $result = false; |
|
304 | + |
|
305 | + if ($share && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
306 | + $removeShare = $this->connection->prepare(' |
|
307 | 307 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
308 | - $removeShare->execute([$id, $this->uid]); |
|
309 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
310 | - |
|
311 | - $this->processNotification($id); |
|
312 | - $result = true; |
|
313 | - } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
314 | - $result = $this->writeShareToDb( |
|
315 | - $share['remote'], |
|
316 | - $share['share_token'], |
|
317 | - $share['password'], |
|
318 | - $share['name'], |
|
319 | - $share['owner'], |
|
320 | - $this->uid, |
|
321 | - $share['mountpoint'], |
|
322 | - $share['mountpoint_hash'], |
|
323 | - 0, |
|
324 | - $share['remote_id'], |
|
325 | - $id, |
|
326 | - $share['share_type']); |
|
327 | - $this->processNotification($id); |
|
328 | - } |
|
329 | - |
|
330 | - return $result; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param int $remoteShare |
|
335 | - */ |
|
336 | - public function processNotification($remoteShare) { |
|
337 | - $filter = $this->notificationManager->createNotification(); |
|
338 | - $filter->setApp('files_sharing') |
|
339 | - ->setUser($this->uid) |
|
340 | - ->setObject('remote_share', (int) $remoteShare); |
|
341 | - $this->notificationManager->markProcessed($filter); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * inform remote server whether server-to-server share was accepted/declined |
|
346 | - * |
|
347 | - * @param string $remote |
|
348 | - * @param string $token |
|
349 | - * @param int $remoteId Share id on the remote host |
|
350 | - * @param string $feedback |
|
351 | - * @return boolean |
|
352 | - */ |
|
353 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
354 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
355 | - |
|
356 | - if ($result === true) { |
|
357 | - return true; |
|
358 | - } |
|
359 | - |
|
360 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
361 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
362 | - |
|
363 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; |
|
364 | - $fields = ['token' => $token]; |
|
365 | - |
|
366 | - $client = $this->clientService->newClient(); |
|
367 | - |
|
368 | - try { |
|
369 | - $response = $client->post( |
|
370 | - $url, |
|
371 | - [ |
|
372 | - 'body' => $fields, |
|
373 | - 'connect_timeout' => 10, |
|
374 | - ] |
|
375 | - ); |
|
376 | - } catch (\Exception $e) { |
|
377 | - return false; |
|
378 | - } |
|
379 | - |
|
380 | - $status = json_decode($response->getBody(), true); |
|
381 | - |
|
382 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * try send accept message to ocm end-point |
|
387 | - * |
|
388 | - * @param string $remoteDomain |
|
389 | - * @param string $token |
|
390 | - * @param $remoteId id of the share |
|
391 | - * @param string $feedback |
|
392 | - * @return bool |
|
393 | - */ |
|
394 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
395 | - switch ($feedback) { |
|
396 | - case 'accept': |
|
397 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
398 | - $notification->setMessage( |
|
399 | - 'SHARE_ACCEPTED', |
|
400 | - 'file', |
|
401 | - $remoteId, |
|
402 | - [ |
|
403 | - 'sharedSecret' => $token, |
|
404 | - 'message' => 'Recipient accept the share' |
|
405 | - ] |
|
406 | - |
|
407 | - ); |
|
408 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
409 | - case 'decline': |
|
410 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
411 | - $notification->setMessage( |
|
412 | - 'SHARE_DECLINED', |
|
413 | - 'file', |
|
414 | - $remoteId, |
|
415 | - [ |
|
416 | - 'sharedSecret' => $token, |
|
417 | - 'message' => 'Recipient declined the share' |
|
418 | - ] |
|
419 | - |
|
420 | - ); |
|
421 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
422 | - } |
|
423 | - |
|
424 | - return false; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * remove '/user/files' from the path and trailing slashes |
|
430 | - * |
|
431 | - * @param string $path |
|
432 | - * @return string |
|
433 | - */ |
|
434 | - protected function stripPath($path) { |
|
435 | - $prefix = '/' . $this->uid . '/files'; |
|
436 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
437 | - } |
|
438 | - |
|
439 | - public function getMount($data) { |
|
440 | - $data['manager'] = $this; |
|
441 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
442 | - $data['mountpoint'] = $mountPoint; |
|
443 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
444 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * @param array $data |
|
449 | - * @return Mount |
|
450 | - */ |
|
451 | - protected function mountShare($data) { |
|
452 | - $mount = $this->getMount($data); |
|
453 | - $this->mountManager->addMount($mount); |
|
454 | - return $mount; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @return \OC\Files\Mount\Manager |
|
459 | - */ |
|
460 | - public function getMountManager() { |
|
461 | - return $this->mountManager; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $source |
|
466 | - * @param string $target |
|
467 | - * @return bool |
|
468 | - */ |
|
469 | - public function setMountPoint($source, $target) { |
|
470 | - $source = $this->stripPath($source); |
|
471 | - $target = $this->stripPath($target); |
|
472 | - $sourceHash = md5($source); |
|
473 | - $targetHash = md5($target); |
|
474 | - |
|
475 | - $query = $this->connection->prepare(' |
|
308 | + $removeShare->execute([$id, $this->uid]); |
|
309 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
310 | + |
|
311 | + $this->processNotification($id); |
|
312 | + $result = true; |
|
313 | + } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
314 | + $result = $this->writeShareToDb( |
|
315 | + $share['remote'], |
|
316 | + $share['share_token'], |
|
317 | + $share['password'], |
|
318 | + $share['name'], |
|
319 | + $share['owner'], |
|
320 | + $this->uid, |
|
321 | + $share['mountpoint'], |
|
322 | + $share['mountpoint_hash'], |
|
323 | + 0, |
|
324 | + $share['remote_id'], |
|
325 | + $id, |
|
326 | + $share['share_type']); |
|
327 | + $this->processNotification($id); |
|
328 | + } |
|
329 | + |
|
330 | + return $result; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param int $remoteShare |
|
335 | + */ |
|
336 | + public function processNotification($remoteShare) { |
|
337 | + $filter = $this->notificationManager->createNotification(); |
|
338 | + $filter->setApp('files_sharing') |
|
339 | + ->setUser($this->uid) |
|
340 | + ->setObject('remote_share', (int) $remoteShare); |
|
341 | + $this->notificationManager->markProcessed($filter); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * inform remote server whether server-to-server share was accepted/declined |
|
346 | + * |
|
347 | + * @param string $remote |
|
348 | + * @param string $token |
|
349 | + * @param int $remoteId Share id on the remote host |
|
350 | + * @param string $feedback |
|
351 | + * @return boolean |
|
352 | + */ |
|
353 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
354 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
355 | + |
|
356 | + if ($result === true) { |
|
357 | + return true; |
|
358 | + } |
|
359 | + |
|
360 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
361 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
362 | + |
|
363 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; |
|
364 | + $fields = ['token' => $token]; |
|
365 | + |
|
366 | + $client = $this->clientService->newClient(); |
|
367 | + |
|
368 | + try { |
|
369 | + $response = $client->post( |
|
370 | + $url, |
|
371 | + [ |
|
372 | + 'body' => $fields, |
|
373 | + 'connect_timeout' => 10, |
|
374 | + ] |
|
375 | + ); |
|
376 | + } catch (\Exception $e) { |
|
377 | + return false; |
|
378 | + } |
|
379 | + |
|
380 | + $status = json_decode($response->getBody(), true); |
|
381 | + |
|
382 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * try send accept message to ocm end-point |
|
387 | + * |
|
388 | + * @param string $remoteDomain |
|
389 | + * @param string $token |
|
390 | + * @param $remoteId id of the share |
|
391 | + * @param string $feedback |
|
392 | + * @return bool |
|
393 | + */ |
|
394 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
395 | + switch ($feedback) { |
|
396 | + case 'accept': |
|
397 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
398 | + $notification->setMessage( |
|
399 | + 'SHARE_ACCEPTED', |
|
400 | + 'file', |
|
401 | + $remoteId, |
|
402 | + [ |
|
403 | + 'sharedSecret' => $token, |
|
404 | + 'message' => 'Recipient accept the share' |
|
405 | + ] |
|
406 | + |
|
407 | + ); |
|
408 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
409 | + case 'decline': |
|
410 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
411 | + $notification->setMessage( |
|
412 | + 'SHARE_DECLINED', |
|
413 | + 'file', |
|
414 | + $remoteId, |
|
415 | + [ |
|
416 | + 'sharedSecret' => $token, |
|
417 | + 'message' => 'Recipient declined the share' |
|
418 | + ] |
|
419 | + |
|
420 | + ); |
|
421 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
422 | + } |
|
423 | + |
|
424 | + return false; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * remove '/user/files' from the path and trailing slashes |
|
430 | + * |
|
431 | + * @param string $path |
|
432 | + * @return string |
|
433 | + */ |
|
434 | + protected function stripPath($path) { |
|
435 | + $prefix = '/' . $this->uid . '/files'; |
|
436 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
437 | + } |
|
438 | + |
|
439 | + public function getMount($data) { |
|
440 | + $data['manager'] = $this; |
|
441 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
442 | + $data['mountpoint'] = $mountPoint; |
|
443 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
444 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * @param array $data |
|
449 | + * @return Mount |
|
450 | + */ |
|
451 | + protected function mountShare($data) { |
|
452 | + $mount = $this->getMount($data); |
|
453 | + $this->mountManager->addMount($mount); |
|
454 | + return $mount; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @return \OC\Files\Mount\Manager |
|
459 | + */ |
|
460 | + public function getMountManager() { |
|
461 | + return $this->mountManager; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $source |
|
466 | + * @param string $target |
|
467 | + * @return bool |
|
468 | + */ |
|
469 | + public function setMountPoint($source, $target) { |
|
470 | + $source = $this->stripPath($source); |
|
471 | + $target = $this->stripPath($target); |
|
472 | + $sourceHash = md5($source); |
|
473 | + $targetHash = md5($target); |
|
474 | + |
|
475 | + $query = $this->connection->prepare(' |
|
476 | 476 | UPDATE `*PREFIX*share_external` |
477 | 477 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
478 | 478 | WHERE `mountpoint_hash` = ? |
479 | 479 | AND `user` = ? |
480 | 480 | '); |
481 | - $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
481 | + $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
482 | 482 | |
483 | - return $result; |
|
484 | - } |
|
483 | + return $result; |
|
484 | + } |
|
485 | 485 | |
486 | - public function removeShare($mountPoint) { |
|
487 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
488 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
486 | + public function removeShare($mountPoint) { |
|
487 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
488 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
489 | 489 | |
490 | - $mountPoint = $this->stripPath($mountPoint); |
|
491 | - $hash = md5($mountPoint); |
|
490 | + $mountPoint = $this->stripPath($mountPoint); |
|
491 | + $hash = md5($mountPoint); |
|
492 | 492 | |
493 | - $getShare = $this->connection->prepare(' |
|
493 | + $getShare = $this->connection->prepare(' |
|
494 | 494 | SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id` |
495 | 495 | FROM `*PREFIX*share_external` |
496 | 496 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
497 | - $result = $getShare->execute([$hash, $this->uid]); |
|
498 | - |
|
499 | - $share = $getShare->fetch(); |
|
500 | - $getShare->closeCursor(); |
|
501 | - if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
502 | - try { |
|
503 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
504 | - } catch (\Throwable $e) { |
|
505 | - // if we fail to notify the remote (probably cause the remote is down) |
|
506 | - // we still want the share to be gone to prevent undeletable remotes |
|
507 | - } |
|
508 | - |
|
509 | - $query = $this->connection->prepare(' |
|
497 | + $result = $getShare->execute([$hash, $this->uid]); |
|
498 | + |
|
499 | + $share = $getShare->fetch(); |
|
500 | + $getShare->closeCursor(); |
|
501 | + if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
502 | + try { |
|
503 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
504 | + } catch (\Throwable $e) { |
|
505 | + // if we fail to notify the remote (probably cause the remote is down) |
|
506 | + // we still want the share to be gone to prevent undeletable remotes |
|
507 | + } |
|
508 | + |
|
509 | + $query = $this->connection->prepare(' |
|
510 | 510 | DELETE FROM `*PREFIX*share_external` |
511 | 511 | WHERE `id` = ? |
512 | 512 | '); |
513 | - $result = (bool)$query->execute([(int)$share['id']]); |
|
514 | - } elseif ($result && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
515 | - $query = $this->connection->prepare(' |
|
513 | + $result = (bool)$query->execute([(int)$share['id']]); |
|
514 | + } elseif ($result && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
515 | + $query = $this->connection->prepare(' |
|
516 | 516 | UPDATE `*PREFIX*share_external` |
517 | 517 | SET `accepted` = ? |
518 | 518 | WHERE `id` = ?'); |
519 | - $result = (bool)$query->execute([0, (int)$share['id']]); |
|
520 | - } |
|
521 | - |
|
522 | - if ($result) { |
|
523 | - $this->removeReShares($id); |
|
524 | - } |
|
525 | - |
|
526 | - return $result; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
531 | - * |
|
532 | - * @param $mountPointId |
|
533 | - */ |
|
534 | - protected function removeReShares($mountPointId) { |
|
535 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
536 | - $query = $this->connection->getQueryBuilder(); |
|
537 | - $selectQuery->select('id')->from('share') |
|
538 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
539 | - $select = $selectQuery->getSQL(); |
|
540 | - |
|
541 | - |
|
542 | - $query->delete('federated_reshares') |
|
543 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
544 | - $query->execute(); |
|
545 | - |
|
546 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
547 | - $deleteReShares->delete('share') |
|
548 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
549 | - $deleteReShares->execute(); |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * remove all shares for user $uid if the user was deleted |
|
554 | - * |
|
555 | - * @param string $uid |
|
556 | - * @return bool |
|
557 | - */ |
|
558 | - public function removeUserShares($uid) { |
|
559 | - $getShare = $this->connection->prepare(' |
|
519 | + $result = (bool)$query->execute([0, (int)$share['id']]); |
|
520 | + } |
|
521 | + |
|
522 | + if ($result) { |
|
523 | + $this->removeReShares($id); |
|
524 | + } |
|
525 | + |
|
526 | + return $result; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
531 | + * |
|
532 | + * @param $mountPointId |
|
533 | + */ |
|
534 | + protected function removeReShares($mountPointId) { |
|
535 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
536 | + $query = $this->connection->getQueryBuilder(); |
|
537 | + $selectQuery->select('id')->from('share') |
|
538 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
539 | + $select = $selectQuery->getSQL(); |
|
540 | + |
|
541 | + |
|
542 | + $query->delete('federated_reshares') |
|
543 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
544 | + $query->execute(); |
|
545 | + |
|
546 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
547 | + $deleteReShares->delete('share') |
|
548 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
549 | + $deleteReShares->execute(); |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * remove all shares for user $uid if the user was deleted |
|
554 | + * |
|
555 | + * @param string $uid |
|
556 | + * @return bool |
|
557 | + */ |
|
558 | + public function removeUserShares($uid) { |
|
559 | + $getShare = $this->connection->prepare(' |
|
560 | 560 | SELECT `remote`, `share_token`, `remote_id` |
561 | 561 | FROM `*PREFIX*share_external` |
562 | 562 | WHERE `user` = ?'); |
563 | - $result = $getShare->execute([$uid]); |
|
563 | + $result = $getShare->execute([$uid]); |
|
564 | 564 | |
565 | - if ($result) { |
|
566 | - $shares = $getShare->fetchAll(); |
|
567 | - foreach ($shares as $share) { |
|
568 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
569 | - } |
|
570 | - } |
|
565 | + if ($result) { |
|
566 | + $shares = $getShare->fetchAll(); |
|
567 | + foreach ($shares as $share) { |
|
568 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
569 | + } |
|
570 | + } |
|
571 | 571 | |
572 | - $query = $this->connection->prepare(' |
|
572 | + $query = $this->connection->prepare(' |
|
573 | 573 | DELETE FROM `*PREFIX*share_external` |
574 | 574 | WHERE `user` = ? |
575 | 575 | '); |
576 | - return (bool)$query->execute([$uid]); |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * return a list of shares which are not yet accepted by the user |
|
581 | - * |
|
582 | - * @return array list of open server-to-server shares |
|
583 | - */ |
|
584 | - public function getOpenShares() { |
|
585 | - return $this->getShares(false); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * return a list of shares which are accepted by the user |
|
590 | - * |
|
591 | - * @return array list of accepted server-to-server shares |
|
592 | - */ |
|
593 | - public function getAcceptedShares() { |
|
594 | - return $this->getShares(true); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * return a list of shares for the user |
|
599 | - * |
|
600 | - * @param bool|null $accepted True for accepted only, |
|
601 | - * false for not accepted, |
|
602 | - * null for all shares of the user |
|
603 | - * @return array list of open server-to-server shares |
|
604 | - */ |
|
605 | - private function getShares($accepted) { |
|
606 | - $user = $this->userManager->get($this->uid); |
|
607 | - $groups = $this->groupManager->getUserGroups($user); |
|
608 | - $userGroups = []; |
|
609 | - foreach ($groups as $group) { |
|
610 | - $userGroups[] = $group->getGID(); |
|
611 | - } |
|
612 | - |
|
613 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
576 | + return (bool)$query->execute([$uid]); |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * return a list of shares which are not yet accepted by the user |
|
581 | + * |
|
582 | + * @return array list of open server-to-server shares |
|
583 | + */ |
|
584 | + public function getOpenShares() { |
|
585 | + return $this->getShares(false); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * return a list of shares which are accepted by the user |
|
590 | + * |
|
591 | + * @return array list of accepted server-to-server shares |
|
592 | + */ |
|
593 | + public function getAcceptedShares() { |
|
594 | + return $this->getShares(true); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * return a list of shares for the user |
|
599 | + * |
|
600 | + * @param bool|null $accepted True for accepted only, |
|
601 | + * false for not accepted, |
|
602 | + * null for all shares of the user |
|
603 | + * @return array list of open server-to-server shares |
|
604 | + */ |
|
605 | + private function getShares($accepted) { |
|
606 | + $user = $this->userManager->get($this->uid); |
|
607 | + $groups = $this->groupManager->getUserGroups($user); |
|
608 | + $userGroups = []; |
|
609 | + foreach ($groups as $group) { |
|
610 | + $userGroups[] = $group->getGID(); |
|
611 | + } |
|
612 | + |
|
613 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
614 | 614 | FROM `*PREFIX*share_external` |
615 | 615 | WHERE (`user` = ? OR `user` IN (?))'; |
616 | - $parameters = [$this->uid, implode(',',$userGroups)]; |
|
617 | - if (!is_null($accepted)) { |
|
618 | - $query .= ' AND `accepted` = ?'; |
|
619 | - $parameters[] = (int) $accepted; |
|
620 | - } |
|
621 | - $query .= ' ORDER BY `id` ASC'; |
|
622 | - |
|
623 | - $shares = $this->connection->prepare($query); |
|
624 | - $result = $shares->execute($parameters); |
|
625 | - |
|
626 | - return $result ? $shares->fetchAll() : []; |
|
627 | - } |
|
616 | + $parameters = [$this->uid, implode(',',$userGroups)]; |
|
617 | + if (!is_null($accepted)) { |
|
618 | + $query .= ' AND `accepted` = ?'; |
|
619 | + $parameters[] = (int) $accepted; |
|
620 | + } |
|
621 | + $query .= ' ORDER BY `id` ASC'; |
|
622 | + |
|
623 | + $shares = $this->connection->prepare($query); |
|
624 | + $result = $shares->execute($parameters); |
|
625 | + |
|
626 | + return $result ? $shares->fetchAll() : []; |
|
627 | + } |
|
628 | 628 | } |
@@ -31,37 +31,37 @@ |
||
31 | 31 | use OCP\EventDispatcher\IEventDispatcher; |
32 | 32 | |
33 | 33 | class Hooks { |
34 | - public static function deleteUser($params) { |
|
35 | - $manager = new External\Manager( |
|
36 | - \OC::$server->getDatabaseConnection(), |
|
37 | - \OC\Files\Filesystem::getMountManager(), |
|
38 | - \OC\Files\Filesystem::getLoader(), |
|
39 | - \OC::$server->getHTTPClientService(), |
|
40 | - \OC::$server->getNotificationManager(), |
|
41 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
42 | - \OC::$server->getCloudFederationProviderManager(), |
|
43 | - \OC::$server->getCloudFederationFactory(), |
|
44 | - \OC::$server->getGroupManager(), |
|
45 | - \OC::$server->getUserManager(), |
|
46 | - $params['uid'], |
|
47 | - \OC::$server->query(IEventDispatcher::class) |
|
48 | - ); |
|
34 | + public static function deleteUser($params) { |
|
35 | + $manager = new External\Manager( |
|
36 | + \OC::$server->getDatabaseConnection(), |
|
37 | + \OC\Files\Filesystem::getMountManager(), |
|
38 | + \OC\Files\Filesystem::getLoader(), |
|
39 | + \OC::$server->getHTTPClientService(), |
|
40 | + \OC::$server->getNotificationManager(), |
|
41 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
42 | + \OC::$server->getCloudFederationProviderManager(), |
|
43 | + \OC::$server->getCloudFederationFactory(), |
|
44 | + \OC::$server->getGroupManager(), |
|
45 | + \OC::$server->getUserManager(), |
|
46 | + $params['uid'], |
|
47 | + \OC::$server->query(IEventDispatcher::class) |
|
48 | + ); |
|
49 | 49 | |
50 | - $manager->removeUserShares($params['uid']); |
|
51 | - } |
|
50 | + $manager->removeUserShares($params['uid']); |
|
51 | + } |
|
52 | 52 | |
53 | - public static function unshareChildren($params) { |
|
54 | - $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
55 | - $view = new \OC\Files\View('/'); |
|
53 | + public static function unshareChildren($params) { |
|
54 | + $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
55 | + $view = new \OC\Files\View('/'); |
|
56 | 56 | |
57 | - // find share mount points within $path and unmount them |
|
58 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
59 | - $mountedShares = $mountManager->findIn($path); |
|
60 | - foreach ($mountedShares as $mount) { |
|
61 | - if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
62 | - $mountPoint = $mount->getMountPoint(); |
|
63 | - $view->unlink($mountPoint); |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
57 | + // find share mount points within $path and unmount them |
|
58 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
59 | + $mountedShares = $mountManager->findIn($path); |
|
60 | + foreach ($mountedShares as $mount) { |
|
61 | + if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
62 | + $mountPoint = $mount->getMountPoint(); |
|
63 | + $view->unlink($mountPoint); |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | } |
@@ -62,178 +62,178 @@ |
||
62 | 62 | use Symfony\Component\EventDispatcher\GenericEvent; |
63 | 63 | |
64 | 64 | class Application extends App { |
65 | - public const APP_ID = 'files_sharing'; |
|
66 | - |
|
67 | - public function __construct(array $urlParams = []) { |
|
68 | - parent::__construct(self::APP_ID, $urlParams); |
|
69 | - |
|
70 | - $container = $this->getContainer(); |
|
71 | - |
|
72 | - /** @var IServerContainer $server */ |
|
73 | - $server = $container->getServer(); |
|
74 | - |
|
75 | - /** @var IEventDispatcher $dispatcher */ |
|
76 | - $dispatcher = $container->query(IEventDispatcher::class); |
|
77 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
78 | - $notifications = $server->getNotificationManager(); |
|
79 | - |
|
80 | - /** |
|
81 | - * Core class wrappers |
|
82 | - */ |
|
83 | - $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { |
|
84 | - $user = $server->getUserSession()->getUser(); |
|
85 | - $uid = $user ? $user->getUID() : null; |
|
86 | - return new \OCA\Files_Sharing\External\Manager( |
|
87 | - $server->getDatabaseConnection(), |
|
88 | - \OC\Files\Filesystem::getMountManager(), |
|
89 | - \OC\Files\Filesystem::getLoader(), |
|
90 | - $server->getHTTPClientService(), |
|
91 | - $server->getNotificationManager(), |
|
92 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
93 | - $server->getCloudFederationProviderManager(), |
|
94 | - $server->getCloudFederationFactory(), |
|
95 | - $server->getGroupManager(), |
|
96 | - $server->getUserManager(), |
|
97 | - $uid, |
|
98 | - $server->query(IEventDispatcher::class) |
|
99 | - ); |
|
100 | - }); |
|
101 | - |
|
102 | - /** |
|
103 | - * Middleware |
|
104 | - */ |
|
105 | - $container->registerMiddleWare(SharingCheckMiddleware::class); |
|
106 | - $container->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
107 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
108 | - |
|
109 | - $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { |
|
110 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
111 | - $c->get(IDBConnection::class), |
|
112 | - function () use ($c) { |
|
113 | - return $c->get(Manager::class); |
|
114 | - }, |
|
115 | - $c->get(ICloudIdManager::class) |
|
116 | - ); |
|
117 | - }); |
|
118 | - |
|
119 | - /** |
|
120 | - * Register capabilities |
|
121 | - */ |
|
122 | - $container->registerCapability(Capabilities::class); |
|
123 | - |
|
124 | - $notifications->registerNotifierService(Notifier::class); |
|
125 | - |
|
126 | - $this->registerMountProviders($mountProviderCollection); |
|
127 | - $this->registerEventsScripts($dispatcher); |
|
128 | - $this->setupSharingMenus(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Always add main sharing script |
|
132 | - */ |
|
133 | - Util::addScript(self::APP_ID, 'dist/main'); |
|
134 | - } |
|
135 | - |
|
136 | - protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) { |
|
137 | - $mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class)); |
|
138 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
139 | - } |
|
140 | - |
|
141 | - protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
142 | - // sidebar and files scripts |
|
143 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
144 | - $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
145 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
146 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
147 | - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
148 | - \OCP\Util::addScript('files_sharing', 'dist/collaboration'); |
|
149 | - }); |
|
150 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
151 | - $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
152 | - |
|
153 | - // notifications api to accept incoming user shares |
|
154 | - $dispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
155 | - /** @var Listener $listener */ |
|
156 | - $listener = $this->getContainer()->query(Listener::class); |
|
157 | - $listener->shareNotification($event); |
|
158 | - }); |
|
159 | - $dispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
160 | - /** @var Listener $listener */ |
|
161 | - $listener = $this->getContainer()->query(Listener::class); |
|
162 | - $listener->userAddedToGroup($event); |
|
163 | - }); |
|
164 | - } |
|
165 | - |
|
166 | - protected function setupSharingMenus() { |
|
167 | - $config = \OC::$server->getConfig(); |
|
168 | - |
|
169 | - if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
170 | - return; |
|
171 | - } |
|
172 | - |
|
173 | - // show_Quick_Access stored as string |
|
174 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
175 | - $config = \OC::$server->getConfig(); |
|
176 | - $l = \OC::$server->getL10N('files_sharing'); |
|
177 | - |
|
178 | - $sharingSublistArray = []; |
|
179 | - |
|
180 | - if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
181 | - $sharingSublistArray[] = [ |
|
182 | - 'id' => 'sharingout', |
|
183 | - 'appname' => 'files_sharing', |
|
184 | - 'script' => 'list.php', |
|
185 | - 'order' => 16, |
|
186 | - 'name' => $l->t('Shared with others'), |
|
187 | - ]; |
|
188 | - } |
|
189 | - |
|
190 | - $sharingSublistArray[] = [ |
|
191 | - 'id' => 'sharingin', |
|
192 | - 'appname' => 'files_sharing', |
|
193 | - 'script' => 'list.php', |
|
194 | - 'order' => 15, |
|
195 | - 'name' => $l->t('Shared with you'), |
|
196 | - ]; |
|
197 | - |
|
198 | - if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
199 | - // Check if sharing by link is enabled |
|
200 | - if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
201 | - $sharingSublistArray[] = [ |
|
202 | - 'id' => 'sharinglinks', |
|
203 | - 'appname' => 'files_sharing', |
|
204 | - 'script' => 'list.php', |
|
205 | - 'order' => 17, |
|
206 | - 'name' => $l->t('Shared by link'), |
|
207 | - ]; |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - $sharingSublistArray[] = [ |
|
212 | - 'id' => 'deletedshares', |
|
213 | - 'appname' => 'files_sharing', |
|
214 | - 'script' => 'list.php', |
|
215 | - 'order' => 19, |
|
216 | - 'name' => $l->t('Deleted shares'), |
|
217 | - ]; |
|
218 | - |
|
219 | - $sharingSublistArray[] = [ |
|
220 | - 'id' => 'pendingshares', |
|
221 | - 'appname' => 'files_sharing', |
|
222 | - 'script' => 'list.php', |
|
223 | - 'order' => 19, |
|
224 | - 'name' => $l->t('Pending shares'), |
|
225 | - ]; |
|
226 | - |
|
227 | - return [ |
|
228 | - 'id' => 'shareoverview', |
|
229 | - 'appname' => 'files_sharing', |
|
230 | - 'script' => 'list.php', |
|
231 | - 'order' => 18, |
|
232 | - 'name' => $l->t('Shares'), |
|
233 | - 'classes' => 'collapsible', |
|
234 | - 'sublist' => $sharingSublistArray, |
|
235 | - 'expandedState' => 'show_sharing_menu' |
|
236 | - ]; |
|
237 | - }); |
|
238 | - } |
|
65 | + public const APP_ID = 'files_sharing'; |
|
66 | + |
|
67 | + public function __construct(array $urlParams = []) { |
|
68 | + parent::__construct(self::APP_ID, $urlParams); |
|
69 | + |
|
70 | + $container = $this->getContainer(); |
|
71 | + |
|
72 | + /** @var IServerContainer $server */ |
|
73 | + $server = $container->getServer(); |
|
74 | + |
|
75 | + /** @var IEventDispatcher $dispatcher */ |
|
76 | + $dispatcher = $container->query(IEventDispatcher::class); |
|
77 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
78 | + $notifications = $server->getNotificationManager(); |
|
79 | + |
|
80 | + /** |
|
81 | + * Core class wrappers |
|
82 | + */ |
|
83 | + $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) { |
|
84 | + $user = $server->getUserSession()->getUser(); |
|
85 | + $uid = $user ? $user->getUID() : null; |
|
86 | + return new \OCA\Files_Sharing\External\Manager( |
|
87 | + $server->getDatabaseConnection(), |
|
88 | + \OC\Files\Filesystem::getMountManager(), |
|
89 | + \OC\Files\Filesystem::getLoader(), |
|
90 | + $server->getHTTPClientService(), |
|
91 | + $server->getNotificationManager(), |
|
92 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
93 | + $server->getCloudFederationProviderManager(), |
|
94 | + $server->getCloudFederationFactory(), |
|
95 | + $server->getGroupManager(), |
|
96 | + $server->getUserManager(), |
|
97 | + $uid, |
|
98 | + $server->query(IEventDispatcher::class) |
|
99 | + ); |
|
100 | + }); |
|
101 | + |
|
102 | + /** |
|
103 | + * Middleware |
|
104 | + */ |
|
105 | + $container->registerMiddleWare(SharingCheckMiddleware::class); |
|
106 | + $container->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
107 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
108 | + |
|
109 | + $container->registerService('ExternalMountProvider', function (ContainerInterface $c) { |
|
110 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
111 | + $c->get(IDBConnection::class), |
|
112 | + function () use ($c) { |
|
113 | + return $c->get(Manager::class); |
|
114 | + }, |
|
115 | + $c->get(ICloudIdManager::class) |
|
116 | + ); |
|
117 | + }); |
|
118 | + |
|
119 | + /** |
|
120 | + * Register capabilities |
|
121 | + */ |
|
122 | + $container->registerCapability(Capabilities::class); |
|
123 | + |
|
124 | + $notifications->registerNotifierService(Notifier::class); |
|
125 | + |
|
126 | + $this->registerMountProviders($mountProviderCollection); |
|
127 | + $this->registerEventsScripts($dispatcher); |
|
128 | + $this->setupSharingMenus(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Always add main sharing script |
|
132 | + */ |
|
133 | + Util::addScript(self::APP_ID, 'dist/main'); |
|
134 | + } |
|
135 | + |
|
136 | + protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) { |
|
137 | + $mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class)); |
|
138 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
139 | + } |
|
140 | + |
|
141 | + protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
142 | + // sidebar and files scripts |
|
143 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
144 | + $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
145 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
146 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
147 | + $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
148 | + \OCP\Util::addScript('files_sharing', 'dist/collaboration'); |
|
149 | + }); |
|
150 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
151 | + $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
152 | + |
|
153 | + // notifications api to accept incoming user shares |
|
154 | + $dispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
155 | + /** @var Listener $listener */ |
|
156 | + $listener = $this->getContainer()->query(Listener::class); |
|
157 | + $listener->shareNotification($event); |
|
158 | + }); |
|
159 | + $dispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
160 | + /** @var Listener $listener */ |
|
161 | + $listener = $this->getContainer()->query(Listener::class); |
|
162 | + $listener->userAddedToGroup($event); |
|
163 | + }); |
|
164 | + } |
|
165 | + |
|
166 | + protected function setupSharingMenus() { |
|
167 | + $config = \OC::$server->getConfig(); |
|
168 | + |
|
169 | + if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
170 | + return; |
|
171 | + } |
|
172 | + |
|
173 | + // show_Quick_Access stored as string |
|
174 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
175 | + $config = \OC::$server->getConfig(); |
|
176 | + $l = \OC::$server->getL10N('files_sharing'); |
|
177 | + |
|
178 | + $sharingSublistArray = []; |
|
179 | + |
|
180 | + if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
181 | + $sharingSublistArray[] = [ |
|
182 | + 'id' => 'sharingout', |
|
183 | + 'appname' => 'files_sharing', |
|
184 | + 'script' => 'list.php', |
|
185 | + 'order' => 16, |
|
186 | + 'name' => $l->t('Shared with others'), |
|
187 | + ]; |
|
188 | + } |
|
189 | + |
|
190 | + $sharingSublistArray[] = [ |
|
191 | + 'id' => 'sharingin', |
|
192 | + 'appname' => 'files_sharing', |
|
193 | + 'script' => 'list.php', |
|
194 | + 'order' => 15, |
|
195 | + 'name' => $l->t('Shared with you'), |
|
196 | + ]; |
|
197 | + |
|
198 | + if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
199 | + // Check if sharing by link is enabled |
|
200 | + if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
201 | + $sharingSublistArray[] = [ |
|
202 | + 'id' => 'sharinglinks', |
|
203 | + 'appname' => 'files_sharing', |
|
204 | + 'script' => 'list.php', |
|
205 | + 'order' => 17, |
|
206 | + 'name' => $l->t('Shared by link'), |
|
207 | + ]; |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + $sharingSublistArray[] = [ |
|
212 | + 'id' => 'deletedshares', |
|
213 | + 'appname' => 'files_sharing', |
|
214 | + 'script' => 'list.php', |
|
215 | + 'order' => 19, |
|
216 | + 'name' => $l->t('Deleted shares'), |
|
217 | + ]; |
|
218 | + |
|
219 | + $sharingSublistArray[] = [ |
|
220 | + 'id' => 'pendingshares', |
|
221 | + 'appname' => 'files_sharing', |
|
222 | + 'script' => 'list.php', |
|
223 | + 'order' => 19, |
|
224 | + 'name' => $l->t('Pending shares'), |
|
225 | + ]; |
|
226 | + |
|
227 | + return [ |
|
228 | + 'id' => 'shareoverview', |
|
229 | + 'appname' => 'files_sharing', |
|
230 | + 'script' => 'list.php', |
|
231 | + 'order' => 18, |
|
232 | + 'name' => $l->t('Shares'), |
|
233 | + 'classes' => 'collapsible', |
|
234 | + 'sublist' => $sharingSublistArray, |
|
235 | + 'expandedState' => 'show_sharing_menu' |
|
236 | + ]; |
|
237 | + }); |
|
238 | + } |
|
239 | 239 | } |