Merge branch 'seeddms-4.3.4' into develop

Conflicts:
	op/op.Login.php
This commit is contained in:
Uwe Steinmann 2014-02-21 07:53:14 +01:00
commit a14c6b85e4
9 changed files with 164 additions and 82 deletions

View File

@ -1,3 +1,9 @@
--------------------------------------------------------------------------------
Changes in version 4.3.4
--------------------------------------------------------------------------------
- clean up and test ldap authentication code
- fix handling of multivalue attributes
--------------------------------------------------------------------------------
Changes in version 4.3.3
--------------------------------------------------------------------------------

View File

@ -105,16 +105,23 @@ class SeedDMS_Core_Object { /* {{{ */
/**
* Returns an attribute of the object for the given attribute definition
*
* @return object object of class SeedDMS_Core_Attribute or false
* @return array|string value of attritbute or false. The value is an array
* if the attribute is defined as multi value
*/
function getAttributeValue($attrdef) { /* {{{ */
if (!$this->_attributes) {
$this->getAttributes();
}
if (isset($this->_attributes[$attrdef->getId()]))
return $this->_attributes[$attrdef->getId()]->getValue();
else
if (isset($this->_attributes[$attrdef->getId()])) {
$value = $this->_attributes[$attrdef->getId()]->getValue();
if($attrdef->getMultipleValues()) {
$sep = substr($value, 0, 1);
return(explode($sep, substr($value, 1)));
} else {
return $value;
}
} else
return false;
} /* }}} */
@ -122,6 +129,9 @@ class SeedDMS_Core_Object { /* {{{ */
/**
* Set an attribute of the object for the given attribute definition
*
* @param object $attrdef definition of attribute
* @param array|sting $value value of attribute, for multiple values this
* must be an array
* @return boolean true if operation was successful, otherwise false
*/
function setAttributeValue($attrdef, $value) { /* {{{ */
@ -129,6 +139,10 @@ class SeedDMS_Core_Object { /* {{{ */
if (!$this->_attributes) {
$this->getAttributes();
}
if($attrdef->getMultipleValues() && is_array($value)) {
$sep = substr($attrdef->getValueSet(), 0, 1);
$value = $sep.implode($sep, $value);
}
if(!isset($this->_attributes[$attrdef->getId()])) {
switch(get_class($this)) {
case "SeedDMS_Core_Document":

View File

@ -15,8 +15,8 @@
<date>2014-02-01</date>
<time>16:19:34</time>
<version>
<release>4.3.3</release>
<api>4.3.3</api>
<release>4.3.4</release>
<api>4.3.4</api>
</version>
<stability>
<release>stable</release>
@ -24,10 +24,7 @@
</stability>
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
<notes>
- SeedDMS_Folder::getDocuments() and SeedDMS_Folder::getSubFolders() do not
do any sorting if $orderby is not set.
- database hostname can have port seperated by ':'
- make all functions in SeedDMS_Core_File static (fixes problem with php 5.5.x)
- fix handling of multivalue attributes
</notes>
<contents>
<dir baseinstalldir="SeedDMS" name="/">
@ -586,5 +583,24 @@ New release
- new methods SeedDMS_Core_DMS::checkFolders() and SeedDMS_Core_DMS::checkDocuments()
</notes>
</release>
</release>
<date>2014-02-01</date>
<time>16:19:34</time>
<version>
<release>4.3.3</release>
<api>4.3.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
<notes>
- SeedDMS_Folder::getDocuments() and SeedDMS_Folder::getSubFolders() do not
do any sorting if $orderby is not set.
- database hostname can have port seperated by ':'
- make all functions in SeedDMS_Core_File static (fixes problem with php 5.5.x)
</notes>
</release>
</changelog>
</package>

View File

@ -58,6 +58,13 @@ if ($action == "addattrdef") {
if (is_object($dms->getAttributeDefinitionByName($name))) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_exists"));
}
if($minvalues > 1 && $multiple == 0) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_must_be_multiple"));
}
if($minvalues > $maxvalues) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_min_greater_max"));
}
$newAttrdef = $dms->addAttributeDefinition($name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset, $regex);
if (!$newAttrdef) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
@ -124,6 +131,14 @@ else if ($action == "editattrdef") {
$maxvalues = intval($_POST["maxvalues"]);
$valueset = trim($_POST["valueset"]);
$regex = trim($_POST["regex"]);
if($minvalues > 1 && $multiple == 0) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_must_be_multiple"));
}
if($minvalues > $maxvalues) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_min_greater_max"));
}
if (!$attrdef->setName($name)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}

View File

@ -231,8 +231,8 @@ if($categories) {
}
}
$oldattributes = $document->getAttributes();
if($attributes) {
$oldattributes = $document->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
@ -251,6 +251,13 @@ if($attributes) {
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
if($sequence != "keep") {
if($document->setSequence($sequence)) {

View File

@ -153,8 +153,8 @@ if(($oldcomment = $folder->getComment()) != $comment) {
}
}
$oldattributes = $folder->getAttributes();
if($attributes) {
$oldattributes = $folder->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
@ -173,6 +173,13 @@ if($attributes) {
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
}
}
if(strcasecmp($sequence, "keep")) {
if($folder->setSequence($sequence)) {

View File

@ -70,6 +70,10 @@ if ((!isset($pwd) || strlen($pwd)==0) && ($login != $guestUser->getLogin())) {
exit;
}
/* Initialy set $user to false. It will contain a valid user record
* if authentication against ldap succeeds.
* _ldapHost will only have a value if the ldap connector has been enabled
*/
$user = false;
if(isset($GLOBALS['SEEDDMS_HOOKS']['authentication'])) {
@ -83,78 +87,70 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['authentication'])) {
}
if (is_bool($user)) {
//
// LDAP Sign In
//
/* new code by doudoux - TO BE TESTED */
if (isset($settings->_ldapBaseDN)) {
$ldapSearchAttribut = "uid=";
$tmpDN = "uid=".$login.",".$settings->_ldapBaseDN;
if (isset($settings->_ldapHost) && strlen($settings->_ldapHost)>0) {
if (isset($settings->_ldapPort) && is_int($settings->_ldapPort)) {
$ds = ldap_connect($settings->_ldapHost, $settings->_ldapPort);
} else {
$ds = ldap_connect($settings->_ldapHost);
}
if (isset($settings->_ldapType)) {
if ($settings->_ldapType==1) {
$ldapSearchAttribut = "sAMAccountName=";
$tmpDN = $login.'@'.$settings->_ldapAccountDomainName;
if (!is_bool($ds)) {
/* Check if ldap base dn is set, and use ldap server if it is */
if (isset($settings->_ldapBaseDN)) {
$ldapSearchAttribut = "uid=";
$tmpDN = "uid=".$login.",".$settings->_ldapBaseDN;
}
}
/* end of new code */
if (isset($settings->_ldapHost) && strlen($settings->_ldapHost)>0) {
if (isset($settings->_ldapPort) && is_int($settings->_ldapPort)) {
$ds = ldap_connect($settings->_ldapHost, $settings->_ldapPort);
}
else {
$ds = ldap_connect($settings->_ldapHost);
}
if (!is_bool($ds)) {
// Ensure that the LDAP connection is set to use version 3 protocol.
// Required for most authentication methods, including SASL.
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// try an anonymous bind first. If it succeeds, get the DN for the user.
if (isset($settings->_ldapBindDN)) {
$bind = @ldap_bind($ds, $settings->_ldapBindDN, $settings->_ldapBindPw);
} else {
$bind = @ldap_bind($ds);
/* Active directory has a different base dn */
if (isset($settings->_ldapType)) {
if ($settings->_ldapType==1) {
$ldapSearchAttribut = "sAMAccountName=";
$tmpDN = $login.'@'.$settings->_ldapAccountDomainName;
}
$dn = false;
/* new code by doudoux - TO BE TESTED */
if ($bind) {
$search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$login);
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]>0) {
$dn = $info[0]['dn'];
}
}
}
/* end of new code */
/* old code */
if ($bind) {
$search = ldap_search($ds, $settings->_ldapBaseDN, "uid=".$login);
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]>0) {
$dn = $info[0]['dn'];
}
}
// Ensure that the LDAP connection is set to use version 3 protocol.
// Required for most authentication methods, including SASL.
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// try an authenticated/anonymous bind first.
// If it succeeds, get the DN for the user and use it for an authentication
// with the users password.
$bind = false;
if (isset($settings->_ldapBindDN)) {
$bind = @ldap_bind($ds, $settings->_ldapBindDN, $settings->_ldapBindPw);
} else {
$bind = @ldap_bind($ds);
}
$dn = false;
/* If bind succeed, then get the dn of for the user */
if ($bind) {
$search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$login);
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]>0) {
$dn = $info[0]['dn'];
}
}
/* end of old code */
}
if (is_bool($dn)) {
// This is the fallback position, in case the anonymous bind does not
// succeed.
/* new code by doudoux - TO BE TESTED */
$dn = $tmpDN;
/* old code */
//$dn = "uid=".$login.",".$settings->_ldapBaseDN;
/* If the previous bind failed, try it with the users creditionals
* by simply setting $dn to a default string
*/
if (is_bool($dn)) {
$dn = $tmpDN;
}
/* No do the actual authentication of the user */
$bind = @ldap_bind($ds, $dn, $pwd);
if ($bind) {
// Successfully authenticated. Now check to see if the user exists within
// the database. If not, add them in if _restricted is not set,
// but do not add their password.
$user = $dms->getUserByLogin($login);
if (is_bool($user) && !$settings->_restricted) {
// Retrieve the user's LDAP information.
$search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut . $login);
}
$bind = @ldap_bind($ds, $dn, $pwd);
if ($bind) {
@ -185,6 +181,7 @@ if (is_bool($user)) {
}
}
}
}
if (is_bool($user)) {
//

View File

@ -186,7 +186,11 @@ function showAttributeDefinitions(selectObj) {
print "<td><a href=\"../out/out.ViewDocument.php?documentid=".$doc->getID()."\">" . htmlspecialchars($doc->getName()) . "</a></td>\n";
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".getOverallStatusText($status["status"])."</td>";
print "<td>".$doc->getAttributeValue($attrdef)."</td>";
$value = $doc->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditDocument.php?documentid=".$doc->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>\n";
@ -209,7 +213,11 @@ function showAttributeDefinitions(selectObj) {
print "<td><i class=\"icon-folder-close-alt\"></i></td>";
print "<td><a href=\"../out/out.ViewFolder.php?folderid=".$folder->getID()."\">" . htmlspecialchars($folder->getName()) . "</a></td>\n";
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".$folder->getAttributeValue($attrdef)."</td>";
$value = $folder->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditFolder.php?folderid=".$folder->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>";
@ -237,7 +245,11 @@ function showAttributeDefinitions(selectObj) {
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".$content->getMimeType()."</td>";
print "<td>".$content->getVersion()."</td>";
print "<td>".$content->getAttributeValue($attrdef)."</td>";
$value = $content->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditDocument.php?documentid=".$doc->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>\n";

View File

@ -878,13 +878,21 @@ function folderSelected<?php echo $formName ?>(id, name) {
function printAttributeEditField($attrdef, $objvalue, $fieldname='attributes') { /* {{{ */
if($valueset = $attrdef->getValueSetAsArray()) {
echo "<select name=\"".$fieldname."[".$attrdef->getId()."]\">";
if($attrdef->getMinValues() < 1) {
echo "<select name=\"".$fieldname."[".$attrdef->getId()."]";
if($attrdef->getMultipleValues()) {
echo "[]\" multiple";
} else {
echo "\"";
}
echo ">";
if(!$attrdef->getMultipleValues()) {
echo "<option value=\"\"></option>";
}
foreach($valueset as $value) {
echo "<option value=\"".htmlspecialchars($value)."\"";
if($value == $objvalue)
if(is_array($objvalue) && in_array($value, $objvalue))
echo " selected";
elseif($value == $objvalue)
echo " selected";
echo ">".htmlspecialchars($value)."</option>";
}