|
33 | 33 | use OCP\IDBConnection; |
34 | 34 | use OCP\IUser; |
35 | 35 | use OCP\IUserManager; |
| 36 | +use OCP\Security\ISecureRandom; |
36 | 37 | use Sabre\CalDAV\Backend\AbstractBackend; |
37 | 38 | use Sabre\CalDAV\Backend\SchedulingSupport; |
38 | 39 | use Sabre\CalDAV\Backend\SubscriptionSupport; |
@@ -124,23 +125,29 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription |
124 | 125 | /** @var IConfig */ |
125 | 126 | private $config; |
126 | 127 |
|
| 128 | + /** @var ISecureRandom */ |
| 129 | + private $random; |
| 130 | + |
127 | 131 | /** |
128 | 132 | * CalDavBackend constructor. |
129 | 133 | * |
130 | 134 | * @param IDBConnection $db |
131 | 135 | * @param Principal $principalBackend |
132 | 136 | * @param IUserManager $userManager |
133 | 137 | * @param IConfig $config |
| 138 | + * @param ISecureRandom $random |
134 | 139 | */ |
135 | 140 | public function __construct(IDBConnection $db, |
136 | 141 | Principal $principalBackend, |
137 | 142 | IUserManager $userManager, |
138 | | - IConfig $config) { |
| 143 | + IConfig $config, |
| 144 | + ISecureRandom $random) { |
139 | 145 | $this->db = $db; |
140 | 146 | $this->principalBackend = $principalBackend; |
141 | 147 | $this->userManager = $userManager; |
142 | 148 | $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
143 | 149 | $this->config = $config; |
| 150 | + $this->random = $random; |
144 | 151 | } |
145 | 152 |
|
146 | 153 | /** |
@@ -400,10 +407,9 @@ public function getPublicCalendar($uri) { |
400 | 407 | if ($row['components']) { |
401 | 408 | $components = explode(',',$row['components']); |
402 | 409 | } |
403 | | - $uri = md5($this->config->getSystemValue('secret', '') . $row['id']); |
404 | 410 | $calendar = [ |
405 | 411 | 'id' => $row['id'], |
406 | | - 'uri' => $uri, |
| 412 | + 'uri' => $row['publicuri'], |
407 | 413 | 'principaluri' => $row['principaluri'], |
408 | 414 | '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
409 | 415 | '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
@@ -1594,24 +1600,28 @@ public function getShares($resourceId) { |
1594 | 1600 | /** |
1595 | 1601 | * @param boolean $value |
1596 | 1602 | * @param \OCA\DAV\CalDAV\Calendar $calendar |
| 1603 | + * @return string|null |
1597 | 1604 | */ |
1598 | 1605 | public function setPublishStatus($value, $calendar) { |
1599 | 1606 | $query = $this->db->getQueryBuilder(); |
1600 | 1607 | if ($value) { |
| 1608 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
1601 | 1609 | $query->insert('dav_shares') |
1602 | 1610 | ->values([ |
1603 | 1611 | 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
1604 | 1612 | 'type' => $query->createNamedParameter('calendar'), |
1605 | 1613 | 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
1606 | 1614 | 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
1607 | | - 'publicuri' => $query->createNamedParameter(md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId())) |
| 1615 | + 'publicuri' => $query->createNamedParameter($publicUri) |
1608 | 1616 | ]); |
1609 | | - } else { |
1610 | | - $query->delete('dav_shares') |
1611 | | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
1612 | | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
| 1617 | + $query->execute(); |
| 1618 | + return $publicUri; |
1613 | 1619 | } |
| 1620 | + $query->delete('dav_shares') |
| 1621 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
| 1622 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
1614 | 1623 | $query->execute(); |
| 1624 | + return null; |
1615 | 1625 | } |
1616 | 1626 |
|
1617 | 1627 | /** |
|
0 commit comments