Permalink
Browse files

Fixing the remote ocs with new webdav

  • Loading branch information...
1 parent 291836f commit 378dfb023c8ed2c23951138c6a8736893f064f99 @ghecquet ghecquet committed Jun 28, 2016
@@ -60,7 +60,7 @@ public static function detectBasicHeader()
{
if(isSet($_SERVER["PHP_AUTH_USER"])) return true;
if(isSet($_SERVER["HTTP_AUTHORIZATION"])) $value = $_SERVER["HTTP_AUTHORIZATION"];
- if(!isSet($value) && isSet($_SERVER["REDIRECT_HTTP_AUTHORIZATION"])) $value = $_SERVER["HTTP_AUTHORIZATION"];
+ if(!isSet($value) && isSet($_SERVER["REDIRECT_HTTP_AUTHORIZATION"])) $value = $_SERVER["REDIRECT_HTTP_AUTHORIZATION"];
if(!isSet($value)) return false;
return (strpos(strtolower($value),'basic') ===0) ;
}
@@ -123,10 +123,10 @@ public function addOption($oName, $oValue);
/**
* @param ContextInterface $ctx
* @param string $oName
+ * @param null $default
* @return mixed
- * @throws \Pydio\Core\Exception\PydioException
*/
- public function getContextOption(ContextInterface $ctx, $oName);
+ public function getContextOption(ContextInterface $ctx, $oName, $default=null);
/**
* @param string $oName
@@ -67,7 +67,11 @@ protected function initRepository(ContextInterface $context)
{
$this->detectStreamWrapper(true);
+ $repository = $context->getRepository();
+ $resourcesFile = $repository->getContextOption($context, "API_RESOURCES_FILE", __DIR__ . "/" . self::RESOURCES_PATH . "/" . self::RESOURCES_FILE);
+
Stream::addContextOption($context, [
+ "resources" => $resourcesFile,
"subscribers" => [
new PathSubscriber(),
new WebDAVSubscriber()
@@ -88,7 +92,7 @@ public static function convertPath($node) {
$ctx = $node->getContext();
$repository = $node->getRepository();
- $basePath = $repository->getContextOption($ctx, "PATH");
+ $basePath = ltrim($repository->getContextOption($ctx, "PATH"), "/");
$path = $node->getPath();
if (isset($path)) {
@@ -21,10 +21,9 @@
namespace Pydio\Access\Core;
+use Normalizer;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Access\Core\Model\AJXP_Node;
-use Pydio\Access\Core\Stream\Stream;
-use Pydio\Access\Core\Stream\StreamWrapper;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\PluginFramework\PluginsService;
@@ -399,7 +398,9 @@ protected function innerReadDirFiltered($resource){
if($test === false || $test == "." || $test == ".."){
return $test;
}
- $test = \Normalizer::normalize($test);
+ if (class_exists("Normalizer")) {
+ $test = Normalizer::normalize($test);
+ }
if($this->currentUniquePath == $test) {
return $test;
}
@@ -350,10 +350,11 @@ public function getSafeOption($oName){
/**
* @param ContextInterface $ctx
* @param string $oName
+ * @param null $default
* @return mixed
- * @throws \Pydio\Core\Exception\PydioException
+ * @throws PydioException
*/
- public function getContextOption(ContextInterface $ctx, $oName){
+ public function getContextOption(ContextInterface $ctx, $oName, $default = null){
if(isSet($this->inferOptionsFromParent) && isSet($this->parentId)){
$parentTemplateObject = RepositoryService::getRepositoryById($this->parentId);
if(empty($parentTemplateObject) || !is_a($parentTemplateObject, "Repository")) {
@@ -375,9 +376,9 @@ public function getContextOption(ContextInterface $ctx, $oName){
return VarsFilter::filter($this->options[$oName], $ctx);
}
if ($this->inferOptionsFromParent && isset($parentTemplateObject)) {
- return $parentTemplateObject->getContextOption($ctx, $oName);
+ return $parentTemplateObject->getContextOption($ctx, $oName);
}
- return null;
+ return $default;
}
@@ -35,7 +35,9 @@ public function __construct(
throw new \Exception("Cannot find user/pass for Remote Access!");
}
- $auth = [$user, $password, 'digest'];
+ $authScheme = Stream::getContextOption($this->context, "authScheme", "basic");
+
+ $auth = [$user, $password, $authScheme];
Stream::addContextOption($this->context, [
"auth" => $auth
@@ -70,8 +70,6 @@ public function __construct(
$apiUrl = $repository->getContextOption($ctx, "API_URL");
$host = $repository->getContextOption($ctx, "HOST");
$uri = $repository->getContextOption($ctx, "URI");
- $resourcePath = $repository->getContextOption($ctx, "API_RESOURCES_PATH");
- $resourceFile = $repository->getContextOption($ctx, "API_RESOURCES_FILE");
if ($apiUrl == "") {
$apiUrl = $options["api_url"];
@@ -81,26 +79,18 @@ public function __construct(
}
}
- if ($resourcePath == "") {
- $resourcePath = $options["api_resources_path"];
- }
-
- if ($resourceFile == "") {
- $resourceFile = $options["api_resources_file"];
- }
-
$options["base_url"] = $apiUrl;
- $default = stream_context_get_options(stream_context_get_default());;
- $options["defaults"] = $default[$node->getScheme()];
+ $options["defaults"] = self::getContextOption($ctx);
+ $resources = $options["defaults"]["resources"];
+ $options["defaults"] = array_intersect_key($options["defaults"], ["subscribers" => "", "auth" => ""]);
// Creating Guzzle instances
$httpClient = new HTTPClient($options);
- $locator = new FileLocator([$resourcePath]);
+ $locator = new FileLocator([dirname($resources)]);
$jsonLoader = new JsonLoader($locator);
- $description = $jsonLoader->load($locator->locate($resourceFile));
+ $description = $jsonLoader->load($locator->locate(basename($resources)));
$description = new Description($description);
$client = new GuzzleClient($httpClient, $description, $options);
-
foreach ($options["defaults"]["subscribers"] as $subscriber) {
$client->getEmitter()->attach($subscriber);
}
@@ -145,18 +135,18 @@ public static function addContextOption(ContextInterface $ctx, array $arr) {
stream_context_set_default($default);
}
- public static function getContextOption(ContextInterface $ctx, $key = null) {
- $default = stream_context_get_options(stream_context_get_default());
+ public static function getContextOption(ContextInterface $ctx, $key = null, $default = null) {
+ $options = stream_context_get_options(stream_context_get_default());
$contextKey = "access." . $ctx->getRepository()->getAccessType();
- if ($key != null && isset($default[$contextKey][$key])) {
- return $default[$contextKey][$key];
+ if ($key != null && isset($options[$contextKey][$key])) {
+ return $options[$contextKey][$key];
} elseif ($key == null) {
- return $default[$contextKey];
+ return $options[$contextKey];
}
- return null;
+ return $default;
}
public function __toString()
@@ -226,8 +226,8 @@ public static function createStream($path) {
$repository = $node->getRepository();
$ctx = $node->getContext();
- $useAuthStream = $repository->getContextOption($ctx, "USE_AUTH_STREAM");
- $useOAuthStream = $repository->getContextOption($ctx, "USE_OAUTH_STREAM");
+ $useAuthStream = $repository->getContextOption($ctx, "USE_AUTH_STREAM", true);
+ $useOAuthStream = $repository->getContextOption($ctx, "USE_OAUTH_STREAM", false);
$nodeStream = Stream::factory($node);
if ($useAuthStream) $nodeStream = new AuthStream($nodeStream, $node);
@@ -23,8 +23,10 @@
use Pydio\Core\Services\ConfService;
use Pydio\Core\Utils\Vars\InputFilter;
+use Pydio\Log\Core\Logger;
use Pydio\OCS\Client\OCSClient;
use Pydio\OCS\Model\SQLStore;
+use Symfony\Component\Config\Definition\Exception\Exception;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -56,19 +58,24 @@ public function switchActions($actionName, $httpVars, $fileVars){
$remoteShare = $store->remoteShareById($remoteShareId);
if($remoteShare !== null){
$client = new OCSClient();
- $client->declineInvitation($remoteShare);
+ try {
+ $client->declineInvitation($remoteShare);
+ } catch (\Exception $e) {
+ // If the reject fails, we still want the share to be removed from the db
+ Logger::error(__CLASS__,"Exception",$e->getMessage());
+ }
$store->deleteRemoteShare($remoteShare);
ConfService::getInstance()->invalidateLoadedRepositories();
}
break;
+
default:
+
break;
+
}
return null;
-
}
-
-
}
@@ -20,6 +20,8 @@
*/
namespace Pydio\OCS;
+use Pydio\Core\Http\Dav\Collection;
+use Pydio\Core\Http\Dav\RootCollection;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\UserInterface;
@@ -28,11 +30,13 @@
use Pydio\Core\Controller\Controller;
use Pydio\Core\PluginFramework\Plugin;
use Pydio\Core\Services\ConfService;
+use Pydio\Core\Services\RepositoryService;
use Pydio\OCS\Server\Dummy;
+use Sabre\DAV\Exception\Forbidden;
defined('AJXP_EXEC') or die('Access not allowed');
-class OCSPlugin extends Plugin{
+class OCSPlugin extends Plugin {
/**
* @var ActionsController $controller
@@ -86,22 +90,19 @@ public function publishServices(){
public function route($baseUri, $endpoint, $uriParts, $parameters){
- if($endpoint == "dav" && $this->federatedEnabled()){
+ if($endpoint == "dav" && $this->federatedEnabled()) {
$server = new Server\Dav\Server();
$server->start($baseUri."/ocs/v2/dav");
- }else if($endpoint == "shares" && $this->federatedEnabled()){
+ } else if($endpoint == "shares" && $this->federatedEnabled()) {
$server = new Server\Federated\Server();
$server->run($uriParts, $parameters);
- }else{
-
+ } else {
Dummy::notImplemented($uriParts, $parameters);
-
}
-
}
/**
@@ -151,8 +152,8 @@ public function remoteRepositoryById($repositoryId, &$repoObject){
}
- public static function startServer($base, $route){
-
+ public static function startServer($base, $route) {
+
$pServ = PluginsService::getInstance(Context::emptyContext());
ConfService::$useSession = false;
AuthService::$useSession = false;
@@ -167,44 +168,43 @@ public static function startServer($base, $route){
*/
$coreLoader = $pServ->getPluginById("core.ocs");
- if( $route == "/ocs-provider"){
+ if ($route == "/ocs-provider") {
$coreLoader->publishServices();
- }else if($route == "/ocs"){
+ } else if ($route == "/ocs") {
$uri = $_SERVER["REQUEST_URI"];
$parts = explode("/", trim(parse_url($uri, PHP_URL_PATH), "/"));
$baseUri = array();
$root = array_shift($parts);
- while(!in_array($root, array("ocs-provider", "ocs")) && count($parts)){
+ while (!in_array($root, array("ocs-provider", "ocs")) && count($parts)) {
$baseUri[] = $root;
$root = array_shift($parts);
}
- if(count($parts) < 2){
+ if (count($parts) < 2) {
$d = new Dummy();
$response = $d->buildResponse("fail", "400", "Wrong URI");
$d->sendResponse($response);
return;
}
$version = array_shift($parts);
- if($version != "v2"){
+ if ($version != "v2") {
$d = new Dummy();
$response = $d->buildResponse("fail", "400", "Api version not supported - Please switch to v2.");
$d->sendResponse($response);
return;
}
$endpoint = array_shift($parts);
- if(count($baseUri)){
- $baseUriStr = "/".implode("/", $baseUri);
- }else{
+ if (count($baseUri)) {
+ $baseUriStr = "/" . implode("/", $baseUri);
+ } else {
$baseUriStr = "";
}
- $coreLoader->route($baseUriStr, $endpoint, $parts, array_merge($_GET, $_POST));
+ $coreLoader->route($baseUriStr, $endpoint, $parts, array_merge($_GET, $_POST));
}
}
-
}
Oops, something went wrong.

0 comments on commit 378dfb0

Please sign in to comment.