@@ -41,216 +41,216 @@ |
||
| 41 | 41 | use Sabre\HTTP\ResponseInterface; |
| 42 | 42 | |
| 43 | 43 | class PublishPlugin extends ServerPlugin { |
| 44 | - public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Reference to SabreDAV server object. |
|
| 48 | - * |
|
| 49 | - * @var \Sabre\DAV\Server |
|
| 50 | - */ |
|
| 51 | - protected $server; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Config instance to get instance secret. |
|
| 55 | - * |
|
| 56 | - * @var IConfig |
|
| 57 | - */ |
|
| 58 | - protected $config; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * URL Generator for absolute URLs. |
|
| 62 | - * |
|
| 63 | - * @var IURLGenerator |
|
| 64 | - */ |
|
| 65 | - protected $urlGenerator; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * PublishPlugin constructor. |
|
| 69 | - * |
|
| 70 | - * @param IConfig $config |
|
| 71 | - * @param IURLGenerator $urlGenerator |
|
| 72 | - */ |
|
| 73 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
| 74 | - $this->config = $config; |
|
| 75 | - $this->urlGenerator = $urlGenerator; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * This method should return a list of server-features. |
|
| 80 | - * |
|
| 81 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 82 | - * in an OPTIONS response. |
|
| 83 | - * |
|
| 84 | - * @return string[] |
|
| 85 | - */ |
|
| 86 | - public function getFeatures() { |
|
| 87 | - // May have to be changed to be detected |
|
| 88 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Returns a plugin name. |
|
| 93 | - * |
|
| 94 | - * Using this name other plugins will be able to access other plugins |
|
| 95 | - * using Sabre\DAV\Server::getPlugin |
|
| 96 | - * |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function getPluginName() { |
|
| 100 | - return 'oc-calendar-publishing'; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * This initializes the plugin. |
|
| 105 | - * |
|
| 106 | - * This function is called by Sabre\DAV\Server, after |
|
| 107 | - * addPlugin is called. |
|
| 108 | - * |
|
| 109 | - * This method should set up the required event subscriptions. |
|
| 110 | - * |
|
| 111 | - * @param Server $server |
|
| 112 | - */ |
|
| 113 | - public function initialize(Server $server) { |
|
| 114 | - $this->server = $server; |
|
| 115 | - |
|
| 116 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 117 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 121 | - if ($node instanceof Calendar) { |
|
| 122 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 123 | - if ($node->getPublishStatus()) { |
|
| 124 | - // We return the publish-url only if the calendar is published. |
|
| 125 | - $token = $node->getPublishStatus(); |
|
| 126 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
| 127 | - |
|
| 128 | - return new Publisher($publishUrl, true); |
|
| 129 | - } |
|
| 130 | - }); |
|
| 131 | - |
|
| 132 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) { |
|
| 133 | - $canShare = (!$node->isSubscription() && $node->canWrite()); |
|
| 134 | - $canPublish = (!$node->isSubscription() && $node->canWrite()); |
|
| 135 | - |
|
| 136 | - if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') { |
|
| 137 | - $canShare &= ($node->getOwner() === $node->getPrincipalURI()); |
|
| 138 | - $canPublish &= ($node->getOwner() === $node->getPrincipalURI()); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return new AllowedSharingModes((bool)$canShare, (bool)$canPublish); |
|
| 142 | - }); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * We intercept this to handle POST requests on calendars. |
|
| 148 | - * |
|
| 149 | - * @param RequestInterface $request |
|
| 150 | - * @param ResponseInterface $response |
|
| 151 | - * |
|
| 152 | - * @return void|bool |
|
| 153 | - */ |
|
| 154 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 155 | - $path = $request->getPath(); |
|
| 156 | - |
|
| 157 | - // Only handling xml |
|
| 158 | - $contentType = $request->getHeader('Content-Type'); |
|
| 159 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 160 | - return; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // Making sure the node exists |
|
| 164 | - try { |
|
| 165 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 166 | - } catch (NotFound $e) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $requestBody = $request->getBodyAsString(); |
|
| 171 | - |
|
| 172 | - // If this request handler could not deal with this POST request, it |
|
| 173 | - // will return 'null' and other plugins get a chance to handle the |
|
| 174 | - // request. |
|
| 175 | - // |
|
| 176 | - // However, we already requested the full body. This is a problem, |
|
| 177 | - // because a body can only be read once. This is why we preemptively |
|
| 178 | - // re-populated the request body with the existing data. |
|
| 179 | - $request->setBody($requestBody); |
|
| 180 | - |
|
| 181 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 182 | - |
|
| 183 | - switch ($documentType) { |
|
| 184 | - |
|
| 185 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar': |
|
| 186 | - |
|
| 187 | - // We can only deal with IShareableCalendar objects |
|
| 188 | - if (!$node instanceof Calendar) { |
|
| 189 | - return; |
|
| 190 | - } |
|
| 191 | - $this->server->transactionType = 'post-publish-calendar'; |
|
| 192 | - |
|
| 193 | - // Getting ACL info |
|
| 194 | - $acl = $this->server->getPlugin('acl'); |
|
| 195 | - |
|
| 196 | - // If there's no ACL support, we allow everything |
|
| 197 | - if ($acl) { |
|
| 198 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 199 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 200 | - |
|
| 201 | - $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 202 | - $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 203 | - if ($limitSharingToOwner && !$isOwner) { |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $node->setPublishStatus(true); |
|
| 209 | - |
|
| 210 | - // iCloud sends back the 202, so we will too. |
|
| 211 | - $response->setStatus(202); |
|
| 212 | - |
|
| 213 | - // Adding this because sending a response body may cause issues, |
|
| 214 | - // and I wanted some type of indicator the response was handled. |
|
| 215 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 216 | - |
|
| 217 | - // Breaking the event chain |
|
| 218 | - return false; |
|
| 219 | - |
|
| 220 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar': |
|
| 221 | - |
|
| 222 | - // We can only deal with IShareableCalendar objects |
|
| 223 | - if (!$node instanceof Calendar) { |
|
| 224 | - return; |
|
| 225 | - } |
|
| 226 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 227 | - |
|
| 228 | - // Getting ACL info |
|
| 229 | - $acl = $this->server->getPlugin('acl'); |
|
| 230 | - |
|
| 231 | - // If there's no ACL support, we allow everything |
|
| 232 | - if ($acl) { |
|
| 233 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 234 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 235 | - |
|
| 236 | - $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 237 | - $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 238 | - if ($limitSharingToOwner && !$isOwner) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $node->setPublishStatus(false); |
|
| 244 | - |
|
| 245 | - $response->setStatus(200); |
|
| 246 | - |
|
| 247 | - // Adding this because sending a response body may cause issues, |
|
| 248 | - // and I wanted some type of indicator the response was handled. |
|
| 249 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 250 | - |
|
| 251 | - // Breaking the event chain |
|
| 252 | - return false; |
|
| 44 | + public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Reference to SabreDAV server object. |
|
| 48 | + * |
|
| 49 | + * @var \Sabre\DAV\Server |
|
| 50 | + */ |
|
| 51 | + protected $server; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Config instance to get instance secret. |
|
| 55 | + * |
|
| 56 | + * @var IConfig |
|
| 57 | + */ |
|
| 58 | + protected $config; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * URL Generator for absolute URLs. |
|
| 62 | + * |
|
| 63 | + * @var IURLGenerator |
|
| 64 | + */ |
|
| 65 | + protected $urlGenerator; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * PublishPlugin constructor. |
|
| 69 | + * |
|
| 70 | + * @param IConfig $config |
|
| 71 | + * @param IURLGenerator $urlGenerator |
|
| 72 | + */ |
|
| 73 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
| 74 | + $this->config = $config; |
|
| 75 | + $this->urlGenerator = $urlGenerator; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * This method should return a list of server-features. |
|
| 80 | + * |
|
| 81 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 82 | + * in an OPTIONS response. |
|
| 83 | + * |
|
| 84 | + * @return string[] |
|
| 85 | + */ |
|
| 86 | + public function getFeatures() { |
|
| 87 | + // May have to be changed to be detected |
|
| 88 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Returns a plugin name. |
|
| 93 | + * |
|
| 94 | + * Using this name other plugins will be able to access other plugins |
|
| 95 | + * using Sabre\DAV\Server::getPlugin |
|
| 96 | + * |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function getPluginName() { |
|
| 100 | + return 'oc-calendar-publishing'; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * This initializes the plugin. |
|
| 105 | + * |
|
| 106 | + * This function is called by Sabre\DAV\Server, after |
|
| 107 | + * addPlugin is called. |
|
| 108 | + * |
|
| 109 | + * This method should set up the required event subscriptions. |
|
| 110 | + * |
|
| 111 | + * @param Server $server |
|
| 112 | + */ |
|
| 113 | + public function initialize(Server $server) { |
|
| 114 | + $this->server = $server; |
|
| 115 | + |
|
| 116 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 117 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 121 | + if ($node instanceof Calendar) { |
|
| 122 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 123 | + if ($node->getPublishStatus()) { |
|
| 124 | + // We return the publish-url only if the calendar is published. |
|
| 125 | + $token = $node->getPublishStatus(); |
|
| 126 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
| 127 | + |
|
| 128 | + return new Publisher($publishUrl, true); |
|
| 129 | + } |
|
| 130 | + }); |
|
| 131 | + |
|
| 132 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) { |
|
| 133 | + $canShare = (!$node->isSubscription() && $node->canWrite()); |
|
| 134 | + $canPublish = (!$node->isSubscription() && $node->canWrite()); |
|
| 135 | + |
|
| 136 | + if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') { |
|
| 137 | + $canShare &= ($node->getOwner() === $node->getPrincipalURI()); |
|
| 138 | + $canPublish &= ($node->getOwner() === $node->getPrincipalURI()); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return new AllowedSharingModes((bool)$canShare, (bool)$canPublish); |
|
| 142 | + }); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * We intercept this to handle POST requests on calendars. |
|
| 148 | + * |
|
| 149 | + * @param RequestInterface $request |
|
| 150 | + * @param ResponseInterface $response |
|
| 151 | + * |
|
| 152 | + * @return void|bool |
|
| 153 | + */ |
|
| 154 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 155 | + $path = $request->getPath(); |
|
| 156 | + |
|
| 157 | + // Only handling xml |
|
| 158 | + $contentType = $request->getHeader('Content-Type'); |
|
| 159 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // Making sure the node exists |
|
| 164 | + try { |
|
| 165 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 166 | + } catch (NotFound $e) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $requestBody = $request->getBodyAsString(); |
|
| 171 | + |
|
| 172 | + // If this request handler could not deal with this POST request, it |
|
| 173 | + // will return 'null' and other plugins get a chance to handle the |
|
| 174 | + // request. |
|
| 175 | + // |
|
| 176 | + // However, we already requested the full body. This is a problem, |
|
| 177 | + // because a body can only be read once. This is why we preemptively |
|
| 178 | + // re-populated the request body with the existing data. |
|
| 179 | + $request->setBody($requestBody); |
|
| 180 | + |
|
| 181 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 182 | + |
|
| 183 | + switch ($documentType) { |
|
| 184 | + |
|
| 185 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar': |
|
| 186 | + |
|
| 187 | + // We can only deal with IShareableCalendar objects |
|
| 188 | + if (!$node instanceof Calendar) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 191 | + $this->server->transactionType = 'post-publish-calendar'; |
|
| 192 | + |
|
| 193 | + // Getting ACL info |
|
| 194 | + $acl = $this->server->getPlugin('acl'); |
|
| 195 | + |
|
| 196 | + // If there's no ACL support, we allow everything |
|
| 197 | + if ($acl) { |
|
| 198 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 199 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 200 | + |
|
| 201 | + $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 202 | + $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 203 | + if ($limitSharingToOwner && !$isOwner) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $node->setPublishStatus(true); |
|
| 209 | + |
|
| 210 | + // iCloud sends back the 202, so we will too. |
|
| 211 | + $response->setStatus(202); |
|
| 212 | + |
|
| 213 | + // Adding this because sending a response body may cause issues, |
|
| 214 | + // and I wanted some type of indicator the response was handled. |
|
| 215 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 216 | + |
|
| 217 | + // Breaking the event chain |
|
| 218 | + return false; |
|
| 219 | + |
|
| 220 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar': |
|
| 221 | + |
|
| 222 | + // We can only deal with IShareableCalendar objects |
|
| 223 | + if (!$node instanceof Calendar) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 227 | + |
|
| 228 | + // Getting ACL info |
|
| 229 | + $acl = $this->server->getPlugin('acl'); |
|
| 230 | + |
|
| 231 | + // If there's no ACL support, we allow everything |
|
| 232 | + if ($acl) { |
|
| 233 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 234 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 235 | + |
|
| 236 | + $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 237 | + $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 238 | + if ($limitSharingToOwner && !$isOwner) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $node->setPublishStatus(false); |
|
| 244 | + |
|
| 245 | + $response->setStatus(200); |
|
| 246 | + |
|
| 247 | + // Adding this because sending a response body may cause issues, |
|
| 248 | + // and I wanted some type of indicator the response was handled. |
|
| 249 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 250 | + |
|
| 251 | + // Breaking the event chain |
|
| 252 | + return false; |
|
| 253 | 253 | |
| 254 | - } |
|
| 255 | - } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | } |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | $this->server = $server; |
| 115 | 115 | |
| 116 | 116 | $this->server->on('method:POST', [$this, 'httpPost']); |
| 117 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 117 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public function propFind(PropFind $propFind, INode $node) { |
| 121 | 121 | if ($node instanceof Calendar) { |
| 122 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 122 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) { |
|
| 123 | 123 | if ($node->getPublishStatus()) { |
| 124 | 124 | // We return the publish-url only if the calendar is published. |
| 125 | 125 | $token = $node->getPublishStatus(); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | 131 | |
| 132 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) { |
|
| 132 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
| 133 | 133 | $canShare = (!$node->isSubscription() && $node->canWrite()); |
| 134 | 134 | $canPublish = (!$node->isSubscription() && $node->canWrite()); |
| 135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $canPublish &= ($node->getOwner() === $node->getPrincipalURI()); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return new AllowedSharingModes((bool)$canShare, (bool)$canPublish); |
|
| 141 | + return new AllowedSharingModes((bool) $canShare, (bool) $canPublish); |
|
| 142 | 142 | }); |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -38,175 +38,175 @@ |
||
| 38 | 38 | use Sabre\HTTP\ResponseInterface; |
| 39 | 39 | |
| 40 | 40 | class Plugin extends ServerPlugin { |
| 41 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 42 | - public const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
| 43 | - |
|
| 44 | - /** @var Auth */ |
|
| 45 | - private $auth; |
|
| 46 | - |
|
| 47 | - /** @var IRequest */ |
|
| 48 | - private $request; |
|
| 49 | - |
|
| 50 | - /** @var IConfig */ |
|
| 51 | - private $config; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Plugin constructor. |
|
| 55 | - * |
|
| 56 | - * @param Auth $authBackEnd |
|
| 57 | - * @param IRequest $request |
|
| 58 | - * @param IConfig $config |
|
| 59 | - */ |
|
| 60 | - public function __construct(Auth $authBackEnd, IRequest $request, IConfig $config) { |
|
| 61 | - $this->auth = $authBackEnd; |
|
| 62 | - $this->request = $request; |
|
| 63 | - $this->config = $config; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Reference to SabreDAV server object. |
|
| 68 | - * |
|
| 69 | - * @var \Sabre\DAV\Server |
|
| 70 | - */ |
|
| 71 | - protected $server; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * This method should return a list of server-features. |
|
| 75 | - * |
|
| 76 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 77 | - * in an OPTIONS response. |
|
| 78 | - * |
|
| 79 | - * @return string[] |
|
| 80 | - */ |
|
| 81 | - public function getFeatures() { |
|
| 82 | - return ['oc-resource-sharing']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Returns a plugin name. |
|
| 87 | - * |
|
| 88 | - * Using this name other plugins will be able to access other plugins |
|
| 89 | - * using Sabre\DAV\Server::getPlugin |
|
| 90 | - * |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function getPluginName() { |
|
| 94 | - return 'oc-resource-sharing'; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * This initializes the plugin. |
|
| 99 | - * |
|
| 100 | - * This function is called by Sabre\DAV\Server, after |
|
| 101 | - * addPlugin is called. |
|
| 102 | - * |
|
| 103 | - * This method should set up the required event subscriptions. |
|
| 104 | - * |
|
| 105 | - * @param Server $server |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function initialize(Server $server) { |
|
| 109 | - $this->server = $server; |
|
| 110 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
| 111 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
| 112 | - |
|
| 113 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 114 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * We intercept this to handle POST requests on a dav resource. |
|
| 119 | - * |
|
| 120 | - * @param RequestInterface $request |
|
| 121 | - * @param ResponseInterface $response |
|
| 122 | - * @return null|false |
|
| 123 | - */ |
|
| 124 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 125 | - $path = $request->getPath(); |
|
| 126 | - |
|
| 127 | - // Only handling xml |
|
| 128 | - $contentType = $request->getHeader('Content-Type'); |
|
| 129 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Making sure the node exists |
|
| 134 | - try { |
|
| 135 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 136 | - } catch (NotFound $e) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $requestBody = $request->getBodyAsString(); |
|
| 141 | - |
|
| 142 | - // If this request handler could not deal with this POST request, it |
|
| 143 | - // will return 'null' and other plugins get a chance to handle the |
|
| 144 | - // request. |
|
| 145 | - // |
|
| 146 | - // However, we already requested the full body. This is a problem, |
|
| 147 | - // because a body can only be read once. This is why we preemptively |
|
| 148 | - // re-populated the request body with the existing data. |
|
| 149 | - $request->setBody($requestBody); |
|
| 150 | - |
|
| 151 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 152 | - |
|
| 153 | - switch ($documentType) { |
|
| 154 | - |
|
| 155 | - // Dealing with the 'share' document, which modified invitees on a |
|
| 156 | - // calendar. |
|
| 157 | - case '{' . self::NS_OWNCLOUD . '}share': |
|
| 158 | - |
|
| 159 | - // We can only deal with IShareableCalendar objects |
|
| 160 | - if (!$node instanceof IShareable) { |
|
| 161 | - return; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
| 165 | - |
|
| 166 | - // Getting ACL info |
|
| 167 | - $acl = $this->server->getPlugin('acl'); |
|
| 168 | - |
|
| 169 | - // If there's no ACL support, we allow everything |
|
| 170 | - if ($acl) { |
|
| 171 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 172 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 173 | - |
|
| 174 | - $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 175 | - $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 176 | - if ($limitSharingToOwner && !$isOwner) { |
|
| 177 | - return; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $node->updateShares($message->set, $message->remove); |
|
| 182 | - |
|
| 183 | - $response->setStatus(200); |
|
| 184 | - // Adding this because sending a response body may cause issues, |
|
| 185 | - // and I wanted some type of indicator the response was handled. |
|
| 186 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 187 | - |
|
| 188 | - // Breaking the event chain |
|
| 189 | - return false; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * This event is triggered when properties are requested for a certain |
|
| 195 | - * node. |
|
| 196 | - * |
|
| 197 | - * This allows us to inject any properties early. |
|
| 198 | - * |
|
| 199 | - * @param PropFind $propFind |
|
| 200 | - * @param INode $node |
|
| 201 | - * @return void |
|
| 202 | - */ |
|
| 203 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 204 | - if ($node instanceof IShareable) { |
|
| 205 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
| 206 | - return new Invite( |
|
| 207 | - $node->getShares() |
|
| 208 | - ); |
|
| 209 | - }); |
|
| 210 | - } |
|
| 211 | - } |
|
| 41 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 42 | + public const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
| 43 | + |
|
| 44 | + /** @var Auth */ |
|
| 45 | + private $auth; |
|
| 46 | + |
|
| 47 | + /** @var IRequest */ |
|
| 48 | + private $request; |
|
| 49 | + |
|
| 50 | + /** @var IConfig */ |
|
| 51 | + private $config; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Plugin constructor. |
|
| 55 | + * |
|
| 56 | + * @param Auth $authBackEnd |
|
| 57 | + * @param IRequest $request |
|
| 58 | + * @param IConfig $config |
|
| 59 | + */ |
|
| 60 | + public function __construct(Auth $authBackEnd, IRequest $request, IConfig $config) { |
|
| 61 | + $this->auth = $authBackEnd; |
|
| 62 | + $this->request = $request; |
|
| 63 | + $this->config = $config; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Reference to SabreDAV server object. |
|
| 68 | + * |
|
| 69 | + * @var \Sabre\DAV\Server |
|
| 70 | + */ |
|
| 71 | + protected $server; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * This method should return a list of server-features. |
|
| 75 | + * |
|
| 76 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 77 | + * in an OPTIONS response. |
|
| 78 | + * |
|
| 79 | + * @return string[] |
|
| 80 | + */ |
|
| 81 | + public function getFeatures() { |
|
| 82 | + return ['oc-resource-sharing']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Returns a plugin name. |
|
| 87 | + * |
|
| 88 | + * Using this name other plugins will be able to access other plugins |
|
| 89 | + * using Sabre\DAV\Server::getPlugin |
|
| 90 | + * |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function getPluginName() { |
|
| 94 | + return 'oc-resource-sharing'; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * This initializes the plugin. |
|
| 99 | + * |
|
| 100 | + * This function is called by Sabre\DAV\Server, after |
|
| 101 | + * addPlugin is called. |
|
| 102 | + * |
|
| 103 | + * This method should set up the required event subscriptions. |
|
| 104 | + * |
|
| 105 | + * @param Server $server |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function initialize(Server $server) { |
|
| 109 | + $this->server = $server; |
|
| 110 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
| 111 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
| 112 | + |
|
| 113 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 114 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * We intercept this to handle POST requests on a dav resource. |
|
| 119 | + * |
|
| 120 | + * @param RequestInterface $request |
|
| 121 | + * @param ResponseInterface $response |
|
| 122 | + * @return null|false |
|
| 123 | + */ |
|
| 124 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 125 | + $path = $request->getPath(); |
|
| 126 | + |
|
| 127 | + // Only handling xml |
|
| 128 | + $contentType = $request->getHeader('Content-Type'); |
|
| 129 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Making sure the node exists |
|
| 134 | + try { |
|
| 135 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 136 | + } catch (NotFound $e) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $requestBody = $request->getBodyAsString(); |
|
| 141 | + |
|
| 142 | + // If this request handler could not deal with this POST request, it |
|
| 143 | + // will return 'null' and other plugins get a chance to handle the |
|
| 144 | + // request. |
|
| 145 | + // |
|
| 146 | + // However, we already requested the full body. This is a problem, |
|
| 147 | + // because a body can only be read once. This is why we preemptively |
|
| 148 | + // re-populated the request body with the existing data. |
|
| 149 | + $request->setBody($requestBody); |
|
| 150 | + |
|
| 151 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 152 | + |
|
| 153 | + switch ($documentType) { |
|
| 154 | + |
|
| 155 | + // Dealing with the 'share' document, which modified invitees on a |
|
| 156 | + // calendar. |
|
| 157 | + case '{' . self::NS_OWNCLOUD . '}share': |
|
| 158 | + |
|
| 159 | + // We can only deal with IShareableCalendar objects |
|
| 160 | + if (!$node instanceof IShareable) { |
|
| 161 | + return; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
| 165 | + |
|
| 166 | + // Getting ACL info |
|
| 167 | + $acl = $this->server->getPlugin('acl'); |
|
| 168 | + |
|
| 169 | + // If there's no ACL support, we allow everything |
|
| 170 | + if ($acl) { |
|
| 171 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
| 172 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 173 | + |
|
| 174 | + $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes'; |
|
| 175 | + $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner(); |
|
| 176 | + if ($limitSharingToOwner && !$isOwner) { |
|
| 177 | + return; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $node->updateShares($message->set, $message->remove); |
|
| 182 | + |
|
| 183 | + $response->setStatus(200); |
|
| 184 | + // Adding this because sending a response body may cause issues, |
|
| 185 | + // and I wanted some type of indicator the response was handled. |
|
| 186 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 187 | + |
|
| 188 | + // Breaking the event chain |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * This event is triggered when properties are requested for a certain |
|
| 195 | + * node. |
|
| 196 | + * |
|
| 197 | + * This allows us to inject any properties early. |
|
| 198 | + * |
|
| 199 | + * @param PropFind $propFind |
|
| 200 | + * @param INode $node |
|
| 201 | + * @return void |
|
| 202 | + */ |
|
| 203 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 204 | + if ($node instanceof IShareable) { |
|
| 205 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
| 206 | + return new Invite( |
|
| 207 | + $node->getShares() |
|
| 208 | + ); |
|
| 209 | + }); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -74,264 +74,264 @@ |
||
| 74 | 74 | |
| 75 | 75 | class Server { |
| 76 | 76 | |
| 77 | - /** @var IRequest */ |
|
| 78 | - private $request; |
|
| 79 | - |
|
| 80 | - /** @var string */ |
|
| 81 | - private $baseUri; |
|
| 82 | - |
|
| 83 | - /** @var Connector\Sabre\Server */ |
|
| 84 | - public $server; |
|
| 85 | - |
|
| 86 | - public function __construct(IRequest $request, $baseUri) { |
|
| 87 | - $this->request = $request; |
|
| 88 | - $this->baseUri = $baseUri; |
|
| 89 | - $logger = \OC::$server->getLogger(); |
|
| 90 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 91 | - |
|
| 92 | - $root = new RootCollection(); |
|
| 93 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 94 | - |
|
| 95 | - // Add maintenance plugin |
|
| 96 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
| 97 | - |
|
| 98 | - // Backends |
|
| 99 | - $authBackend = new Auth( |
|
| 100 | - \OC::$server->getSession(), |
|
| 101 | - \OC::$server->getUserSession(), |
|
| 102 | - \OC::$server->getRequest(), |
|
| 103 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 104 | - \OC::$server->getBruteForceThrottler() |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // Set URL explicitly due to reverse-proxy situations |
|
| 108 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 109 | - $this->server->setBaseUri($this->baseUri); |
|
| 110 | - |
|
| 111 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 112 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 113 | - $authPlugin = new Plugin(); |
|
| 114 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 115 | - $this->server->addPlugin($authPlugin); |
|
| 116 | - |
|
| 117 | - // allow setup of additional auth backends |
|
| 118 | - $event = new SabrePluginEvent($this->server); |
|
| 119 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 120 | - |
|
| 121 | - $bearerAuthBackend = new BearerAuth( |
|
| 122 | - \OC::$server->getUserSession(), |
|
| 123 | - \OC::$server->getSession(), |
|
| 124 | - \OC::$server->getRequest() |
|
| 125 | - ); |
|
| 126 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 127 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 128 | - $authPlugin->addBackend($authBackend); |
|
| 129 | - |
|
| 130 | - // debugging |
|
| 131 | - if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 132 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 133 | - } else { |
|
| 134 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 138 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 139 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 140 | - |
|
| 141 | - // acl |
|
| 142 | - $acl = new DavAclPlugin(); |
|
| 143 | - $acl->principalCollectionSet = [ |
|
| 144 | - 'principals/users', |
|
| 145 | - 'principals/groups', |
|
| 146 | - 'principals/calendar-resources', |
|
| 147 | - 'principals/calendar-rooms', |
|
| 148 | - ]; |
|
| 149 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 150 | - $this->server->addPlugin($acl); |
|
| 151 | - |
|
| 152 | - // calendar plugins |
|
| 153 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 154 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 155 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 156 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
| 157 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 158 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
| 162 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 163 | - |
|
| 164 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 165 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 166 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 167 | - \OC::$server->getConfig(), |
|
| 168 | - \OC::$server->getURLGenerator() |
|
| 169 | - )); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // addressbook plugins |
|
| 173 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 174 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 175 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 176 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 177 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 178 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 179 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
| 180 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
| 181 | - \OC::$server->getLogger()) |
|
| 182 | - )); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // system tags plugins |
|
| 186 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 187 | - \OC::$server->getSystemTagManager(), |
|
| 188 | - \OC::$server->getGroupManager(), |
|
| 189 | - \OC::$server->getUserSession() |
|
| 190 | - )); |
|
| 191 | - |
|
| 192 | - // comments plugin |
|
| 193 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 194 | - \OC::$server->getCommentsManager(), |
|
| 195 | - \OC::$server->getUserSession() |
|
| 196 | - )); |
|
| 197 | - |
|
| 198 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 199 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
| 200 | - |
|
| 201 | - // allow setup of additional plugins |
|
| 202 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 203 | - |
|
| 204 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 205 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 206 | - if ($request->isUserAgent([ |
|
| 207 | - '/WebDAVFS/', |
|
| 208 | - '/OneNote/', |
|
| 209 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 210 | - ])) { |
|
| 211 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 215 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $lazySearchBackend = new LazySearchBackend(); |
|
| 219 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 220 | - |
|
| 221 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 222 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
| 223 | - // custom properties plugin must be the last one |
|
| 224 | - $userSession = \OC::$server->getUserSession(); |
|
| 225 | - $user = $userSession->getUser(); |
|
| 226 | - if ($user !== null) { |
|
| 227 | - $view = \OC\Files\Filesystem::getView(); |
|
| 228 | - $this->server->addPlugin( |
|
| 229 | - new FilesPlugin( |
|
| 230 | - $this->server->tree, |
|
| 231 | - \OC::$server->getConfig(), |
|
| 232 | - $this->request, |
|
| 233 | - \OC::$server->getPreviewManager(), |
|
| 234 | - false, |
|
| 235 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 236 | - ) |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - $this->server->addPlugin( |
|
| 240 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 241 | - new CustomPropertiesBackend( |
|
| 242 | - $this->server->tree, |
|
| 243 | - \OC::$server->getDatabaseConnection(), |
|
| 244 | - \OC::$server->getUserSession()->getUser() |
|
| 245 | - ) |
|
| 246 | - ) |
|
| 247 | - ); |
|
| 248 | - if ($view !== null) { |
|
| 249 | - $this->server->addPlugin( |
|
| 250 | - new QuotaPlugin($view, false)); |
|
| 251 | - } |
|
| 252 | - $this->server->addPlugin( |
|
| 253 | - new TagsPlugin( |
|
| 254 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 255 | - ) |
|
| 256 | - ); |
|
| 257 | - // TODO: switch to LazyUserFolder |
|
| 258 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 259 | - $this->server->addPlugin(new SharesPlugin( |
|
| 260 | - $this->server->tree, |
|
| 261 | - $userSession, |
|
| 262 | - $userFolder, |
|
| 263 | - \OC::$server->getShareManager() |
|
| 264 | - )); |
|
| 265 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 266 | - \OC::$server->getCommentsManager(), |
|
| 267 | - $userSession |
|
| 268 | - )); |
|
| 269 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 270 | - if ($view !== null) { |
|
| 271 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 272 | - $this->server->tree, |
|
| 273 | - $view, |
|
| 274 | - \OC::$server->getSystemTagManager(), |
|
| 275 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 276 | - \OC::$server->getTagManager(), |
|
| 277 | - $userSession, |
|
| 278 | - \OC::$server->getGroupManager(), |
|
| 279 | - $userFolder, |
|
| 280 | - \OC::$server->getAppManager() |
|
| 281 | - )); |
|
| 282 | - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
| 283 | - $this->server->tree, |
|
| 284 | - $user, |
|
| 285 | - \OC::$server->getRootFolder(), |
|
| 286 | - \OC::$server->getShareManager(), |
|
| 287 | - $view |
|
| 288 | - )); |
|
| 289 | - } |
|
| 290 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 291 | - \OC::$server->getConfig(), |
|
| 292 | - \OC::$server->query(BirthdayService::class) |
|
| 293 | - )); |
|
| 294 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 295 | - \OC::$server->getUserSession(), |
|
| 296 | - \OC::$server->getURLGenerator(), |
|
| 297 | - \OC::$server->getThemingDefaults(), |
|
| 298 | - \OC::$server->getRequest(), |
|
| 299 | - \OC::$server->getL10N('dav'), |
|
| 300 | - function () { |
|
| 301 | - return UUIDUtil::getUUID(); |
|
| 302 | - } |
|
| 303 | - )); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - // register plugins from apps |
|
| 307 | - $pluginManager = new PluginManager( |
|
| 308 | - \OC::$server, |
|
| 309 | - \OC::$server->getAppManager() |
|
| 310 | - ); |
|
| 311 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 312 | - $this->server->addPlugin($appPlugin); |
|
| 313 | - } |
|
| 314 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 315 | - $root->addChild($appCollection); |
|
| 316 | - } |
|
| 317 | - }); |
|
| 318 | - |
|
| 319 | - $this->server->addPlugin( |
|
| 320 | - new PropfindCompressionPlugin() |
|
| 321 | - ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - public function exec() { |
|
| 325 | - $this->server->exec(); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - private function requestIsForSubtree(array $subTrees): bool { |
|
| 329 | - foreach ($subTrees as $subTree) { |
|
| 330 | - $subTree = trim($subTree, ' /'); |
|
| 331 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 332 | - return true; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 77 | + /** @var IRequest */ |
|
| 78 | + private $request; |
|
| 79 | + |
|
| 80 | + /** @var string */ |
|
| 81 | + private $baseUri; |
|
| 82 | + |
|
| 83 | + /** @var Connector\Sabre\Server */ |
|
| 84 | + public $server; |
|
| 85 | + |
|
| 86 | + public function __construct(IRequest $request, $baseUri) { |
|
| 87 | + $this->request = $request; |
|
| 88 | + $this->baseUri = $baseUri; |
|
| 89 | + $logger = \OC::$server->getLogger(); |
|
| 90 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 91 | + |
|
| 92 | + $root = new RootCollection(); |
|
| 93 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 94 | + |
|
| 95 | + // Add maintenance plugin |
|
| 96 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
| 97 | + |
|
| 98 | + // Backends |
|
| 99 | + $authBackend = new Auth( |
|
| 100 | + \OC::$server->getSession(), |
|
| 101 | + \OC::$server->getUserSession(), |
|
| 102 | + \OC::$server->getRequest(), |
|
| 103 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 104 | + \OC::$server->getBruteForceThrottler() |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // Set URL explicitly due to reverse-proxy situations |
|
| 108 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 109 | + $this->server->setBaseUri($this->baseUri); |
|
| 110 | + |
|
| 111 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 112 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 113 | + $authPlugin = new Plugin(); |
|
| 114 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 115 | + $this->server->addPlugin($authPlugin); |
|
| 116 | + |
|
| 117 | + // allow setup of additional auth backends |
|
| 118 | + $event = new SabrePluginEvent($this->server); |
|
| 119 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 120 | + |
|
| 121 | + $bearerAuthBackend = new BearerAuth( |
|
| 122 | + \OC::$server->getUserSession(), |
|
| 123 | + \OC::$server->getSession(), |
|
| 124 | + \OC::$server->getRequest() |
|
| 125 | + ); |
|
| 126 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 127 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 128 | + $authPlugin->addBackend($authBackend); |
|
| 129 | + |
|
| 130 | + // debugging |
|
| 131 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 132 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 133 | + } else { |
|
| 134 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 138 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 139 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 140 | + |
|
| 141 | + // acl |
|
| 142 | + $acl = new DavAclPlugin(); |
|
| 143 | + $acl->principalCollectionSet = [ |
|
| 144 | + 'principals/users', |
|
| 145 | + 'principals/groups', |
|
| 146 | + 'principals/calendar-resources', |
|
| 147 | + 'principals/calendar-rooms', |
|
| 148 | + ]; |
|
| 149 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 150 | + $this->server->addPlugin($acl); |
|
| 151 | + |
|
| 152 | + // calendar plugins |
|
| 153 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 154 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 155 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
| 156 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
| 157 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 158 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
| 162 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 163 | + |
|
| 164 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 165 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 166 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 167 | + \OC::$server->getConfig(), |
|
| 168 | + \OC::$server->getURLGenerator() |
|
| 169 | + )); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // addressbook plugins |
|
| 173 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 174 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
| 175 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 176 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 177 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 178 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 179 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
| 180 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
| 181 | + \OC::$server->getLogger()) |
|
| 182 | + )); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // system tags plugins |
|
| 186 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 187 | + \OC::$server->getSystemTagManager(), |
|
| 188 | + \OC::$server->getGroupManager(), |
|
| 189 | + \OC::$server->getUserSession() |
|
| 190 | + )); |
|
| 191 | + |
|
| 192 | + // comments plugin |
|
| 193 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 194 | + \OC::$server->getCommentsManager(), |
|
| 195 | + \OC::$server->getUserSession() |
|
| 196 | + )); |
|
| 197 | + |
|
| 198 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 199 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
| 200 | + |
|
| 201 | + // allow setup of additional plugins |
|
| 202 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 203 | + |
|
| 204 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 205 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 206 | + if ($request->isUserAgent([ |
|
| 207 | + '/WebDAVFS/', |
|
| 208 | + '/OneNote/', |
|
| 209 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 210 | + ])) { |
|
| 211 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 215 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $lazySearchBackend = new LazySearchBackend(); |
|
| 219 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 220 | + |
|
| 221 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 222 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
| 223 | + // custom properties plugin must be the last one |
|
| 224 | + $userSession = \OC::$server->getUserSession(); |
|
| 225 | + $user = $userSession->getUser(); |
|
| 226 | + if ($user !== null) { |
|
| 227 | + $view = \OC\Files\Filesystem::getView(); |
|
| 228 | + $this->server->addPlugin( |
|
| 229 | + new FilesPlugin( |
|
| 230 | + $this->server->tree, |
|
| 231 | + \OC::$server->getConfig(), |
|
| 232 | + $this->request, |
|
| 233 | + \OC::$server->getPreviewManager(), |
|
| 234 | + false, |
|
| 235 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 236 | + ) |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + $this->server->addPlugin( |
|
| 240 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 241 | + new CustomPropertiesBackend( |
|
| 242 | + $this->server->tree, |
|
| 243 | + \OC::$server->getDatabaseConnection(), |
|
| 244 | + \OC::$server->getUserSession()->getUser() |
|
| 245 | + ) |
|
| 246 | + ) |
|
| 247 | + ); |
|
| 248 | + if ($view !== null) { |
|
| 249 | + $this->server->addPlugin( |
|
| 250 | + new QuotaPlugin($view, false)); |
|
| 251 | + } |
|
| 252 | + $this->server->addPlugin( |
|
| 253 | + new TagsPlugin( |
|
| 254 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 255 | + ) |
|
| 256 | + ); |
|
| 257 | + // TODO: switch to LazyUserFolder |
|
| 258 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 259 | + $this->server->addPlugin(new SharesPlugin( |
|
| 260 | + $this->server->tree, |
|
| 261 | + $userSession, |
|
| 262 | + $userFolder, |
|
| 263 | + \OC::$server->getShareManager() |
|
| 264 | + )); |
|
| 265 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 266 | + \OC::$server->getCommentsManager(), |
|
| 267 | + $userSession |
|
| 268 | + )); |
|
| 269 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 270 | + if ($view !== null) { |
|
| 271 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 272 | + $this->server->tree, |
|
| 273 | + $view, |
|
| 274 | + \OC::$server->getSystemTagManager(), |
|
| 275 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 276 | + \OC::$server->getTagManager(), |
|
| 277 | + $userSession, |
|
| 278 | + \OC::$server->getGroupManager(), |
|
| 279 | + $userFolder, |
|
| 280 | + \OC::$server->getAppManager() |
|
| 281 | + )); |
|
| 282 | + $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
| 283 | + $this->server->tree, |
|
| 284 | + $user, |
|
| 285 | + \OC::$server->getRootFolder(), |
|
| 286 | + \OC::$server->getShareManager(), |
|
| 287 | + $view |
|
| 288 | + )); |
|
| 289 | + } |
|
| 290 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
| 291 | + \OC::$server->getConfig(), |
|
| 292 | + \OC::$server->query(BirthdayService::class) |
|
| 293 | + )); |
|
| 294 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 295 | + \OC::$server->getUserSession(), |
|
| 296 | + \OC::$server->getURLGenerator(), |
|
| 297 | + \OC::$server->getThemingDefaults(), |
|
| 298 | + \OC::$server->getRequest(), |
|
| 299 | + \OC::$server->getL10N('dav'), |
|
| 300 | + function () { |
|
| 301 | + return UUIDUtil::getUUID(); |
|
| 302 | + } |
|
| 303 | + )); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + // register plugins from apps |
|
| 307 | + $pluginManager = new PluginManager( |
|
| 308 | + \OC::$server, |
|
| 309 | + \OC::$server->getAppManager() |
|
| 310 | + ); |
|
| 311 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 312 | + $this->server->addPlugin($appPlugin); |
|
| 313 | + } |
|
| 314 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 315 | + $root->addChild($appCollection); |
|
| 316 | + } |
|
| 317 | + }); |
|
| 318 | + |
|
| 319 | + $this->server->addPlugin( |
|
| 320 | + new PropfindCompressionPlugin() |
|
| 321 | + ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + public function exec() { |
|
| 325 | + $this->server->exec(); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + private function requestIsForSubtree(array $subTrees): bool { |
|
| 329 | + foreach ($subTrees as $subTree) { |
|
| 330 | + $subTree = trim($subTree, ' /'); |
|
| 331 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
| 332 | + return true; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | 337 | } |