Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Added layer between pydio and pydio.dav to handle auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Feb 23, 2016
1 parent a546674 commit 819e7bb
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 74 deletions.
15 changes: 14 additions & 1 deletion core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1616,6 +1616,19 @@ public static function safeParseUrl($path)
return $parts;
}

/**
* Sanitize a URL removin all unwanted / trailing slashes
*
* @param array url_parts
* return string url
*/
public function getSanitizedUrl($arr) {
$credentials = join(':', array_filter([$arr['user'], $arr['pass']]));
$hostname = join(':', array_filter([$arr['host'], $arr['port']]));
$domain = join('@', array_filter([$credentials, $hostname]));
return $arr['scheme'] . '://' . join('/', array_filter([$domain, $arr['path']]));
}

/**
* @static
* @param string $url
Expand Down Expand Up @@ -2092,5 +2105,5 @@ public static function regexpToLdap($regexp)
public static function winSetHidden($file)
{
@shell_exec("attrib +H " . escapeshellarg($file));
}
}
}
4 changes: 2 additions & 2 deletions core/src/plugins/access.webdav/composer.json
Expand Up @@ -4,8 +4,8 @@
"homepage": "http://pydio.com/",
"autoload": {
"psr-4": {
"CoreAccess\\": "../core.access/src",
"CoreAccess\\Stream\\Client\\": "./src/"
"Pydio\\Access\\Core\\": "../core.access/src",
"Pydio\\Access\\WebDAV\\": "./src/"
}
}
}
4 changes: 2 additions & 2 deletions core/src/plugins/access.webdav/manifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ajxpdriver name="webdav" enabled="false" label="CONF_MESSAGE[WebDAV]" description="CONF_MESSAGE[Access WebDAV through Guzzle and SabreDAV]" mixins="credentials_consumer,filesystem_commons,slug_provider,template_provider" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
<class_definition filename="plugins/access.webdav/class.webdavAccessDriver.php" classname="webdavAccessDriver"/>
<class_definition filename="plugins/access.webdav/vendor/autoload.php" classname="Pydio\Access\WebDAV\Driver"/>
<client_settings icon="plugins/access.fs/icon.png" description_template="{HOST}/{PATH}" iconClass="icon-sitemap">
<resources>
<i18n namespace="dav_access" path="plugins/access.webdav/i18n"/>
Expand All @@ -22,5 +22,5 @@
<dependencies>
<pluginClass pluginName="access.fs"/>
</dependencies>
<class_stream_wrapper filename="plugins/core.access/src/Stream/StreamWrapper.php" classname="CoreAccess\Stream\StreamWrapper" protocol="ajxp.dav"/>
<class_stream_wrapper filename="plugins/core.access/vendor/autoload.php" classname="Pydio\Access\WebDAV\Wrapper" protocol="ajxp.dav"/>
</ajxpdriver>
Expand Up @@ -14,14 +14,16 @@
* permissions and limitations under the License.
*/

namespace CoreAccess\Stream\Client;
namespace Pydio\Access\WebDAV;

require_once(__DIR__ . '/../../../core/classes/guzzle/vendor/autoload.php');
require_once(__DIR__ . '/../../../core/classes/sabredav/lib/Sabre/autoload.php');

use CoreAccess\Stream\StreamWrapper;
use CoreAccess\Stream\Listener\PathListener;
use CoreAccess\Stream\Iterator\DirIterator;

use Pydio\Access\Core\Stream\Client as CoreClient;
use Pydio\Access\Core\Stream\Listener\PathListener;
use Pydio\Access\Core\Stream\Iterator\DirIterator;
use Pydio\Access\Core\Stream\StreamWrapper;
use Guzzle\Service\Loader\JsonLoader;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description as GuzzleDescription;
Expand All @@ -33,9 +35,9 @@
* Client to interact with a WebDAV FS
*
*/
class DAVClient extends AbstractClient
class Client extends CoreClient
{
const PROTOCOL = "dav";
const PROTOCOL = "pydio.dav";
const RESOURCES_PATH = "Resources";
const RESOURCES_FILE = "dav.json";

Expand Down Expand Up @@ -74,7 +76,7 @@ public function __construct($config = array())
*/
public function registerStreamWrapper()
{
StreamWrapper::register($this);
StreamWrapper::register($this, self::PROTOCOL);

return $this;
}
Expand Down Expand Up @@ -113,8 +115,8 @@ private function _formatUrlStat($arr) {
private function _getSabreDAVClient($params) {
return new SabreDAVClient([
'baseUri' => $this->urlParams["scheme"] . "://" . $this->urlParams['host'],
'userName' => $params['auth'][0],
'password' => $params['auth'][1]
'userName' => $params['user'],
'password' => $params['password']
]);
}

Expand Down
Expand Up @@ -20,19 +20,16 @@
*
*/

defined('AJXP_EXEC') or die( 'Access not allowed');

use CoreAccess\Stream\Client\DAVClient;
use CoreAccess\Stream\StreamWrapper;
namespace Pydio\Access\WebDAV;

require_once __DIR__ . '/vendor/autoload.php';
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
* AJXP_Plugin to access a webdav enabled server
* @package AjaXplorer_Plugins
* @subpackage Access
*/
class webdavAccessDriver extends fsAccessDriver
class Driver extends \fsAccessDriver
{
/**
* @var Repository
Expand All @@ -58,6 +55,9 @@ public function detectStreamWrapper($register = false){
*/
public function initRepository()
{

$this->detectStreamWrapper(true);

if (is_array($this->pluginConf)) {
$this->driverConf = $this->pluginConf;
} else {
Expand All @@ -72,35 +72,23 @@ public function initRepository()

// Connexion
$settings = array(
'baseUri' => $this->getSanitizedUrl($hostParts) . "/" . trim($path, '/'),
'baseUri' => \AJXP_Utils::getSanitizedUrl($hostParts) . "/" . trim($path, '/'),
);

$this->client = new DAVClient($settings);
$this->client = new Client($settings);
$this->client->registerStreamWrapper();


// Params
$recycle = $this->repository->getOption("RECYCLE_BIN");

// Config
ConfService::setConf("PROBE_REAL_SIZE", false);
\ConfService::setConf("PROBE_REAL_SIZE", false);
$this->urlBase = "pydio://".$this->repository->getId();
if ($recycle != "") {
RecycleBinManager::init($this->urlBase, "/".$recycle);
\RecycleBinManager::init($this->urlBase, "/".$recycle);
}
}

/**
* Sanitize a URL removin all unwanted / trailing slashes
*
* @param array url_parts
* return string url
*/
public function getSanitizedUrl($arr) {
$credentials = join(':', array_filter([$arr['user'], $arr['pass']]));
$hostname = join(':', array_filter([$arr['host'], $arr['port']]));
$domain = join('@', array_filter([$credentials, $hostname]));
return $arr['scheme'] . '://' . join('/', array_filter([$domain, $arr['path']]));
}


}
79 changes: 79 additions & 0 deletions core/src/plugins/access.webdav/src/Wrapper.php
@@ -0,0 +1,79 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*
*/
namespace Pydio\Access\WebDAV;

defined('AJXP_EXEC') or die( 'Access not allowed');

require_once(AJXP_INSTALL_PATH."/plugins/access.fs/class.fsAccessWrapper.php");

/**
* @package AjaXplorer_Plugins
* @subpackage Access
*/
class Wrapper extends \fsAccessWrapper
{

const PROTOCOL = "pydio.dav";

/**
* Initialize the stream from the given path.
* Concretely, transform ajxp.dav:// into dav://
*
* @param string $path
* @return mixed Real path or -1 if currentListing contains the listing : original path converted to real path
*/
protected static function initPath($path, $streamType, $storeOpenContext = false, $skipZip = false)
{
$url = parse_url($path);
$repoId = $url["host"];
$repository = \ConfService::getRepositoryById($repoId);

if (!isSet($repository)) {
$e = new Exception("Cannot find repository with id ".$repoId);
self::$lastException = $e;
throw $e;
}

$credentials = \AJXP_Safe::tryLoadingCredentialsFromSources($url, $repository);

$default = stream_context_get_options(stream_context_get_default());

$default[self::PROTOCOL]['user'] = $credentials['user'];
$default[self::PROTOCOL]['password'] = $credentials['password'];

if (!isset($credentials['user'])) {
throw new \AJXP_Exception("Cannot find user/pass for Remote server access!");
}

$client = $default[self::PROTOCOL]['client'];
if (!isset($client)) {
throw new Exception("Client not configured");
}

$client->setConfig('defaults/request_options/auth', [$username, $password]);
stream_context_set_default($default);

$url['scheme'] = self::PROTOCOL;
return \AJXP_Utils::getSanitizedUrl($url);
}

}
Expand Up @@ -6,6 +6,6 @@
$baseDir = dirname($vendorDir);

return array(
'CoreAccess\\Stream\\Client\\' => array($baseDir . '/src'),
'CoreAccess\\' => array($baseDir . '/../core.access/src'),
'Pydio\\Access\\WebDAV\\' => array($baseDir . '/src'),
'Pydio\\Access\\Core\\' => array($baseDir . '/../core.access/src'),
);
7 changes: 5 additions & 2 deletions core/src/plugins/core.access/composer.json
@@ -1,7 +1,10 @@
{
"autoload" : {
"name": "CoreAccess",
"description": "Pydio Core Access to Filesystems",
"homepage": "https://pydio.com/",
"autoload": {
"psr-4": {
"CoreAccess\\": "src/"
"Pydio\\Access\\Core\\": "./src"
}
}
}
Expand Up @@ -19,7 +19,7 @@
* The latest code can be found at <http://pyd.io/>.
*/

namespace CoreAccess\Stream\Client;
namespace Pydio\Access\Core\Stream;

use GuzzleHttp\Command\Guzzle\GuzzleClient;

Expand All @@ -30,7 +30,7 @@
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html User guide
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html API docs
*/
abstract class AbstractClient extends GuzzleClient
class Client extends GuzzleClient implements ClientInterface
{
const LATEST_API_VERSION = '2016-01-01';

Expand Down Expand Up @@ -68,7 +68,9 @@ public function __construct__(
/**
* Register this client on the StreamWrapper
*/
public abstract function registerStreamWrapper();
public function registerStreamWrapper() {
StreamWrapper::register($this);
}

/**
* Redefine a file stat
Expand All @@ -77,7 +79,9 @@ public abstract function registerStreamWrapper();
*
* @return array Associative array containing the stats
*/
public abstract function formatUrlStat($arr);
public function formatUrlStat($arr) {
return $STAT_TEMPLATE;
}

/**
* Get a Directory Iterator based on the given array
Expand All @@ -86,7 +90,9 @@ public abstract function formatUrlStat($arr);
*
* @return DirIterator
*/
public abstract function getIterator($arr);
public function getIterator($arr) {
return new Iterator\DirIterator($arr);
}

/**
* Get the params from the passed path
Expand All @@ -98,14 +104,6 @@ public abstract function getIterator($arr);
public function getParams($path, $prefix = "")
{
$parts = parse_url($path);
$repositoryId = $parts["host"];
$repository = \ConfService::getRepositoryById($repositoryId);
$credentials = \AJXP_Safe::tryLoadingCredentialsFromSources($parts, $repository);

$username = $credentials["user"];
$password = $credentials["password"];

$this->setConfig('defaults/request_options/auth', [$username, $password]);

$parts[$prefix . 'path'] = $parts['path'];

Expand Down

0 comments on commit 819e7bb

Please sign in to comment.