|
<?php
|
|
|
|
class tx_Webdav_Controller_WebdavController {
|
|
|
|
/**
|
|
* The users' file Storages
|
|
*
|
|
* @var \TYPO3\CMS\Core\Resource\ResourceStorage[]
|
|
*/
|
|
protected $storages = NULL;
|
|
|
|
/**
|
|
* @var string The base uri of the server
|
|
*/
|
|
private $baseUri = null;
|
|
|
|
/**
|
|
* @var string The Realm of the server
|
|
*/
|
|
private $realm = null;
|
|
|
|
/**
|
|
* @var Sabre_HTTP_BasicAuth
|
|
*/
|
|
private $auth;
|
|
|
|
/**
|
|
* @var Sabre_DAV_ObjectTree
|
|
*/
|
|
private $objectTree;
|
|
|
|
function main() {
|
|
$settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['webdav']);
|
|
if($_SERVER['SERVER_NAME'] === $settings['webdavHostname']) {
|
|
$this->baseUri = dirname($_SERVER["SCRIPT_NAME"]);
|
|
$this->realm = $settings['webdavRealm'];
|
|
$this->initBeUser();
|
|
$this->initDav();
|
|
if($this->authenticate()) {
|
|
$this->buildVFS();
|
|
$this->handleRequest();
|
|
}
|
|
die();
|
|
}
|
|
}
|
|
|
|
function initBeUser() {
|
|
//global $TYPO3_CONF_VARS;
|
|
// create a new backendusersession ;) need to use basic auth here
|
|
$GLOBALS['BE_USER'] = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
|
|
$GLOBALS['BE_USER']->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
|
|
$GLOBALS['BE_USER']->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
|
|
$GLOBALS['BE_USER']->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
|
|
$GLOBALS['BE_USER']->OS = TYPO3_OS;
|
|
// deactivate caching for be user
|
|
if(version_compare(TYPO3_version,'4.5','<=')) {
|
|
$GLOBALS['BE_USER']->userTS_dontGetCached = 1;
|
|
}
|
|
$GLOBALS['BE_USER']->start();
|
|
$GLOBALS['BE_USER']->unpack_uc('');
|
|
}
|
|
function initDav() {
|
|
// sabredav initialization
|
|
require_once (t3lib_extMgm::extPath('webdav') . 'Resources/Contrib/SabreDav/vendor/autoload.php');
|
|
require_once (t3lib_extMgm::extPath('webdav') . 'Classes/class.tx_webdav_rootDirs.php');
|
|
require_once (t3lib_extMgm::extPath('webdav') . 'Classes/class.tx_webdav_browser_plugin.php');
|
|
require_once (t3lib_extMgm::extPath('webdav') . 'Classes/class.tx_webdav_permission_plugin.php');
|
|
}
|
|
function authenticate() {
|
|
|
|
$this->auth = new \Sabre\HTTP\DigestAuth();
|
|
$this->auth->init();
|
|
$this->auth->setRealm($this->realm);
|
|
$GLOBALS['BE_USER']->setBeUserByName($this->auth->getUsername());
|
|
|
|
if ($GLOBALS['BE_USER']->user['tx_webdav_acceptlogin'] != 1 || !$this->auth->validateA1($GLOBALS['BE_USER']->user['tx_webdav_password'])) {
|
|
|
|
$this->auth->requireLogin();
|
|
|
|
// Render template with fluid
|
|
$base = dirname(dirname($this->baseUri)) == '/' ? '/' : dirname(dirname($this->baseUri)) . '/';
|
|
$extRoot = $base . t3lib_extMgm::siteRelPath('webdav');
|
|
$typo3root = $base . 'typo3/';
|
|
$view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
|
|
$view->setTemplatePathAndFilename(t3lib_extMgm::extPath('webdav').'Resources/Public/Templates/accessdenied.html');
|
|
//asign
|
|
$view->assign('extRoot', $extRoot);
|
|
$view->assign('typo3Root', $typo3root);
|
|
$view->assign('sabre', array(
|
|
'version' => \Sabre\DAV\Version::VERSION,
|
|
'stability' => \Sabre\DAV\Version::STABILITY,
|
|
)
|
|
);
|
|
echo $view->render();
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
/**
|
|
* Check password of user with a given one
|
|
*
|
|
* Thanks to Georg Ringer (typo3.dev mailinglist 15.02.2012)
|
|
*
|
|
* @param array $userRecord
|
|
* @param string $password
|
|
* @return boolean
|
|
*/
|
|
private function checkUserCredentials(array $userRecord, $password) {
|
|
if(t3lib_extMgm::isLoaded('saltedpasswords', false)) {
|
|
t3lib_div::requireOnce(t3lib_extMgm::extPath('saltedpasswords', 'classes/salts/class.tx_saltedpasswords_salts_factory.php'));
|
|
$this->objInstanceSaltedPW = tx_saltedpasswords_salts_factory::getSaltingInstance($userRecord['password'], 'BE');
|
|
if (is_object($this->objInstanceSaltedPW)) {
|
|
return $this->objInstanceSaltedPW->checkPassword($password, $userRecord['password']);
|
|
}
|
|
}
|
|
return md5($password) == $userRecord['password'];
|
|
}
|
|
function buildVFS() {
|
|
// fetch filemounts
|
|
$GLOBALS['BE_USER']->fetchGroupData();
|
|
|
|
if (t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version) >= 6000000) {
|
|
$storages = $GLOBALS['BE_USER']->getFileStorages();
|
|
foreach ($storages as $storageObject) {
|
|
$storageMounts = $storageObject->getFileMounts();
|
|
if (count($storageMounts)) {
|
|
foreach ($storageMounts as $storageMountInfo) {
|
|
$fileMounts[] = array(
|
|
'path' => $storageMountInfo['folder']->getPublicUrl(),
|
|
'name' => $storageMountInfo['title'],
|
|
);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$fileMounts = $GLOBALS['BE_USER']->returnFilemounts();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
// create virtual directories for the filemounts in typo3
|
|
$mounts = array();
|
|
$mountArray = array();
|
|
foreach($fileMounts as $fileMount) {
|
|
$mountArray[] = $m = new tx_webdav_rootDirs($fileMount['path']);;
|
|
$m->setName($fileMount['name']);
|
|
}
|
|
$mounts = $mountArray; //@todo remove later on, this is just for compatibility and use the next line instead
|
|
#$mounts[] = new Sabre_DAV_SimpleCollection('T3 - Mounts',$mountArray);
|
|
//----------------------------------------------------------------------
|
|
// add special folders for admins
|
|
if($GLOBALS['BE_USER']->isAdmin()) {
|
|
//------------------------------------------------------------------
|
|
// add root folder
|
|
if(is_dir(PATH_site)) {
|
|
$mounts[] = $m = new tx_webdav_rootDirs(PATH_site);
|
|
$m->setName('T3 - PATH_site');
|
|
}
|
|
//------------------------------------------------------------------
|
|
// add extension folder
|
|
if(is_dir(PATH_typo3conf . 'ext/')) {
|
|
$mounts[] = $m = new tx_webdav_rootDirs(PATH_site.'typo3conf/ext/');
|
|
$m->setName('T3 - PATH_typo3conf-ext');
|
|
}
|
|
//------------------------------------------------------------------
|
|
// add typo3conf folder
|
|
if(is_dir(PATH_typo3conf)) {
|
|
$mounts[] = $m = new tx_webdav_rootDirs(PATH_site.'typo3conf/');
|
|
$m->setName('T3 - PATH_typo3conf');
|
|
}
|
|
//------------------------------------------------------------------
|
|
// add t3lib folder
|
|
if(is_dir(PATH_site.'typo3temp/')) {
|
|
$mounts[] = $m = new tx_webdav_rootDirs(PATH_site.'typo3temp/');
|
|
$m->setName('T3 - PATH_t3temp');
|
|
}
|
|
//------------------------------------------------------------------
|
|
// add user home folder
|
|
if(is_dir($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'])) {
|
|
$userDirs = array();
|
|
$userDirArray = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
|
'uid,username',
|
|
'be_users',
|
|
'',
|
|
'',
|
|
'username'
|
|
);
|
|
|
|
foreach($userDirArray as $userDir) {
|
|
if(is_dir($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'].'/'.$userDir['uid'])) {
|
|
$userDirs[] = $m = new tx_webdav_rootDirs($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'].'/'.$userDir['uid']);
|
|
$m->setName($userDir['username']);
|
|
}
|
|
}
|
|
unset($userDirArray);
|
|
if(count($userDirs)>0) {
|
|
$mounts[] = $m = new Sabre\DAV\SimpleCollection('T3 - HomePathForUser',$userDirs);
|
|
}
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
// add group folder
|
|
if(is_dir($GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'])) {
|
|
$groupDirs = array();
|
|
$groupDirArray = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
|
'uid,title',
|
|
'be_groups',
|
|
'',
|
|
'',
|
|
'title'
|
|
);
|
|
foreach($groupDirArray as $groupDir) {
|
|
if(is_dir($GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'].'/'.$groupDir['uid'])) {
|
|
$groupDirs[] = $m = new tx_webdav_rootDirs($GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'].'/'.$groupDir['uid']);
|
|
$m->setName($groupDir['title']);
|
|
}
|
|
}
|
|
unset($groupDirArray);
|
|
if(count($groupDirs)>0) {
|
|
$mounts[] = $m = new Sabre\DAV\SimpleCollection('T3 - HomePathForGroup',$groupDirs);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$root = new Sabre\DAV\SimpleCollection('root',$mounts);
|
|
$this->objectTree = new Sabre\DAV\ObjectTree($root);
|
|
|
|
}
|
|
function handleRequest() {
|
|
// configure dav server
|
|
$server = new \Sabre\DAV\Server($this->objectTree);
|
|
//$server = new \Sabre\DAV\Server(new \Sabre\DAV\FS\Directory('fileadmin'));
|
|
|
|
$server->setBaseUri($this->baseUri);
|
|
|
|
// add plugins
|
|
$lockBackend = new Sabre\DAV\Locks\Backend\File('temp/dav/locksdb');
|
|
$server->addPlugin(new Sabre\DAV\Locks\Plugin($lockBackend));
|
|
$server->addPlugin(new Sabre\DAV\Mount\Plugin());
|
|
$server->addPlugin(new tx_webdav_browser_plugin());
|
|
$server->addPlugin(new tx_webdav_permission_plugin());
|
|
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
|
|
$server->addPlugin(new \Sabre\DAV\TemporaryFileFilterPlugin('temp/dav'));
|
|
|
|
//----------------------------------------------------------------------
|
|
// start server
|
|
$server->exec();
|
|
}
|
|
}
|