Check if a direct link is expired

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-04-23 22:15:29 +02:00
parent 6a385dd20b
commit 042340ccf6
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 31 additions and 21 deletions

View File

@ -46,47 +46,47 @@ class DirectFile implements IFile {
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
} }
function put($data) { public function put($data) {
throw new Forbidden(); throw new Forbidden();
} }
function get() { public function get() {
$this->getFile(); $this->getFile();
return $this->file->fopen('rb'); return $this->file->fopen('rb');
} }
function getContentType() { public function getContentType() {
$this->getFile(); $this->getFile();
return $this->file->getMimeType(); return $this->file->getMimeType();
} }
function getETag() { public function getETag() {
$this->getFile(); $this->getFile();
return $this->file->getEtag(); return $this->file->getEtag();
} }
function getSize() { public function getSize() {
$this->getFile(); $this->getFile();
return $this->file->getSize(); return $this->file->getSize();
} }
function delete() { public function delete() {
throw new Forbidden(); throw new Forbidden();
} }
function getName() { public function getName() {
return $this->direct->getToken(); return $this->direct->getToken();
} }
function setName($name) { public function setName($name) {
throw new Forbidden(); throw new Forbidden();
} }
function getLastModified() { public function getLastModified() {
$this->getFile(); $this->getFile();
return $this->file->getMTime(); return $this->file->getMTime();
@ -97,8 +97,6 @@ class DirectFile implements IFile {
$userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId()); $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId());
$files = $userFolder->getById($this->direct->getFileId()); $files = $userFolder->getById($this->direct->getFileId());
//TODO check expiration
if ($files === []) { if ($files === []) {
throw new NotFound(); throw new NotFound();
} }

View File

@ -26,6 +26,7 @@ namespace OCA\DAV\Direct;
use OCA\DAV\Db\DirectMapper; use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\Exception\MethodNotAllowed;
@ -40,23 +41,34 @@ class DirectHome implements ICollection {
/** @var DirectMapper */ /** @var DirectMapper */
private $mapper; private $mapper;
public function __construct(IRootFolder $rootFolder, DirectMapper $mapper) { /** @var ITimeFactory */
private $timeFactory;
public function __construct(IRootFolder $rootFolder,
DirectMapper $mapper,
ITimeFactory $timeFactory) {
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->mapper = $mapper; $this->mapper = $mapper;
$this->timeFactory = $timeFactory;
} }
function createFile($name, $data = null) { public function createFile($name, $data = null) {
throw new Forbidden(); throw new Forbidden();
} }
function createDirectory($name) { public function createDirectory($name) {
throw new Forbidden(); throw new Forbidden();
} }
public function getChild($name) { public function getChild($name): DirectFile {
try { try {
$direct = $this->mapper->getByToken($name); $direct = $this->mapper->getByToken($name);
// Expired
if ($direct->getExpiration() >= $this->timeFactory->getTime()) {
throw new NotFound();
}
return new DirectFile($direct, $this->rootFolder); return new DirectFile($direct, $this->rootFolder);
} catch (DoesNotExistException $e) { } catch (DoesNotExistException $e) {
//TODO: throttle the ip to avoid brute forcing //TODO: throttle the ip to avoid brute forcing
@ -65,27 +77,27 @@ class DirectHome implements ICollection {
} }
} }
function getChildren() { public function getChildren() {
throw new MethodNotAllowed('Listing members of this collection is disabled'); throw new MethodNotAllowed('Listing members of this collection is disabled');
} }
function childExists($name) { public function childExists($name): bool {
return false; return false;
} }
function delete() { public function delete() {
throw new Forbidden(); throw new Forbidden();
} }
function getName() { public function getName(): string {
return 'direct'; return 'direct';
} }
function setName($name) { public function setName($name) {
throw new Forbidden(); throw new Forbidden();
} }
function getLastModified() { public function getLastModified(): int {
return 0; return 0;
} }