diff options
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 28 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Publishing/PublishPlugin.php | 34 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 4 |
3 files changed, 63 insertions, 3 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 8c651251106..b1d85e09808 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1514,6 +1514,34 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * @param string $token + * @param string secret + * @return int | boolean + * + * Function to get the ressource we're insteressed in. Most probably to put somewhere else. + */ + public function getResourceIdFromToken($token, $secret) { + $query = $this->db->getQueryBuilder(); + $result = $query->select('resourceid') + ->from('dav_shares') + ->where($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) + ->execute(); + + $publications = []; + while($row = $result->fetch()) { + $publications[] = $row['resourceid']; + } + + $i = 0; + $found = false; + while ($i < count($publications) && !$found) { + $found = md5($secret.$publications[$i]) === $token; + if (!$found) $i++; + } + return ($found) ? $publications[$i] : false; + } + + /** * @param int $resourceId * @param array $acl * @return array diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index 704f0263238..f1f3540d68c 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -59,7 +59,7 @@ class PublishPlugin extends ServerPlugin */ public function getFeatures() { - return ['oc-calendar-publishing']; + return ['oc-calendar-publishing']; // May have to be changed to be detected } /** @@ -91,6 +91,7 @@ class PublishPlugin extends ServerPlugin $this->server->on('method:POST', [$this, 'httpPost']); $this->server->on('propFind', [$this, 'propFind']); + $this->server->on('method:GET', [$this, 'httpGet'], 90); // 90 because it needs to be called before auth } public function propFind(PropFind $propFind, INode $node) @@ -102,12 +103,12 @@ class PublishPlugin extends ServerPlugin $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) { if ($node->getPublishStatus()) { - return new Publisher($publishUrl, true); + return new Publisher($publishUrl, true); // We return the publish-url only if the calendar is published. } }); $propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) { - return new Publisher($publishUrl, false); + return new Publisher($publishUrl, false); // The pre-publish-url is always returned }); } } @@ -209,4 +210,31 @@ class PublishPlugin extends ServerPlugin } } + + /** + * We intercept the GET requests to provide our shared calendars. + * + * @param Sabre\HTTP\RequestInterface $request + * @param Sabre\HTTP\ResponseInterface $response + */ + public function httpGet(RequestInterface $request, ResponseInterface $response) + { + $path = $request->getPath(); + + // TODO : Find a better way to do this + list($path, $token) = explode('/', $path); + if ($path !== 'public-calendars') { + return; + } + + // This is where the magic happens + // Find a place to put the functions getResourceIdFromToken($token) and getRessource($id) + + $this->server->transactionType = 'access-published-calendar'; + + $response->setStatus(200); + $response->setBody('Success !'); + + return false; + } } diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index dd5f958ed4c..7da49e13130 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -244,6 +244,10 @@ class FilesPlugin extends ServerPlugin { * @param ResponseInterface $response */ function httpGet(RequestInterface $request, ResponseInterface $response) { + // Exclude published calendars + // TODO : Find a better way to do this + if (explode('/', $request->getPath())[0] === 'public-calendars') return; + // Only handle valid files $node = $this->tree->getNodeForPath($request->getPath()); if (!($node instanceof IFile)) return; |