Detect removed public shares
This commit is contained in:
parent
99960d7747
commit
1c43081d38
|
@ -19,23 +19,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scanAll() {
|
public function scanAll() {
|
||||||
$remote = $this->storage->getRemote();
|
$data = $this->storage->getShareInfo();
|
||||||
$token = $this->storage->getToken();
|
|
||||||
$password = $this->storage->getPassword();
|
|
||||||
$url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
|
|
||||||
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
|
||||||
http_build_query(array('password' => $password)));
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
$data = json_decode($result, true);
|
|
||||||
if ($data['status'] === 'success') {
|
if ($data['status'] === 'success') {
|
||||||
$this->addResult($data['data'], '');
|
$this->addResult($data['data'], '');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,11 @@ namespace OCA\Files_Sharing\External;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Storage\DAV;
|
use OC\Files\Storage\DAV;
|
||||||
|
use OC\ForbiddenException;
|
||||||
use OCA\Files_Sharing\ISharedStorage;
|
use OCA\Files_Sharing\ISharedStorage;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\Files\StorageInvalidException;
|
||||||
|
use OCP\Files\StorageNotAvailableException;
|
||||||
|
|
||||||
class Storage extends DAV implements ISharedStorage {
|
class Storage extends DAV implements ISharedStorage {
|
||||||
/**
|
/**
|
||||||
|
@ -108,6 +112,8 @@ class Storage extends DAV implements ISharedStorage {
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $time
|
* @param int $time
|
||||||
|
* @throws \OCP\Files\StorageNotAvailableException
|
||||||
|
* @throws \OCP\Files\StorageInvalidException
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasUpdated($path, $time) {
|
public function hasUpdated($path, $time) {
|
||||||
|
@ -117,6 +123,75 @@ class Storage extends DAV implements ISharedStorage {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->updateChecked = true;
|
$this->updateChecked = true;
|
||||||
return parent::hasUpdated('', $time);
|
try {
|
||||||
|
return parent::hasUpdated('', $time);
|
||||||
|
} catch (StorageNotAvailableException $e) {
|
||||||
|
// see if we can find out why the share is unavailable\
|
||||||
|
try {
|
||||||
|
$this->getShareInfo();
|
||||||
|
} catch (NotFoundException $shareException) {
|
||||||
|
// a 404 can either mean that the share no longer exists or there is no ownCloud on the remote
|
||||||
|
if ($this->testRemote()) {
|
||||||
|
// valid ownCloud instance means that the public share no longer exists
|
||||||
|
// since this is permanent (re-sharing the file will create a new token)
|
||||||
|
// we mark the storage as invalid
|
||||||
|
throw new StorageInvalidException();
|
||||||
|
} else {
|
||||||
|
// ownCloud instance is gone, likely to be a temporary server configuration error
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
} catch(\Exception $shareException) {
|
||||||
|
// todo, maybe handle 403 better and ask the user for a new password
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if the configured remote is a valid ownCloud instance
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function testRemote() {
|
||||||
|
try {
|
||||||
|
$result = file_get_contents($this->remote . '/status.php');
|
||||||
|
$data = json_decode($result);
|
||||||
|
return is_object($data) and !empty($data->version);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShareInfo() {
|
||||||
|
$remote = $this->getRemote();
|
||||||
|
$token = $this->getToken();
|
||||||
|
$password = $this->getPassword();
|
||||||
|
$url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||||
|
http_build_query(array('password' => $password)));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
|
||||||
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
switch ($status) {
|
||||||
|
case 401:
|
||||||
|
case 403:
|
||||||
|
throw new ForbiddenException();
|
||||||
|
case 404:
|
||||||
|
throw new NotFoundException();
|
||||||
|
case 500:
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($result, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public interface of ownCloud for apps to use.
|
||||||
|
* Files/AlreadyExistsException class
|
||||||
|
*/
|
||||||
|
|
||||||
|
// use OCP namespace for all classes that are considered public.
|
||||||
|
// This means that they should be used by apps instead of the internal ownCloud classes
|
||||||
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage has invalid configuration
|
||||||
|
*/
|
||||||
|
class StorageInvalidException extends \Exception {
|
||||||
|
}
|
|
@ -15,5 +15,8 @@
|
||||||
// This means that they should be used by apps instead of the internal ownCloud classes
|
// This means that they should be used by apps instead of the internal ownCloud classes
|
||||||
namespace OCP\Files;
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage is temporarily not available
|
||||||
|
*/
|
||||||
class StorageNotAvailableException extends \Exception {
|
class StorageNotAvailableException extends \Exception {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue