@@ -24,7 +24,6 @@ |
||
24 | 24 | namespace OC\Share20; |
25 | 25 | |
26 | 26 | use OCA\FederatedFileSharing\AddressHandler; |
27 | -use OCA\FederatedFileSharing\DiscoveryManager; |
|
28 | 27 | use OCA\FederatedFileSharing\FederatedShareProvider; |
29 | 28 | use OCA\FederatedFileSharing\Notifications; |
30 | 29 | use OCA\FederatedFileSharing\TokenHandler; |
@@ -40,220 +40,220 @@ |
||
40 | 40 | */ |
41 | 41 | class ProviderFactory implements IProviderFactory { |
42 | 42 | |
43 | - /** @var IServerContainer */ |
|
44 | - private $serverContainer; |
|
45 | - /** @var DefaultShareProvider */ |
|
46 | - private $defaultProvider = null; |
|
47 | - /** @var FederatedShareProvider */ |
|
48 | - private $federatedProvider = null; |
|
49 | - /** @var ShareByMailProvider */ |
|
50 | - private $shareByMailProvider; |
|
51 | - /** @var \OCA\Circles\ShareByCircleProvider; |
|
52 | - * ShareByCircleProvider */ |
|
53 | - private $shareByCircleProvider; |
|
54 | - |
|
55 | - /** |
|
56 | - * IProviderFactory constructor. |
|
57 | - * |
|
58 | - * @param IServerContainer $serverContainer |
|
59 | - */ |
|
60 | - public function __construct(IServerContainer $serverContainer) { |
|
61 | - $this->serverContainer = $serverContainer; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Create the default share provider. |
|
66 | - * |
|
67 | - * @return DefaultShareProvider |
|
68 | - */ |
|
69 | - protected function defaultShareProvider() { |
|
70 | - if ($this->defaultProvider === null) { |
|
71 | - $this->defaultProvider = new DefaultShareProvider( |
|
72 | - $this->serverContainer->getDatabaseConnection(), |
|
73 | - $this->serverContainer->getUserManager(), |
|
74 | - $this->serverContainer->getGroupManager(), |
|
75 | - $this->serverContainer->getLazyRootFolder() |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - return $this->defaultProvider; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Create the federated share provider |
|
84 | - * |
|
85 | - * @return FederatedShareProvider |
|
86 | - */ |
|
87 | - protected function federatedShareProvider() { |
|
88 | - if ($this->federatedProvider === null) { |
|
89 | - /* |
|
43 | + /** @var IServerContainer */ |
|
44 | + private $serverContainer; |
|
45 | + /** @var DefaultShareProvider */ |
|
46 | + private $defaultProvider = null; |
|
47 | + /** @var FederatedShareProvider */ |
|
48 | + private $federatedProvider = null; |
|
49 | + /** @var ShareByMailProvider */ |
|
50 | + private $shareByMailProvider; |
|
51 | + /** @var \OCA\Circles\ShareByCircleProvider; |
|
52 | + * ShareByCircleProvider */ |
|
53 | + private $shareByCircleProvider; |
|
54 | + |
|
55 | + /** |
|
56 | + * IProviderFactory constructor. |
|
57 | + * |
|
58 | + * @param IServerContainer $serverContainer |
|
59 | + */ |
|
60 | + public function __construct(IServerContainer $serverContainer) { |
|
61 | + $this->serverContainer = $serverContainer; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Create the default share provider. |
|
66 | + * |
|
67 | + * @return DefaultShareProvider |
|
68 | + */ |
|
69 | + protected function defaultShareProvider() { |
|
70 | + if ($this->defaultProvider === null) { |
|
71 | + $this->defaultProvider = new DefaultShareProvider( |
|
72 | + $this->serverContainer->getDatabaseConnection(), |
|
73 | + $this->serverContainer->getUserManager(), |
|
74 | + $this->serverContainer->getGroupManager(), |
|
75 | + $this->serverContainer->getLazyRootFolder() |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + return $this->defaultProvider; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Create the federated share provider |
|
84 | + * |
|
85 | + * @return FederatedShareProvider |
|
86 | + */ |
|
87 | + protected function federatedShareProvider() { |
|
88 | + if ($this->federatedProvider === null) { |
|
89 | + /* |
|
90 | 90 | * Check if the app is enabled |
91 | 91 | */ |
92 | - $appManager = $this->serverContainer->getAppManager(); |
|
93 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
94 | - return null; |
|
95 | - } |
|
92 | + $appManager = $this->serverContainer->getAppManager(); |
|
93 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
94 | + return null; |
|
95 | + } |
|
96 | 96 | |
97 | - /* |
|
97 | + /* |
|
98 | 98 | * TODO: add factory to federated sharing app |
99 | 99 | */ |
100 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
101 | - $addressHandler = new AddressHandler( |
|
102 | - $this->serverContainer->getURLGenerator(), |
|
103 | - $l, |
|
104 | - $this->serverContainer->getCloudIdManager() |
|
105 | - ); |
|
106 | - $notifications = new Notifications( |
|
107 | - $addressHandler, |
|
108 | - $this->serverContainer->getHTTPClientService(), |
|
109 | - $this->serverContainer->getOCSDiscoveryService(), |
|
110 | - $this->serverContainer->getJobList() |
|
111 | - ); |
|
112 | - $tokenHandler = new TokenHandler( |
|
113 | - $this->serverContainer->getSecureRandom() |
|
114 | - ); |
|
115 | - |
|
116 | - $this->federatedProvider = new FederatedShareProvider( |
|
117 | - $this->serverContainer->getDatabaseConnection(), |
|
118 | - $addressHandler, |
|
119 | - $notifications, |
|
120 | - $tokenHandler, |
|
121 | - $l, |
|
122 | - $this->serverContainer->getLogger(), |
|
123 | - $this->serverContainer->getLazyRootFolder(), |
|
124 | - $this->serverContainer->getConfig(), |
|
125 | - $this->serverContainer->getUserManager(), |
|
126 | - $this->serverContainer->getCloudIdManager() |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - return $this->federatedProvider; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Create the federated share provider |
|
135 | - * |
|
136 | - * @return ShareByMailProvider |
|
137 | - */ |
|
138 | - protected function getShareByMailProvider() { |
|
139 | - if ($this->shareByMailProvider === null) { |
|
140 | - /* |
|
100 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
101 | + $addressHandler = new AddressHandler( |
|
102 | + $this->serverContainer->getURLGenerator(), |
|
103 | + $l, |
|
104 | + $this->serverContainer->getCloudIdManager() |
|
105 | + ); |
|
106 | + $notifications = new Notifications( |
|
107 | + $addressHandler, |
|
108 | + $this->serverContainer->getHTTPClientService(), |
|
109 | + $this->serverContainer->getOCSDiscoveryService(), |
|
110 | + $this->serverContainer->getJobList() |
|
111 | + ); |
|
112 | + $tokenHandler = new TokenHandler( |
|
113 | + $this->serverContainer->getSecureRandom() |
|
114 | + ); |
|
115 | + |
|
116 | + $this->federatedProvider = new FederatedShareProvider( |
|
117 | + $this->serverContainer->getDatabaseConnection(), |
|
118 | + $addressHandler, |
|
119 | + $notifications, |
|
120 | + $tokenHandler, |
|
121 | + $l, |
|
122 | + $this->serverContainer->getLogger(), |
|
123 | + $this->serverContainer->getLazyRootFolder(), |
|
124 | + $this->serverContainer->getConfig(), |
|
125 | + $this->serverContainer->getUserManager(), |
|
126 | + $this->serverContainer->getCloudIdManager() |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + return $this->federatedProvider; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Create the federated share provider |
|
135 | + * |
|
136 | + * @return ShareByMailProvider |
|
137 | + */ |
|
138 | + protected function getShareByMailProvider() { |
|
139 | + if ($this->shareByMailProvider === null) { |
|
140 | + /* |
|
141 | 141 | * Check if the app is enabled |
142 | 142 | */ |
143 | - $appManager = $this->serverContainer->getAppManager(); |
|
144 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - |
|
148 | - $l = $this->serverContainer->getL10N('sharebymail'); |
|
149 | - |
|
150 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
151 | - $this->serverContainer->getDatabaseConnection(), |
|
152 | - $this->serverContainer->getSecureRandom(), |
|
153 | - $this->serverContainer->getUserManager(), |
|
154 | - $this->serverContainer->getLazyRootFolder(), |
|
155 | - $l, |
|
156 | - $this->serverContainer->getLogger(), |
|
157 | - $this->serverContainer->getMailer(), |
|
158 | - $this->serverContainer->getURLGenerator(), |
|
159 | - $this->serverContainer->getActivityManager() |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - return $this->shareByMailProvider; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Create the circle share provider |
|
169 | - * |
|
170 | - * @return FederatedShareProvider |
|
171 | - */ |
|
172 | - protected function getShareByCircleProvider() { |
|
173 | - |
|
174 | - $appManager = $this->serverContainer->getAppManager(); |
|
175 | - if (!$appManager->isEnabledForUser('circles')) { |
|
176 | - return null; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - if ($this->shareByCircleProvider === null) { |
|
181 | - |
|
182 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
183 | - $this->serverContainer->getDatabaseConnection(), |
|
184 | - $this->serverContainer->getSecureRandom(), |
|
185 | - $this->serverContainer->getUserManager(), |
|
186 | - $this->serverContainer->getLazyRootFolder(), |
|
187 | - $this->serverContainer->getL10N('circles'), |
|
188 | - $this->serverContainer->getLogger(), |
|
189 | - $this->serverContainer->getURLGenerator() |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - return $this->shareByCircleProvider; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @inheritdoc |
|
199 | - */ |
|
200 | - public function getProvider($id) { |
|
201 | - $provider = null; |
|
202 | - if ($id === 'ocinternal') { |
|
203 | - $provider = $this->defaultShareProvider(); |
|
204 | - } else if ($id === 'ocFederatedSharing') { |
|
205 | - $provider = $this->federatedShareProvider(); |
|
206 | - } else if ($id === 'ocMailShare') { |
|
207 | - $provider = $this->getShareByMailProvider(); |
|
208 | - } else if ($id === 'ocCircleShare') { |
|
209 | - $provider = $this->getShareByCircleProvider(); |
|
210 | - } |
|
211 | - |
|
212 | - if ($provider === null) { |
|
213 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
214 | - } |
|
215 | - |
|
216 | - return $provider; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @inheritdoc |
|
221 | - */ |
|
222 | - public function getProviderForType($shareType) { |
|
223 | - $provider = null; |
|
224 | - |
|
225 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
226 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
227 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
228 | - ) { |
|
229 | - $provider = $this->defaultShareProvider(); |
|
230 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
231 | - $provider = $this->federatedShareProvider(); |
|
232 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
233 | - $provider = $this->getShareByMailProvider(); |
|
234 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
235 | - $provider = $this->getShareByCircleProvider(); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - if ($provider === null) { |
|
240 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
241 | - } |
|
242 | - |
|
243 | - return $provider; |
|
244 | - } |
|
245 | - |
|
246 | - public function getAllProviders() { |
|
247 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
248 | - $shareByMail = $this->getShareByMailProvider(); |
|
249 | - if ($shareByMail !== null) { |
|
250 | - $shares[] = $shareByMail; |
|
251 | - } |
|
252 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
253 | - if ($shareByCircle !== null) { |
|
254 | - $shares[] = $shareByCircle; |
|
255 | - } |
|
256 | - |
|
257 | - return $shares; |
|
258 | - } |
|
143 | + $appManager = $this->serverContainer->getAppManager(); |
|
144 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + |
|
148 | + $l = $this->serverContainer->getL10N('sharebymail'); |
|
149 | + |
|
150 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
151 | + $this->serverContainer->getDatabaseConnection(), |
|
152 | + $this->serverContainer->getSecureRandom(), |
|
153 | + $this->serverContainer->getUserManager(), |
|
154 | + $this->serverContainer->getLazyRootFolder(), |
|
155 | + $l, |
|
156 | + $this->serverContainer->getLogger(), |
|
157 | + $this->serverContainer->getMailer(), |
|
158 | + $this->serverContainer->getURLGenerator(), |
|
159 | + $this->serverContainer->getActivityManager() |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + return $this->shareByMailProvider; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Create the circle share provider |
|
169 | + * |
|
170 | + * @return FederatedShareProvider |
|
171 | + */ |
|
172 | + protected function getShareByCircleProvider() { |
|
173 | + |
|
174 | + $appManager = $this->serverContainer->getAppManager(); |
|
175 | + if (!$appManager->isEnabledForUser('circles')) { |
|
176 | + return null; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + if ($this->shareByCircleProvider === null) { |
|
181 | + |
|
182 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
183 | + $this->serverContainer->getDatabaseConnection(), |
|
184 | + $this->serverContainer->getSecureRandom(), |
|
185 | + $this->serverContainer->getUserManager(), |
|
186 | + $this->serverContainer->getLazyRootFolder(), |
|
187 | + $this->serverContainer->getL10N('circles'), |
|
188 | + $this->serverContainer->getLogger(), |
|
189 | + $this->serverContainer->getURLGenerator() |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + return $this->shareByCircleProvider; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @inheritdoc |
|
199 | + */ |
|
200 | + public function getProvider($id) { |
|
201 | + $provider = null; |
|
202 | + if ($id === 'ocinternal') { |
|
203 | + $provider = $this->defaultShareProvider(); |
|
204 | + } else if ($id === 'ocFederatedSharing') { |
|
205 | + $provider = $this->federatedShareProvider(); |
|
206 | + } else if ($id === 'ocMailShare') { |
|
207 | + $provider = $this->getShareByMailProvider(); |
|
208 | + } else if ($id === 'ocCircleShare') { |
|
209 | + $provider = $this->getShareByCircleProvider(); |
|
210 | + } |
|
211 | + |
|
212 | + if ($provider === null) { |
|
213 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
214 | + } |
|
215 | + |
|
216 | + return $provider; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @inheritdoc |
|
221 | + */ |
|
222 | + public function getProviderForType($shareType) { |
|
223 | + $provider = null; |
|
224 | + |
|
225 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
226 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
227 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
228 | + ) { |
|
229 | + $provider = $this->defaultShareProvider(); |
|
230 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
231 | + $provider = $this->federatedShareProvider(); |
|
232 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
233 | + $provider = $this->getShareByMailProvider(); |
|
234 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
235 | + $provider = $this->getShareByCircleProvider(); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + if ($provider === null) { |
|
240 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
241 | + } |
|
242 | + |
|
243 | + return $provider; |
|
244 | + } |
|
245 | + |
|
246 | + public function getAllProviders() { |
|
247 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
248 | + $shareByMail = $this->getShareByMailProvider(); |
|
249 | + if ($shareByMail !== null) { |
|
250 | + $shares[] = $shareByMail; |
|
251 | + } |
|
252 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
253 | + if ($shareByCircle !== null) { |
|
254 | + $shares[] = $shareByCircle; |
|
255 | + } |
|
256 | + |
|
257 | + return $shares; |
|
258 | + } |
|
259 | 259 | } |
@@ -33,91 +33,91 @@ |
||
33 | 33 | |
34 | 34 | class Application extends App { |
35 | 35 | |
36 | - /** @var FederatedShareProvider */ |
|
37 | - protected $federatedShareProvider; |
|
36 | + /** @var FederatedShareProvider */ |
|
37 | + protected $federatedShareProvider; |
|
38 | 38 | |
39 | - public function __construct() { |
|
40 | - parent::__construct('federatedfilesharing'); |
|
39 | + public function __construct() { |
|
40 | + parent::__construct('federatedfilesharing'); |
|
41 | 41 | |
42 | - $container = $this->getContainer(); |
|
43 | - $server = $container->getServer(); |
|
42 | + $container = $this->getContainer(); |
|
43 | + $server = $container->getServer(); |
|
44 | 44 | |
45 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
46 | - $addressHandler = new AddressHandler( |
|
47 | - $server->getURLGenerator(), |
|
48 | - $server->getL10N('federatedfilesharing'), |
|
49 | - $server->getCloudIdManager() |
|
50 | - ); |
|
51 | - $notification = new Notifications( |
|
52 | - $addressHandler, |
|
53 | - $server->getHTTPClientService(), |
|
54 | - $server->getOCSDiscoveryService(), |
|
55 | - \OC::$server->getJobList() |
|
56 | - ); |
|
57 | - return new RequestHandlerController( |
|
58 | - $c->query('AppName'), |
|
59 | - $server->getRequest(), |
|
60 | - $this->getFederatedShareProvider(), |
|
61 | - $server->getDatabaseConnection(), |
|
62 | - $server->getShareManager(), |
|
63 | - $notification, |
|
64 | - $addressHandler, |
|
65 | - $server->getUserManager(), |
|
66 | - $server->getCloudIdManager() |
|
67 | - ); |
|
68 | - }); |
|
69 | - } |
|
45 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
46 | + $addressHandler = new AddressHandler( |
|
47 | + $server->getURLGenerator(), |
|
48 | + $server->getL10N('federatedfilesharing'), |
|
49 | + $server->getCloudIdManager() |
|
50 | + ); |
|
51 | + $notification = new Notifications( |
|
52 | + $addressHandler, |
|
53 | + $server->getHTTPClientService(), |
|
54 | + $server->getOCSDiscoveryService(), |
|
55 | + \OC::$server->getJobList() |
|
56 | + ); |
|
57 | + return new RequestHandlerController( |
|
58 | + $c->query('AppName'), |
|
59 | + $server->getRequest(), |
|
60 | + $this->getFederatedShareProvider(), |
|
61 | + $server->getDatabaseConnection(), |
|
62 | + $server->getShareManager(), |
|
63 | + $notification, |
|
64 | + $addressHandler, |
|
65 | + $server->getUserManager(), |
|
66 | + $server->getCloudIdManager() |
|
67 | + ); |
|
68 | + }); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * register personal and admin settings page |
|
73 | - */ |
|
74 | - public function registerSettings() { |
|
75 | - \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); |
|
76 | - } |
|
71 | + /** |
|
72 | + * register personal and admin settings page |
|
73 | + */ |
|
74 | + public function registerSettings() { |
|
75 | + \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * get instance of federated share provider |
|
80 | - * |
|
81 | - * @return FederatedShareProvider |
|
82 | - */ |
|
83 | - public function getFederatedShareProvider() { |
|
84 | - if ($this->federatedShareProvider === null) { |
|
85 | - $this->initFederatedShareProvider(); |
|
86 | - } |
|
87 | - return $this->federatedShareProvider; |
|
88 | - } |
|
78 | + /** |
|
79 | + * get instance of federated share provider |
|
80 | + * |
|
81 | + * @return FederatedShareProvider |
|
82 | + */ |
|
83 | + public function getFederatedShareProvider() { |
|
84 | + if ($this->federatedShareProvider === null) { |
|
85 | + $this->initFederatedShareProvider(); |
|
86 | + } |
|
87 | + return $this->federatedShareProvider; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * initialize federated share provider |
|
92 | - */ |
|
93 | - protected function initFederatedShareProvider() { |
|
94 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
95 | - \OC::$server->getURLGenerator(), |
|
96 | - \OC::$server->getL10N('federatedfilesharing'), |
|
97 | - \OC::$server->getCloudIdManager() |
|
98 | - ); |
|
99 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
100 | - $addressHandler, |
|
101 | - \OC::$server->getHTTPClientService(), |
|
102 | - \OC::$server->getOCSDiscoveryService(), |
|
103 | - \OC::$server->getJobList() |
|
104 | - ); |
|
105 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
106 | - \OC::$server->getSecureRandom() |
|
107 | - ); |
|
90 | + /** |
|
91 | + * initialize federated share provider |
|
92 | + */ |
|
93 | + protected function initFederatedShareProvider() { |
|
94 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
95 | + \OC::$server->getURLGenerator(), |
|
96 | + \OC::$server->getL10N('federatedfilesharing'), |
|
97 | + \OC::$server->getCloudIdManager() |
|
98 | + ); |
|
99 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
100 | + $addressHandler, |
|
101 | + \OC::$server->getHTTPClientService(), |
|
102 | + \OC::$server->getOCSDiscoveryService(), |
|
103 | + \OC::$server->getJobList() |
|
104 | + ); |
|
105 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
106 | + \OC::$server->getSecureRandom() |
|
107 | + ); |
|
108 | 108 | |
109 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
110 | - \OC::$server->getDatabaseConnection(), |
|
111 | - $addressHandler, |
|
112 | - $notifications, |
|
113 | - $tokenHandler, |
|
114 | - \OC::$server->getL10N('federatedfilesharing'), |
|
115 | - \OC::$server->getLogger(), |
|
116 | - \OC::$server->getLazyRootFolder(), |
|
117 | - \OC::$server->getConfig(), |
|
118 | - \OC::$server->getUserManager(), |
|
119 | - \OC::$server->getCloudIdManager() |
|
120 | - ); |
|
121 | - } |
|
109 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
110 | + \OC::$server->getDatabaseConnection(), |
|
111 | + $addressHandler, |
|
112 | + $notifications, |
|
113 | + $tokenHandler, |
|
114 | + \OC::$server->getL10N('federatedfilesharing'), |
|
115 | + \OC::$server->getLogger(), |
|
116 | + \OC::$server->getLazyRootFolder(), |
|
117 | + \OC::$server->getConfig(), |
|
118 | + \OC::$server->getUserManager(), |
|
119 | + \OC::$server->getCloudIdManager() |
|
120 | + ); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | } |
@@ -42,103 +42,103 @@ |
||
42 | 42 | */ |
43 | 43 | class RetryJob extends Job { |
44 | 44 | |
45 | - /** @var bool */ |
|
46 | - private $retainJob = true; |
|
47 | - |
|
48 | - /** @var Notifications */ |
|
49 | - private $notifications; |
|
50 | - |
|
51 | - /** @var int max number of attempts to send the request */ |
|
52 | - private $maxTry = 20; |
|
53 | - |
|
54 | - /** @var int how much time should be between two tries (10 minutes) */ |
|
55 | - private $interval = 600; |
|
56 | - |
|
57 | - /** |
|
58 | - * UnShare constructor. |
|
59 | - * |
|
60 | - * @param Notifications $notifications |
|
61 | - */ |
|
62 | - public function __construct(Notifications $notifications = null) { |
|
63 | - if ($notifications) { |
|
64 | - $this->notifications = $notifications; |
|
65 | - } else { |
|
66 | - $addressHandler = new AddressHandler( |
|
67 | - \OC::$server->getURLGenerator(), |
|
68 | - \OC::$server->getL10N('federatedfilesharing'), |
|
69 | - \OC::$server->getCloudIdManager() |
|
70 | - ); |
|
71 | - $this->notifications = new Notifications( |
|
72 | - $addressHandler, |
|
73 | - \OC::$server->getHTTPClientService(), |
|
74 | - \OC::$server->getOCSDiscoveryService(), |
|
75 | - \OC::$server->getJobList() |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * run the job, then remove it from the jobList |
|
83 | - * |
|
84 | - * @param JobList $jobList |
|
85 | - * @param ILogger $logger |
|
86 | - */ |
|
87 | - public function execute($jobList, ILogger $logger = null) { |
|
88 | - |
|
89 | - if ($this->shouldRun($this->argument)) { |
|
90 | - parent::execute($jobList, $logger); |
|
91 | - $jobList->remove($this, $this->argument); |
|
92 | - if ($this->retainJob) { |
|
93 | - $this->reAddJob($jobList, $this->argument); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - protected function run($argument) { |
|
99 | - $remote = $argument['remote']; |
|
100 | - $remoteId = $argument['remoteId']; |
|
101 | - $token = $argument['token']; |
|
102 | - $action = $argument['action']; |
|
103 | - $data = json_decode($argument['data'], true); |
|
104 | - $try = (int)$argument['try'] + 1; |
|
105 | - |
|
106 | - $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
107 | - |
|
108 | - if ($result === true || $try > $this->maxTry) { |
|
109 | - $this->retainJob = false; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * re-add background job with new arguments |
|
115 | - * |
|
116 | - * @param IJobList $jobList |
|
117 | - * @param array $argument |
|
118 | - */ |
|
119 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
120 | - $jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
121 | - [ |
|
122 | - 'remote' => $argument['remote'], |
|
123 | - 'remoteId' => $argument['remoteId'], |
|
124 | - 'token' => $argument['token'], |
|
125 | - 'data' => $argument['data'], |
|
126 | - 'action' => $argument['action'], |
|
127 | - 'try' => (int)$argument['try'] + 1, |
|
128 | - 'lastRun' => time() |
|
129 | - ] |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * test if it is time for the next run |
|
135 | - * |
|
136 | - * @param array $argument |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - protected function shouldRun(array $argument) { |
|
140 | - $lastRun = (int)$argument['lastRun']; |
|
141 | - return ((time() - $lastRun) > $this->interval); |
|
142 | - } |
|
45 | + /** @var bool */ |
|
46 | + private $retainJob = true; |
|
47 | + |
|
48 | + /** @var Notifications */ |
|
49 | + private $notifications; |
|
50 | + |
|
51 | + /** @var int max number of attempts to send the request */ |
|
52 | + private $maxTry = 20; |
|
53 | + |
|
54 | + /** @var int how much time should be between two tries (10 minutes) */ |
|
55 | + private $interval = 600; |
|
56 | + |
|
57 | + /** |
|
58 | + * UnShare constructor. |
|
59 | + * |
|
60 | + * @param Notifications $notifications |
|
61 | + */ |
|
62 | + public function __construct(Notifications $notifications = null) { |
|
63 | + if ($notifications) { |
|
64 | + $this->notifications = $notifications; |
|
65 | + } else { |
|
66 | + $addressHandler = new AddressHandler( |
|
67 | + \OC::$server->getURLGenerator(), |
|
68 | + \OC::$server->getL10N('federatedfilesharing'), |
|
69 | + \OC::$server->getCloudIdManager() |
|
70 | + ); |
|
71 | + $this->notifications = new Notifications( |
|
72 | + $addressHandler, |
|
73 | + \OC::$server->getHTTPClientService(), |
|
74 | + \OC::$server->getOCSDiscoveryService(), |
|
75 | + \OC::$server->getJobList() |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * run the job, then remove it from the jobList |
|
83 | + * |
|
84 | + * @param JobList $jobList |
|
85 | + * @param ILogger $logger |
|
86 | + */ |
|
87 | + public function execute($jobList, ILogger $logger = null) { |
|
88 | + |
|
89 | + if ($this->shouldRun($this->argument)) { |
|
90 | + parent::execute($jobList, $logger); |
|
91 | + $jobList->remove($this, $this->argument); |
|
92 | + if ($this->retainJob) { |
|
93 | + $this->reAddJob($jobList, $this->argument); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + protected function run($argument) { |
|
99 | + $remote = $argument['remote']; |
|
100 | + $remoteId = $argument['remoteId']; |
|
101 | + $token = $argument['token']; |
|
102 | + $action = $argument['action']; |
|
103 | + $data = json_decode($argument['data'], true); |
|
104 | + $try = (int)$argument['try'] + 1; |
|
105 | + |
|
106 | + $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
107 | + |
|
108 | + if ($result === true || $try > $this->maxTry) { |
|
109 | + $this->retainJob = false; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * re-add background job with new arguments |
|
115 | + * |
|
116 | + * @param IJobList $jobList |
|
117 | + * @param array $argument |
|
118 | + */ |
|
119 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
120 | + $jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
121 | + [ |
|
122 | + 'remote' => $argument['remote'], |
|
123 | + 'remoteId' => $argument['remoteId'], |
|
124 | + 'token' => $argument['token'], |
|
125 | + 'data' => $argument['data'], |
|
126 | + 'action' => $argument['action'], |
|
127 | + 'try' => (int)$argument['try'] + 1, |
|
128 | + 'lastRun' => time() |
|
129 | + ] |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * test if it is time for the next run |
|
135 | + * |
|
136 | + * @param array $argument |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + protected function shouldRun(array $argument) { |
|
140 | + $lastRun = (int)$argument['lastRun']; |
|
141 | + return ((time() - $lastRun) > $this->interval); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | } |
@@ -33,280 +33,280 @@ |
||
33 | 33 | use OCP\OCS\IDiscoveryService; |
34 | 34 | |
35 | 35 | class Notifications { |
36 | - const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | - |
|
38 | - /** @var AddressHandler */ |
|
39 | - private $addressHandler; |
|
40 | - |
|
41 | - /** @var IClientService */ |
|
42 | - private $httpClientService; |
|
43 | - |
|
44 | - /** @var IDiscoveryService */ |
|
45 | - private $discoveryService; |
|
46 | - |
|
47 | - /** @var IJobList */ |
|
48 | - private $jobList; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param AddressHandler $addressHandler |
|
52 | - * @param IClientService $httpClientService |
|
53 | - * @param IDiscoveryService $discoveryService |
|
54 | - * @param IJobList $jobList |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - AddressHandler $addressHandler, |
|
58 | - IClientService $httpClientService, |
|
59 | - IDiscoveryService $discoveryService, |
|
60 | - IJobList $jobList |
|
61 | - ) { |
|
62 | - $this->addressHandler = $addressHandler; |
|
63 | - $this->httpClientService = $httpClientService; |
|
64 | - $this->discoveryService = $discoveryService; |
|
65 | - $this->jobList = $jobList; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * send server-to-server share to remote server |
|
70 | - * |
|
71 | - * @param string $token |
|
72 | - * @param string $shareWith |
|
73 | - * @param string $name |
|
74 | - * @param int $remote_id |
|
75 | - * @param string $owner |
|
76 | - * @param string $ownerFederatedId |
|
77 | - * @param string $sharedBy |
|
78 | - * @param string $sharedByFederatedId |
|
79 | - * @return bool |
|
80 | - * @throws \OC\HintException |
|
81 | - * @throws \OC\ServerNotAvailableException |
|
82 | - */ |
|
83 | - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
84 | - |
|
85 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
86 | - |
|
87 | - if ($user && $remote) { |
|
88 | - $local = $this->addressHandler->generateRemoteURL(); |
|
89 | - |
|
90 | - $fields = array( |
|
91 | - 'shareWith' => $user, |
|
92 | - 'token' => $token, |
|
93 | - 'name' => $name, |
|
94 | - 'remoteId' => $remote_id, |
|
95 | - 'owner' => $owner, |
|
96 | - 'ownerFederatedId' => $ownerFederatedId, |
|
97 | - 'sharedBy' => $sharedBy, |
|
98 | - 'sharedByFederatedId' => $sharedByFederatedId, |
|
99 | - 'remote' => $local, |
|
100 | - ); |
|
101 | - |
|
102 | - $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
103 | - $status = json_decode($result['result'], true); |
|
104 | - |
|
105 | - if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { |
|
106 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
107 | - return true; |
|
108 | - } |
|
109 | - |
|
110 | - } |
|
111 | - |
|
112 | - return false; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * ask owner to re-share the file with the given user |
|
117 | - * |
|
118 | - * @param string $token |
|
119 | - * @param int $id remote Id |
|
120 | - * @param int $shareId internal share Id |
|
121 | - * @param string $remote remote address of the owner |
|
122 | - * @param string $shareWith |
|
123 | - * @param int $permission |
|
124 | - * @return bool |
|
125 | - * @throws \OC\HintException |
|
126 | - * @throws \OC\ServerNotAvailableException |
|
127 | - */ |
|
128 | - public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { |
|
129 | - |
|
130 | - $fields = array( |
|
131 | - 'shareWith' => $shareWith, |
|
132 | - 'token' => $token, |
|
133 | - 'permission' => $permission, |
|
134 | - 'remoteId' => $shareId |
|
135 | - ); |
|
136 | - |
|
137 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
138 | - $status = json_decode($result['result'], true); |
|
139 | - |
|
140 | - $httpRequestSuccessful = $result['success']; |
|
141 | - $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
142 | - $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
143 | - $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
144 | - |
|
145 | - if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
146 | - return [ |
|
147 | - $status['ocs']['data']['token'], |
|
148 | - (int)$status['ocs']['data']['remoteId'] |
|
149 | - ]; |
|
150 | - } |
|
151 | - |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * send server-to-server unshare to remote server |
|
157 | - * |
|
158 | - * @param string $remote url |
|
159 | - * @param int $id share id |
|
160 | - * @param string $token |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function sendRemoteUnShare($remote, $id, $token) { |
|
164 | - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * send server-to-server unshare to remote server |
|
169 | - * |
|
170 | - * @param string $remote url |
|
171 | - * @param int $id share id |
|
172 | - * @param string $token |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function sendRevokeShare($remote, $id, $token) { |
|
176 | - $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * send notification to remote server if the permissions was changed |
|
181 | - * |
|
182 | - * @param string $remote |
|
183 | - * @param int $remoteId |
|
184 | - * @param string $token |
|
185 | - * @param int $permissions |
|
186 | - * @return bool |
|
187 | - */ |
|
188 | - public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
189 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * forward accept reShare to remote server |
|
194 | - * |
|
195 | - * @param string $remote |
|
196 | - * @param int $remoteId |
|
197 | - * @param string $token |
|
198 | - */ |
|
199 | - public function sendAcceptShare($remote, $remoteId, $token) { |
|
200 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * forward decline reShare to remote server |
|
205 | - * |
|
206 | - * @param string $remote |
|
207 | - * @param int $remoteId |
|
208 | - * @param string $token |
|
209 | - */ |
|
210 | - public function sendDeclineShare($remote, $remoteId, $token) { |
|
211 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * inform remote server whether server-to-server share was accepted/declined |
|
216 | - * |
|
217 | - * @param string $remote |
|
218 | - * @param string $token |
|
219 | - * @param int $remoteId Share id on the remote host |
|
220 | - * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
221 | - * @param array $data |
|
222 | - * @param int $try |
|
223 | - * @return boolean |
|
224 | - */ |
|
225 | - public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
226 | - |
|
227 | - $fields = array('token' => $token); |
|
228 | - foreach ($data as $key => $value) { |
|
229 | - $fields[$key] = $value; |
|
230 | - } |
|
231 | - |
|
232 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
233 | - $status = json_decode($result['result'], true); |
|
234 | - |
|
235 | - if ($result['success'] && |
|
236 | - ($status['ocs']['meta']['statuscode'] === 100 || |
|
237 | - $status['ocs']['meta']['statuscode'] === 200 |
|
238 | - ) |
|
239 | - ) { |
|
240 | - return true; |
|
241 | - } elseif ($try === 0) { |
|
242 | - // only add new job on first try |
|
243 | - $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
244 | - [ |
|
245 | - 'remote' => $remote, |
|
246 | - 'remoteId' => $remoteId, |
|
247 | - 'token' => $token, |
|
248 | - 'action' => $action, |
|
249 | - 'data' => json_encode($data), |
|
250 | - 'try' => $try, |
|
251 | - 'lastRun' => $this->getTimestamp() |
|
252 | - ] |
|
253 | - ); |
|
254 | - } |
|
255 | - |
|
256 | - return false; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * return current timestamp |
|
262 | - * |
|
263 | - * @return int |
|
264 | - */ |
|
265 | - protected function getTimestamp() { |
|
266 | - return time(); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * try http post with the given protocol, if no protocol is given we pick |
|
271 | - * the secure one (https) |
|
272 | - * |
|
273 | - * @param string $remoteDomain |
|
274 | - * @param string $urlSuffix |
|
275 | - * @param array $fields post parameters |
|
276 | - * @return array |
|
277 | - * @throws \Exception |
|
278 | - */ |
|
279 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { |
|
280 | - $client = $this->httpClientService->newClient(); |
|
281 | - |
|
282 | - if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
283 | - $remoteDomain = 'https://' . $remoteDomain; |
|
284 | - } |
|
285 | - |
|
286 | - $result = [ |
|
287 | - 'success' => false, |
|
288 | - 'result' => '', |
|
289 | - ]; |
|
290 | - |
|
291 | - $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
292 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
293 | - try { |
|
294 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
295 | - 'body' => $fields, |
|
296 | - 'timeout' => 10, |
|
297 | - 'connect_timeout' => 10, |
|
298 | - ]); |
|
299 | - $result['result'] = $response->getBody(); |
|
300 | - $result['success'] = true; |
|
301 | - } catch (\Exception $e) { |
|
302 | - // if flat re-sharing is not supported by the remote server |
|
303 | - // we re-throw the exception and fall back to the old behaviour. |
|
304 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
305 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
306 | - throw $e; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - return $result; |
|
311 | - } |
|
36 | + const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | + |
|
38 | + /** @var AddressHandler */ |
|
39 | + private $addressHandler; |
|
40 | + |
|
41 | + /** @var IClientService */ |
|
42 | + private $httpClientService; |
|
43 | + |
|
44 | + /** @var IDiscoveryService */ |
|
45 | + private $discoveryService; |
|
46 | + |
|
47 | + /** @var IJobList */ |
|
48 | + private $jobList; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param AddressHandler $addressHandler |
|
52 | + * @param IClientService $httpClientService |
|
53 | + * @param IDiscoveryService $discoveryService |
|
54 | + * @param IJobList $jobList |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + AddressHandler $addressHandler, |
|
58 | + IClientService $httpClientService, |
|
59 | + IDiscoveryService $discoveryService, |
|
60 | + IJobList $jobList |
|
61 | + ) { |
|
62 | + $this->addressHandler = $addressHandler; |
|
63 | + $this->httpClientService = $httpClientService; |
|
64 | + $this->discoveryService = $discoveryService; |
|
65 | + $this->jobList = $jobList; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * send server-to-server share to remote server |
|
70 | + * |
|
71 | + * @param string $token |
|
72 | + * @param string $shareWith |
|
73 | + * @param string $name |
|
74 | + * @param int $remote_id |
|
75 | + * @param string $owner |
|
76 | + * @param string $ownerFederatedId |
|
77 | + * @param string $sharedBy |
|
78 | + * @param string $sharedByFederatedId |
|
79 | + * @return bool |
|
80 | + * @throws \OC\HintException |
|
81 | + * @throws \OC\ServerNotAvailableException |
|
82 | + */ |
|
83 | + public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
84 | + |
|
85 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
86 | + |
|
87 | + if ($user && $remote) { |
|
88 | + $local = $this->addressHandler->generateRemoteURL(); |
|
89 | + |
|
90 | + $fields = array( |
|
91 | + 'shareWith' => $user, |
|
92 | + 'token' => $token, |
|
93 | + 'name' => $name, |
|
94 | + 'remoteId' => $remote_id, |
|
95 | + 'owner' => $owner, |
|
96 | + 'ownerFederatedId' => $ownerFederatedId, |
|
97 | + 'sharedBy' => $sharedBy, |
|
98 | + 'sharedByFederatedId' => $sharedByFederatedId, |
|
99 | + 'remote' => $local, |
|
100 | + ); |
|
101 | + |
|
102 | + $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
103 | + $status = json_decode($result['result'], true); |
|
104 | + |
|
105 | + if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { |
|
106 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
107 | + return true; |
|
108 | + } |
|
109 | + |
|
110 | + } |
|
111 | + |
|
112 | + return false; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * ask owner to re-share the file with the given user |
|
117 | + * |
|
118 | + * @param string $token |
|
119 | + * @param int $id remote Id |
|
120 | + * @param int $shareId internal share Id |
|
121 | + * @param string $remote remote address of the owner |
|
122 | + * @param string $shareWith |
|
123 | + * @param int $permission |
|
124 | + * @return bool |
|
125 | + * @throws \OC\HintException |
|
126 | + * @throws \OC\ServerNotAvailableException |
|
127 | + */ |
|
128 | + public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { |
|
129 | + |
|
130 | + $fields = array( |
|
131 | + 'shareWith' => $shareWith, |
|
132 | + 'token' => $token, |
|
133 | + 'permission' => $permission, |
|
134 | + 'remoteId' => $shareId |
|
135 | + ); |
|
136 | + |
|
137 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
138 | + $status = json_decode($result['result'], true); |
|
139 | + |
|
140 | + $httpRequestSuccessful = $result['success']; |
|
141 | + $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
142 | + $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
143 | + $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
144 | + |
|
145 | + if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
146 | + return [ |
|
147 | + $status['ocs']['data']['token'], |
|
148 | + (int)$status['ocs']['data']['remoteId'] |
|
149 | + ]; |
|
150 | + } |
|
151 | + |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * send server-to-server unshare to remote server |
|
157 | + * |
|
158 | + * @param string $remote url |
|
159 | + * @param int $id share id |
|
160 | + * @param string $token |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function sendRemoteUnShare($remote, $id, $token) { |
|
164 | + $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * send server-to-server unshare to remote server |
|
169 | + * |
|
170 | + * @param string $remote url |
|
171 | + * @param int $id share id |
|
172 | + * @param string $token |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function sendRevokeShare($remote, $id, $token) { |
|
176 | + $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * send notification to remote server if the permissions was changed |
|
181 | + * |
|
182 | + * @param string $remote |
|
183 | + * @param int $remoteId |
|
184 | + * @param string $token |
|
185 | + * @param int $permissions |
|
186 | + * @return bool |
|
187 | + */ |
|
188 | + public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
189 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * forward accept reShare to remote server |
|
194 | + * |
|
195 | + * @param string $remote |
|
196 | + * @param int $remoteId |
|
197 | + * @param string $token |
|
198 | + */ |
|
199 | + public function sendAcceptShare($remote, $remoteId, $token) { |
|
200 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * forward decline reShare to remote server |
|
205 | + * |
|
206 | + * @param string $remote |
|
207 | + * @param int $remoteId |
|
208 | + * @param string $token |
|
209 | + */ |
|
210 | + public function sendDeclineShare($remote, $remoteId, $token) { |
|
211 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * inform remote server whether server-to-server share was accepted/declined |
|
216 | + * |
|
217 | + * @param string $remote |
|
218 | + * @param string $token |
|
219 | + * @param int $remoteId Share id on the remote host |
|
220 | + * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
221 | + * @param array $data |
|
222 | + * @param int $try |
|
223 | + * @return boolean |
|
224 | + */ |
|
225 | + public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
226 | + |
|
227 | + $fields = array('token' => $token); |
|
228 | + foreach ($data as $key => $value) { |
|
229 | + $fields[$key] = $value; |
|
230 | + } |
|
231 | + |
|
232 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
233 | + $status = json_decode($result['result'], true); |
|
234 | + |
|
235 | + if ($result['success'] && |
|
236 | + ($status['ocs']['meta']['statuscode'] === 100 || |
|
237 | + $status['ocs']['meta']['statuscode'] === 200 |
|
238 | + ) |
|
239 | + ) { |
|
240 | + return true; |
|
241 | + } elseif ($try === 0) { |
|
242 | + // only add new job on first try |
|
243 | + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
244 | + [ |
|
245 | + 'remote' => $remote, |
|
246 | + 'remoteId' => $remoteId, |
|
247 | + 'token' => $token, |
|
248 | + 'action' => $action, |
|
249 | + 'data' => json_encode($data), |
|
250 | + 'try' => $try, |
|
251 | + 'lastRun' => $this->getTimestamp() |
|
252 | + ] |
|
253 | + ); |
|
254 | + } |
|
255 | + |
|
256 | + return false; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * return current timestamp |
|
262 | + * |
|
263 | + * @return int |
|
264 | + */ |
|
265 | + protected function getTimestamp() { |
|
266 | + return time(); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * try http post with the given protocol, if no protocol is given we pick |
|
271 | + * the secure one (https) |
|
272 | + * |
|
273 | + * @param string $remoteDomain |
|
274 | + * @param string $urlSuffix |
|
275 | + * @param array $fields post parameters |
|
276 | + * @return array |
|
277 | + * @throws \Exception |
|
278 | + */ |
|
279 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { |
|
280 | + $client = $this->httpClientService->newClient(); |
|
281 | + |
|
282 | + if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
283 | + $remoteDomain = 'https://' . $remoteDomain; |
|
284 | + } |
|
285 | + |
|
286 | + $result = [ |
|
287 | + 'success' => false, |
|
288 | + 'result' => '', |
|
289 | + ]; |
|
290 | + |
|
291 | + $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
292 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
293 | + try { |
|
294 | + $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
295 | + 'body' => $fields, |
|
296 | + 'timeout' => 10, |
|
297 | + 'connect_timeout' => 10, |
|
298 | + ]); |
|
299 | + $result['result'] = $response->getBody(); |
|
300 | + $result['success'] = true; |
|
301 | + } catch (\Exception $e) { |
|
302 | + // if flat re-sharing is not supported by the remote server |
|
303 | + // we re-throw the exception and fall back to the old behaviour. |
|
304 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
305 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
306 | + throw $e; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + return $result; |
|
311 | + } |
|
312 | 312 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'remoteId' => $shareId |
135 | 135 | ); |
136 | 136 | |
137 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
137 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$id.'/reshare', $fields); |
|
138 | 138 | $status = json_decode($result['result'], true); |
139 | 139 | |
140 | 140 | $httpRequestSuccessful = $result['success']; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
146 | 146 | return [ |
147 | 147 | $status['ocs']['data']['token'], |
148 | - (int)$status['ocs']['data']['remoteId'] |
|
148 | + (int) $status['ocs']['data']['remoteId'] |
|
149 | 149 | ]; |
150 | 150 | } |
151 | 151 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $fields[$key] = $value; |
230 | 230 | } |
231 | 231 | |
232 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
232 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$remoteId.'/'.$action, $fields); |
|
233 | 233 | $status = json_decode($result['result'], true); |
234 | 234 | |
235 | 235 | if ($result['success'] && |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $client = $this->httpClientService->newClient(); |
281 | 281 | |
282 | 282 | if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
283 | - $remoteDomain = 'https://' . $remoteDomain; |
|
283 | + $remoteDomain = 'https://'.$remoteDomain; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | $result = [ |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
292 | 292 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
293 | 293 | try { |
294 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
294 | + $response = $client->post($remoteDomain.$endpoint.$urlSuffix.'?format='.self::RESPONSE_FORMAT, [ |
|
295 | 295 | 'body' => $fields, |
296 | 296 | 'timeout' => 10, |
297 | 297 | 'connect_timeout' => 10, |
@@ -31,31 +31,31 @@ |
||
31 | 31 | |
32 | 32 | class Hooks { |
33 | 33 | |
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->getOCSDiscoveryService(), |
|
42 | - $params['uid']); |
|
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->getOCSDiscoveryService(), |
|
42 | + $params['uid']); |
|
43 | 43 | |
44 | - $manager->removeUserShares($params['uid']); |
|
45 | - } |
|
44 | + $manager->removeUserShares($params['uid']); |
|
45 | + } |
|
46 | 46 | |
47 | - public static function unshareChildren($params) { |
|
48 | - $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
49 | - $view = new \OC\Files\View('/'); |
|
47 | + public static function unshareChildren($params) { |
|
48 | + $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
49 | + $view = new \OC\Files\View('/'); |
|
50 | 50 | |
51 | - // find share mount points within $path and unmount them |
|
52 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
53 | - $mountedShares = $mountManager->findIn($path); |
|
54 | - foreach ($mountedShares as $mount) { |
|
55 | - if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
56 | - $mountPoint = $mount->getMountPoint(); |
|
57 | - $view->unlink($mountPoint); |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
51 | + // find share mount points within $path and unmount them |
|
52 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
53 | + $mountedShares = $mountManager->findIn($path); |
|
54 | + foreach ($mountedShares as $mount) { |
|
55 | + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
56 | + $mountPoint = $mount->getMountPoint(); |
|
57 | + $view->unlink($mountPoint); |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | 61 | } |
@@ -56,485 +56,485 @@ |
||
56 | 56 | */ |
57 | 57 | interface IServerContainer extends IContainer { |
58 | 58 | |
59 | - /** |
|
60 | - * The contacts manager will act as a broker between consumers for contacts information and |
|
61 | - * providers which actual deliver the contact information. |
|
62 | - * |
|
63 | - * @return \OCP\Contacts\IManager |
|
64 | - * @since 6.0.0 |
|
65 | - */ |
|
66 | - public function getContactsManager(); |
|
67 | - |
|
68 | - /** |
|
69 | - * The current request object holding all information about the request currently being processed |
|
70 | - * is returned from this method. |
|
71 | - * In case the current execution was not initiated by a web request null is returned |
|
72 | - * |
|
73 | - * @return \OCP\IRequest |
|
74 | - * @since 6.0.0 |
|
75 | - */ |
|
76 | - public function getRequest(); |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns the preview manager which can create preview images for a given file |
|
80 | - * |
|
81 | - * @return \OCP\IPreview |
|
82 | - * @since 6.0.0 |
|
83 | - */ |
|
84 | - public function getPreviewManager(); |
|
85 | - |
|
86 | - /** |
|
87 | - * Returns the tag manager which can get and set tags for different object types |
|
88 | - * |
|
89 | - * @see \OCP\ITagManager::load() |
|
90 | - * @return \OCP\ITagManager |
|
91 | - * @since 6.0.0 |
|
92 | - */ |
|
93 | - public function getTagManager(); |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns the root folder of ownCloud's data directory |
|
97 | - * |
|
98 | - * @return \OCP\Files\IRootFolder |
|
99 | - * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
100 | - */ |
|
101 | - public function getRootFolder(); |
|
102 | - |
|
103 | - /** |
|
104 | - * Returns a view to ownCloud's files folder |
|
105 | - * |
|
106 | - * @param string $userId user ID |
|
107 | - * @return \OCP\Files\Folder |
|
108 | - * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
109 | - * @see getUserFolder in \OCP\Files\IRootFolder |
|
110 | - */ |
|
111 | - public function getUserFolder($userId = null); |
|
112 | - |
|
113 | - /** |
|
114 | - * Returns an app-specific view in ownClouds data directory |
|
115 | - * |
|
116 | - * @return \OCP\Files\Folder |
|
117 | - * @since 6.0.0 |
|
118 | - * @deprecated since 9.2.0 use IAppData |
|
119 | - */ |
|
120 | - public function getAppFolder(); |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns a user manager |
|
124 | - * |
|
125 | - * @return \OCP\IUserManager |
|
126 | - * @since 8.0.0 |
|
127 | - */ |
|
128 | - public function getUserManager(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Returns a group manager |
|
132 | - * |
|
133 | - * @return \OCP\IGroupManager |
|
134 | - * @since 8.0.0 |
|
135 | - */ |
|
136 | - public function getGroupManager(); |
|
137 | - |
|
138 | - /** |
|
139 | - * Returns the user session |
|
140 | - * |
|
141 | - * @return \OCP\IUserSession |
|
142 | - * @since 6.0.0 |
|
143 | - */ |
|
144 | - public function getUserSession(); |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns the navigation manager |
|
148 | - * |
|
149 | - * @return \OCP\INavigationManager |
|
150 | - * @since 6.0.0 |
|
151 | - */ |
|
152 | - public function getNavigationManager(); |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the config manager |
|
156 | - * |
|
157 | - * @return \OCP\IConfig |
|
158 | - * @since 6.0.0 |
|
159 | - */ |
|
160 | - public function getConfig(); |
|
161 | - |
|
162 | - /** |
|
163 | - * Returns a Crypto instance |
|
164 | - * |
|
165 | - * @return \OCP\Security\ICrypto |
|
166 | - * @since 8.0.0 |
|
167 | - */ |
|
168 | - public function getCrypto(); |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns a Hasher instance |
|
172 | - * |
|
173 | - * @return \OCP\Security\IHasher |
|
174 | - * @since 8.0.0 |
|
175 | - */ |
|
176 | - public function getHasher(); |
|
177 | - |
|
178 | - /** |
|
179 | - * Returns a SecureRandom instance |
|
180 | - * |
|
181 | - * @return \OCP\Security\ISecureRandom |
|
182 | - * @since 8.1.0 |
|
183 | - */ |
|
184 | - public function getSecureRandom(); |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns a CredentialsManager instance |
|
188 | - * |
|
189 | - * @return \OCP\Security\ICredentialsManager |
|
190 | - * @since 9.0.0 |
|
191 | - */ |
|
192 | - public function getCredentialsManager(); |
|
193 | - |
|
194 | - /** |
|
195 | - * Returns the app config manager |
|
196 | - * |
|
197 | - * @return \OCP\IAppConfig |
|
198 | - * @since 7.0.0 |
|
199 | - */ |
|
200 | - public function getAppConfig(); |
|
201 | - |
|
202 | - /** |
|
203 | - * @return \OCP\L10N\IFactory |
|
204 | - * @since 8.2.0 |
|
205 | - */ |
|
206 | - public function getL10NFactory(); |
|
207 | - |
|
208 | - /** |
|
209 | - * get an L10N instance |
|
210 | - * @param string $app appid |
|
211 | - * @param string $lang |
|
212 | - * @return \OCP\IL10N |
|
213 | - * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
214 | - */ |
|
215 | - public function getL10N($app, $lang = null); |
|
216 | - |
|
217 | - /** |
|
218 | - * @return \OC\Encryption\Manager |
|
219 | - * @since 8.1.0 |
|
220 | - */ |
|
221 | - public function getEncryptionManager(); |
|
222 | - |
|
223 | - /** |
|
224 | - * @return \OC\Encryption\File |
|
225 | - * @since 8.1.0 |
|
226 | - */ |
|
227 | - public function getEncryptionFilesHelper(); |
|
228 | - |
|
229 | - /** |
|
230 | - * @return \OCP\Encryption\Keys\IStorage |
|
231 | - * @since 8.1.0 |
|
232 | - */ |
|
233 | - public function getEncryptionKeyStorage(); |
|
234 | - |
|
235 | - /** |
|
236 | - * Returns the URL generator |
|
237 | - * |
|
238 | - * @return \OCP\IURLGenerator |
|
239 | - * @since 6.0.0 |
|
240 | - */ |
|
241 | - public function getURLGenerator(); |
|
242 | - |
|
243 | - /** |
|
244 | - * Returns the Helper |
|
245 | - * |
|
246 | - * @return \OCP\IHelper |
|
247 | - * @since 6.0.0 |
|
248 | - */ |
|
249 | - public function getHelper(); |
|
250 | - |
|
251 | - /** |
|
252 | - * Returns an ICache instance |
|
253 | - * |
|
254 | - * @return \OCP\ICache |
|
255 | - * @since 6.0.0 |
|
256 | - */ |
|
257 | - public function getCache(); |
|
258 | - |
|
259 | - /** |
|
260 | - * Returns an \OCP\CacheFactory instance |
|
261 | - * |
|
262 | - * @return \OCP\ICacheFactory |
|
263 | - * @since 7.0.0 |
|
264 | - */ |
|
265 | - public function getMemCacheFactory(); |
|
266 | - |
|
267 | - /** |
|
268 | - * Returns the current session |
|
269 | - * |
|
270 | - * @return \OCP\ISession |
|
271 | - * @since 6.0.0 |
|
272 | - */ |
|
273 | - public function getSession(); |
|
274 | - |
|
275 | - /** |
|
276 | - * Returns the activity manager |
|
277 | - * |
|
278 | - * @return \OCP\Activity\IManager |
|
279 | - * @since 6.0.0 |
|
280 | - */ |
|
281 | - public function getActivityManager(); |
|
282 | - |
|
283 | - /** |
|
284 | - * Returns the current session |
|
285 | - * |
|
286 | - * @return \OCP\IDBConnection |
|
287 | - * @since 6.0.0 |
|
288 | - */ |
|
289 | - public function getDatabaseConnection(); |
|
290 | - |
|
291 | - /** |
|
292 | - * Returns an avatar manager, used for avatar functionality |
|
293 | - * |
|
294 | - * @return \OCP\IAvatarManager |
|
295 | - * @since 6.0.0 |
|
296 | - */ |
|
297 | - public function getAvatarManager(); |
|
298 | - |
|
299 | - /** |
|
300 | - * Returns an job list for controlling background jobs |
|
301 | - * |
|
302 | - * @return \OCP\BackgroundJob\IJobList |
|
303 | - * @since 7.0.0 |
|
304 | - */ |
|
305 | - public function getJobList(); |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns a logger instance |
|
309 | - * |
|
310 | - * @return \OCP\ILogger |
|
311 | - * @since 8.0.0 |
|
312 | - */ |
|
313 | - public function getLogger(); |
|
314 | - |
|
315 | - /** |
|
316 | - * Returns a router for generating and matching urls |
|
317 | - * |
|
318 | - * @return \OCP\Route\IRouter |
|
319 | - * @since 7.0.0 |
|
320 | - */ |
|
321 | - public function getRouter(); |
|
322 | - |
|
323 | - /** |
|
324 | - * Returns a search instance |
|
325 | - * |
|
326 | - * @return \OCP\ISearch |
|
327 | - * @since 7.0.0 |
|
328 | - */ |
|
329 | - public function getSearch(); |
|
330 | - |
|
331 | - /** |
|
332 | - * Get the certificate manager for the user |
|
333 | - * |
|
334 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
335 | - * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
336 | - * @since 8.0.0 |
|
337 | - */ |
|
338 | - public function getCertificateManager($userId = null); |
|
339 | - |
|
340 | - /** |
|
341 | - * Create a new event source |
|
342 | - * |
|
343 | - * @return \OCP\IEventSource |
|
344 | - * @since 8.0.0 |
|
345 | - */ |
|
346 | - public function createEventSource(); |
|
347 | - |
|
348 | - /** |
|
349 | - * Returns an instance of the HTTP helper class |
|
350 | - * @return \OC\HTTPHelper |
|
351 | - * @deprecated 8.1.0 Use \OCP\Http\Client\IClientService |
|
352 | - * @since 8.0.0 |
|
353 | - */ |
|
354 | - public function getHTTPHelper(); |
|
355 | - |
|
356 | - /** |
|
357 | - * Returns an instance of the HTTP client service |
|
358 | - * |
|
359 | - * @return \OCP\Http\Client\IClientService |
|
360 | - * @since 8.1.0 |
|
361 | - */ |
|
362 | - public function getHTTPClientService(); |
|
363 | - |
|
364 | - /** |
|
365 | - * Get the active event logger |
|
366 | - * |
|
367 | - * @return \OCP\Diagnostics\IEventLogger |
|
368 | - * @since 8.0.0 |
|
369 | - */ |
|
370 | - public function getEventLogger(); |
|
371 | - |
|
372 | - /** |
|
373 | - * Get the active query logger |
|
374 | - * |
|
375 | - * The returned logger only logs data when debug mode is enabled |
|
376 | - * |
|
377 | - * @return \OCP\Diagnostics\IQueryLogger |
|
378 | - * @since 8.0.0 |
|
379 | - */ |
|
380 | - public function getQueryLogger(); |
|
381 | - |
|
382 | - /** |
|
383 | - * Get the manager for temporary files and folders |
|
384 | - * |
|
385 | - * @return \OCP\ITempManager |
|
386 | - * @since 8.0.0 |
|
387 | - */ |
|
388 | - public function getTempManager(); |
|
389 | - |
|
390 | - /** |
|
391 | - * Get the app manager |
|
392 | - * |
|
393 | - * @return \OCP\App\IAppManager |
|
394 | - * @since 8.0.0 |
|
395 | - */ |
|
396 | - public function getAppManager(); |
|
397 | - |
|
398 | - /** |
|
399 | - * Get the webroot |
|
400 | - * |
|
401 | - * @return string |
|
402 | - * @since 8.0.0 |
|
403 | - */ |
|
404 | - public function getWebRoot(); |
|
405 | - |
|
406 | - /** |
|
407 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
408 | - * @since 8.0.0 |
|
409 | - */ |
|
410 | - public function getMountProviderCollection(); |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the IniWrapper |
|
414 | - * |
|
415 | - * @return \bantu\IniGetWrapper\IniGetWrapper |
|
416 | - * @since 8.0.0 |
|
417 | - */ |
|
418 | - public function getIniWrapper(); |
|
419 | - /** |
|
420 | - * @return \OCP\Command\IBus |
|
421 | - * @since 8.1.0 |
|
422 | - */ |
|
423 | - public function getCommandBus(); |
|
424 | - |
|
425 | - /** |
|
426 | - * Creates a new mailer |
|
427 | - * |
|
428 | - * @return \OCP\Mail\IMailer |
|
429 | - * @since 8.1.0 |
|
430 | - */ |
|
431 | - public function getMailer(); |
|
432 | - |
|
433 | - /** |
|
434 | - * Get the locking provider |
|
435 | - * |
|
436 | - * @return \OCP\Lock\ILockingProvider |
|
437 | - * @since 8.1.0 |
|
438 | - */ |
|
439 | - public function getLockingProvider(); |
|
440 | - |
|
441 | - /** |
|
442 | - * @return \OCP\Files\Mount\IMountManager |
|
443 | - * @since 8.2.0 |
|
444 | - */ |
|
445 | - public function getMountManager(); |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the MimeTypeDetector |
|
449 | - * |
|
450 | - * @return \OCP\Files\IMimeTypeDetector |
|
451 | - * @since 8.2.0 |
|
452 | - */ |
|
453 | - public function getMimeTypeDetector(); |
|
454 | - |
|
455 | - /** |
|
456 | - * Get the MimeTypeLoader |
|
457 | - * |
|
458 | - * @return \OCP\Files\IMimeTypeLoader |
|
459 | - * @since 8.2.0 |
|
460 | - */ |
|
461 | - public function getMimeTypeLoader(); |
|
462 | - |
|
463 | - /** |
|
464 | - * Get the EventDispatcher |
|
465 | - * |
|
466 | - * @return EventDispatcherInterface |
|
467 | - * @since 8.2.0 |
|
468 | - */ |
|
469 | - public function getEventDispatcher(); |
|
470 | - |
|
471 | - /** |
|
472 | - * Get the Notification Manager |
|
473 | - * |
|
474 | - * @return \OCP\Notification\IManager |
|
475 | - * @since 9.0.0 |
|
476 | - */ |
|
477 | - public function getNotificationManager(); |
|
478 | - |
|
479 | - /** |
|
480 | - * @return \OCP\Comments\ICommentsManager |
|
481 | - * @since 9.0.0 |
|
482 | - */ |
|
483 | - public function getCommentsManager(); |
|
484 | - |
|
485 | - /** |
|
486 | - * Returns the system-tag manager |
|
487 | - * |
|
488 | - * @return \OCP\SystemTag\ISystemTagManager |
|
489 | - * |
|
490 | - * @since 9.0.0 |
|
491 | - */ |
|
492 | - public function getSystemTagManager(); |
|
493 | - |
|
494 | - /** |
|
495 | - * Returns the system-tag object mapper |
|
496 | - * |
|
497 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
498 | - * |
|
499 | - * @since 9.0.0 |
|
500 | - */ |
|
501 | - public function getSystemTagObjectMapper(); |
|
502 | - |
|
503 | - /** |
|
504 | - * Returns the share manager |
|
505 | - * |
|
506 | - * @return \OCP\Share\IManager |
|
507 | - * @since 9.0.0 |
|
508 | - */ |
|
509 | - public function getShareManager(); |
|
510 | - |
|
511 | - /** |
|
512 | - * @return IContentSecurityPolicyManager |
|
513 | - * @since 9.0.0 |
|
514 | - */ |
|
515 | - public function getContentSecurityPolicyManager(); |
|
516 | - |
|
517 | - /** |
|
518 | - * @return \OCP\IDateTimeZone |
|
519 | - * @since 8.0.0 |
|
520 | - */ |
|
521 | - public function getDateTimeZone(); |
|
522 | - |
|
523 | - /** |
|
524 | - * @return \OCP\IDateTimeFormatter |
|
525 | - * @since 8.0.0 |
|
526 | - */ |
|
527 | - public function getDateTimeFormatter(); |
|
528 | - |
|
529 | - /** |
|
530 | - * @return \OCP\Federation\ICloudIdManager |
|
531 | - * @since 12.0.0 |
|
532 | - */ |
|
533 | - public function getCloudIdManager(); |
|
534 | - |
|
535 | - /** |
|
536 | - * @return \OC\OCS\DiscoveryService |
|
537 | - * @since 12.0.0 |
|
538 | - */ |
|
539 | - public function getOCSDiscoveryService(); |
|
59 | + /** |
|
60 | + * The contacts manager will act as a broker between consumers for contacts information and |
|
61 | + * providers which actual deliver the contact information. |
|
62 | + * |
|
63 | + * @return \OCP\Contacts\IManager |
|
64 | + * @since 6.0.0 |
|
65 | + */ |
|
66 | + public function getContactsManager(); |
|
67 | + |
|
68 | + /** |
|
69 | + * The current request object holding all information about the request currently being processed |
|
70 | + * is returned from this method. |
|
71 | + * In case the current execution was not initiated by a web request null is returned |
|
72 | + * |
|
73 | + * @return \OCP\IRequest |
|
74 | + * @since 6.0.0 |
|
75 | + */ |
|
76 | + public function getRequest(); |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns the preview manager which can create preview images for a given file |
|
80 | + * |
|
81 | + * @return \OCP\IPreview |
|
82 | + * @since 6.0.0 |
|
83 | + */ |
|
84 | + public function getPreviewManager(); |
|
85 | + |
|
86 | + /** |
|
87 | + * Returns the tag manager which can get and set tags for different object types |
|
88 | + * |
|
89 | + * @see \OCP\ITagManager::load() |
|
90 | + * @return \OCP\ITagManager |
|
91 | + * @since 6.0.0 |
|
92 | + */ |
|
93 | + public function getTagManager(); |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns the root folder of ownCloud's data directory |
|
97 | + * |
|
98 | + * @return \OCP\Files\IRootFolder |
|
99 | + * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
100 | + */ |
|
101 | + public function getRootFolder(); |
|
102 | + |
|
103 | + /** |
|
104 | + * Returns a view to ownCloud's files folder |
|
105 | + * |
|
106 | + * @param string $userId user ID |
|
107 | + * @return \OCP\Files\Folder |
|
108 | + * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
109 | + * @see getUserFolder in \OCP\Files\IRootFolder |
|
110 | + */ |
|
111 | + public function getUserFolder($userId = null); |
|
112 | + |
|
113 | + /** |
|
114 | + * Returns an app-specific view in ownClouds data directory |
|
115 | + * |
|
116 | + * @return \OCP\Files\Folder |
|
117 | + * @since 6.0.0 |
|
118 | + * @deprecated since 9.2.0 use IAppData |
|
119 | + */ |
|
120 | + public function getAppFolder(); |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns a user manager |
|
124 | + * |
|
125 | + * @return \OCP\IUserManager |
|
126 | + * @since 8.0.0 |
|
127 | + */ |
|
128 | + public function getUserManager(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Returns a group manager |
|
132 | + * |
|
133 | + * @return \OCP\IGroupManager |
|
134 | + * @since 8.0.0 |
|
135 | + */ |
|
136 | + public function getGroupManager(); |
|
137 | + |
|
138 | + /** |
|
139 | + * Returns the user session |
|
140 | + * |
|
141 | + * @return \OCP\IUserSession |
|
142 | + * @since 6.0.0 |
|
143 | + */ |
|
144 | + public function getUserSession(); |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns the navigation manager |
|
148 | + * |
|
149 | + * @return \OCP\INavigationManager |
|
150 | + * @since 6.0.0 |
|
151 | + */ |
|
152 | + public function getNavigationManager(); |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the config manager |
|
156 | + * |
|
157 | + * @return \OCP\IConfig |
|
158 | + * @since 6.0.0 |
|
159 | + */ |
|
160 | + public function getConfig(); |
|
161 | + |
|
162 | + /** |
|
163 | + * Returns a Crypto instance |
|
164 | + * |
|
165 | + * @return \OCP\Security\ICrypto |
|
166 | + * @since 8.0.0 |
|
167 | + */ |
|
168 | + public function getCrypto(); |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns a Hasher instance |
|
172 | + * |
|
173 | + * @return \OCP\Security\IHasher |
|
174 | + * @since 8.0.0 |
|
175 | + */ |
|
176 | + public function getHasher(); |
|
177 | + |
|
178 | + /** |
|
179 | + * Returns a SecureRandom instance |
|
180 | + * |
|
181 | + * @return \OCP\Security\ISecureRandom |
|
182 | + * @since 8.1.0 |
|
183 | + */ |
|
184 | + public function getSecureRandom(); |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns a CredentialsManager instance |
|
188 | + * |
|
189 | + * @return \OCP\Security\ICredentialsManager |
|
190 | + * @since 9.0.0 |
|
191 | + */ |
|
192 | + public function getCredentialsManager(); |
|
193 | + |
|
194 | + /** |
|
195 | + * Returns the app config manager |
|
196 | + * |
|
197 | + * @return \OCP\IAppConfig |
|
198 | + * @since 7.0.0 |
|
199 | + */ |
|
200 | + public function getAppConfig(); |
|
201 | + |
|
202 | + /** |
|
203 | + * @return \OCP\L10N\IFactory |
|
204 | + * @since 8.2.0 |
|
205 | + */ |
|
206 | + public function getL10NFactory(); |
|
207 | + |
|
208 | + /** |
|
209 | + * get an L10N instance |
|
210 | + * @param string $app appid |
|
211 | + * @param string $lang |
|
212 | + * @return \OCP\IL10N |
|
213 | + * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
214 | + */ |
|
215 | + public function getL10N($app, $lang = null); |
|
216 | + |
|
217 | + /** |
|
218 | + * @return \OC\Encryption\Manager |
|
219 | + * @since 8.1.0 |
|
220 | + */ |
|
221 | + public function getEncryptionManager(); |
|
222 | + |
|
223 | + /** |
|
224 | + * @return \OC\Encryption\File |
|
225 | + * @since 8.1.0 |
|
226 | + */ |
|
227 | + public function getEncryptionFilesHelper(); |
|
228 | + |
|
229 | + /** |
|
230 | + * @return \OCP\Encryption\Keys\IStorage |
|
231 | + * @since 8.1.0 |
|
232 | + */ |
|
233 | + public function getEncryptionKeyStorage(); |
|
234 | + |
|
235 | + /** |
|
236 | + * Returns the URL generator |
|
237 | + * |
|
238 | + * @return \OCP\IURLGenerator |
|
239 | + * @since 6.0.0 |
|
240 | + */ |
|
241 | + public function getURLGenerator(); |
|
242 | + |
|
243 | + /** |
|
244 | + * Returns the Helper |
|
245 | + * |
|
246 | + * @return \OCP\IHelper |
|
247 | + * @since 6.0.0 |
|
248 | + */ |
|
249 | + public function getHelper(); |
|
250 | + |
|
251 | + /** |
|
252 | + * Returns an ICache instance |
|
253 | + * |
|
254 | + * @return \OCP\ICache |
|
255 | + * @since 6.0.0 |
|
256 | + */ |
|
257 | + public function getCache(); |
|
258 | + |
|
259 | + /** |
|
260 | + * Returns an \OCP\CacheFactory instance |
|
261 | + * |
|
262 | + * @return \OCP\ICacheFactory |
|
263 | + * @since 7.0.0 |
|
264 | + */ |
|
265 | + public function getMemCacheFactory(); |
|
266 | + |
|
267 | + /** |
|
268 | + * Returns the current session |
|
269 | + * |
|
270 | + * @return \OCP\ISession |
|
271 | + * @since 6.0.0 |
|
272 | + */ |
|
273 | + public function getSession(); |
|
274 | + |
|
275 | + /** |
|
276 | + * Returns the activity manager |
|
277 | + * |
|
278 | + * @return \OCP\Activity\IManager |
|
279 | + * @since 6.0.0 |
|
280 | + */ |
|
281 | + public function getActivityManager(); |
|
282 | + |
|
283 | + /** |
|
284 | + * Returns the current session |
|
285 | + * |
|
286 | + * @return \OCP\IDBConnection |
|
287 | + * @since 6.0.0 |
|
288 | + */ |
|
289 | + public function getDatabaseConnection(); |
|
290 | + |
|
291 | + /** |
|
292 | + * Returns an avatar manager, used for avatar functionality |
|
293 | + * |
|
294 | + * @return \OCP\IAvatarManager |
|
295 | + * @since 6.0.0 |
|
296 | + */ |
|
297 | + public function getAvatarManager(); |
|
298 | + |
|
299 | + /** |
|
300 | + * Returns an job list for controlling background jobs |
|
301 | + * |
|
302 | + * @return \OCP\BackgroundJob\IJobList |
|
303 | + * @since 7.0.0 |
|
304 | + */ |
|
305 | + public function getJobList(); |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns a logger instance |
|
309 | + * |
|
310 | + * @return \OCP\ILogger |
|
311 | + * @since 8.0.0 |
|
312 | + */ |
|
313 | + public function getLogger(); |
|
314 | + |
|
315 | + /** |
|
316 | + * Returns a router for generating and matching urls |
|
317 | + * |
|
318 | + * @return \OCP\Route\IRouter |
|
319 | + * @since 7.0.0 |
|
320 | + */ |
|
321 | + public function getRouter(); |
|
322 | + |
|
323 | + /** |
|
324 | + * Returns a search instance |
|
325 | + * |
|
326 | + * @return \OCP\ISearch |
|
327 | + * @since 7.0.0 |
|
328 | + */ |
|
329 | + public function getSearch(); |
|
330 | + |
|
331 | + /** |
|
332 | + * Get the certificate manager for the user |
|
333 | + * |
|
334 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
335 | + * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
336 | + * @since 8.0.0 |
|
337 | + */ |
|
338 | + public function getCertificateManager($userId = null); |
|
339 | + |
|
340 | + /** |
|
341 | + * Create a new event source |
|
342 | + * |
|
343 | + * @return \OCP\IEventSource |
|
344 | + * @since 8.0.0 |
|
345 | + */ |
|
346 | + public function createEventSource(); |
|
347 | + |
|
348 | + /** |
|
349 | + * Returns an instance of the HTTP helper class |
|
350 | + * @return \OC\HTTPHelper |
|
351 | + * @deprecated 8.1.0 Use \OCP\Http\Client\IClientService |
|
352 | + * @since 8.0.0 |
|
353 | + */ |
|
354 | + public function getHTTPHelper(); |
|
355 | + |
|
356 | + /** |
|
357 | + * Returns an instance of the HTTP client service |
|
358 | + * |
|
359 | + * @return \OCP\Http\Client\IClientService |
|
360 | + * @since 8.1.0 |
|
361 | + */ |
|
362 | + public function getHTTPClientService(); |
|
363 | + |
|
364 | + /** |
|
365 | + * Get the active event logger |
|
366 | + * |
|
367 | + * @return \OCP\Diagnostics\IEventLogger |
|
368 | + * @since 8.0.0 |
|
369 | + */ |
|
370 | + public function getEventLogger(); |
|
371 | + |
|
372 | + /** |
|
373 | + * Get the active query logger |
|
374 | + * |
|
375 | + * The returned logger only logs data when debug mode is enabled |
|
376 | + * |
|
377 | + * @return \OCP\Diagnostics\IQueryLogger |
|
378 | + * @since 8.0.0 |
|
379 | + */ |
|
380 | + public function getQueryLogger(); |
|
381 | + |
|
382 | + /** |
|
383 | + * Get the manager for temporary files and folders |
|
384 | + * |
|
385 | + * @return \OCP\ITempManager |
|
386 | + * @since 8.0.0 |
|
387 | + */ |
|
388 | + public function getTempManager(); |
|
389 | + |
|
390 | + /** |
|
391 | + * Get the app manager |
|
392 | + * |
|
393 | + * @return \OCP\App\IAppManager |
|
394 | + * @since 8.0.0 |
|
395 | + */ |
|
396 | + public function getAppManager(); |
|
397 | + |
|
398 | + /** |
|
399 | + * Get the webroot |
|
400 | + * |
|
401 | + * @return string |
|
402 | + * @since 8.0.0 |
|
403 | + */ |
|
404 | + public function getWebRoot(); |
|
405 | + |
|
406 | + /** |
|
407 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
408 | + * @since 8.0.0 |
|
409 | + */ |
|
410 | + public function getMountProviderCollection(); |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the IniWrapper |
|
414 | + * |
|
415 | + * @return \bantu\IniGetWrapper\IniGetWrapper |
|
416 | + * @since 8.0.0 |
|
417 | + */ |
|
418 | + public function getIniWrapper(); |
|
419 | + /** |
|
420 | + * @return \OCP\Command\IBus |
|
421 | + * @since 8.1.0 |
|
422 | + */ |
|
423 | + public function getCommandBus(); |
|
424 | + |
|
425 | + /** |
|
426 | + * Creates a new mailer |
|
427 | + * |
|
428 | + * @return \OCP\Mail\IMailer |
|
429 | + * @since 8.1.0 |
|
430 | + */ |
|
431 | + public function getMailer(); |
|
432 | + |
|
433 | + /** |
|
434 | + * Get the locking provider |
|
435 | + * |
|
436 | + * @return \OCP\Lock\ILockingProvider |
|
437 | + * @since 8.1.0 |
|
438 | + */ |
|
439 | + public function getLockingProvider(); |
|
440 | + |
|
441 | + /** |
|
442 | + * @return \OCP\Files\Mount\IMountManager |
|
443 | + * @since 8.2.0 |
|
444 | + */ |
|
445 | + public function getMountManager(); |
|
446 | + |
|
447 | + /** |
|
448 | + * Get the MimeTypeDetector |
|
449 | + * |
|
450 | + * @return \OCP\Files\IMimeTypeDetector |
|
451 | + * @since 8.2.0 |
|
452 | + */ |
|
453 | + public function getMimeTypeDetector(); |
|
454 | + |
|
455 | + /** |
|
456 | + * Get the MimeTypeLoader |
|
457 | + * |
|
458 | + * @return \OCP\Files\IMimeTypeLoader |
|
459 | + * @since 8.2.0 |
|
460 | + */ |
|
461 | + public function getMimeTypeLoader(); |
|
462 | + |
|
463 | + /** |
|
464 | + * Get the EventDispatcher |
|
465 | + * |
|
466 | + * @return EventDispatcherInterface |
|
467 | + * @since 8.2.0 |
|
468 | + */ |
|
469 | + public function getEventDispatcher(); |
|
470 | + |
|
471 | + /** |
|
472 | + * Get the Notification Manager |
|
473 | + * |
|
474 | + * @return \OCP\Notification\IManager |
|
475 | + * @since 9.0.0 |
|
476 | + */ |
|
477 | + public function getNotificationManager(); |
|
478 | + |
|
479 | + /** |
|
480 | + * @return \OCP\Comments\ICommentsManager |
|
481 | + * @since 9.0.0 |
|
482 | + */ |
|
483 | + public function getCommentsManager(); |
|
484 | + |
|
485 | + /** |
|
486 | + * Returns the system-tag manager |
|
487 | + * |
|
488 | + * @return \OCP\SystemTag\ISystemTagManager |
|
489 | + * |
|
490 | + * @since 9.0.0 |
|
491 | + */ |
|
492 | + public function getSystemTagManager(); |
|
493 | + |
|
494 | + /** |
|
495 | + * Returns the system-tag object mapper |
|
496 | + * |
|
497 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
498 | + * |
|
499 | + * @since 9.0.0 |
|
500 | + */ |
|
501 | + public function getSystemTagObjectMapper(); |
|
502 | + |
|
503 | + /** |
|
504 | + * Returns the share manager |
|
505 | + * |
|
506 | + * @return \OCP\Share\IManager |
|
507 | + * @since 9.0.0 |
|
508 | + */ |
|
509 | + public function getShareManager(); |
|
510 | + |
|
511 | + /** |
|
512 | + * @return IContentSecurityPolicyManager |
|
513 | + * @since 9.0.0 |
|
514 | + */ |
|
515 | + public function getContentSecurityPolicyManager(); |
|
516 | + |
|
517 | + /** |
|
518 | + * @return \OCP\IDateTimeZone |
|
519 | + * @since 8.0.0 |
|
520 | + */ |
|
521 | + public function getDateTimeZone(); |
|
522 | + |
|
523 | + /** |
|
524 | + * @return \OCP\IDateTimeFormatter |
|
525 | + * @since 8.0.0 |
|
526 | + */ |
|
527 | + public function getDateTimeFormatter(); |
|
528 | + |
|
529 | + /** |
|
530 | + * @return \OCP\Federation\ICloudIdManager |
|
531 | + * @since 12.0.0 |
|
532 | + */ |
|
533 | + public function getCloudIdManager(); |
|
534 | + |
|
535 | + /** |
|
536 | + * @return \OC\OCS\DiscoveryService |
|
537 | + * @since 12.0.0 |
|
538 | + */ |
|
539 | + public function getOCSDiscoveryService(); |
|
540 | 540 | } |
@@ -46,169 +46,169 @@ |
||
46 | 46 | */ |
47 | 47 | class OCSAuthAPIController extends OCSController{ |
48 | 48 | |
49 | - /** @var ISecureRandom */ |
|
50 | - private $secureRandom; |
|
51 | - |
|
52 | - /** @var IJobList */ |
|
53 | - private $jobList; |
|
54 | - |
|
55 | - /** @var TrustedServers */ |
|
56 | - private $trustedServers; |
|
57 | - |
|
58 | - /** @var DbHandler */ |
|
59 | - private $dbHandler; |
|
60 | - |
|
61 | - /** @var ILogger */ |
|
62 | - private $logger; |
|
63 | - |
|
64 | - /** |
|
65 | - * OCSAuthAPI constructor. |
|
66 | - * |
|
67 | - * @param string $appName |
|
68 | - * @param IRequest $request |
|
69 | - * @param ISecureRandom $secureRandom |
|
70 | - * @param IJobList $jobList |
|
71 | - * @param TrustedServers $trustedServers |
|
72 | - * @param DbHandler $dbHandler |
|
73 | - * @param ILogger $logger |
|
74 | - */ |
|
75 | - public function __construct( |
|
76 | - $appName, |
|
77 | - IRequest $request, |
|
78 | - ISecureRandom $secureRandom, |
|
79 | - IJobList $jobList, |
|
80 | - TrustedServers $trustedServers, |
|
81 | - DbHandler $dbHandler, |
|
82 | - ILogger $logger |
|
83 | - ) { |
|
84 | - parent::__construct($appName, $request); |
|
85 | - |
|
86 | - $this->secureRandom = $secureRandom; |
|
87 | - $this->jobList = $jobList; |
|
88 | - $this->trustedServers = $trustedServers; |
|
89 | - $this->dbHandler = $dbHandler; |
|
90 | - $this->logger = $logger; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @NoCSRFRequired |
|
95 | - * @PublicPage |
|
96 | - * |
|
97 | - * request received to ask remote server for a shared secret, for legacy end-points |
|
98 | - * |
|
99 | - * @param string $url |
|
100 | - * @param string $token |
|
101 | - * @return Http\DataResponse |
|
102 | - * @throws OCSForbiddenException |
|
103 | - */ |
|
104 | - public function requestSharedSecretLegacy($url, $token) { |
|
105 | - return $this->requestSharedSecret($url, $token); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @NoCSRFRequired |
|
111 | - * @PublicPage |
|
112 | - * |
|
113 | - * create shared secret and return it, for legacy end-points |
|
114 | - * |
|
115 | - * @param string $url |
|
116 | - * @param string $token |
|
117 | - * @return Http\DataResponse |
|
118 | - * @throws OCSForbiddenException |
|
119 | - */ |
|
120 | - public function getSharedSecretLegacy($url, $token) { |
|
121 | - return $this->getSharedSecret($url, $token); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @NoCSRFRequired |
|
126 | - * @PublicPage |
|
127 | - * |
|
128 | - * request received to ask remote server for a shared secret |
|
129 | - * |
|
130 | - * @param string $url |
|
131 | - * @param string $token |
|
132 | - * @return Http\DataResponse |
|
133 | - * @throws OCSForbiddenException |
|
134 | - */ |
|
135 | - public function requestSharedSecret($url, $token) { |
|
136 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
137 | - $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
138 | - throw new OCSForbiddenException(); |
|
139 | - } |
|
140 | - |
|
141 | - // if both server initiated the exchange of the shared secret the greater |
|
142 | - // token wins |
|
143 | - $localToken = $this->dbHandler->getToken($url); |
|
144 | - if (strcmp($localToken, $token) > 0) { |
|
145 | - $this->logger->info( |
|
146 | - 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
147 | - ['app' => 'federation'] |
|
148 | - ); |
|
149 | - throw new OCSForbiddenException(); |
|
150 | - } |
|
151 | - |
|
152 | - // we ask for the shared secret so we no longer have to ask the other server |
|
153 | - // to request the shared secret |
|
154 | - $this->jobList->remove('OCA\Federation\BackgroundJob\RequestSharedSecret', |
|
155 | - [ |
|
156 | - 'url' => $url, |
|
157 | - 'token' => $localToken |
|
158 | - ] |
|
159 | - ); |
|
160 | - |
|
161 | - $this->jobList->add( |
|
162 | - 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
163 | - [ |
|
164 | - 'url' => $url, |
|
165 | - 'token' => $token, |
|
166 | - ] |
|
167 | - ); |
|
168 | - |
|
169 | - return new Http\DataResponse(); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @NoCSRFRequired |
|
174 | - * @PublicPage |
|
175 | - * |
|
176 | - * create shared secret and return it |
|
177 | - * |
|
178 | - * @param string $url |
|
179 | - * @param string $token |
|
180 | - * @return Http\DataResponse |
|
181 | - * @throws OCSForbiddenException |
|
182 | - */ |
|
183 | - public function getSharedSecret($url, $token) { |
|
184 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
185 | - $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
186 | - throw new OCSForbiddenException(); |
|
187 | - } |
|
188 | - |
|
189 | - if ($this->isValidToken($url, $token) === false) { |
|
190 | - $expectedToken = $this->dbHandler->getToken($url); |
|
191 | - $this->logger->error( |
|
192 | - 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
193 | - ['app' => 'federation'] |
|
194 | - ); |
|
195 | - throw new OCSForbiddenException(); |
|
196 | - } |
|
197 | - |
|
198 | - $sharedSecret = $this->secureRandom->generate(32); |
|
199 | - |
|
200 | - $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
201 | - // reset token after the exchange of the shared secret was successful |
|
202 | - $this->dbHandler->addToken($url, ''); |
|
203 | - |
|
204 | - return new Http\DataResponse([ |
|
205 | - 'sharedSecret' => $sharedSecret |
|
206 | - ]); |
|
207 | - } |
|
208 | - |
|
209 | - protected function isValidToken($url, $token) { |
|
210 | - $storedToken = $this->dbHandler->getToken($url); |
|
211 | - return hash_equals($storedToken, $token); |
|
212 | - } |
|
49 | + /** @var ISecureRandom */ |
|
50 | + private $secureRandom; |
|
51 | + |
|
52 | + /** @var IJobList */ |
|
53 | + private $jobList; |
|
54 | + |
|
55 | + /** @var TrustedServers */ |
|
56 | + private $trustedServers; |
|
57 | + |
|
58 | + /** @var DbHandler */ |
|
59 | + private $dbHandler; |
|
60 | + |
|
61 | + /** @var ILogger */ |
|
62 | + private $logger; |
|
63 | + |
|
64 | + /** |
|
65 | + * OCSAuthAPI constructor. |
|
66 | + * |
|
67 | + * @param string $appName |
|
68 | + * @param IRequest $request |
|
69 | + * @param ISecureRandom $secureRandom |
|
70 | + * @param IJobList $jobList |
|
71 | + * @param TrustedServers $trustedServers |
|
72 | + * @param DbHandler $dbHandler |
|
73 | + * @param ILogger $logger |
|
74 | + */ |
|
75 | + public function __construct( |
|
76 | + $appName, |
|
77 | + IRequest $request, |
|
78 | + ISecureRandom $secureRandom, |
|
79 | + IJobList $jobList, |
|
80 | + TrustedServers $trustedServers, |
|
81 | + DbHandler $dbHandler, |
|
82 | + ILogger $logger |
|
83 | + ) { |
|
84 | + parent::__construct($appName, $request); |
|
85 | + |
|
86 | + $this->secureRandom = $secureRandom; |
|
87 | + $this->jobList = $jobList; |
|
88 | + $this->trustedServers = $trustedServers; |
|
89 | + $this->dbHandler = $dbHandler; |
|
90 | + $this->logger = $logger; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @NoCSRFRequired |
|
95 | + * @PublicPage |
|
96 | + * |
|
97 | + * request received to ask remote server for a shared secret, for legacy end-points |
|
98 | + * |
|
99 | + * @param string $url |
|
100 | + * @param string $token |
|
101 | + * @return Http\DataResponse |
|
102 | + * @throws OCSForbiddenException |
|
103 | + */ |
|
104 | + public function requestSharedSecretLegacy($url, $token) { |
|
105 | + return $this->requestSharedSecret($url, $token); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @NoCSRFRequired |
|
111 | + * @PublicPage |
|
112 | + * |
|
113 | + * create shared secret and return it, for legacy end-points |
|
114 | + * |
|
115 | + * @param string $url |
|
116 | + * @param string $token |
|
117 | + * @return Http\DataResponse |
|
118 | + * @throws OCSForbiddenException |
|
119 | + */ |
|
120 | + public function getSharedSecretLegacy($url, $token) { |
|
121 | + return $this->getSharedSecret($url, $token); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @NoCSRFRequired |
|
126 | + * @PublicPage |
|
127 | + * |
|
128 | + * request received to ask remote server for a shared secret |
|
129 | + * |
|
130 | + * @param string $url |
|
131 | + * @param string $token |
|
132 | + * @return Http\DataResponse |
|
133 | + * @throws OCSForbiddenException |
|
134 | + */ |
|
135 | + public function requestSharedSecret($url, $token) { |
|
136 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
137 | + $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
138 | + throw new OCSForbiddenException(); |
|
139 | + } |
|
140 | + |
|
141 | + // if both server initiated the exchange of the shared secret the greater |
|
142 | + // token wins |
|
143 | + $localToken = $this->dbHandler->getToken($url); |
|
144 | + if (strcmp($localToken, $token) > 0) { |
|
145 | + $this->logger->info( |
|
146 | + 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
147 | + ['app' => 'federation'] |
|
148 | + ); |
|
149 | + throw new OCSForbiddenException(); |
|
150 | + } |
|
151 | + |
|
152 | + // we ask for the shared secret so we no longer have to ask the other server |
|
153 | + // to request the shared secret |
|
154 | + $this->jobList->remove('OCA\Federation\BackgroundJob\RequestSharedSecret', |
|
155 | + [ |
|
156 | + 'url' => $url, |
|
157 | + 'token' => $localToken |
|
158 | + ] |
|
159 | + ); |
|
160 | + |
|
161 | + $this->jobList->add( |
|
162 | + 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
163 | + [ |
|
164 | + 'url' => $url, |
|
165 | + 'token' => $token, |
|
166 | + ] |
|
167 | + ); |
|
168 | + |
|
169 | + return new Http\DataResponse(); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @NoCSRFRequired |
|
174 | + * @PublicPage |
|
175 | + * |
|
176 | + * create shared secret and return it |
|
177 | + * |
|
178 | + * @param string $url |
|
179 | + * @param string $token |
|
180 | + * @return Http\DataResponse |
|
181 | + * @throws OCSForbiddenException |
|
182 | + */ |
|
183 | + public function getSharedSecret($url, $token) { |
|
184 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
185 | + $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
186 | + throw new OCSForbiddenException(); |
|
187 | + } |
|
188 | + |
|
189 | + if ($this->isValidToken($url, $token) === false) { |
|
190 | + $expectedToken = $this->dbHandler->getToken($url); |
|
191 | + $this->logger->error( |
|
192 | + 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
193 | + ['app' => 'federation'] |
|
194 | + ); |
|
195 | + throw new OCSForbiddenException(); |
|
196 | + } |
|
197 | + |
|
198 | + $sharedSecret = $this->secureRandom->generate(32); |
|
199 | + |
|
200 | + $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
201 | + // reset token after the exchange of the shared secret was successful |
|
202 | + $this->dbHandler->addToken($url, ''); |
|
203 | + |
|
204 | + return new Http\DataResponse([ |
|
205 | + 'sharedSecret' => $sharedSecret |
|
206 | + ]); |
|
207 | + } |
|
208 | + |
|
209 | + protected function isValidToken($url, $token) { |
|
210 | + $storedToken = $this->dbHandler->getToken($url); |
|
211 | + return hash_equals($storedToken, $token); |
|
212 | + } |
|
213 | 213 | |
214 | 214 | } |
@@ -23,50 +23,50 @@ |
||
23 | 23 | $application = new \OCA\Federation\AppInfo\Application(); |
24 | 24 | |
25 | 25 | $application->registerRoutes( |
26 | - $this, |
|
27 | - [ |
|
28 | - 'routes' => [ |
|
29 | - [ |
|
30 | - 'name' => 'Settings#addServer', |
|
31 | - 'url' => '/trusted-servers', |
|
32 | - 'verb' => 'POST' |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'Settings#removeServer', |
|
36 | - 'url' => '/trusted-servers/{id}', |
|
37 | - 'verb' => 'DELETE' |
|
38 | - ], |
|
39 | - [ |
|
40 | - 'name' => 'Settings#autoAddServers', |
|
41 | - 'url' => '/auto-add-servers', |
|
42 | - 'verb' => 'POST' |
|
43 | - ], |
|
44 | - ], |
|
45 | - 'ocs' => [ |
|
46 | - // old endpoints, only used by Nextcloud and ownCloud |
|
47 | - [ |
|
48 | - 'name' => 'OCSAuthAPI#getSharedSecretLegacy', |
|
49 | - 'url' => '/api/v1/shared-secret', |
|
50 | - 'verb' => 'GET', |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'OCSAuthAPI#requestSharedSecretLegacy', |
|
54 | - 'url' => '/api/v1/request-shared-secret', |
|
55 | - 'verb' => 'POST', |
|
56 | - ], |
|
57 | - // new endpoints, published as public api |
|
58 | - [ |
|
59 | - 'name' => 'OCSAuthAPI#getSharedSecret', |
|
60 | - 'root' => '/cloud', |
|
61 | - 'url' => '/shared-secret', |
|
62 | - 'verb' => 'GET', |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'OCSAuthAPI#requestSharedSecret', |
|
66 | - 'root' => '/cloud', |
|
67 | - 'url' => '/shared-secret', |
|
68 | - 'verb' => 'POST', |
|
69 | - ], |
|
70 | - ], |
|
71 | - ] |
|
26 | + $this, |
|
27 | + [ |
|
28 | + 'routes' => [ |
|
29 | + [ |
|
30 | + 'name' => 'Settings#addServer', |
|
31 | + 'url' => '/trusted-servers', |
|
32 | + 'verb' => 'POST' |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'Settings#removeServer', |
|
36 | + 'url' => '/trusted-servers/{id}', |
|
37 | + 'verb' => 'DELETE' |
|
38 | + ], |
|
39 | + [ |
|
40 | + 'name' => 'Settings#autoAddServers', |
|
41 | + 'url' => '/auto-add-servers', |
|
42 | + 'verb' => 'POST' |
|
43 | + ], |
|
44 | + ], |
|
45 | + 'ocs' => [ |
|
46 | + // old endpoints, only used by Nextcloud and ownCloud |
|
47 | + [ |
|
48 | + 'name' => 'OCSAuthAPI#getSharedSecretLegacy', |
|
49 | + 'url' => '/api/v1/shared-secret', |
|
50 | + 'verb' => 'GET', |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'OCSAuthAPI#requestSharedSecretLegacy', |
|
54 | + 'url' => '/api/v1/request-shared-secret', |
|
55 | + 'verb' => 'POST', |
|
56 | + ], |
|
57 | + // new endpoints, published as public api |
|
58 | + [ |
|
59 | + 'name' => 'OCSAuthAPI#getSharedSecret', |
|
60 | + 'root' => '/cloud', |
|
61 | + 'url' => '/shared-secret', |
|
62 | + 'verb' => 'GET', |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'OCSAuthAPI#requestSharedSecret', |
|
66 | + 'root' => '/cloud', |
|
67 | + 'url' => '/shared-secret', |
|
68 | + 'verb' => 'POST', |
|
69 | + ], |
|
70 | + ], |
|
71 | + ] |
|
72 | 72 | ); |
@@ -31,95 +31,95 @@ |
||
31 | 31 | |
32 | 32 | class DiscoveryService implements IDiscoveryService { |
33 | 33 | |
34 | - /** @var ICache */ |
|
35 | - private $cache; |
|
36 | - |
|
37 | - /** @var IClient */ |
|
38 | - private $client; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param ICacheFactory $cacheFactory |
|
42 | - * @param IClientService $clientService |
|
43 | - */ |
|
44 | - public function __construct(ICacheFactory $cacheFactory, |
|
45 | - IClientService $clientService |
|
46 | - ) { |
|
47 | - $this->cache = $cacheFactory->create('ocs-discovery'); |
|
48 | - $this->client = $clientService->newClient(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Discover OCS end-points |
|
54 | - * |
|
55 | - * If no valid discovery data is found the defaults are returned |
|
56 | - * |
|
57 | - * @param string $remote |
|
58 | - * @param string $service the service you want to discover |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function discover($remote, $service) { |
|
62 | - // Check the cache first |
|
63 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
64 | - if($cacheData) { |
|
65 | - return json_decode($cacheData, true); |
|
66 | - } |
|
67 | - |
|
68 | - $discoveredServices = []; |
|
69 | - |
|
70 | - // query the remote server for available services |
|
71 | - try { |
|
72 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
73 | - 'timeout' => 10, |
|
74 | - 'connect_timeout' => 10, |
|
75 | - ]); |
|
76 | - if($response->getStatusCode() === Http::STATUS_OK) { |
|
77 | - $decodedServices = json_decode($response->getBody(), true); |
|
78 | - $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
79 | - } |
|
80 | - } catch (\Exception $e) { |
|
81 | - // if we couldn't discover the service or any end-points we return a empty array |
|
82 | - return []; |
|
83 | - } |
|
84 | - |
|
85 | - // Write into cache |
|
86 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices)); |
|
87 | - return $discoveredServices; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * get requested end-points from the requested service |
|
92 | - * |
|
93 | - * @param $decodedServices |
|
94 | - * @param $service |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function getEndpoints($decodedServices, $service) { |
|
98 | - |
|
99 | - $discoveredServices = []; |
|
100 | - |
|
101 | - if(is_array($decodedServices) && |
|
102 | - isset($decodedServices['services'][$service]['endpoints']) |
|
103 | - ) { |
|
104 | - foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
105 | - if($this->isSafeUrl($url)) { |
|
106 | - $discoveredServices[$endpoint] = $url; |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - return $discoveredServices; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Returns whether the specified URL includes only safe characters, if not |
|
116 | - * returns false |
|
117 | - * |
|
118 | - * @param string $url |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - protected function isSafeUrl($url) { |
|
122 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
123 | - } |
|
34 | + /** @var ICache */ |
|
35 | + private $cache; |
|
36 | + |
|
37 | + /** @var IClient */ |
|
38 | + private $client; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param ICacheFactory $cacheFactory |
|
42 | + * @param IClientService $clientService |
|
43 | + */ |
|
44 | + public function __construct(ICacheFactory $cacheFactory, |
|
45 | + IClientService $clientService |
|
46 | + ) { |
|
47 | + $this->cache = $cacheFactory->create('ocs-discovery'); |
|
48 | + $this->client = $clientService->newClient(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Discover OCS end-points |
|
54 | + * |
|
55 | + * If no valid discovery data is found the defaults are returned |
|
56 | + * |
|
57 | + * @param string $remote |
|
58 | + * @param string $service the service you want to discover |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function discover($remote, $service) { |
|
62 | + // Check the cache first |
|
63 | + $cacheData = $this->cache->get($remote . '#' . $service); |
|
64 | + if($cacheData) { |
|
65 | + return json_decode($cacheData, true); |
|
66 | + } |
|
67 | + |
|
68 | + $discoveredServices = []; |
|
69 | + |
|
70 | + // query the remote server for available services |
|
71 | + try { |
|
72 | + $response = $this->client->get($remote . '/ocs-provider/', [ |
|
73 | + 'timeout' => 10, |
|
74 | + 'connect_timeout' => 10, |
|
75 | + ]); |
|
76 | + if($response->getStatusCode() === Http::STATUS_OK) { |
|
77 | + $decodedServices = json_decode($response->getBody(), true); |
|
78 | + $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
79 | + } |
|
80 | + } catch (\Exception $e) { |
|
81 | + // if we couldn't discover the service or any end-points we return a empty array |
|
82 | + return []; |
|
83 | + } |
|
84 | + |
|
85 | + // Write into cache |
|
86 | + $this->cache->set($remote . '#' . $service, json_encode($discoveredServices)); |
|
87 | + return $discoveredServices; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * get requested end-points from the requested service |
|
92 | + * |
|
93 | + * @param $decodedServices |
|
94 | + * @param $service |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function getEndpoints($decodedServices, $service) { |
|
98 | + |
|
99 | + $discoveredServices = []; |
|
100 | + |
|
101 | + if(is_array($decodedServices) && |
|
102 | + isset($decodedServices['services'][$service]['endpoints']) |
|
103 | + ) { |
|
104 | + foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
105 | + if($this->isSafeUrl($url)) { |
|
106 | + $discoveredServices[$endpoint] = $url; |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + return $discoveredServices; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Returns whether the specified URL includes only safe characters, if not |
|
116 | + * returns false |
|
117 | + * |
|
118 | + * @param string $url |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + protected function isSafeUrl($url) { |
|
122 | + return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function discover($remote, $service) { |
62 | 62 | // Check the cache first |
63 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
64 | - if($cacheData) { |
|
63 | + $cacheData = $this->cache->get($remote.'#'.$service); |
|
64 | + if ($cacheData) { |
|
65 | 65 | return json_decode($cacheData, true); |
66 | 66 | } |
67 | 67 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | |
70 | 70 | // query the remote server for available services |
71 | 71 | try { |
72 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
72 | + $response = $this->client->get($remote.'/ocs-provider/', [ |
|
73 | 73 | 'timeout' => 10, |
74 | 74 | 'connect_timeout' => 10, |
75 | 75 | ]); |
76 | - if($response->getStatusCode() === Http::STATUS_OK) { |
|
76 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
77 | 77 | $decodedServices = json_decode($response->getBody(), true); |
78 | 78 | $discoveredServices = $this->getEndpoints($decodedServices, $service); |
79 | 79 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | // Write into cache |
86 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices)); |
|
86 | + $this->cache->set($remote.'#'.$service, json_encode($discoveredServices)); |
|
87 | 87 | return $discoveredServices; |
88 | 88 | } |
89 | 89 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | |
99 | 99 | $discoveredServices = []; |
100 | 100 | |
101 | - if(is_array($decodedServices) && |
|
101 | + if (is_array($decodedServices) && |
|
102 | 102 | isset($decodedServices['services'][$service]['endpoints']) |
103 | 103 | ) { |
104 | 104 | foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
105 | - if($this->isSafeUrl($url)) { |
|
105 | + if ($this->isSafeUrl($url)) { |
|
106 | 106 | $discoveredServices[$endpoint] = $url; |
107 | 107 | } |
108 | 108 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return bool |
120 | 120 | */ |
121 | 121 | protected function isSafeUrl($url) { |
122 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
122 | + return (bool) preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | } |