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

Commit

Permalink
Move back the remote share /dav/ to root, do not create virtual folde…
Browse files Browse the repository at this point in the history
…r anymore. For files, both the / and the /filename.ext send the same answer (stat of the file).
  • Loading branch information
cdujeu committed Mar 1, 2016
1 parent 499a755 commit d71a66e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/core.ocs/src/Model/RemoteShare.php
Expand Up @@ -126,7 +126,7 @@ public function buildVirtualRepository(){
"DRIVER" => "webdav",
"DRIVER_OPTIONS"=> array(
"HOST" => $parts["scheme"]."://".$parts["host"],
"PATH" => $parts["path"].($this->isDocumentIsLeaf()? "":"/".$this->getDocumentName()),
"PATH" => $parts["path"],
"USER" => $this->getOcsToken(),
"PASS" => ($this->hasPassword()?$this->getPassword() : ""),
"DEFAULT_RIGHTS"=> "",
Expand Down
92 changes: 67 additions & 25 deletions core/src/plugins/core.ocs/src/Server/Dav/Server.php
Expand Up @@ -26,14 +26,21 @@

use Sabre;

class Server
class Server extends Sabre\DAV\Server
{
var $rootCollection;
var $uniqueBaseFile;

public function __construct()
{
$this->rootCollection = new \AJXP_Sabre_Collection("/", null, null);
parent::__construct($this->rootCollection);
}

/**
* @param $baseUri
* @return \AJXP_Sabre_Collection|SharingCollection
* @throws \Exception
* @return string
*/
protected function initCollectionForFileOrFolder(&$baseUri){
protected function pointToBaseFile(){
try{
$testBackend = new BasicAuthNoPass();
$userPass = $testBackend->getUserPass();
Expand All @@ -42,33 +49,31 @@ protected function initCollectionForFileOrFolder(&$baseUri){
$shareData = $shareStore->loadShare($userPass[0]);
if(isSet($shareData) && isSet($shareData["REPOSITORY"])){
$repo = \ConfService::getRepositoryById($shareData["REPOSITORY"]);
if(!empty($repo) && !$repo->hasContentFilter()){
$baseDir = basename($repo->getOption("PATH"));
if(!empty($repo) && $repo->hasContentFilter()){
return "/".$repo->getContentFilter()->getUniquePath();
}
}
}
}catch (\Exception $e){}
$rootCollection = new \AJXP_Sabre_Collection("/", null, null);
if(isSet($baseDir)){
$currentPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if($currentPath == $baseUri || $currentPath == $baseUri."/"){
$rootCollection = new SharingCollection("/", null, null);
}else{
$baseUri .= "/$baseDir";
}
return null;
}

public function calculateUri($uri) {
$uri = parent::calculateUri($uri);
if(!empty($this->uniqueBaseFile) && '/'.$uri !== $this->uniqueBaseFile){
$uri.= $this->uniqueBaseFile;
}
return $rootCollection;
return $uri;
}

public function start($baseUri = "/"){

$rootCollection = $this->initCollectionForFileOrFolder($baseUri);
$server = new Sabre\DAV\Server($rootCollection);
$server->setBaseUri($baseUri);
$this->uniqueBaseFile = $this->pointToBaseFile();
$this->setBaseUri($baseUri);

$authBackend = new AuthSharingBackend($rootCollection);
$authBackend = new AuthSharingBackend($this->rootCollection);
$authPlugin = new Sabre\DAV\Auth\Plugin($authBackend, \ConfService::getCoreConf("WEBDAV_DIGESTREALM"));
$server->addPlugin($authPlugin);
$this->addPlugin($authPlugin);

if (!is_dir(AJXP_DATA_PATH."/plugins/server.sabredav")) {
mkdir(AJXP_DATA_PATH."/plugins/server.sabredav", 0755);
Expand All @@ -79,19 +84,56 @@ public function start($baseUri = "/"){

$lockBackend = new Sabre\DAV\Locks\Backend\File(AJXP_DATA_PATH."/plugins/server.sabredav/locks");
$lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$this->addPlugin($lockPlugin);

if (\ConfService::getCoreConf("WEBDAV_BROWSER_LISTING")) {
$browerPlugin = new \AJXP_Sabre_BrowserPlugin((isSet($repository)?$repository->getDisplay():null));
$extPlugin = new Sabre\DAV\Browser\GuessContentType();
$server->addPlugin($browerPlugin);
$server->addPlugin($extPlugin);
$this->addPlugin($browerPlugin);
$this->addPlugin($extPlugin);
}
try {
$server->exec();
$this->exec();
} catch ( \Exception $e ) {
\AJXP_Logger::error(__CLASS__,"Exception",$e->getMessage());
}
}

/**
* Not used for the moment
* This will expose folder as /dav/FolderName and file as /dav/FileName.txt
*
* @param $baseUri
* @return \AJXP_Sabre_Collection|SharingCollection
* @throws \Exception
*/
protected function initCollectionForFileOrFolderAsUniqueItem(&$baseUri){
try{
$testBackend = new BasicAuthNoPass();
$userPass = $testBackend->getUserPass();
if(isSet($userPass[0])){
$shareStore = new \ShareStore(\ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"));
$shareData = $shareStore->loadShare($userPass[0]);
if(isSet($shareData) && isSet($shareData["REPOSITORY"])){
$repo = \ConfService::getRepositoryById($shareData["REPOSITORY"]);
if(!empty($repo) && !$repo->hasContentFilter()){
$baseDir = basename($repo->getOption("PATH"));
}
}
}
}catch (\Exception $e){}
$rootCollection = new \AJXP_Sabre_Collection("/", null, null);
if(isSet($baseDir)){
$currentPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if($currentPath == $baseUri || $currentPath == $baseUri."/"){
$rootCollection = new SharingCollection("/", null, null);
}else{
$baseUri .= "/$baseDir";
}
}
return $rootCollection;
}



}

0 comments on commit d71a66e

Please sign in to comment.