if ($this->shareManager->checkPassword($share, $password)) {
$this->session->set('public_link_authenticated', (string)$share->getId());
} else {
+ $this->emitAccessShareHook($share, 403, 'Wrong password');
return false;
}
} else {
return true;
}
+ /**
+ * throws hooks when a share is attempted to be accessed
+ *
+ * @param \OC\Share20\Share|string $share the Share instance if available,
+ * otherwise token
+ * @param int $errorCode
+ * @param string $errorMessage
+ * @throws NotFoundException
+ * @throws OC\HintException
+ * @throws OC\ServerNotAvailableException
+ */
+ protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') {
+ $itemType = $itemSource = $uidOwner = '';
+ $token = $share;
+ $exception = null;
+ if($share instanceof \OC\Share20\Share) {
+ try {
+ $token = $share->getToken();
+ $uidOwner = $share->getSharedBy();
+ $itemType = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
+ $itemSource = $share->getNode()->getId();
+ } catch (\Exception $e) {
+ // we log what we know and pass on the exception afterwards
+ $exception = $e;
+ }
+ }
+ \OC_Hook::emit('OCP\Share', 'share_link_access', [
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'uidOwner' => $uidOwner,
+ 'token' => $token,
+ 'errorCode' => $errorCode,
+ 'errorMessage' => $errorMessage,
+ ]);
+ if(!is_null($exception)) {
+ throw $exception;
+ }
+ }
+
/**
* @PublicPage
* @NoCSRFRequired
try {
$share = $this->shareManager->getShareByToken($token);
} catch (ShareNotFound $e) {
+ $this->emitAccessShareHook($token, 404, 'Share not found');
return new NotFoundResponse();
}
}
// We can't get the path of a file share
- if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
- throw new NotFoundException();
+ try {
+ if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
+ $this->emitAccessShareHook($share, 404, 'Share not found');
+ throw new NotFoundException();
+ }
+ } catch (\Exception $e) {
+ $this->emitAccessShareHook($share, 404, 'Share not found');
+ throw $e;
}
$rootFolder = null;
try {
$path = $rootFolder->get($path);
} catch (\OCP\Files\NotFoundException $e) {
+ $this->emitAccessShareHook($share, 404, 'Share not found');
throw new NotFoundException();
}
}
$response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
$response->setContentSecurityPolicy($csp);
+ $this->emitAccessShareHook($share);
+
return $response;
}
try {
$node = $node->get($path);
} catch (NotFoundException $e) {
+ $this->emitAccessShareHook($share, 404, 'Share not found');
return new NotFoundResponse();
}
}
setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
}
+ $this->emitAccessShareHook($share);
+
// download selected files
if (!is_null($files)) {
// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well