pass notification and authentication service to ServeRequest

This commit is contained in:
Uwe Steinmann 2022-11-29 10:44:19 +01:00
parent f7ebe88822
commit e9b3b25b64
2 changed files with 50 additions and 78 deletions

View File

@ -39,7 +39,7 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) {
include("webdav.php");
$server = new HTTP_WebDAV_Server_SeedDMS();
$server->ServeRequest($dms, $logger, $notifier);
$server->ServeRequest($dms, $settings, $logger, $notifier, $authenticator);
//$files = array();
//$options = array('path'=>'/Test1/subdir', 'depth'=>1);
//echo $server->MKCOL(&$options);

View File

@ -32,7 +32,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
var $logger = null;
/**
* A reference to a notifier
* A reference to a notification service
*
* This is set by ServeRequest
*
@ -41,6 +41,16 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
var $notifier = null;
/**
* A reference to the authentication service
*
* This is set by ServeRequest
*
* @access private
* @var object
*/
var $authenticator = null;
/**
* Currently logged in user
*
@ -77,7 +87,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
* @access public
* @param object $dms reference to DMS
*/
function ServeRequest($dms = null, $logger = null, $notifier = null) /* {{{ */
function ServeRequest($dms = null, $settings = null, $logger = null, $notifier = null, $authenticator = null) /* {{{ */
{
// set root directory, defaults to webserver document root if not set
if ($dms) {
@ -86,12 +96,22 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
return false;
}
// set settings
if ($settings) {
$this->settings = $settings;
} else {
return false;
}
// set logger
$this->logger = $logger;
// set notifier
// set notification service
$this->notifier = $notifier;
// set authentication service
$this->authenticator = $authenticator;
// special treatment for litmus compliance test
// reply on its identifier header
// not needed for the test itself but eases debugging
@ -148,12 +168,11 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function check_auth($type, $user, $pass) /* {{{ */
{
global $settings;
if($this->logger)
$this->logger->log('check_auth: type='.$type.', user='.$user.'', PEAR_LOG_INFO);
$controller = Controller::factory('Login', array('dms'=>$this->dms));
$controller->setParam('authenticator', $this->authenticator);
$controller->setParam('login', $user);
$controller->setParam('pwd', $pass);
$controller->setParam('source', 'webdav');
@ -171,51 +190,6 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$this->user = $controller->getUser();
return true;
$userobj = false;
/* Authenticate against LDAP server {{{ */
if (!$userobj && isset($settings->_ldapHost) && strlen($settings->_ldapHost)>0) {
require_once("../inc/inc.ClassLdapAuthentication.php");
$authobj = new SeedDMS_LdapAuthentication($this->dms, $settings);
$userobj = $authobj->authenticate($user, $pass);
if($userobj && $this->logger)
$this->logger->log('check_auth: type='.$type.', user='.$user.' authenticated against LDAP', PEAR_LOG_INFO);
} /* }}} */
/* Authenticate against SeedDMS database {{{ */
if(!$userobj) {
require_once("../inc/inc.ClassDbAuthentication.php");
$authobj = new SeedDMS_DbAuthentication($this->dms, $settings);
$userobj = $authobj->authenticate($user, $pass);
if($userobj && $this->logger)
$this->logger->log('check_auth: type='.$type.', user='.$user.' authenticated against database', PEAR_LOG_INFO);
} /* }}} */
if(!$userobj) {
if($this->logger)
$this->logger->log('check_auth: No such user '.$user, PEAR_LOG_NOTICE);
return false;
}
if(($userobj->getID() == $settings->_guestID) && (!$settings->_enableGuestLogin)) {
if($this->logger)
$this->logger->log('check_auth: Login as guest is not allowed', PEAR_LOG_NOTICE);
return false;
}
if($userobj->isDisabled())
return false;
if($userobj->isAdmin() && ($_SERVER['REMOTE_ADDR'] != $settings->_adminIP ) && ( $settings->_adminIP != ""))
return false;
/* Clear login failures if login was successful */
$userobj->clearLoginFailures();
$this->user = $userobj;
return true;
} /* }}} */
@ -463,6 +437,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$info["props"][] = $this->mkprop("SeedDMS:", "keywords", $keywords);
$info["props"][] = $this->mkprop("SeedDMS:", "id", $obj->getID());
$info["props"][] = $this->mkprop("SeedDMS:", "version", $content->getVersion());
if($content->getComment())
$info["props"][] = $this->mkprop("SeedDMS:", "version-comment", $content->getComment());
$status = $content->getStatus();
$info["props"][] = $this->mkprop("SeedDMS:", "status", $status['status']);
$info["props"][] = $this->mkprop("SeedDMS:", "status-comment", $status['comment']);
@ -645,7 +621,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function PUT(&$options) /* {{{ */
{
global $settings, $fulltextservice;
global $fulltextservice;
$this->log_options('PUT', $options);
@ -731,7 +707,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$name == $lc->getOriginalFileName() &&
$fileType == $lc->getFileType() &&
$mimetype == $lc->getMimeType() &&
$settings->_enableWebdavReplaceDoc) {
$this->settings->_enableWebdavReplaceDoc) {
if($this->logger)
$this->logger->log('PUT: replacing latest version', PEAR_LOG_INFO);
if(!$document->replaceContent($lc->getVersion(), $this->user, $tmpFile, $name, $fileType, $mimetype)) {
@ -749,12 +725,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$reviewers = array('i'=>[], 'g'=>[]);
$approvers = array('i'=>[], 'g'=>[]);
$workflow = null;
if($settings->_workflowMode == 'traditional' || $settings->_workflowMode == 'traditional_only_approval') {
if($settings->_workflowMode == 'traditional') {
if($this->settings->_workflowMode == 'traditional' || $this->settings->_workflowMode == 'traditional_only_approval') {
if($this->settings->_workflowMode == 'traditional') {
$reviewers = getMandatoryReviewers($document->getFolder(), $this->user);
}
$approvers = getMandatoryApprovers($document->getFolder(), $this->user);
} elseif($settings->_workflowMode == 'advanced') {
} elseif($this->settings->_workflowMode == 'advanced') {
if($workflows = $this->user->getMandatoryWorkflows()) {
$workflow = array_shift($workflows);
}
@ -803,7 +779,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/* Check if name already exists in the folder */
/*
if(!$settings->_enableDuplicateDocNames) {
if(!$this->settings->_enableDuplicateDocNames) {
if($folder->hasDocumentByName($name)) {
return "403 Forbidden";
}
@ -813,12 +789,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$reviewers = array('i'=>[], 'g'=>[]);
$approvers = array('i'=>[], 'g'=>[]);
$workflow = null;
if($settings->_workflowMode == 'traditional' || $settings->_workflowMode == 'traditional_only_approval') {
if($settings->_workflowMode == 'traditional') {
if($this->settings->_workflowMode == 'traditional' || $this->settings->_workflowMode == 'traditional_only_approval') {
if($this->settings->_workflowMode == 'traditional') {
$reviewers = getMandatoryReviewers($folder, $this->user);
}
$approvers = getMandatoryApprovers($folder, $this->user);
} elseif($settings->_workflowMode == 'advanced') {
} elseif($this->settings->_workflowMode == 'advanced') {
if($workflows = $this->user->getMandatoryWorkflows()) {
$workflow = array_shift($workflows);
}
@ -841,7 +817,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$controller->setParam('filetype', $fileType);
$controller->setParam('userfiletype', $mimetype);
$minmax = $folder->getDocumentsMinMax();
if($settings->_defaultDocPosition == 'start')
if($this->settings->_defaultDocPosition == 'start')
$controller->setParam('sequence', $minmax['min'] - 1);
else
$controller->setParam('sequence', $minmax['max'] + 1);
@ -854,8 +830,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$controller->setParam('workflow', $workflow);
$controller->setParam('notificationgroups', array());
$controller->setParam('notificationusers', array());
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
$controller->setParam('maxsizeforfulltext', $this->settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $this->settings->_defaultAccessDocs);
if(!$document = $controller()) {
// if(!$res = $folder->addDocument($name, '', 0, $this->user, '', array(), $tmpFile, $name, $fileType, $mimetype, 0, array(), array(), 0, "")) {
unlink($tmpFile);
@ -883,8 +859,6 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function MKCOL($options) /* {{{ */
{
global $settings;
$this->log_options('MKCOL', $options);
$path = $options["path"];
@ -963,7 +937,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function DELETE($options) /* {{{ */
{
global $settings, $fulltextservice;
global $fulltextservice;
$this->log_options('DELETE', $options);
@ -1036,8 +1010,6 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function MOVE($options) /* {{{ */
{
global $settings;
$this->log_options('MOVE', $options);
// no copying to different WebDAV Servers yet
@ -1112,7 +1084,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/* Set the new Folder of the source object */
if(get_class($objsource) == $this->dms->getClassname('document')) {
/* Check if name already exists in the folder */
if(!$settings->_enableDuplicateDocNames) {
if(!$this->settings->_enableDuplicateDocNames) {
if($newdocname) {
if($objdest->hasDocumentByName($newdocname)) {
return "403 Forbidden";
@ -1136,7 +1108,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
}
} elseif(get_class($objsource) == $this->dms->getClassname('folder')) {
/* Check if name already exists in the folder */
if(!$settings->_enableDuplicateSubFolderNames) {
if(!$this->settings->_enableDuplicateSubFolderNames) {
if($newdocname) {
if($objdest->hasSubFolderByName($newdocname)) {
return "403 Forbidden";
@ -1173,7 +1145,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
*/
function COPY($options) /* {{{ */
{
global $settings, $fulltextservice;
global $fulltextservice;
$this->log_options('COPY', $options);
@ -1273,7 +1245,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/* Check if name already exists in the folder */
/*
if(!$settings->_enableDuplicateDocNames) {
if(!$this->settings->_enableDuplicateDocNames) {
if($objdest->hasDocumentByName($newdocname)) {
return "403 Forbidden";
}
@ -1283,12 +1255,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$reviewers = array('i'=>[], 'g'=>[]);
$approvers = array('i'=>[], 'g'=>[]);
$workflow = null;
if($settings->_workflowMode == 'traditional' || $settings->_workflowMode == 'traditional_only_approval') {
if($settings->_workflowMode == 'traditional') {
if($this->settings->_workflowMode == 'traditional' || $this->settings->_workflowMode == 'traditional_only_approval') {
if($this->settings->_workflowMode == 'traditional') {
$reviewers = getMandatoryReviewers($objdest, $this->user);
}
$approvers = getMandatoryApprovers($objdest, $this->user);
} elseif($settings->_workflowMode == 'advanced') {
} elseif($this->settings->_workflowMode == 'advanced') {
if($workflows = $this->user->getMandatoryWorkflows()) {
$workflow = array_shift($workflows);
}
@ -1315,7 +1287,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$controller->setParam('filetype', $content->getFileType());
$controller->setParam('userfiletype', $content->getMimeType());
$minmax = $objdest->getDocumentsMinMax();
if($settings->_defaultDocPosition == 'start')
if($this->settings->_defaultDocPosition == 'start')
$controller->setParam('sequence', $minmax['min'] - 1);
else
$controller->setParam('sequence', $minmax['max'] + 1);
@ -1328,8 +1300,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$controller->setParam('workflow', $workflow);
$controller->setParam('notificationgroups', array());
$controller->setParam('notificationusers', array());
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
$controller->setParam('maxsizeforfulltext', $this->settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $this->settings->_defaultAccessDocs);
if(!$document = $controller()) {
if($this->logger)
$this->logger->log('COPY: error copying object', PEAR_LOG_ERR);