diff --git a/README.md b/README.md index 598953d..50c4e11 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Take a look at the [Docker Container](https://github.com/leenooks/phpLDAPadmin/w The update to v2 is progressing well - here is a list of work to do and done: -- [ ] Creating new LDAP entries +- [X] Creating new LDAP entries - [ ] Delete existing LDAP entries - [X] Updating existing LDAP Entries - [X] Password attributes diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index 4ae4c19..a60ce12 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -311,707 +311,4 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator { $this->is_rdn = TRUE; } - - /** - * Return the name of the attribute. - * - * @param boolean $lower - Return the attribute in normal or lower case (default lower) - * @param boolean $real - Return the real attribute name (with ;binary, or just the name) - * @return string Attribute name - * - public function getName($lower=true,$real=false) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); - - if ($real) - return $lower ? strtolower($this->name) : $this->name; - else - return $lower ? strtolower($this->real_attr_name()) : $this->real_attr_name(); - } - - public function getValues() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->values); - - return $this->values; - } - - public function getOldValues() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->oldvalues); - - return $this->oldvalues; - } - - public function getValueCount() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->values); - - return count($this->values); - } - - public function getSource() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->source); - - return $this->source; - } - - /** - * Autovalue is called after the attribute is initialised, and thus the values from the ldap server will be set. - * - public function autoValue($new_val) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->values) - return; - - $this->values = $new_val; - } - - public function initValue($new_val) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->values || $this->oldvalues) { - debug_dump(array('new_val'=>$new_val,'this'=>$this)); - debug_dump_backtrace('new and/or old values are set',1); - } - - $this->values = $new_val; - } - - public function clearValue() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->values = array(); - } - - public function setOldValue($val) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->oldvalues = $val; - } - - public function setValue($new_val) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->values) { - if ($this->values == $new_val) - return; - - if ($this->oldvalues) { - debug_dump($this); - debug_dump_backtrace('old values are set',1); - } else - $this->oldvalues = $this->values; - } - - if ($new_val == $this->values) - return; - - $this->values = $new_val; - $this->justModified(); - } - - public function addValue($new_val,$i=-1) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($i < 0) - $i = $this->getValueCount(); - - $old_val = $this->getValue($i); - if (is_null($old_val) || ($old_val != $new_val)) - $this->justModified(); - - $this->values[$i] = $new_val; - } - - public function delValue($i=-1) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($i < 0) - $this->setValue(array()); - - if (! $this->hasBeenModified()) - $this->oldvalues = $this->values; - - if (isset($this->values[$i])) { - unset($this->values[$i]); - $this->values = array_values($this->values); - $this->justModified(); - } - } - - public function justModified() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->modified = true; - } - - public function hasBeenModified() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->modified); - - return $this->modified; - } - - public function isForceDelete() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->forcedelete); - - return $this->forcedelete; - } - - public function setForceDelete() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->forcedelete = true; - $this->oldvalues = $this->values; - $this->values = array(); - $this->justModified(); - } - - public function isRequired() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->getMinValueCount() > 0) - return true; - elseif ($this->ldaptype == 'must') - return true; - elseif ($this->isRDN()) - return true; - else - return false; - } - - public function isMay() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (($this->ldaptype == 'may') && ! $this->isRequired()) - return true; - else - return false; - } - - public function setType($type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->type = strtolower($type); - } - - public function getType() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); - - return $this->type; - } - - public function setLDAPtype($type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->ldaptype = strtolower($type); - } - - public function getLDAPtype() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->ldaptype); - - return $this->ldaptype; - } - - public function setProperties($properties) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - foreach ($properties as $index => $value) { - if ($index == 'maxvalnb') { - $this->setMaxValueCount($value); - continue; - - } elseif ($index == 'minvalnb') { - $this->setMinValueCount($value); - continue; - - } elseif ($index == 'maxlength') { - $this->setMinValueCount($value); - continue; - - } elseif ($index == 'hidden') { - $this->visible = $value; - continue; - - } elseif (in_array($index,array('cols','rows'))) { - # @todo To be implemented - continue; - } - - if (isset($this->$index)) - $this->$index = $value; - else { - debug_dump($this); - debug_dump_backtrace(sprintf('Unknown property (%s) with value (%s) for (%s)',$index,$value,$this->getName()),1); - } - } - } - - public function setRequired() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->getMinValueCount() <= 0) - $this->setMinValueCount(1); - } - - public function setOptional() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->setMinValueCount(0); - } - - public function isReadOnly() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->readonly); - - return $this->readonly; - } - - public function setReadOnly() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->readonly = true; - } - - public function isMultiple() { - return false; - } - - public function isVisible() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $this->visible && (! $this->forcehide); - } - - public function hide() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->visible = false; - } - - public function show() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->visible = true; - } - - public function haveFriendlyName() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $_SESSION[APPCONFIG]->haveFriendlyName($this); - } - - public function getFriendlyName() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->display); - - if ($this->display) - return $this->display; - else - return $_SESSION[APPCONFIG]->getFriendlyName($this); - } - - public function setDescription($description) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->description = $description; - } - - public function getDescription() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); - - return $this->description; - } - - public function setIcon($icon) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->icon = $icon; - } - - public function getIcon() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon); - - return $this->icon ? sprintf('%s/%s',IMGDIR,$this->icon) : ''; - } - - public function getHint() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->hint); - - return $this->hint; - } - - public function setHint($hint) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->hint = $hint; - } - - public function getMaxLength() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->maxlength); - - return $this->maxlength; - } - - public function setMaxLength($maxlength) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->maxlength = $maxlength; - } - - public function getSize() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->size); - - return $this->size; - } - - public function setSize($size) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->size = $size; - } - - public function getSpacer() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->spacer); - - return $this->spacer; - } - - public function getPage() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->page); - - return $this->page; - } - public function setPage($page) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->page = $page; - } - - public function getOnChange() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->onchange); - - return $this->onchange; - } - - public function getHelper() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helper); - - return $this->helper; - } - - public function getHelperValue() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helpervalue); - - return $this->helpervalue; - } - - public function getVerify() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->verify); - - return $this->verify; - } - - /** - * Capture all the LDAP details we are interested in - * - * @param sattr Schema Attribute - * - private function setLDAPdetails($sattr) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # By default, set this as a MAY attribute, later processing should make it a MUST attribute if it is. - if (! $this->ldaptype) - $this->ldaptype = 'may'; - - # Store our Aliases - foreach ($sattr->getAliases() as $alias) - array_push($this->aliases,strtolower($alias)); - - if ($sattr->getIsSingleValue()) - $this->setMaxValueCount(1); - } - - /** - * Return a list of aliases for this Attribute (as defined by the schema) - * This list will be lowercase. - * - public function getAliases() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->aliases); - - return $this->aliases; - } - - public function getAutoValue() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->autovalue); - - return $this->autovalue; - } - - public function getPostValue() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->postvalue); - - return $this->postvalue; - } - - public function setPostValue($postvalue) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->postvalue = $postvalue; - } - - public function setXML($values) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Mostly all the time, this should be an array - if (is_array($values)) - foreach ($values as $index => $value) - switch ($index) { - # Helpers should be accompanied with a attribute. - case 'helper': - if (! isset($values['post']) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>sprintf('%s [%s]',_('Missing [post] setting in XML file'),$index), - 'body'=>_('[helper] needs an accompanying [post] action.'), - 'type'=>'warn')); - - if (isset($value['value']) && ! is_array($value['value']) && preg_match('/^=php\.(\w+)\((.*)\)$/',$value['value'],$matches)) { - $this->helpervalue['function'] = $matches[1]; - $this->helpervalue['args'] = $matches[2]; - - unset ($value['value']); - } - - foreach ($value as $i => $detail) { - if (! in_array($i,array('default','display','id','value'))) { - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$i), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting for helper will be ignored.'),$detail), - 'type'=>'warn')); - - unset($value[$i]); - } - } - - $this->$index = $value; - - break; - - case 'hidden': $value ? $this->visible = false : $this->visible = true; - break; - - case 'spacer': $value ? $this->$index = true : $this->$index = false; - break; - - # Essentially, we ignore type, it is used to select an Attribute type in the Factory. But we'll generated a warning if there is an unknown type. - case 'type': - if (! in_array($value,array('password','multiselect','select','textarea')) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting will be ignored.'),$value), - 'type'=>'warn')); - - break; - - case 'post': - if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) { - $this->postvalue['function'] = $matches[1]; - $this->postvalue['args'] = $matches[2]; - - } else - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting will be ignored.'),$value), - 'type'=>'warn')); - - case 'value': - if (is_array($value)) - foreach ($value as $x => $y) { - if (! $this->haveMoreValues()) { - system_message(array( - 'title'=>_('Automatically removed attribute values from template'), - 'body'=>sprintf('%s [%s]',_('Template defines more values than can be accepted by attribute.'),$this->getName(true)), - 'type'=>'warn')); - - $this->clearValue(); - - break; - - } else - $this->addValue($x,$y); - } - - else - # Check to see if the value is auto generated. - if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) { - $this->autovalue['function'] = $matches[1]; - $this->autovalue['args'] = $matches[2]; - - # We'll add a hint too - if (! $this->hint) - $this->hint = _('Automatically determined'); - - } else - $this->addValue($value); - - break; - - # Queries - case 'ordersort': - - # Creation/Editing Templates - case 'cols': - case 'default': - case 'display': - case 'hint': - case 'icon': - case 'maxlength': - case 'onchange': - case 'order': - case 'page': - case 'readonly': - case 'rows': - case 'size': - case 'values': - case 'verify': $this->$index = $value; - break; - - case 'max': - if ($this->getMaxValueCount() == -1) - $this->setMaxValueCount($value); - - default: - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown attribute setting will be ignored.'),serialize($value)), - 'type'=>'warn')); - } - - elseif (is_string($values) && (strlen($values) > 0)) - $this->values = array($values); - } - - /** - * Display the values removed in an attribute. - * - public function getRemovedValues() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return array_diff($this->getOldValues(),$this->getValues()); - } - - /** - * Display the values removed in an attribute. - * - public function getAddedValues() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return array_diff($this->getValues(),$this->getOldValues()); - } - - /** - * Prunes off anything after the ";" in an attr name. This is useful for - * attributes that may have ";binary" appended to their names. With - * real_attr_name(), you can more easily fetch these attributes' schema - * with their "real" attribute name. - * - * @param string $attr_name The name of the attribute to examine. - * @return string - * - private function real_attr_name() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); - - return preg_replace('/;.*$/U','',$this->name); - } - - /** - * Does this attribute need supporting JS - * - public function needJS($type=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (is_null($type)) { - foreach (array('focus','blur','validate') as $type) - if ($this->needJS($type)) - return true; - - return false; - - } elseif ($type == 'focus') { - # We dont have any focus javascript routines. - return false; - - } elseif ($type == 'blur') { - if ($this->onchange || $this->isRequired()) - return true; - else - return false; - - } elseif ($type == 'validate') { - if ($this->isRequired()) - return true; - else - return false; - - } else - debug_dump_backtrace(sprintf('Unknown JS request %s',$type),1); - } - */ } \ No newline at end of file diff --git a/app/Classes/LDAP/Schema/AttributeType.php b/app/Classes/LDAP/Schema/AttributeType.php index 25ddc8e..49d8f84 100644 --- a/app/Classes/LDAP/Schema/AttributeType.php +++ b/app/Classes/LDAP/Schema/AttributeType.php @@ -418,18 +418,6 @@ final class AttributeType extends Base { return $this->ordering; } - /** - * Gets the list of "required by" objectClasses, that is the list of objectClasses - * which provide must have attribute. - * - * @return array An array of names of objectclasses (strings) which provide this attribute - */ - public function getRequiredByObjectClasses() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->required_by_object_classes); - - return $this->required_by_object_classes; - } /** * Gets this attribute's substring matching specification * @@ -465,29 +453,6 @@ final class AttributeType extends Base { return $this->syntax_oid; } - /** - * Gets this attribute's raw syntax string (ie: "1.2.3.4{16}"). - * - * @return string The raw syntax string - */ - public function getSyntaxString() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->syntax); - - return $this->syntax; - } - - /** - * Gets this attribute's type - * - * @return string The attribute's type. - * @deprecated use $this->type; - */ - public function getType() - { - return $this->type; - } - /** * Gets this attribute's usage string as defined by the LDAP server * @@ -511,23 +476,6 @@ final class AttributeType extends Base { return $this->used_in_object_classes; } - /** - * Returns whether the specified attribute is an alias for this one (based on this attribute's alias list). - * - * @param string $attr_name The name of the attribute to check. - * @return boolean TRUE if the specified attribute is an alias for this one, or FALSE otherwise. - */ - public function isAliasFor($attr_name) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); - - foreach ($this->aliases as $alias_attr_name) - if (strcasecmp($alias_attr_name,$attr_name) == 0) - return TRUE; - - return FALSE; - } - /** * @return bool * @deprecated use $this->forced_as_may @@ -563,9 +511,6 @@ final class AttributeType extends Base { * This function will mark this attribute as a forced MAY attribute */ public function setForceMay() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); - $this->forced_as_may = TRUE; } @@ -589,18 +534,6 @@ final class AttributeType extends Base { $this->sup_attribute = trim($attr); } - /** - * Sets this attribute's type. - * - * @param string $type The new type. - */ - public function setType($type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->type = $type; - } - /** * Return Request validation array * diff --git a/app/Classes/LDAP/Server.php b/app/Classes/LDAP/Server.php index cf9124c..cf2e369 100644 --- a/app/Classes/LDAP/Server.php +++ b/app/Classes/LDAP/Server.php @@ -338,16 +338,6 @@ final class Server break; - /* - case 'matchingruleuse': - if (isset($this->matchingruleuse)) - return is_null($key) ? $this->matchingruleuse : $this->matchingruleuse->get($key); - else - $this->matchingruleuse = collect(); - - break; - */ - case 'objectclasses': if (isset($this->objectclasses)) return $this->objectclasses; @@ -381,21 +371,6 @@ final class Server $o = new AttributeType($line); $this->attributetypes->put($o->name_lc,$o); - - /* - if (isset($syntaxes[$attr->getSyntaxOID()])) { - $syntax = $syntaxes[$attr->getSyntaxOID()]; - $attr->setType($syntax->getDescription()); - } - $this->attributetypes[$attr->getName()] = $attr; - */ - - /** - * bug 856832: create an entry in the $attrs_oid array too. This - * will be a ref to the $attrs entry for maintenance and performance - * reasons - */ - //$attrs_oid[$attr->getOID()] = &$attrs[$attr->getName()]; } // go back and add data from aliased attributeTypes diff --git a/config/config.php.example b/config/config.php.example deleted file mode 100644 index f19408a..0000000 --- a/config/config.php.example +++ /dev/null @@ -1,568 +0,0 @@ -custom variable to do so. - * For example, the default for defining the language in config_default.php - * - * $this->default->appearance['language'] = array( - * 'desc'=>'Language', - * 'default'=>'auto'); - * - * to override this, use $config->custom->appearance['language'] = 'en_EN'; - * - * This file is also used to configure your LDAP server connections. - * - * You must specify at least one LDAP server there. You may add - * as many as you like. You can also specify your language, and - * many other options. - * - * NOTE: Commented out values in this file prefixed by //, represent the - * defaults that have been defined in config_default.php. - * Commented out values prefixed by #, dont reflect their default value, you can - * check config_default.php if you want to see what the default is. - * - * DONT change config_default.php, you changes will be lost by the next release - * of PLA. Instead change this file - as it will NOT be replaced by a new - * version of phpLDAPadmin. - */ - -/********************************************* - * Useful important configuration overrides * - *********************************************/ - -/* If you are asked to put PLA in debug mode, this is how you do it: */ -# $config->custom->debug['level'] = 255; -# $config->custom->debug['syslog'] = true; -# $config->custom->debug['file'] = '/tmp/pla_debug.log'; - -/* phpLDAPadmin can encrypt the content of sensitive cookies if you set this - to a big random string. */ -// $config->custom->session['blowfish'] = null; - -/* If your auth_type is http, you can override your HTTP Authentication Realm. */ -// $config->custom->session['http_realm'] = sprintf('%s %s',app_name(),'login'); - -/* The language setting. If you set this to 'auto', phpLDAPadmin will attempt - to determine your language automatically. - If PLA doesnt show (all) strings in your language, then you can do some - translation at http://translations.launchpad.net/phpldapadmin and download - the translation files, replacing those provided with PLA. - (We'll pick up the translations before making the next release too!) */ -// $config->custom->appearance['language'] = 'auto'; - -/* The temporary storage directory where we will put jpegPhoto data - This directory must be readable and writable by your web server. */ -// $config->custom->jpeg['tmpdir'] = '/tmp'; // Example for Unix systems -# $config->custom->jpeg['tmpdir'] = 'c:\\temp'; // Example for Windows systems - -/* Set this to (bool)true if you do NOT want a random salt used when - calling crypt(). Instead, use the first two letters of the user's - password. This is insecure but unfortunately needed for some older - environments. */ -# $config->custom->password['no_random_crypt_salt'] = true; - -/* PHP script timeout control. If php runs longer than this many seconds then - PHP will stop with an Maximum Execution time error. Increase this value from - the default if queries to your LDAP server are slow. The default is either - 30 seconds or the setting of max_exection_time if this is null. */ -// $config->custom->session['timelimit'] = 30; - -/* Our local timezone - This is to make sure that when we ask the system for the current time, we - get the right local time. If this is not set, all time() calculations will - assume UTC if you have not set PHP date.timezone. */ -// $config->custom->appearance['timezone'] = null; -# $config->custom->appearance['timezone'] = 'Australia/Melbourne'; - -/********************************************* - * Commands * - *********************************************/ - -/* Command availability ; if you don't authorize a command the command - links will not be shown and the command action will not be permitted. - For better security, set also ACL in your ldap directory. */ -/* -$config->custom->commands['cmd'] = array( - 'entry_internal_attributes_show' => true, - 'entry_refresh' => true, - 'oslinks' => true, - 'switch_template' => true -); - -$config->custom->commands['script'] = array( - 'add_attr_form' => true, - 'add_oclass_form' => true, - 'add_value_form' => true, - 'collapse' => true, - 'compare' => true, - 'compare_form' => true, - 'copy' => true, - 'copy_form' => true, - 'create' => true, - 'create_confirm' => true, - 'delete' => true, - 'delete_attr' => true, - 'delete_form' => true, - 'draw_tree_node' => true, - 'expand' => true, - 'export' => true, - 'export_form' => true, - 'import' => true, - 'import_form' => true, - 'login' => true, - 'logout' => true, - 'login_form' => true, - 'mass_delete' => true, - 'mass_edit' => true, - 'mass_update' => true, - 'modify_member_form' => true, - 'monitor' => true, - 'purge_cache' => true, - 'query_engine' => true, - 'rename' => true, - 'rename_form' => true, - 'rdelete' => true, - 'refresh' => true, - 'schema' => true, - 'server_info' => true, - 'show_cache' => true, - 'template_engine' => true, - 'update_confirm' => true, - 'update' => true -); -*/ - -/********************************************* - * Appearance * - *********************************************/ - -/* If you want to choose the appearance of the tree, specify a class name which - inherits from the Tree class. */ -// $config->custom->appearance['tree'] = 'AJAXTree'; -# $config->custom->appearance['tree'] = 'HTMLTree'; - -/* Just show your custom templates. */ -// $config->custom->appearance['custom_templates_only'] = false; - -/* Disable the default template. */ -// $config->custom->appearance['disable_default_template'] = false; - -/* Hide the warnings for invalid objectClasses/attributes in templates. */ -// $config->custom->appearance['hide_template_warning'] = false; - -/* Set to true if you would like to hide header and footer parts. */ -// $config->custom->appearance['minimalMode'] = false; - -/* Configure what objects are shown in left hand tree */ -// $config->custom->appearance['tree_filter'] = '(objectclass=*)'; - -/* The height and width of the tree. If these values are not set, then - no tree scroll bars are provided. */ -// $config->custom->appearance['tree_height'] = null; -# $config->custom->appearance['tree_height'] = 600; -// $config->custom->appearance['tree_width'] = null; -# $config->custom->appearance['tree_width'] = 250; - -/* Confirm create and update operations, allowing you to review the changes - and optionally skip attributes during the create/update operation. */ -// $config->custom->confirm['create'] = true; -// $config->custom->confirm['update'] = true; - -/* Confirm copy operations, and treat them like create operations. This allows - you to edit the attributes (thus changing any that might conflict with - uniqueness) before creating the new entry. */ -// $config->custom->confirm['copy'] = true; - -/********************************************* - * User-friendly attribute translation * - *********************************************/ - -/* Use this array to map attribute names to user friendly names. For example, if - you don't want to see "facsimileTelephoneNumber" but rather "Fax". */ -// $config->custom->appearance['friendly_attrs'] = array(); -$config->custom->appearance['friendly_attrs'] = array( - 'facsimileTelephoneNumber' => 'Fax', - 'gid' => 'Group', - 'mail' => 'Email', - 'telephoneNumber' => 'Telephone', - 'uid' => 'User Name', - 'userPassword' => 'Password' -); - -/********************************************* - * Hidden attributes * - *********************************************/ - -/* You may want to hide certain attributes from being edited. If you want to - hide attributes from the user, you should use your LDAP servers ACLs. - NOTE: The user must be able to read the hide_attrs_exempt entry to be - excluded. */ -// $config->custom->appearance['hide_attrs'] = array(); -# $config->custom->appearance['hide_attrs'] = array('objectClass'); - -/* Members of this list will be exempt from the hidden attributes. */ -// $config->custom->appearance['hide_attrs_exempt'] = null; -# $config->custom->appearance['hide_attrs_exempt'] = 'cn=PLA UnHide,ou=Groups,c=AU'; - -/********************************************* - * Read-only attributes * - *********************************************/ - -/* You may want to phpLDAPadmin to display certain attributes as read only, - meaning that users will not be presented a form for modifying those - attributes, and they will not be allowed to be modified on the "back-end" - either. You may configure this list here: - NOTE: The user must be able to read the readonly_attrs_exempt entry to be - excluded. */ -// $config->custom->appearance['readonly_attrs'] = array(); - -/* Members of this list will be exempt from the readonly attributes. */ -// $config->custom->appearance['readonly_attrs_exempt'] = null; -# $config->custom->appearance['readonly_attrs_exempt'] = 'cn=PLA ReadWrite,ou=Groups,c=AU'; - -/********************************************* - * Group attributes * - *********************************************/ - -/* Add "modify group members" link to the attribute. */ -// $config->custom->modify_member['groupattr'] = array('member','uniqueMember','memberUid','sudoUser'); - -/* Configure filter for member search. This only applies to "modify group members" feature */ -// $config->custom->modify_member['filter'] = '(objectclass=Person)'; - -/* Attribute that is added to the group member attribute. */ -// $config->custom->modify_member['attr'] = 'dn'; - - -/* For Posix attributes */ -// $config->custom->modify_member['posixattr'] = 'uid'; -// $config->custom->modify_member['posixfilter'] = '(uid=*)'; -// $config->custom->modify_member['posixgroupattr'] = 'memberUid'; - -/********************************************* - * Define your LDAP servers in this section * - *********************************************/ - -$servers = new Datastore(); - -/* $servers->NewServer('ldap_pla') must be called before each new LDAP server - declaration. */ -$servers->newServer('ldap_pla'); - -/* A convenient name that will appear in the tree viewer and throughout - phpLDAPadmin to identify this LDAP server to users. */ -$servers->setValue('server','name','My LDAP Server'); - -/* Examples: - 'ldap.example.com', - 'ldaps://ldap.example.com/', - 'ldapi://%2fusr%local%2fvar%2frun%2fldapi' - (Unix socket at /usr/local/var/run/ldap) */ -// $servers->setValue('server','host','127.0.0.1'); - -/* The port your LDAP server listens on (no quotes). 389 is standard. */ -// $servers->setValue('server','port',389); - -/* Array of base DNs of your LDAP server. Leave this blank to have phpLDAPadmin - auto-detect it for you. */ -// $servers->setValue('server','base',array('')); - -/* Five options for auth_type: - 1. 'cookie': you will login via a web form, and a client-side cookie will - store your login dn and password. - 2. 'session': same as cookie but your login dn and password are stored on the - web server in a persistent session variable. - 3. 'http': same as session but your login dn and password are retrieved via - HTTP authentication. - 4. 'config': specify your login dn and password here in this config file. No - login will be required to use phpLDAPadmin for this server. - 5. 'sasl': login will be taken from the webserver's kerberos authentication. - Currently only GSSAPI has been tested (using mod_auth_kerb). - - Choose wisely to protect your authentication information appropriately for - your situation. If you choose 'cookie', your cookie contents will be - encrypted using blowfish and the secret your specify above as - session['blowfish']. */ -// $servers->setValue('login','auth_type','session'); - -/* The DN of the user for phpLDAPadmin to bind with. For anonymous binds or - 'cookie','session' or 'sasl' auth_types, LEAVE THE LOGIN_DN AND LOGIN_PASS - BLANK. If you specify a login_attr in conjunction with a cookie or session - auth_type, then you can also specify the bind_id/bind_pass here for searching - the directory for users (ie, if your LDAP server does not allow anonymous - binds. */ -// $servers->setValue('login','bind_id',''); -# $servers->setValue('login','bind_id','cn=Manager,dc=example,dc=com'); - -/* Your LDAP password. If you specified an empty bind_id above, this MUST also - be blank. */ -// $servers->setValue('login','bind_pass',''); -# $servers->setValue('login','bind_pass','secret'); - -/* Use TLS (Transport Layer Security) to connect to the LDAP server. */ -// $servers->setValue('server','tls',false); - -/************************************ - * SASL Authentication * - ************************************/ - -/* Enable SASL authentication LDAP SASL authentication requires PHP 5.x - configured with --with-ldap-sasl=DIR. If this option is disabled (ie, set to - false), then all other sasl options are ignored. */ -# $servers->setValue('login','auth_type','sasl'); - -/* SASL GSSAPI auth mechanism (requires auth_type of sasl) */ -// $servers->setValue('sasl','mech','GSSAPI'); - -/* SASL PLAIN support... this mech converts simple binds to SASL - PLAIN binds using any auth_type (or other bind_id/pass) as credentials. - NOTE: auth_type must be simple auth compatible (ie not sasl) */ -# $servers->setValue('sasl','mech','PLAIN'); - -/* SASL authentication realm name */ -// $servers->setValue('sasl','realm',''); -# $servers->setValue('sasl','realm','EXAMPLE.COM'); - -/* SASL authorization ID name - If this option is undefined, authorization id will be computed from bind DN, - using authz_id_regex and authz_id_replacement. */ -// $servers->setValue('sasl','authz_id', null); - -/* SASL authorization id regex and replacement - When authz_id property is not set (default), phpLDAPAdmin will try to - figure out authorization id by itself from bind distinguished name (DN). - - This procedure is done by calling preg_replace() php function in the - following way: - - $authz_id = preg_replace($sasl_authz_id_regex,$sasl_authz_id_replacement, - $bind_dn); - - For info about pcre regexes, see: - - pcre(3), perlre(3) - - http://www.php.net/preg_replace */ -// $servers->setValue('sasl','authz_id_regex',null); -// $servers->setValue('sasl','authz_id_replacement',null); -# $servers->setValue('sasl','authz_id_regex','/^uid=([^,]+)(.+)/i'); -# $servers->setValue('sasl','authz_id_replacement','$1'); - -/* SASL auth security props. - See http://beepcore-tcl.sourceforge.net/tclsasl.html#anchor5 for explanation. */ -// $servers->setValue('sasl','props',null); - -/* Default password hashing algorithm. One of md5, ssha, sha, md5crpyt, smd5, - blowfish, crypt or leave blank for now default algorithm. */ -// $servers->setValue('appearance','pla_password_hash','md5'); - -/* If you specified 'cookie' or 'session' as the auth_type above, you can - optionally specify here an attribute to use when logging in. If you enter - 'uid' and login as 'dsmith', phpLDAPadmin will search for (uid=dsmith) - and log in as that user. - Leave blank or specify 'dn' to use full DN for logging in. Note also that if - your LDAP server requires you to login to perform searches, you can enter the - DN to use when searching in 'bind_id' and 'bind_pass' above. */ -// $servers->setValue('login','attr','dn'); - -/* Base DNs to used for logins. If this value is not set, then the LDAP server - Base DNs are used. */ -// $servers->setValue('login','base',array()); - -/* If login_attr was set to 'dn', it is possible to specify a template string to - build the DN from. Use '%s' where user input should be inserted. A user may - still enter the complete DN. In this case the template will not be used. */ -// $servers->setValue('login','bind_dn_template',null); -# $servers->setValue('login','bind_dn_template','cn=%s,ou=people,dc=example,dc=com'); - -/* If you specified something different from 'dn', for example 'uid', as the - login_attr above, you can optionally specify here to fall back to - authentication with dn. - This is useful, when users should be able to log in with their uid, but - the ldap administrator wants to log in with his root-dn, that does not - necessarily have the uid attribute. - When using this feature, login_class is ignored. */ -// $servers->setValue('login','fallback_dn',false); - -/* Specify true If you want phpLDAPadmin to not display or permit any - modification to the LDAP server. */ -// $servers->setValue('server','read_only',false); - -/* Specify false if you do not want phpLDAPadmin to draw the 'Create new' links - in the tree viewer. */ -// $servers->setValue('appearance','show_create',true); - -/* Set to true if you would like to initially open the first level of each tree. */ -// $servers->setValue('appearance','open_tree',false); - -/* Set to true to display authorization ID in place of login dn (PHP 7.2+) */ -// $servers->setValue('appearance','show_authz',false); - -/* This feature allows phpLDAPadmin to automatically determine the next - available uidNumber for a new entry. */ -// $servers->setValue('auto_number','enable',true); - -/* The mechanism to use when finding the next available uidNumber. Two possible - values: 'uidpool' or 'search'. - The 'uidpool' mechanism uses an existing uidPool entry in your LDAP server to - blindly lookup the next available uidNumber. The 'search' mechanism searches - for entries with a uidNumber value and finds the first available uidNumber - (slower). */ -// $servers->setValue('auto_number','mechanism','search'); - -/* The DN of the search base when the 'search' mechanism is used above. */ -# $servers->setValue('auto_number','search_base','ou=People,dc=example,dc=com'); - -/* The minimum number to use when searching for the next available number - (only when 'search' is used for auto_number. */ -// $servers->setValue('auto_number','min',array('uidNumber'=>1000,'gidNumber'=>500)); - -/* If you set this, then phpldapadmin will bind to LDAP with this user ID when - searching for the uidnumber. The idea is, this user id would have full - (readonly) access to uidnumber in your ldap directory (the logged in user - may not), so that you can be guaranteed to get a unique uidnumber for your - directory. */ -// $servers->setValue('auto_number','dn',null); - -/* The password for the dn above. */ -// $servers->setValue('auto_number','pass',null); - -/* Enable anonymous bind login. */ -// $servers->setValue('login','anon_bind',true); - -/* Use customized page with prefix when available. */ -# $servers->setValue('custom','pages_prefix','custom_'); - -/* If you set this, then only these DNs are allowed to log in. This array can - contain individual users, groups or ldap search filter(s). Keep in mind that - the user has not authenticated yet, so this will be an anonymous search to - the LDAP server, so make your ACLs allow these searches to return results! */ -# $servers->setValue('login','allowed_dns',array( -# 'uid=stran,ou=People,dc=example,dc=com', -# '(&(gidNumber=811)(objectClass=groupOfNames))', -# '(|(uidNumber=200)(uidNumber=201))', -# 'cn=callcenter,ou=Group,dc=example,dc=com')); - -/* Set this if you dont want this LDAP server to show in the tree */ -// $servers->setValue('server','visible',true); - -/* Set this if you want to hide the base DNs that dont exist instead of - displaying the message "The base entry doesnt exist, create it?" -// $servers->setValue('server','hide_noaccess_base',false); -# $servers->setValue('server','hide_noaccess_base',true); - -/* This is the time out value in minutes for the server. After as many minutes - of inactivity you will be automatically logged out. If not set, the default - value will be ( session_cache_expire()-1 ) */ -# $servers->setValue('login','timeout',30); - -/* Set this if you want phpldapadmin to perform rename operation on entry which - has children. Certain servers are known to allow it, certain are not. */ -// $servers->setValue('server','branch_rename',false); - -/* If you set this, then phpldapadmin will show these attributes as - internal attributes, even if they are not defined in your schema. */ -// $servers->setValue('server','custom_sys_attrs',array('')); -# $servers->setValue('server','custom_sys_attrs',array('passwordExpirationTime','passwordAllowChangeTime')); - -/* If you set this, then phpldapadmin will show these attributes on - objects, even if they are not defined in your schema. */ -// $servers->setValue('server','custom_attrs',array('')); -# $servers->setValue('server','custom_attrs',array('nsRoleDN','nsRole','nsAccountLock')); - -/********************************************* - * Unique attributes * - *********************************************/ - -/* You may want phpLDAPadmin to enforce some attributes to have unique values - (ie: not belong to other entries in your tree. This (together with - 'unique','dn' and 'unique','pass' option will not let updates to - occur with other attributes have the same value. */ -# $servers->setValue('unique','attrs',array('mail','uid','uidNumber')); - -/* If you set this, then phpldapadmin will bind to LDAP with this user ID when - searching for attribute uniqueness. The idea is, this user id would have full - (readonly) access to your ldap directory (the logged in user may not), so - that you can be guaranteed to get a unique uidnumber for your directory. */ -// $servers->setValue('unique','dn',null); - -/* The password for the dn above. */ -// $servers->setValue('unique','pass',null); - -/************************************************************************** - * If you want to configure additional LDAP servers, do so below. * - * Remove the commented lines and use this section as a template for all * - * your other LDAP servers. * - **************************************************************************/ - -/* -$servers->newServer('ldap_pla'); -$servers->setValue('server','name','LDAP Server'); -$servers->setValue('server','host','127.0.0.1'); -$servers->setValue('server','port',389); -$servers->setValue('server','base',array('')); -$servers->setValue('login','auth_type','cookie'); -$servers->setValue('login','bind_id',''); -$servers->setValue('login','bind_pass',''); -$servers->setValue('server','tls',false); - -# SASL auth -$servers->setValue('login','auth_type','sasl'); -$servers->setValue('sasl','mech','GSSAPI'); -$servers->setValue('sasl','realm','EXAMPLE.COM'); -$servers->setValue('sasl','authz_id',null); -$servers->setValue('sasl','authz_id_regex','/^uid=([^,]+)(.+)/i'); -$servers->setValue('sasl','authz_id_replacement','$1'); -$servers->setValue('sasl','props',null); - -$servers->setValue('appearance','pla_password_hash','md5'); -$servers->setValue('login','attr','dn'); -$servers->setValue('login','fallback_dn',false); -$servers->setValue('login','class',null); -$servers->setValue('server','read_only',false); -$servers->setValue('appearance','show_create',true); - -$servers->setValue('auto_number','enable',true); -$servers->setValue('auto_number','mechanism','search'); -$servers->setValue('auto_number','search_base',null); -$servers->setValue('auto_number','min',array('uidNumber'=>1000,'gidNumber'=>500)); -$servers->setValue('auto_number','dn',null); -$servers->setValue('auto_number','pass',null); - -$servers->setValue('login','anon_bind',true); -$servers->setValue('custom','pages_prefix','custom_'); -$servers->setValue('unique','attrs',array('mail','uid','uidNumber')); -$servers->setValue('unique','dn',null); -$servers->setValue('unique','pass',null); - -$servers->setValue('server','visible',true); -$servers->setValue('login','timeout',30); -$servers->setValue('server','branch_rename',false); -$servers->setValue('server','custom_sys_attrs',array('passwordExpirationTime','passwordAllowChangeTime')); -$servers->setValue('server','custom_attrs',array('nsRoleDN','nsRole','nsAccountLock')); -$servers->setValue('server','force_may',array('uidNumber','gidNumber','sambaSID')); -*/ - - -/*********************************************************************************** - * If you want to configure Google reCAPTCHA on autentication form, do so below. * - * Remove the commented lines and use this section as a template for all * - * reCAPTCHA v2 Generate on https://www.google.com/recaptcha/ * - * * - * IMPORTANT: Select reCAPTCHA v2 on Type of reCAPTCHA * - ***********************************************************************************/ - - -$config->custom->session['reCAPTCHA-enable'] = false; -$config->custom->session['reCAPTCHA-key-site'] = ''; -$config->custom->session['reCAPTCHA-key-server'] = ''; - -?> diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php deleted file mode 100644 index 956d70f..0000000 --- a/database/factories/UserFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -define(User::class, function (Faker $faker) { - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; -}); -*/ diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php deleted file mode 100644 index 237dfc5..0000000 --- a/database/seeds/DatabaseSeeder.php +++ /dev/null @@ -1,16 +0,0 @@ -call(UserSeeder::class); - } -} diff --git a/htdocs/common.php b/htdocs/common.php deleted file mode 100644 index de4122c..0000000 --- a/htdocs/common.php +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/htdocs/compare.php b/htdocs/compare.php deleted file mode 100644 index 47a80db..0000000 --- a/htdocs/compare.php +++ /dev/null @@ -1,188 +0,0 @@ -getServer(get_request('server_id_src')); -$ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst')); - -if (! $ldap['SRC']->dnExists($request['dnSRC'])) - error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnSRC'])),'error','index.php'); - -if (! $ldap['DST']->dnExists($request['dnDST'])) - error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnDST'])),'error','index.php'); - -$request['pageSRC'] = new PageRender($ldap['SRC']->getIndex(),get_request('template','REQUEST',false,'none')); -$request['pageSRC']->setDN($request['dnSRC']); -$request['pageSRC']->accept(); -$request['templateSRC'] = $request['pageSRC']->getTemplate(); - -$request['pageDST'] = new PageRender($ldap['DST']->getIndex(),get_request('template','REQUEST',false,'none')); -$request['pageDST']->setDN($request['dnDST']); -$request['pageDST']->accept(); -$request['templateDST'] = $request['pageDST']->getTemplate(); - -# Get a list of all attributes. -$attrs_all = array_unique(array_merge($request['templateSRC']->getAttributeNames(),$request['templateDST']->getAttributeNames())); - -$request['pageSRC']->drawTitle(_('Comparing the following DNs')); - -echo '
'; - -echo ''; -echo ''; - -$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', - $ldap['SRC']->getIndex(),rawurlencode($request['dnSRC'])); -printf('', - _('Server'),$ldap['SRC']->getName(),_('Distinguished Name'), - htmlspecialchars($href),$request['dnSRC']); - -$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', - $ldap['DST']->getIndex(),rawurlencode($request['dnDST'])); -printf('', - _('Server'),$ldap['DST']->getName(),_('Distinguished Name'), - htmlspecialchars($href),$request['dnDST']); - -echo ''; - -echo ''; -echo ''; -echo ''; - -if (! is_array($attrs_all) || ! count($attrs_all)) { - printf('',_('This entry has no attributes')); - print '
%s: %s
%s: %s
%s: %s
%s: %s
'; -echo '
'; -echo '
'; -printf('',$app['server']->getIndex()); -printf('',$ldap['DST']->getIndex()); -printf('',$ldap['SRC']->getIndex()); -printf('',htmlspecialchars($request['dnDST'])); -printf('',htmlspecialchars($request['dnSRC'])); -printf('',_('Switch Entry')); -echo '
'; -echo '
'; -echo '
(%s)
'; - - return; -} - -sort($attrs_all); - -# Work through each of the attributes. -foreach ($attrs_all as $attr) { - # Has the config.php specified that this attribute is to be hidden or shown? - if ($ldap['SRC']->isAttrHidden($attr) || $ldap['DST']->isAttrHidden($attr)) - continue; - - $attributeSRC = $request['templateSRC']->getAttribute($attr); - $attributeDST = $request['templateDST']->getAttribute($attr); - - # Get the values and see if they are the same. - if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues())) - echo ''; - else - echo ''; - - foreach (array('src','dst') as $side) { - # If we are on the source side, show the attribute name. - switch ($side) { - case 'src': - if ($attributeSRC) { - echo ''; - $request['pageSRC']->draw('Name',$attributeSRC); - echo ''; - - if ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID()) - echo ' '; - - else { - echo ''; - $request['pageSRC']->draw('Notes',$attributeSRC); - echo ''; - } - - } else { - echo ' '; - } - - break; - - case 'dst': - if ($attributeDST) { - if ($attributeSRC && ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID())) - echo ' '; - - else { - echo ''; - $request['pageDST']->draw('Name',$attributeDST); - echo ''; - } - - echo ''; - $request['pageDST']->draw('Notes',$attributeDST); - echo ''; - - } else { - echo ' '; - } - - break; - } - } - - echo ''; - echo "\n\n"; - - # Get the values and see if they are the same. - if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues())) - echo ''; - else - echo ''; - - foreach (array('src','dst') as $side) { - echo ''; - echo ''; - echo '
'; - - switch ($side) { - case 'src': - - if ($attributeSRC && count($attributeSRC->getValues())) - $request['pageSRC']->draw('CurrentValues',$attributeSRC); - else - echo ' '; - - break; - - case 'dst': - if ($attributeDST && count($attributeDST->getValues())) - $request['pageDST']->draw('CurrentValues',$attributeDST); - else - echo ' '; - - break; - } - - echo '
'; - } - - echo ''; -} -echo ''; -?> diff --git a/htdocs/compare_form.php b/htdocs/compare_form.php deleted file mode 100644 index 56962bd..0000000 --- a/htdocs/compare_form.php +++ /dev/null @@ -1,65 +0,0 @@ -dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); - -$request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setDN($request['dn']); -$request['page']->accept(); - -# Render the form -$request['page']->drawTitle(sprintf('%s %s',_('Compare another DN with'),get_rdn($request['dn']))); -$request['page']->drawSubTitle(); - -printf('',JSDIR); -echo '
'; -printf('%s %s %s
',_('Compare'),get_rdn($request['dn']),_('with ')); -echo '
'; - -echo '
'; -echo '
'; -echo ''; -printf('',$app['server']->getIndex()); -printf('',$app['server']->getIndex()); -printf('',htmlspecialchars($request['dn'])); -echo '
'; -echo "\n"; - -echo ''; - -echo ''; -printf('', - _('Compare this DN with another'),_('Destination DN')); -echo ''; -echo ''; -echo "\n"; - -printf('',_('Destination Server'),server_select_list($app['server']->getIndex(),true,'server_id_dst')); -echo "\n"; - -printf('',_('Compare')); -echo "\n"; - -echo '
%s:'; -echo ''; -draw_chooser_link('compare_form','dn_dst','true',''); -echo '
%s:%s
'; -echo '
'; -?> diff --git a/htdocs/copy.php b/htdocs/copy.php deleted file mode 100644 index fad7d92..0000000 --- a/htdocs/copy.php +++ /dev/null @@ -1,209 +0,0 @@ -getServer(get_request('server_id_src')); -$ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst')); - -# Error checking -if (! trim($request['dnDST'])) - error(_('You left the destination DN blank.'),'error','index.php'); - -if ($ldap['DST']->isReadOnly()) - error(_('Destination server is currently READ-ONLY.'),'error','index.php'); - -if ($ldap['DST']->dnExists($request['dnDST'])) - error(sprintf(_('The destination entry (%s) already exists.'),pretty_print_dn($request['dnDST'])),'error','index.php'); - -if (! $ldap['DST']->dnExists($ldap['DST']->getContainer($request['dnDST']))) - error(sprintf(_('The destination container (%s) does not exist.'), - pretty_print_dn($ldap['DST']->getContainer($request['dnDST']))),'error','index.php'); - -if (pla_compare_dns($request['dnSRC'],$request['dnDST']) == 0 && $ldap['SRC']->getIndex() == $ldap['DST']->getIndex()) - error(_('The source and destination DN are the same.'),'error','index.php'); - -$request['recursive'] = (get_request('recursive') == 'on') ? true : false; -$request['remove'] = (get_request('remove') == 'yes') ? true : false; - -if ($request['recursive']) { - $filter = get_request('filter','POST',false,'(objectClass=*)'); - - # Build a tree similar to that of the tree browser to give to r_copy_dn - $ldap['tree'] = array(); - printf('

%s%s

',_('Copying '),$request['dnSRC']); - printf('

%s

',_('Recursive copy progress')); - print '

'; - - print ''; - printf ('%s...',_('Building snapshot of tree to copy')); - - $ldap['tree'] = build_tree($ldap['SRC'],$request['dnSRC'],array(),$filter); - printf('%s
',_('Success')); - - # Prevent script from bailing early on a long delete - @set_time_limit(0); - - $copy_result = r_copy_dn($ldap['SRC'],$ldap['DST'],$ldap['tree'],$request['dnSRC'],$request['dnDST'],$request['remove']); - $copy_message = $copy_result; - print '
'; - -} else { - if ($_SESSION[APPCONFIG]->getValue('confirm','copy') && !$request['remove']) { - $request['pageSRC'] = new TemplateRender($ldap['SRC']->getIndex(),get_request('template','REQUEST',false,null)); - $request['pageSRC']->setDN($request['dnSRC']); - $request['pageSRC']->accept(true); - - $request['pageDST'] = new TemplateRender($ldap['DST']->getIndex(),get_request('template','REQUEST',false,'none')); - $request['pageDST']->setContainer($app['server']->getContainer($request['dnDST'])); - $request['pageDST']->accept(true); - - $request['templateSRC'] = $request['pageSRC']->getTemplate(); - $request['templateDST'] = $request['pageDST']->getTemplate(); - - $request['templateDST']->copy($request['templateSRC'],get_rdn($request['dnDST']),true); - - # Set all attributes with a values as shown, and remove the add value options - foreach ($request['templateDST']->getAttributes(true) as $sattribute) - if ($sattribute->getValues() && ! $sattribute->isInternal()) { - $sattribute->show(); - $sattribute->setMaxValueCount(count($sattribute->getValues())); - } - - $request['pageDST']->accept(); - - return; - - } else { - $copy_result = copy_dn($ldap['SRC'],$ldap['DST'],$request['dnSRC'],$request['dnDST'],$request['remove']); - - if ($copy_result) - $copy_message = sprintf('%s %s: %s %s', - $request['remove'] ? _('Move successful') : _('Copy successful'), - _('DN'),$request['dnDST'],_('has been created.')); - else - $copy_message = sprintf('%s %s: %s %s', - $request['remove'] ? _('Move NOT successful') : _('Copy NOT successful'), - _('DN'),$request['dnDST'],_('has NOT been created.')); - } -} - -if ($copy_result) { - $redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&refresh=SID_%s_nodes&noheader=1', - $ldap['DST']->getIndex(),rawurlencode($request['dnDST']),$ldap['DST']->getIndex()); - - system_message(array( - 'title'=>_('Copy Entry'), - 'body'=>$copy_message, - 'type'=>'info'), - $redirect_url); -} - -function r_copy_dn($serverSRC,$serverDST,$snapshottree,$dnSRC,$dnDST,$remove) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $copy_message = array(); - - $children = isset($snapshottree[$dnSRC]) ? $snapshottree[$dnSRC] : null; - - # If we have children, then we need to copy, then delete for a move - if (is_array($children) && count($children)) { - - $copy_result = copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,false); - - if (! $copy_result) - return false; - - array_push($copy_message,sprintf('%s %s: %s %s',_('Copy successful'),_('DN'),$dnDST,_('has been created.'))); - - $hadError = false; - foreach ($children as $child_dn) { - $dnDST_new = sprintf('%s,%s',get_rdn($child_dn),$dnDST); - $copy_result = r_copy_dn($serverSRC,$serverDST,$snapshottree,$child_dn,$dnDST_new,$remove); - $copy_message = array_merge($copy_message,array_values($copy_result)); - - if (! $copy_result) - $hadError = true; - } - - if (! $hadError && $remove) { - $delete_result = $serverSRC->delete($dnSRC); - - if ($delete_result) - array_push($copy_message,sprintf('%s %s: %s %s',_('Delete successful'),_('DN'),$dnDST,_('has been deleted.'))); - } - - } else { - $copy_result = copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,$remove); - - if ($copy_result) - array_push($copy_message,sprintf('%s %s: %s %s', - $remove ? _('Move successful') : _('Copy successful'), - _('DN'),$dnDST,_('has been created.'))); - else - array_push($copy_message,sprintf('%s %s: %s %s', - $remove ? _('Move NOT successful') : _('Copy NOT successful'), - _('DN'),$dnDST,_('has NOT been created.'))); - } - - return $copy_message; -} - -function copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,$remove) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $request = array(); - $request['pageSRC'] = new PageRender($serverSRC->getIndex(),get_request('template','REQUEST',false,'none')); - $request['pageSRC']->setDN($dnSRC); - $request['pageSRC']->accept(); - - $request['pageDST'] = new PageRender($serverDST->getIndex(),get_request('template','REQUEST',false,'none')); - $request['pageDST']->setContainer($serverDST->getContainer($dnDST)); - $request['pageDST']->accept(); - - $request['templateSRC'] = $request['pageSRC']->getTemplate(); - $request['templateDST'] = $request['pageDST']->getTemplate(); - $request['templateDST']->copy($request['pageSRC']->getTemplate(),get_rdn($dnDST,0)); - - # Create of move the entry - if ($remove) - return $serverDST->rename($request['templateSRC']->getDN(),$request['templateDST']->getRDN(),$serverDST->getContainer($dnDST),true); - else - return $serverDST->add($request['templateDST']->getDN(),$request['templateDST']->getLDAPadd()); -} - -function build_tree($server,$dn,$buildtree) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # We search all children, not only the visible children in the tree - $children = $server->getContainerContents($dn,null,0); - - if (count($children)) { - $buildtree[$dn] = $children; - foreach ($children as $child_dn) - $buildtree = build_tree($server,$child_dn,$buildtree); - } - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$buildtree); - - return $buildtree; -} -?> diff --git a/htdocs/copy_form.php b/htdocs/copy_form.php deleted file mode 100644 index 749b78e..0000000 --- a/htdocs/copy_form.php +++ /dev/null @@ -1,103 +0,0 @@ -dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); - -$request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setDN($request['dn']); -$request['page']->accept(); - -# Render the form -$request['page']->drawTitle(sprintf('%s %s',_('Copy'),get_rdn($request['dn']))); -$request['page']->drawSubTitle(); - -printf('',JSDIR); -echo '
'; -printf('%s %s %s:

',_('Copy'),get_rdn($request['dn']),_('to a new object')); -echo '
'; - -echo '
'; -echo '
'; -echo ''; -printf('',$app['server']->getIndex()); -printf('',$app['server']->getIndex()); -printf('',htmlspecialchars($request['dn'])); -echo '
'; -echo "\n"; - -echo ''; - -echo ''; -printf('', - _('The full DN of the new entry to be created when copying the source entry'),_('Destination DN')); -echo ''; -echo ''; -echo "\n"; - -printf('',_('Destination Server'),server_select_list($app['server']->getIndex(),true,'server_id_dst')); -echo "\n"; - -# We search all children, not only the visible children in the tree -$request['children'] = $app['server']->getContainerContents($request['dn']); - -if (count($request['children']) > 0) { - echo ''; - printf('',_('Recursive copy')); - echo '',_('Recursively copy all children of this object as well.')); - echo ''; - echo "\n"; - - echo ''; - printf('', - _('When performing a recursive copy, only copy those entries which match this filter'),_('Filter')); - echo ''; - echo "\n"; - - echo ''; - printf('',_('Delete after copy (move):')); - echo ''; - echo "\n"; - -} else { - printf('',_('Delete after copy (move):')); -} -echo "\n"; - -printf('',_('Copy ')); -echo "\n"; - -echo '
%s:'; -printf('',htmlspecialchars($request['dn'])); -draw_chooser_link('copy_form','dn_dst','true',get_rdn($request['dn'])); -echo '
%s:%s
:'; - printf('(%s)
%s:'; - echo '
%s'; - printf('(%s)',_('Make sure your filter (above) will select all child records.')); - echo '
%s
'; -echo '
'; - -if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints')) - printf('
Light%s
', - IMGDIR,_('Hint: Copying between different servers only works if there are no schema violations')); - - -# Draw the javascrpt to enable/disable the filter field if this may be a recursive copy -if (count($request['children']) > 0) - printf('',JSDIR); -?> diff --git a/htdocs/create.php b/htdocs/create.php deleted file mode 100644 index e9c69fb..0000000 --- a/htdocs/create.php +++ /dev/null @@ -1,103 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setContainer(get_request('container','REQUEST',true)); -$request['page']->accept(); -$request['template'] = $request['page']->getTemplate(); - -if ((! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) && ! get_request('create_base')) - error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php'); - -# Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... -$tree = get_cached_item($app['server']->getIndex(),'tree'); - -$request['container'] = $tree->getEntry($request['template']->getContainer()); -if (! $request['container'] && ! get_request('create_base')) { - $tree->addEntry($request['template']->getContainer()); - $request['container'] = $tree->getEntry($request['template']->getContainer()); -} - -# Check our RDN -if (! count($request['template']->getRDNAttrs())) - error(_('The were no attributes marked as an RDN attribute.'),'error','index.php'); -if (! $request['template']->getRDN()) - error(_('The RDN field is empty?'),'error','index.php'); - -# Some other attribute checking... -foreach ($request['template']->getAttributes() as $attribute) { - # Check that our Required Attributes have a value - we shouldnt really return a hit here, the template engine shouldnt have allowed this to slip through. - if ($attribute->isRequired() && ! count($attribute->getValues())) - error(sprintf(_('You left the value blank for required attribute (%s).'), - $attribute->getName(false)),'error','index.php'); -} - -# Create the entry -$add_result = $app['server']->add($request['template']->getDN(),$request['template']->getLDAPadd()); - -if ($add_result) { - $action_number = $_SESSION[APPCONFIG]->getValue('appearance','action_after_creation'); - $href = sprintf('cmd=template_engine&server_id=%s',$app['server']->getIndex()); - - if ($request['redirect']) - $redirect_url = $request['redirect']; - - else if ($action_number == 2) - $redirect_url = sprintf('cmd.php?%s&template=%s&container=%s', - $href,'default',$request['template']->getContainerEncode()); - - else - $redirect_url = sprintf('cmd.php?%s&template=%s&dn=%s', - $href,'default',$request['template']->getDNEncode()); - - if ($action_number == 1 || $action_number == 2) - printf('',$redirect_url); - - if ($action_number == 1 || $action_number == 2) { - $create_message = sprintf('%s %s: %s %s', - _('Creation successful!'),_('DN'),$request['template']->getDN(),_('has been created.')); - - if (isAjaxEnabled()) - $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1',$app['server']->getIndex()); - - system_message(array( - 'title'=>_('Create Entry'), - 'body'=>$create_message, - 'type'=>'info'), - $redirect_url); - - } else { - $request['page']->drawTitle(_('Entry created')); - $request['page']->drawSubTitle(sprintf('%s: %s   %s: %s', - _('Server'),$app['server']->getName(),_('Distinguished Name'),$request['template']->getDN())); - - echo '
'; - echo '
'; - printf('%s.', - htmlspecialchars($href),rawurlencode($request['template']->getDN()),_('Display the new created entry')); - echo '
'; - printf('%s.', - htmlspecialchars($href),rawurlencode($request['template']->getContainer()),_('Create another entry')); - echo '
'; - } -} -?> diff --git a/htdocs/create_confirm.php b/htdocs/create_confirm.php deleted file mode 100644 index 96a30a8..0000000 --- a/htdocs/create_confirm.php +++ /dev/null @@ -1,142 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setContainer(get_request('container','REQUEST',true)); -$request['page']->accept(); -$request['template'] = $request['page']->getTemplate(); - -if (! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) - error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php'); - -# Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... -$tree = get_cached_item($app['server']->getIndex(),'tree'); - -$request['container'] = $tree->getEntry($request['template']->getContainer()); -if (! $request['container']) { - $tree->addEntry($request['template']->getContainer()); - $request['container'] = $tree->getEntry($request['template']->getContainer()); -} - -# Check our RDN -if (! count($request['template']->getRDNAttrs())) - error(_('The were no attributes marked as an RDN attribute.'),'error','index.php'); -if (! $request['template']->getRDN()) - error(_('The RDN field is empty?'),'error','index.php'); - -# Some other attribute checking... -foreach ($request['template']->getAttributes() as $attribute) { - # Check that our Required Attributes have a value - we shouldnt really return a hit here, the template engine shouldnt have allowed this to slip through. - if ($attribute->isRequired() && ! count($attribute->getValues())) - error(sprintf(_('You left the value blank for required attribute (%s).'), - $attribute->getName(false)),'error','index.php'); -} - -# Check for unique attributes -$app['server']->checkUniqueAttrs($request['template']->getDN(),$request['template']->getLDAPadd()); - -$request['page']->drawTitle(_('Create LDAP Entry')); -$request['page']->drawSubTitle(sprintf('%s: %s   %s: %s', - _('Server'),$app['server']->getName(),_('Container'),$request['template']->getContainer())); - -# Confirm the creation -if (count($request['template']->getLDAPadd(true))) { - echo '
'; - echo _('Do you want to create this entry?'); - echo '

'; - echo '
'; - - echo "\n\n"; - echo '
'; - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - printf('',$request['template']->getContainerEncode(false)); - printf('',$request['template']->getID()); - foreach ($request['template']->getRDNAttrs() as $rdn) - printf('',htmlspecialchars($rdn)); - echo "\n"; - - $request['page']->drawHiddenAttributes(); - echo '
'; - - echo ''; - echo "\n"; - - printf('', - _('Attribute'),_('New Value'),_('Skip')); - echo "\n\n"; - - $counter = 0; - printf('',$counter%2 ? 'even' : 'odd',htmlspecialchars($request['template']->getDN())); - - foreach ($request['template']->getLDAPadd(true) as $attribute) { - $counter++; - - printf('',$counter%2 ? 'even' : 'odd'); - printf('',$attribute->getFriendlyName()); - - # Show NEW Values - echo ''; - - # Show SKIP Option - $input_disabled = ''; - $input_onclick = ''; - - if ($attribute->isRequired()) - $input_disabled = 'disabled="disabled"'; - - printf('', - htmlspecialchars($attribute->getName()),htmlspecialchars($attribute->getName()),$input_disabled,$input_onclick); - echo ''; - echo "\n\n"; - } - - echo '
%s%s%s
%s
%s'; - $request['page']->draw('CurrentValues',$attribute); - echo '
'; - - echo '
'; - echo '
'; - - printf('', - _('Commit'), - (isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'create_form\'),\'%s\');"',_('Updating Object')) : '')); - - printf('', - _('Cancel'), - (isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&container=%s\',\'%s\');"',$app['server']->getIndex(),$request['template']->getContainer(),_('Retrieving DN')) : '')); - - echo '
'; - echo '
'; - echo '
'; - -} else { - $href = sprintf('cmd=template_engine&server_id=%s&dn=%s', - $app['server']->getIndex(),$request['template']->getDNEncode()); - - echo '
'; - echo _('You made no changes'); - - if (isAjaxEnabled()) - printf(' %s.', - htmlspecialchars($href),htmlspecialchars($href),_('Retrieving DN'),_('Go back')); - else - printf(' %s.',htmlspecialchars($href),_('Go back')); - - echo '
'; -} -?> diff --git a/htdocs/delete.php b/htdocs/delete.php deleted file mode 100644 index 137055c..0000000 --- a/htdocs/delete.php +++ /dev/null @@ -1,40 +0,0 @@ -dnExists($request['dn'])) - error(sprintf('%s (%s)',_('No such entry.'),''.pretty_print_dn($request['dn']).''),'error','index.php'); - -# Delete the entry. -$result = $app['server']->delete($request['dn']); - -if ($result) { - $redirect_url = ''; - - if (isAjaxEnabled()) - $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1',$app['server']->getIndex()); - - system_message(array( - 'title'=>_('Delete DN'), - 'body'=>_('Successfully deleted DN ').sprintf('%s',$request['dn']), - 'type'=>'info'), - sprintf('index.php?server_id=%s%s',$app['server']->getIndex(),$redirect_url)); -} else - system_message(array( - 'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($request['dn'])), - 'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)), - 'type'=>'error')); -?> diff --git a/htdocs/delete_attr.php b/htdocs/delete_attr.php deleted file mode 100644 index ad323fa..0000000 --- a/htdocs/delete_attr.php +++ /dev/null @@ -1,49 +0,0 @@ -isAttrReadOnly($request['attr'])) - error(sprintf(_('The attribute "%s" is flagged as read-only in the phpLDAPadmin configuration.'),$request['attr']),'error','index.php'); - -$update_array = array(); -$update_array[$request['attr']] = $app['server']->getDNAttrValue($request['dn'],$request['attr']); - -$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', - $app['server']->getIndex(),rawurlencode($request['dn'])); - -if (! isset($update_array[$request['attr']][$request['index']])) - system_message(array( - 'title'=>_('Could not delete attribute value.'), - 'body'=>sprintf('%s. %s/%s',_('The attribute value does not exist'),$request['attr'],$request['index']), - 'type'=>'warn'),$redirect_url); - -else { - unset($update_array[$request['attr']][$request['index']]); - foreach ($update_array as $key => $values) - $update_array[$key] = array_values($values); - - $result = $app['server']->modify($request['dn'],$update_array); - - if ($result) { - foreach ($update_array as $attr => $junk) - $redirect_url .= sprintf('&modified_attrs[]=%s',$attr); - - header("Location: $redirect_url"); - die(); - } -} -?> diff --git a/htdocs/delete_form.php b/htdocs/delete_form.php deleted file mode 100644 index 3f0d44c..0000000 --- a/htdocs/delete_form.php +++ /dev/null @@ -1,157 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setDN($request['dn']); -$request['page']->accept(); -$request['template'] = $request['page']->getTemplate(); - -# Check if the entry exists. -if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s)',_('The entry does not exist'),$request['dn']), - 'type'=>'error'),'index.php'); - -# We search all children, not only the visible children in the tree -$request['children'] = $app['server']->getContainerContents($request['dn'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER); - -printf('

%s %s

',_('Delete'),htmlspecialchars(get_rdn($request['dn']))); -printf('

%s: %s     %s: %s

', - _('Server'),$app['server']->getName(),_('Distinguished Name'),$request['dn']); -echo "\n"; - -echo '
'; - -if (count($request['children'])) { - printf('%s

',_('Permanently delete all children also?')); - - $search['href'] = htmlspecialchars(sprintf('cmd.php?cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=sub&query=none&format=list', - $app['server']->getIndex(),rawurlencode('objectClass=*'),rawurlencode($request['dn']))); - - $query = array(); - $query['base'] = $request['dn']; - $query['scope'] = 'sub'; - $query['attrs'] = array('dn'); - $query['size_limit'] = 0; - $query['deref'] = LDAP_DEREF_NEVER; - $request['search'] = $app['server']->query($query,null); - - echo ''; - echo ''; - echo ''; - - echo ''; - - printf('', - sprintf(_('phpLDAPadmin can recursively delete this entry and all %s of its children. See below for a list of all the entries that this action will delete. Do you want to do this?'),count($request['search']))); - - echo ''; - - printf('', - _('Note: this is potentially very dangerous and you do this at your own risk. This operation cannot be undone. Take into consideration aliases, referrals, and other things that may cause problems.')); - echo "\n"; - - echo ''; - echo ''; - - echo ''; - echo ''; - echo "\n"; - - echo '
'; - printf(_('This entry is the root of a sub-tree containing %s entries.'),count($request['search'])); - printf(' (%s)', - $search['href'],_('view entries')); - echo '
 
%s
 
%s
'; - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - printf('',$request['template']->getDNEncode(false)); - //@todo need to refresh the tree after a delete - printf('', - sprintf(_('Delete all %s objects'),count($request['search'])), - (isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'delete_form\'),\'%s\');"',_('Deleting Object(s)')) : '')); - echo '
'; - echo '
'; - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - printf('',$request['template']->getDNEncode(false)); - printf('', - _('Cancel'), - (isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&dn=%s\',\'%s\');"',$app['server']->getIndex(),$request['template']->getDNEncode(),_('Retrieving DN')) : '')); - echo '
'; - echo '
'; - echo "\n"; - - echo '

'; - echo _('List of entries to be deleted:'); - echo '
'; - - $i = 0; - printf(''; - echo "\n"; - -} else { - echo ''; - - printf('',_('Are you sure you want to permanently delete this object?')); - echo ''; - - printf('',_('Server'),$app['server']->getName()); - printf('', - _('Distinguished Name'),_('DN'),$request['dn']); - echo ''; - echo "\n"; - - echo ''; - echo ''; - echo ''; - echo ''; - echo '
%s
 
%s:%s
%s%s
 
'; - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - printf('',$request['template']->getDNEncode(false)); - //@todo need to refresh the tree after a delete - printf('', - _('Delete'), - (isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'delete_form\'),\'%s\');"',_('Deleting Object(s)')) : '')); - echo '
'; - - echo '
'; - - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - printf('',$request['template']->getDNEncode(false)); - printf('', - _('Cancel'), - (isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&dn=%s\',\'%s\');"',$app['server']->getIndex(),$request['template']->getDNEncode(),_('Retrieving DN')) : '')); - echo '
'; - - echo '
'; - echo "\n"; -} - -echo '
'; -echo '
'; -?> diff --git a/htdocs/entry_chooser.php b/htdocs/entry_chooser.php deleted file mode 100644 index e2d7bf5..0000000 --- a/htdocs/entry_chooser.php +++ /dev/null @@ -1,135 +0,0 @@ -'; -printf('

%s

',_('Entry Chooser')); - -echo ''; - -echo ''; -if ($request['container']) { - printf('',_('Server'),$app['server']->getName()); - printf('',_('Looking in'),htmlspecialchars($request['container'])); - echo ''; -} - -# Has the user already begun to descend into a specific server tree? -if (isset($app['server']) && ! is_null($request['container'])) { - $tree = get_cached_item($app['server']->getIndex(),'tree'); - - $request['children'] = $app['server']->getContainerContents($request['container'],null,0,'(objectClass=*)',$_SESSION[APPCONFIG]->getValue('deref','tree')); - sort($request['children']); - - foreach ($app['server']->getBaseDN() as $base) { - if (DEBUG_ENABLED) - debug_log('Comparing BaseDN [%s] with container [%s]',64,0,__FILE__,__LINE__,__METHOD__,$base,$request['container']); - - if (! pla_compare_dns($request['container'],$base)) { - $parent_container = false; - $href['up'] = sprintf('entry_chooser.php?form=%s&element=%s&rdn=%s',$request['form'],$request['element'],rawurlencode($request['rdn'])); - break; - - } else { - $parent_container = $app['server']->getContainer($request['container']); - $href['up'] = sprintf('entry_chooser.php?form=%s&element=%s&rdn=%s&server_id=%s&container=%s', - $request['form'],$request['element'],$request['rdn'],$app['server']->getIndex(),rawurlencode($parent_container)); - } - } - - echo ''; - echo ''; - printf('',$href['up'],IMGDIR); - printf('',$href['up'],_('Back Up')); - echo ''; - - if (! count($request['children'])) - printf('',_('no entries')); - - else - foreach ($request['children'] as $dn) { - $href['return'] = sprintf("javascript:returnDN('%s%s')",($request['rdn'] ? sprintf('%s,',$request['rdn']) : ''),str_replace('\\','\\\\',$dn)); - $href['expand'] = sprintf('entry_chooser.php?server_id=%s&form=%s&element=%s&rdn=%s&container=%s', - $app['server']->getIndex(),$request['form'],$request['element'],$request['rdn'],rawurlencode($dn)); - - echo ''; - echo ''; - printf('',$href['expand'],IMGDIR); - - $entry = $tree->getEntry($dn); - if (is_null($entry)) { - $tree->addEntry($dn); - $entry = $tree->getEntry($dn); - } - - if ($entry) - $item = draw_formatted_dn($app['server'], $entry); - else - $item = $dn; - - printf('',$href['return'], $item ); - echo ''; - echo "\n\n"; - } - -# Draw the root of the selection tree (ie, list all the servers) -} else { - foreach ($_SESSION[APPCONFIG]->getServerList() as $index => $server) { - if ($server->isLoggedIn(null)) { - printf('',_('Server'),$server->getName()); - foreach ($server->getBaseDN() as $dn) { - if (! $dn) { - printf('',_('Could not determine base DN')); - - } else { - $href['return'] = sprintf("javascript:returnDN('%s%s')",($request['rdn'] ? sprintf('%s,',$request['rdn']) : ''),rawurlencode($dn)); - $href['expand'] = htmlspecialchars(sprintf('entry_chooser.php?server_id=%s&form=%s&element=%s&rdn=%s&container=%s', - $server->getIndex(),$request['form'],$request['element'],$request['rdn'],rawurlencode($dn))); - - echo ''; - echo ''; - printf('',$href['expand'],IMGDIR); - printf('',$href['return'],$dn); - } - } - - echo ''; - } - } -} - -echo '
%s:%s
%s:%s
 
 Up%s...
 (%s)
 Plus%s
%s:%s
 (%s)
 Plus%s
 
'; -echo ''; - -# Capture the output and put into the body of the page. -$www['body'] = new block(); -$www['body']->SetBody(ob_get_contents()); -$www['page']->block_add('body',$www['body']); -ob_end_clean(); - -# Render the popup. -$www['page']->display(array('CONTROL'=>false,'FOOT'=>false,'HEAD'=>false,'TREE'=>false)); -?> diff --git a/htdocs/js/modify_member.js b/htdocs/js/modify_member.js deleted file mode 100644 index a601ccb..0000000 --- a/htdocs/js/modify_member.js +++ /dev/null @@ -1,89 +0,0 @@ -var m1 = document.getElementById('member').notmembers; -var m2 = document.getElementById('member').members; - -/* This function generates hidden input array from new group members - * when submit button is pressed. - * see modify_member_form.php -*/ -function update_new_values(memberattr) { - el = document.getElementById("dnu"); - - for (i=0;i"; - } -} - - -/* This function moves members from left select box to right one - * see modify_member_form.php - */ -function one2two() { - m1len = m1.length ; - - for (i=0;i=0;i--){ - if (m1.options[i].selected == true) { - m1.options[i] = null; - } - } -} - -/* This function moves members from right select box to left one - * see modify_member_form.php - */ -function two2one() { - m2len = m2.length ; - - for (i=0;i=0;i--) { - if (m2.options[i].selected == true) { - m2.options[i] = null; - } - } -} - -/* This function moves all members from left select box to right one - * see modify_member_form.php - */ -function all2two() { - m1len = m1.length ; - - for (i=0;i=0;i--) { - m1.options[i] = null; - } -} - -/* This function moves all members from right select box to left one - * see modify_member_form.php - */ -function all2one() { - m2len = m2.length ; - - for (i=0;i=0;i--) { - m2.options[i] = null; - } -} diff --git a/htdocs/mass_delete.php b/htdocs/mass_delete.php deleted file mode 100644 index 4f91ae4..0000000 --- a/htdocs/mass_delete.php +++ /dev/null @@ -1,147 +0,0 @@ -_('No entry selected'), - 'body'=>_('No entry was selected to delete'), - 'type'=>'warn'),'index.php'); - -if (! is_array($request['dn'])) - $request['dn'] = array($request['dn']); - -$request['children'] = array(); -$request['parent'] = array(); -foreach ($request['dn'] as $dn) { - # Check if the entry exists. - if (! $dn || ! $app['server']->dnExists($dn)) - system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn), - 'type'=>'error')); - - # We search all children, not only the visible children in the tree - if (! in_array_ignore_case($dn,$request['children'])) { - $request['children'] = array_merge($request['children'],$app['server']->getContainerContents($dn,null,0,'(objectClass=*)',LDAP_DEREF_NEVER)); - array_push($request['parent'],$dn); - } -} - -printf('

%s

',_('Mass Delete')); -printf('

%s: %s

',_('Server'),$app['server']->getName()); -echo "\n"; - -echo '
'; -echo ''; - -if (count($request['parent']) == 1) - printf('',_('Are you sure you want to permanently delete this object?')); -else - printf('',_('Are you sure you want to permanently delete these objects?')); - -echo ''; -printf('',_('Server'),$app['server']->getName()); - -foreach ($request['parent'] as $dn) - printf('', - _('Distinguished Name'),_('DN'),$dn); - -echo ''; - -$request['delete'] = $request['parent']; - -if (count($request['children'])) { - printf('',_('Permanently delete all children also?')); - echo ''; - - # We need to see if the children have children - $query = array(); - $query['scope'] = 'sub'; - $query['attrs'] = array('dn'); - $query['size_limit'] = 0; - $query['deref'] = LDAP_DEREF_NEVER; - - $request['search'] = array(); - foreach ($request['children'] as $dn) { - $query['base'] = $dn; - $request['search'] = array_merge($request['search'],$app['server']->query($query,null)); - } - - foreach ($request['search'] as $value) - array_push($request['delete'],$value['dn']); - - echo ''; - echo ''; - - printf('', - sprintf(_('phpLDAPadmin can also recursively delete all %s of the child entries. See below for a list of all the entries that this action will delete. Do you want to do this?'),count($request['children']))); - - echo ''; - - printf('', - _('Note: this is potentially very dangerous and you do this at your own risk. This operation cannot be undone. Take into consideration aliases, referrals, and other things that may cause problems.')); - echo "\n"; - - echo ''; - - echo "\n"; - - printf('',_('List of entries to be deleted:')); - echo ''; - - $i = 0; - echo ''; - echo "\n"; - - echo ''; -} - -echo ''; -echo ''; - -echo ''; -echo ''; -echo "\n"; - -echo '
%s
%s
 
%s:%s
%s%s
 
%s
 
'; - printf(_('This request also includes %s children entries.'),count($request['children'])); - echo '
%s
 
%s
 
%s
 
'; - printf(''; - echo '
 
'; -echo '
'; -echo ''; -printf('',$app['server']->getIndex()); -foreach ($request['parent'] as $dn) - printf('',htmlspecialchars($dn)); -printf('',sprintf(_('Delete all %s objects'),count($request['delete']))); -echo '
'; -echo '
'; - -echo '
'; -echo ''; -printf('',$app['server']->getIndex()); -printf('',_('Cancel')); -echo '
'; - -echo '
'; -echo '
'; - -echo '
'; -?> diff --git a/htdocs/mass_edit.php b/htdocs/mass_edit.php deleted file mode 100644 index 1ea7001..0000000 --- a/htdocs/mass_edit.php +++ /dev/null @@ -1,133 +0,0 @@ -dnExists($dn)) { - system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn), - 'type'=>'error')); - - continue; - } - - $request['page'][$counter] = new MassRender($app['server']->getIndex(),'none'); - $request['page'][$counter]->setDN($dn); - $request['page'][$counter]->accept(true); - - $template = $request['page'][$counter]->getTemplate(); - - # Mark our attributes to edit as shown. - foreach ($template->getAttributes(true) as $attribute) { - if ($attribute->isInternal()) - continue; - - if (in_array_ignore_case($attribute->getName(),$request['attrs']) || in_array('*',$request['attrs'])) { - $attribute->show(); - - # Get a list of our columns (we are not interested in these attribute values) - if (! isset($attrcols[$attribute->getName()])) - $attrcols[$attribute->getName()] = $attribute; - } - } - - $counter++; -} - -usort($attrcols,'sortAttrs'); - -if (! count($request['page'])) - header('Location: index.php'); - -# We'll render this forms Title with the first DN's object. -$request['page'][0]->drawTitle(_('Bulk edit the following DNs')); -$request['page'][0]->drawSubTitle(sprintf('%s: %s',_('Server'),$app['server']->getName())); - -echo '
'; -echo '
'; -echo ''; -printf('',$app['server']->getIndex()); - -foreach ($request['page'] as $j => $page) - printf('',$j,$page->getTemplate()->getDN()); - -echo '
'; - -echo ''; -echo ''; -echo ''; - -foreach ($attrcols as $attribute) { - echo ''; -} - -echo ''; - -$counter = 0; -foreach ($request['page'] as $j => $page) { - $template = $page->getTemplate(); - - printf('',$counter++%2==0?'even':'odd'); - printf('', - $template->getDN(),substr($template->getDN(),0,20)); - - foreach ($attrcols as $attrcol) { - $attribute = $template->getAttribute($attrcol->getName()); - - echo ''; - } - - echo ''; -} - -echo '
DN'; - $request['page'][0]->draw('Name',$attribute); - echo '
%s...'; - if ($attribute) { - foreach ($attribute->getValues() as $i => $val) - $page->draw('MassFormReadWriteValue',$attribute,$i,$j); - - # The attribute doesnt exist. If it is available by the shema, we can draw an empty input box. - } else { - $match = false; - - foreach ($template->getAvailAttrs() as $attribute) { - if ($attrcol->getName() == $attribute->getName()) { - $page->draw('MassFormReadWriteValue',$attribute,0,$j); - $match = true; - - break; - } - } - - if (! $match) - printf('
%s
', _('Attribute not available')); - } - - echo '
'; -echo '
'; -echo '
'; -printf('',_('Update Values')); -echo '
'; -echo '
'; -?> diff --git a/htdocs/mass_update.php b/htdocs/mass_update.php deleted file mode 100644 index 8a9dd01..0000000 --- a/htdocs/mass_update.php +++ /dev/null @@ -1,175 +0,0 @@ - $dn) { - # Check if the entry exists. - if (! $dn || ! $app['server']->dnExists($dn)) { - system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn), - 'type'=>'error')); - - continue; - } - - # Simulate the requirements for *Render->accept() - if (! isset($request['mass_values'][$index])) - continue; - - $_REQUEST['new_values'] = $request['mass_values'][$index]; - - $render = new MassRender($app['server']->getIndex(),'none'); - $render->setDN($dn); - $render->accept(true); - - if ($render->getTemplate()->getLDAPmodify(false,$index)) - $request['update'][$index] = $render; -} - -# We can use the $render to give us a title -$render->drawTitle(_('Bulk update the following DNs')); -$render->drawSubTitle(sprintf('%s: %s',_('Server'),$app['server']->getName())); - -if (count($request['update'])) { - if (get_request('confirm','REQUEST')) { - foreach ($request['update'] as $index => $page) { - $template = $page->getTemplate(); - - # Perform the modification - $result = $app['server']->modify($template->getDN(),$template->getLDAPmodify(false,$index)); - - if ($result) - printf('%s: %s
',$template->getDN(),_('Modification successful!')); - else - printf('%s: %s
',$template->getDN(),_('Modification NOT successful!')); - } - - } else { - echo '
'; - echo ''; - printf('',$app['server']->getIndex()); - echo ''; - - foreach ($request['update'] as $j => $page) - printf('',$j,$page->getTemplate()->getDN()); - - echo ''; - echo ''; - echo '
'; - - echo '
'; - - echo ''; - echo ''; - echo '
'; - printf(_('There will be %s updates done with this mass update'),sprintf('%s',count($request['update']))); - echo '
'; - - echo '
'; - - foreach ($request['update'] as $index => $page) { - $template = $page->getTemplate(); - - echo ''; - echo ''; - printf('',IMGDIR,get_icon($app['server']->getIndex(),$template->getDN())); - - printf('', - $app['server']->getIndex(),rawurlencode(dn_unescape($template->getDN())),htmlspecialchars(get_rdn($template->getDN()))); - echo ''; - - printf('', - htmlspecialchars(dn_unescape($template->getDN())),_('Old Value')); - - foreach ($template->getLDAPmodify(true,$index) as $attribute) { - echo ''; - echo ''; - - echo ''; - - # Show NEW Values - echo ''; - - # Show OLD Values - echo ''; - - echo ''; - } - - echo '
icon%s
 dn%s%s
 '; - $page->draw('Name',$attribute); - echo ''; - - if (! $attribute->getValueCount() || $attribute->isForceDelete()) { - printf('[%s]',_('attribute deleted')); - printf('',$index,$attribute->getName(),0,''); - } - - foreach ($attribute->getValues() as $key => $value) { - # For multiple values, we'll highlight the changed ones - if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues())) - echo ''; - - $page->draw('CurrentValue',$attribute,$key); - - # For multiple values, close the highlighting - if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues())) - echo ''; - - echo '
'; - printf('',$index,$attribute->getName(),$key,$value); - } - - echo '
'; - - if (! $attribute->getOldValues()) - printf('[%s]',_('attribute doesnt exist')); - - foreach ($attribute->getOldValues() as $key => $value) { - # For multiple values, we'll highlight the changed ones - if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues())) - echo ''; - - $page->draw('OldValue',$attribute,$key); - - # For multiple values, close the highlighting - if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues())) - echo ''; - - echo '
'; - } - - echo '
'; - - echo '
'; - } - - echo '
'; - printf('',_('Update Values')); - echo '
'; - } - -} else { - echo '
'; - echo _('You made no changes'); - echo '
'; -} -?> diff --git a/htdocs/modify_member_form.php b/htdocs/modify_member_form.php deleted file mode 100644 index a3e4d09..0000000 --- a/htdocs/modify_member_form.php +++ /dev/null @@ -1,178 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,null)); -$request['page']->setDN($request['dn']); -$request['page']->accept(true); -$request['template'] = $request['page']->getTemplate(); - -if (! is_null($request['dn'])) - $rdn = get_rdn($request['dn']); -else - $rdn = null; - -# Get all current group members -$current_members = $app['server']->getDNAttrValue($request['dn'],$request['attr']); -usort($current_members,'pla_compare_dns'); - -# Loop through all base dn's and search possible member entries -$query = array(); - -# Get all entries that can be added to the group -if (preg_match("/^".$request['attr']."$/i",$_SESSION[APPCONFIG]->getValue('modify_member','posixgroupattr'))) { - $query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member','posixfilter'); - $attr = $_SESSION[APPCONFIG]->getValue('modify_member','posixattr'); - -} else { - $query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member','filter'); - $attr = $_SESSION[APPCONFIG]->getValue('modify_member','attr'); -} - -$query['attrs'] = array($attr); - -$possible_values = array(); -foreach ($app['server']->getBaseDN() as $base) { - $query['base'] = $base; - - $possible_values = array_merge($possible_values,$app['server']->query($query,null)); -} - -usort($possible_values,'pla_compare_dns'); - -$request['page']->drawTitle(sprintf('%s %s',_('Modify group'),get_rdn($request['dn']))); -$request['page']->drawSubTitle(); - -printf('%s %s %s %s:', - _('There are'),count($current_members),_('members in group'),htmlspecialchars(get_rdn($request['dn']))); - -$possible_members = array(); -for ($i=0;$igetValue('modify_member','posixgroupattr'))) - $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','posixattr')][0]; - else - $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','attr')][0]; -} - -# Show only user that are not already in group. -$possible_members = array_diff($possible_members,$current_members); -usort($possible_members,'pla_compare_dns'); - -/* Draw form with select boxes, left for all possible members and - * right one for those that belong to group */ - -# Modifications will be sent to update_confirm which takes care of rest of the processing -echo '
'; -echo '
'; - -echo '
'; -echo '
'; -if ($_SESSION[APPCONFIG]->getValue('confirm','update')) - echo ''; -else - echo ''; -echo '
'; - -echo ''; - -echo ''; -printf('',IMGDIR,_('Available members')); -printf('',IMGDIR,_('Group members')); -echo ''; - -# Generate select box from all possible members -echo ''; -echo ''; - -# Generate select box from all current members -echo ''; - -echo ''; - -# Show buttons which move users from left to right and vice versa -echo ''; -echo ''; -echo ''; -echo ''; - -echo ''; - -echo '
Users %sMembers %s
'; -echo ''; -echo ''; -echo ''; -echo '
'; -printf(' ', - _('Add selected'),_('Add all')); -echo ''; -printf(' ', - _('Remove selected'),('Remove all')); -echo '
'; - -# Hidden attributes for update_confirm.php -printf('',$app['server']->getIndex()); -printf('',rawurlencode($request['dn'])); -printf('',$request['attr']); - -/* Generate array of input text boxes from current members. - * update_confirm.php will see this as old_values[member-attribute][item] */ -for ($i=0; $i', - htmlspecialchars($request['attr']),$i,htmlspecialchars($current_members[$i])); - -/* Javascript generates array of input text boxes from new members. - * update_confirm.php will see this as new_values[member-attribute][item] - * Input text boxes will be generated to div=dnu */ -echo '
'; -printf('',htmlspecialchars($request['attr'])); -echo '
'; - -# Submit values to update_confirm.php and when clicked, run addSelected -printf('',_('Save changes'),$request['attr']); -echo '
'; -echo '
'; -printf('',JSDIR); -?> diff --git a/htdocs/password_checker.php b/htdocs/password_checker.php deleted file mode 100644 index c616e2e..0000000 --- a/htdocs/password_checker.php +++ /dev/null @@ -1,88 +0,0 @@ -%s',_('Password Checker Tool')); - -echo '
'; -echo ''; -printf('',$request['attribute']); - -echo ''; - -echo ''; -printf('',_('Compare')); -printf('', - (obfuscate_password_display($request['enc_type']) ? 'password' : 'text'),htmlspecialchars($request['hash'])); -echo ''; - -echo ''; -printf('',_('To')); -printf('', - htmlspecialchars($request['password'])); -echo ''; - -echo ''; -echo ''; - -echo ''; -echo ''; -echo '
%s
%s
 '; - -if ($request['action'] == 'compare') { - echo '    '; - - if (password_check($request['hash'],$request['password'],$request['attribute'])) - printf('%s',_('Passwords match!')); - else - printf('%s',_('Passwords do not match!')); - - echo ''; -} - -echo '
'; -echo '
'; - -# Pull our password from the form that opened this window. -if ($request['componentid']) { - echo ''; -} - -# Capture the output and put into the body of the page. -$www['body'] = new block(); -$www['body']->SetBody(ob_get_contents()); -$www['page']->block_add('body',$www['body']); -ob_end_clean(); - -# Render the popup. -$www['page']->display(array('CONTROL'=>false,'FOOT'=>false,'HEAD'=>false,'TREE'=>false)); -?> diff --git a/htdocs/query_engine.php b/htdocs/query_engine.php deleted file mode 100644 index a94fedd..0000000 --- a/htdocs/query_engine.php +++ /dev/null @@ -1,19 +0,0 @@ -getIndex(),get_request('query','REQUEST',false,null)); -$request['page']->accept(); -?> diff --git a/htdocs/rdelete.php b/htdocs/rdelete.php deleted file mode 100644 index bb864a9..0000000 --- a/htdocs/rdelete.php +++ /dev/null @@ -1,89 +0,0 @@ -dnExists($dn)) - system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s)',_('Unable to delete entry, it does not exist'),$dn), - 'type'=>'error')); - else - array_push($request['parent'],$dn); - -printf('

%s

',_('Delete LDAP entries')); -printf('

%s

',_('Recursive delete progress')); - -# Prevent script from bailing early on a long delete -@set_time_limit(0); - -foreach ($request['parent'] as $dn) { - echo '

'; - echo ''; - $result = pla_rdelete($app['server'],$dn); - echo '
'; - - if ($result) { - printf(_('Entry %s and sub-tree deleted successfully.'),''.$dn.''); - - } else { - system_message(array( - 'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($request['dn'])), - 'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)), - 'type'=>'error')); - } -} - -function pla_rdelete($server,$dn) { - # We delete all children, not only the visible children in the tree - $children = $server->getContainerContents($dn,null,0,'(objectClass=*)',LDAP_DEREF_NEVER); - - if (! is_array($children) || count($children) == 0) { - printf('%s %s...',_('Deleting'),$dn); - - if ($server->delete($dn)) { - printf(' %s
',_('Success')); - return true; - - } else { - system_message(array( - 'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($dn)), - 'body'=>ldap_error_msg($server->getErrorMessage(null),$server->getErrorNum(null)), - 'type'=>'error')); - } - - } else { - foreach ($children as $child_dn) - pla_rdelete($server,$child_dn); - - printf('%s %s...',_('Deleting'),$dn); - - if ($server->delete($dn)) { - printf(' %s
',_('Success')); - return true; - - } else { - system_message(array( - 'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($dn)), - 'body'=>ldap_error_msg($server->getErrorMessage(null),$server->getErrorNum(null)), - 'type'=>'error')); - } - } -} -?> diff --git a/htdocs/rename.php b/htdocs/rename.php deleted file mode 100644 index 96c2e33..0000000 --- a/htdocs/rename.php +++ /dev/null @@ -1,64 +0,0 @@ -getContainer($request['dnSRC']); - -# Error checking -if (! $app['server']->isBranchRenameEnabled()) { - # We search all children, not only the visible children in the tree - $children = $app['server']->getContainerContents($request['dnSRC'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER); - - if (count($children) > 0) - error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'),'error','index.php'); -} - -$request['dnDST'] = sprintf('%s,%s',$request['rdnDST'],$request['container']); - -if ($request['dnDST'] == $request['dnSRC']) - error(_('You did not change the RDN'),'error','index.php'); - -$rdnattr = array(); -$rdnattr['SRC'] = explode('=',$request['dnSRC']); -$rdnattr['SRC'] = $rdnattr['SRC'][0]; - -$new_dn_value = explode('=',$request['rdnDST'],2); -$rdnattr['DST'] = $new_dn_value[0]; - -if (count($new_dn_value) != 2 || ! isset($new_dn_value[1])) - error(_('Invalid RDN value'),'error','index.php'); - -$deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST']; -$success = $app['server']->rename($request['dnSRC'],$request['rdnDST'],$request['container'],$deleteoldrdn); - -if ($success) { - $rename_message = sprintf('%s',_('Rename successful!')); - $redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&template=%s', - $app['server']->getIndex(),rawurlencode($request['dnDST']),get_request('template','REQUEST')); - - system_message(array( - 'title'=>_('Rename Entry'), - 'body'=>$rename_message, - 'type'=>'info'), - $redirect_url); - -} else { - system_message(array( - 'title'=>_('Could not rename the entry.'), - 'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)), - 'type'=>'error')); -} -?> diff --git a/htdocs/rename_form.php b/htdocs/rename_form.php deleted file mode 100644 index aebc5fb..0000000 --- a/htdocs/rename_form.php +++ /dev/null @@ -1,40 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,'none')); -$request['page']->setDN($request['dn']); -$request['page']->accept(); - -# Render the form -$request['page']->drawTitle(sprintf('%s %s',_('Rename'),get_rdn($request['dn']))); -$request['page']->drawSubTitle(); - -echo '
'; -printf('%s %s %s:

',_('Rename'),get_rdn($request['dn']),_('to a new object')); - -echo '
'; -printf('',$app['server']->getIndex()); -printf('',rawurlencode($request['dn'])); -printf('',$request['template']); -printf('',get_rdn($request['dn'])); -printf('',_('Rename')); -echo '
'; - -echo '
'; -echo "\n"; -?> diff --git a/htdocs/template_engine.php b/htdocs/template_engine.php deleted file mode 100644 index 1cfaba9..0000000 --- a/htdocs/template_engine.php +++ /dev/null @@ -1,57 +0,0 @@ -getIndex(),get_request('template','REQUEST',false,null)); - -# If we have a DN, then this is to edit the entry. -if ($request['dn']) { - $app['server']->dnExists($request['dn']) - or error(sprintf('%s (%s)',_('No such entry'),pretty_print_dn($request['dn'])),'error','index.php'); - - $request['page']->setDN($request['dn']); - $request['page']->accept(); - -} else { - if ($app['server']->isReadOnly()) - error(_('You cannot perform updates while server is in read-only mode'),'error','index.php'); - - $request['page']->setContainer(get_request('container','REQUEST')); - $request['page']->accept(); -} -?> diff --git a/lib/MassRender.php b/lib/MassRender.php deleted file mode 100644 index f0bf67e..0000000 --- a/lib/MassRender.php +++ /dev/null @@ -1,48 +0,0 @@ -%s
',__METHOD__); - - $val = $attribute->getValue($i); - - if ($attribute->getHelper()) - echo '
'; - - printf('', - $j,htmlspecialchars($attribute->getName()),$i, - $j,htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($val), - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - if ($attribute->getHelper()) { - echo ''; - $this->draw('AttributeHelper',$attribute,$i); - echo '
'; - } - } - - protected function drawMassFormReadWriteValueBinaryAttribute($attribute,$i,$j) { - $this->drawFormReadWriteValueBinaryAttribute($attribute,$i); - } - - protected function drawMassFormReadWriteValueJpegAttribute($attribute,$i,$j) { - $this->drawFormReadOnlyValueJpegAttribute($attribute,$i); - } -} -?> diff --git a/lib/PageRender.php b/lib/PageRender.php deleted file mode 100644 index 5d88498..0000000 --- a/lib/PageRender.php +++ /dev/null @@ -1,1201 +0,0 @@ -server_id = $server_id; - $this->template_id = $template_id; - } - - /** - * Dummy method... - */ - protected function visitAttribute() {} - - /** - * Get our templates applicable for this object - */ - protected function getTemplates() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return new Templates($this->server_id); - } - - public function getTemplate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $this->template; - } - - public function getTemplateID() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $this->template->getID(); - } - - /** - * Initialise the PageRender - */ - public function accept() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s:%s
',time(),__METHOD__); - - if ($this->template_id) { - $templates = $this->getTemplates(); - $this->template = $templates->getTemplate($this->template_id); - - if ($this->dn) - $this->template->setDN($this->dn); - elseif ($this->container) - $this->template->setContainer($this->container); - - $this->template->accept(); - - # Process our actions - if (get_request('post_value','REQUEST')) - foreach (get_request('post_value','REQUEST') as $attr => $values) { - $attribute = $this->template->getAttribute($attr); - - if (! $attribute) - debug_dump_backtrace(sprintf('There was a post_value for an attribute [%s], but it doesnt exist?',$attr),1); - - foreach ($values as $index) - if ($attribute->getPostValue()) - $this->get('Post',$attribute,$index); - else - $this->get('AutoPost',$attribute,$index); - } - - foreach ($this->template->getAttributes(true) as $attribute) { - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Accept:%s]
',__METHOD__,get_class($attribute)); - - $this->visit('',$attribute); - } - - // Sort our attribute values for display, if we are the custom template. - if ($this->template->getID() == 'none') - $this->template->sort(); - } - } - - public function drawTitle($title='Title') { - printf('

%s

',$title); - } - - public function drawSubTitle($subtitle=null) { - if (is_null($subtitle)) - $subtitle = sprintf('%s: %s   %s: %s', - _('Server'),$this->getServer()->getName(),_('Distinguished Name'),$this->dn); - - printf('

%s

',$subtitle); - } - - public function setDN($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->container) - system_message(array( - 'title'=>__METHOD__, - 'body'=>'CONTAINER set while setting DN', - 'type'=>'info')); - - $this->dn = $dn; - } - - public function setContainer($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->dn) - system_message(array( - 'title'=>__METHOD__, - 'body'=>'DN set while setting CONTAINER', - 'type'=>'info')); - - $this->container = $dn; - } - - /** - * May be overloaded in other classes - */ - protected function getMode() {} - protected function getModeContainer() {} - - /** - * Process our arguments from the templates - */ - protected function getPostAttribute($attribute,$i) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $autovalue = $attribute->getPostValue(); - $args = explode(';',$autovalue['args']); - $server = $this->getServer(); - $vals = $attribute->getValues(); - - switch ($autovalue['function']) { - /** - * Join will concatenate values with a string, similiar to explode() - * eg: =php.Join(-;%sambaSID%,%sidsuffix%) - * - * * arg 0 - * - character to use when joining the attributes - * - * * arg 1 - * - values to concatenate together. we'll explode %attr% values. - */ - case 'Join': - preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',$args[1],$matchall); - $matchattrs = $matchall[1]; - $char = $args[0]; - - $values = array(); - $blank = 0; - foreach ($matchattrs as $joinattr) { - $attribute2 = $this->template->getAttribute($joinattr); - - if (! $attribute2) { - if (($pv = get_request(strtolower($joinattr),'REQUEST')) && isset($pv[$attribute->getName()][$i])) { - array_push($values,$pv[$attribute->getName()][$i]); - - if (! $pv[$attribute->getName()][$i]) - $blank++; - - } else { - array_push($values,''); - $blank++; - } - - } elseif (count($attribute2->getValues()) == 0) { - return; - - } elseif (count($attribute2->getValues()) != 1) { - array_push($values,''); - $blank++; - - system_message(array( - 'title'=>_('Invalid value count for [post] processing'), - 'body'=>sprintf('%s (%s [%s])',_('Function() variable expansion can only handle 1 value'), - $attribute->getName(false),count($attribute->getValues())), - 'type'=>'warn')); - - } else - array_push($values,$attribute2->getValue(0)); - } - - # If all our value expansion results in blanks, we'll return no value - if (count($matchattrs) == $blank) - if (count($vals) > 1) - $vals[$i] = null; - else - $vals = null; - - else - $vals[$i] = implode($char,$values); - - break; - - /** - * PasswordEncrypt will encrypt a password - * eg: =php.PasswordEncrypt(%enc%;%userPassword%) - * - * This function will encrypt the users password "userPassword" using the "enc" method. - */ - case 'PasswordEncrypt': - if (count($args) != 2) { - system_message(array( - 'title'=>_('Invalid argument count for PasswordEncrypt'), - 'body'=>sprintf('%s (%s)',_('PasswordEncrypt() only accepts two arguments'),$autovalue['args']), - 'type'=>'warn')); - - return; - } - - if (! $attribute->hasBeenModified()) - return; - - # Get the attribute. - if (preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',strtolower($args[1]),$matchall)) { - if (count($matchall[1]) != 1) - system_message(array( - 'title'=>_('Invalid value count for PasswordEncrypt'), - 'body'=>sprintf('%s (%s)',_('Unable to get the attribute value for PasswordEncrypt()'),count($matchall[1])), - 'type'=>'warn')); - - $passwordattr = $matchall[1][0]; - $passwordvalue = $_REQUEST['new_values'][$passwordattr][$i]; - - } else - $passwordvalue = $args[1]; - - if (! trim($passwordvalue) || in_array($passwordvalue,$attribute->getOldValues())) - return; - - # Get the encoding - if ($passwordattr && preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',strtolower($args[0]),$matchall)) { - if (count($matchall[1]) != 1) - system_message(array( - 'title'=>_('Invalid value count for PasswordEncrypt'), - 'body'=>sprintf('%s (%s)',_('Unable to get the attribute value for PasswordEncrypt()'),count($matchall[1])), - 'type'=>'warn')); - - $enc = $_REQUEST[$matchall[1][0]][$passwordattr][$i]; - - } else - $enc = $args[0]; - - $enc = strtolower($enc); - - switch ($enc) { - case 'lm': - $sambapassword = new smbHash; - $vals[$i] = $sambapassword->lmhash($passwordvalue); - - break; - - case 'nt': - $sambapassword = new smbHash; - $vals[$i] = $sambapassword->nthash($passwordvalue); - - break; - - default: - $vals[$i] = pla_password_hash($passwordvalue,$enc); - } - - $vals = array_unique($vals); - - break; - - default: - $vals = $this->get('AutoPost',$attribute,$i); - } - - if (! $vals || $vals == $attribute->getValues()) - return; - - $attribute->clearValue(); - - if (! is_array($vals)) - $attribute->setValue(array($vals)); - else - $attribute->setValue($vals); - } - - /** - * This function is invoked if we dont know which template we should be using. - * - * @return string Template ID to be used or null if the user was presented with a list. - */ - protected function getTemplateChoice() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # First work out our template - $templates = $this->getTemplates(); - $template = $templates->getTemplate($this->template_id); - - # If the template we asked for is available - if ($this->template_id === $template->getID()) { - if (DEBUGTMP) printf('%s:%s
',__METHOD__,'Choosing the SELECTED template'); - - return $this->template_id; - - # If there are no defined templates - } elseif (count($templates->getTemplates($this->getMode(),$this->getModeContainer(),false)) <= 0) { - if (DEBUGTMP) printf('%s:%s
',__METHOD__,'Choosing the DEFAULT template, no other template applicable'); - - # Since getTemplate() returns a default template if the one we want doesnt exist, we can return $templates->getID(), it should be the default. - if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template') AND $this->getMode() == 'creation') { - - system_message(array( - 'title'=>_('No available templates'), - 'body'=>_('There are no available active templates for this container.'), - 'type'=>'warn')); - - return 'invalid'; - - } else - return $template->getID(); - - # If there is only 1 defined template, and no default available, then that is our template. - } elseif ((count($templates->getTemplates($this->getMode(),$this->getModeContainer(),true)) == 1) && ! $this->haveDefaultTemplate()) { - if (DEBUGTMP) printf('%s:%s
',__METHOD__,'AUTOMATIC choosing a template, only 1 template applicable'); - - $template = $templates->getTemplates($this->getMode(),$this->getModeContainer(),true); - $template = array_shift($template); - - # Dont render the only available template if it is invalid. - if (! $template->isInvalid()) - return $template->getID(); - else - $this->drawTemplateChoice(); - - } else { - if (DEBUGTMP) printf('%s:%s
',__METHOD__,'SELECT a template to use.'); - - # Propose the template choice - $this->drawTemplateChoice(); - } - - # If we got here, then there wasnt a template. - return null; - } - - /** DRAW ATTRIBUTE NAME **/ - - final protected function drawNameAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=attributes&viewvalue=%s', - $this->getServerID(),$attribute->getName()); - - if (! $_SESSION[APPCONFIG]->getValue('appearance','show_schema_link') || !$_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) - printf('%s',_($attribute->getFriendlyName())); - - elseif ($attribute->getLDAPtype()) - printf('%s', - htmlspecialchars($href), - _('Click to view the schema definition for attribute type'),$attribute->getName(false),_($attribute->getFriendlyName())); - else - printf('%s',_('This attribute is not defined in the LDAP schema'),_($attribute->getFriendlyName())); - - if (DEBUGTMPSUB) printf(' [%s]',get_class($attribute)); - } - - /** ATTRIBUTE NOTES */ - - protected function drawNotesAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $attr_note = ''; - - foreach (array('NoteAlias','NoteRequired','NoteRDN','NoteHint','NoteRO') as $note) { - $alias_note = $this->get($note,$attribute); - - if ($alias_note) { - if (trim($attr_note)) - $attr_note .= ', '; - - $attr_note .= $alias_note; - } - } - - if ($attr_note) - printf('%s',$attr_note); - } - - protected function getNoteAliasAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Is there a user-friendly translation available for this attribute? - $friendly_name = $attribute->getFriendlyName(); - - if (strtolower($friendly_name) != $attribute->getName()) - return sprintf('%s', - _('Note'),$friendly_name,_('is an alias for'),$attribute->getName(false),_('alias')); - else - return ''; - } - - protected function getNoteRDNAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Is this attribute required because its the RDN - if ($attribute->isRDN()) - return sprintf('rdn',_('This attribute is required for the RDN.')); - else - return ''; - } - - protected function getNoteHintAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Is there a hint for this attribute - if ($attribute->getHint()) - return sprintf('%s',_($attribute->getHint()),_('hint')); - else - return ''; - } - - protected function getNoteROAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Is this attribute is readonly - if ($attribute->isReadOnly()) - return sprintf('ro',_('This attribute has been marked as Read Only.')); - else - return ''; - } - /** DRAW HIDDEN VALUES **/ - - /** - * Draw all hidden attributes - */ - final public function drawHiddenAttributes() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - foreach ($this->template->getAttributes(true) as $attribute) - if ($attribute->hasbeenModified()) { - if ($attribute->getValues()) - foreach ($attribute->getValues() as $index => $details) - $this->draw('HiddenValue',$attribute,$index); - - # We are deleting this attribute, so we need to display an empty value - else - $this->draw('HiddenValue',$attribute,0); - } - } - - /** - * Draw specific hidden attribute - */ - final protected function drawHiddenValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - printf('', - htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($val)); - } - - /** DRAW DISPLAYED OLD VALUES **/ - protected function drawOldValuesAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - foreach ($attribute->getValues() as $index => $details) - $this->draw('OldValue',$attribute,$index); - } - - final protected function drawOldValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo $attribute->getOldValue($i); - } - - /** DRAW DISPLAYED CURRENT VALUES **/ - - protected function drawCurrentValuesAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - for ($i=0;$i<$attribute->getValueCount();$i++) { - if ($i > 0) - echo '
'; - - $this->draw('CurrentValue',$attribute,$i); - } - } - - /** - * Draw the current specific value of an attribute - */ - final protected function drawCurrentValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - echo htmlspecialchars($attribute->getValue($i)); - } - - /** - * Draw a input value for an attribute - used in a form. - */ - protected function drawFormValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - if ($this->getServer()->isReadOnly() || $attribute->isReadOnly() - || ($attribute->isRDN() && $this->template->getType() != 'creation' && $i < count($attribute->getValues()))) - - $this->draw('FormReadOnlyValue',$attribute,$i); - else - $this->draw('FormReadWriteValue',$attribute,$i); - - # Show the ADDVALUE DIV if the attribute can have more values, and we have rendered the last value - if ($attribute->haveMoreValues() && $attribute->getValueCount() == $i+1) - printf('
',$attribute->getName()); - - if ($attribute->getPostValue()) - printf('',$attribute->getName(),$i); - } - - protected function drawFormReadOnlyValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - printf('', - htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,htmlspecialchars($val)); - } - - protected function drawFormReadWriteValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - if ($attribute->getHelper() || $attribute->getVerify()) - echo ''; - - } elseif ($attribute->getVerify()) - echo ''; - - if ($attribute->getVerify()) { - printf(''; - } - - if ($attribute->getHelper() || $attribute->getVerify()) - echo '
'; - - printf('', - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($val), - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - if ($attribute->getHelper()) { - echo ''; - $this->draw('AttributeHelper',$attribute,$i); - echo '
', - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - echo ''; - printf('(%s)',_('confirm')); - echo '
'; - } - - /** - * Draw specific hidden binary attribute - */ - final protected function drawHiddenValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - printf('', - htmlspecialchars($attribute->getName()),$i,base64_encode($val)); - } - - final protected function drawOldValueBinaryAttribute($attribute,$i) { - # If we dont have a value, we'll just return; - if (! $attribute->getOldValue($i)) - return; - - printf('[%s]',_('Binary Value')); - } - - final protected function drawCurrentValueBinaryAttribute($attribute,$i) { - printf('[%s]',_('Binary Value')); - - if (in_array($attribute->getName(),array('objectsid'))) - printf(' (%s)', binSIDtoText($attribute->getValue(0))); - } - - protected function drawFormReadOnlyValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->draw('CurrentValue',$attribute,$i); - echo '

'; - - $href = sprintf('download_binary_attr.php?server_id=%s&dn=%s&attr=%s&index=%s', - $this->getServerID(),rawurlencode($this->template->getDN()),$attribute->getName(),$i); - - printf('Save %s', - htmlspecialchars($href),IMGDIR,_('download value')); - - echo '
'; - } - - protected function drawFormReadWriteValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($attribute->getValue($i)) { - $this->draw('FormReadOnlyValue',$attribute,$i); - - if (! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr')) - printf('Trash %s', - $attribute->getName(),$attribute->getFriendlyName(),$i,IMGDIR,_('delete attribute')); - - } else { - printf('
', - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', - ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); - } - } - - protected function drawFormReadWriteValueDateAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - echo ''; - printf(' ', - $attribute->getName(),$i, - htmlspecialchars($attribute->getName()),$i,htmlspecialchars($val), - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - $this->draw('SelectorPopup',$attribute,$i); - echo ''."\n"; - } - - protected function drawFormReadWriteValueDnAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - if ($attribute->getHelper()) - echo '
'; - - $input_name = sprintf('new_values[%s][%s]',htmlspecialchars($attribute->getName()),$i); - $id = sprintf('new_values_%s_%s',htmlspecialchars($attribute->getName()),$i); - - printf(' ', - $input_name,$id,htmlspecialchars($val), - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', - ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); - - # Draw a link for popping up the entry browser if this is the type of attribute that houses DNs. - draw_chooser_link('entry_form',$id,false); - echo ''; - - if ($attribute->getHelper()) { - echo ''; - $this->draw('Helper',$attribute,$i); - echo '
'; - } - - echo "\n"; - } - - protected function drawFormReadWriteValueGidAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->drawFormReadWriteValueAttribute($attribute,$i); - - $server = $this->getServer(); - $val = $attribute->getValue($i); - - # If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience - if ($this->template->getDN() && ! in_array_ignore_case('posixGroup',$this->getServer()->getDNAttrValue($this->template->getDN(),'objectclass'))) { - $query['filter'] = sprintf('(&(objectClass=posixGroup)(gidNumber=%s))',$val); - $query['attrs'] = array('dn','description'); - - # Reorganise our base, so that our base is first - $bases = array_unique(array_merge(array($server->getContainerTop($this->template->getDN())),$server->getBaseDN())); - - # Search our bases, until we find a match. - foreach ($bases as $base) { - $query['base'] = $base; - $group = $this->getServer()->query($query,null); - - if (count($group) > 0) { - echo '
'; - - $group = array_pop($group); - $group_dn = $group['dn']; - $group_name = explode('=',get_rdn($group_dn)); - $group_name = $group_name[1]; - $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', - $this->getServerID(),rawurlencode($group_dn)); - - echo ''; - printf('%s',htmlspecialchars($href),$group_name); - - $description = isset($group['description']) ? $group['description'] : null; - - if (is_array($description)) - foreach ($description as $item) - printf(' (%s)',$item); - else - printf(' (%s)',$description); - - echo ''; - - break; - } - } - } - } - - /** - * Draw a Jpeg Attribute - */ - final protected function drawOldValueJpegAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - # If we dont have a value, we'll just return; - if (! $attribute->getOldValue($i)) - return; - - draw_jpeg_photo($this->getServer(),$this->template->getDN(),$attribute->getName(),$i,false,false); - } - - /** - * Draw a Jpeg Attribute - */ - final protected function drawCurrentValueJpegAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - # If we dont have a value, we'll just return; - if (! $attribute->getValue($i)) - return; - - # If the attribute is modified, the new value needs to be stored in a session variable for the draw_jpeg_photo callback. - if ($attribute->hasBeenModified()) { - $_SESSION['tmp'][$attribute->getName()][$i] = $attribute->getValue($i); - draw_jpeg_photo(null,$this->template->getDN(),$attribute->getName(),$i,false,false); - } else - draw_jpeg_photo($this->getServer(),$this->template->getDN(),$attribute->getName(),$i,false,false); - } - - protected function drawFormReadOnlyValueJpegAttribute($attribute,$i) { - $this->draw('HiddenValue',$attribute,$i); - $_SESSION['tmp'][$attribute->getName()][$i] = $attribute->getValue($i); - - draw_jpeg_photo(null,$this->template->getDN(),$attribute->getName(),$i,false,false); - } - - protected function drawFormReadOnlyValueMultiLineAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - printf('', - ($attribute->getRows() > 0) ? $attribute->getRows() : 5, - ($attribute->getCols() > 0) ? $attribute->getCols() : 100, - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - $val); - } - - protected function drawFormReadWriteValueMultiLineAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - printf('', - ($attribute->getRows() > 0) ? $attribute->getRows() : 5, - ($attribute->getCols() > 0) ? $attribute->getCols() : 100, - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - $val); - } - - protected function drawFormValueObjectClassAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $val = $attribute->getValue($i); - - /* It seems that openLDAP allows us to remove additional structural objectclasses - however other LDAP servers, dont remove them (even if we ask them to). */ - # Do we have our internal attributes. - $internal = $this->template->getAttribute('structuralobjectclass'); - - if ($internal) { - $structural = in_array_ignore_case($val,$internal->getValues()); - - # We'll work it out the traditional way. - } else { - # If this schema structural? - $schema_object = ($val) ? $this->getServer()->getSchemaObjectClass($val) : false; - $structural = (is_object($schema_object) && $schema_object->getType() == 'structural'); - } - - if ($structural) { - $this->draw('FormReadOnlyValue',$attribute,$i); - - printf(' (%s)', - _('This is a structural ObjectClass and cannot be removed.'), - _('structural')); - - } else - $this->draw('FormReadWriteValue',$attribute,$i); - } - - protected function getAutoPostPasswordAttribute($attribute,$i) { - # If the password is already encoded, then we'll return - if (preg_match('/^\{.+\}.+/',$attribute->getValue($i))) - return; - - $attribute->setPostValue(array('function'=>'PasswordEncrypt','args'=>sprintf('%%enc%%;%%%s%%',$attribute->getName()))); - $this->get('Post',$attribute,$i); - } - - protected function drawOldValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - $val = $attribute->getOldValue($i); - - if (obfuscate_password_display(get_enc_type($val))) - echo str_repeat('*',16); - else - echo nl2br(htmlspecialchars($attribute->getOldValue($i))); - } - - final protected function drawCurrentValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); - - $val = $attribute->getValue($i); - - if (obfuscate_password_display(get_enc_type($val))) - echo str_repeat('*',16); - else - echo nl2br(htmlspecialchars($attribute->getValue($i))); - } - - protected function drawFormReadOnlyValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $server = $this->getServer(); - $val = $attribute->getValue($i); - - if (trim($val)) - $enc_type = get_enc_type($val); - else - $enc_type = $server->getValue('appearance','pla_password_hash'); - - $obfuscate_password = obfuscate_password_display($enc_type); - - printf('
', - ($obfuscate_password ? 'password' : 'text'), - htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()), - $i,htmlspecialchars($val),($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : ''); - - if (trim($val)) - $this->draw('CheckLink',$attribute,'new_values_'.htmlspecialchars($attribute->getName()).'_'.$i); - } - - protected function drawFormReadWriteValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $server = $this->getServer(); - $val = $attribute->getValue($i); - - $enc_type = get_enc_type($val); - - # Set the default hashing type if the password is blank (must be newly created) - if (trim($val)) - $enc_type = get_enc_type($val); - else - $enc_type = $server->getValue('appearance','pla_password_hash'); - - echo '
'; - - $obfuscate_password = obfuscate_password_display($enc_type); - $id = sprintf('new_values_%s_%s',htmlspecialchars($attribute->getName()),$i); - - printf('', - ($obfuscate_password ? 'password' : 'text'), - htmlspecialchars($attribute->getName()),$i,$id, - htmlspecialchars($val), - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - echo ''; - - if ($attribute->getHelper()) - $this->draw('Helper',$attribute,$i); - else - $this->draw('DefaultHelper',$attribute,$i); - - echo '
'; - - if ($attribute->getVerify() && $obfuscate_password) { - printf('', - htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($attribute->getName()),$i, - ($attribute->getSize() > 0) ? sprintf('size="%s"',$attribute->getSize()) : '', - ($attribute->getMaxLength() > 0) ? sprintf('maxlength="%s"',$attribute->getMaxLength()) : ''); - - echo ''; - printf('(%s)',_('confirm')); - echo '
'; - } - - $this->draw('CheckLink',$attribute,$id); - echo '
'; - } - - protected function drawFormReadWriteValueSelectionAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($attribute->isMultiple()) { - # For multiple selection, we draw the component only one time - if ($i > 0) - return; - - $selected = array(); - $vals = $attribute->getValues(); - $j = 0; - - if (! $vals && ! is_null($attribute->getDefault()) && ! is_array($vals = $attribute->getDefault())) - $vals = array($attribute->getDefault()); - - if (($attribute->getSize() > 0) && ($attribute->getSize() < $attribute->getOptionCount())) { - - printf(''; - - } else { - echo ''; - - // For checkbox items, we need to render a blank entry, so that we detect an all-unselect situation - printf('', - htmlspecialchars($attribute->getName()),$j++, - htmlspecialchars($attribute->getName()),''); - - foreach ($attribute->getSelection() as $value => $description) { - if (in_array($value,$vals)) - $selected[$value] = true; - - printf('', - htmlspecialchars($attribute->getName()),$j++, - htmlspecialchars($attribute->getName()),$value, - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - isset($selected[$value]) ? 'checked="checked"' : '', - $description); - } - - foreach ($vals as $val) - if (! isset($selected[$val])) - printf('', - htmlspecialchars($attribute->getName()),$j++, - htmlspecialchars($attribute->getName()),$val, - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', - $val); - - echo '
 %s
 %s
'; - } - - # This is a single value attribute - } else { - $val = $attribute->getValue($i) ? $attribute->getValue($i) : $attribute->getDefault(); - - if ($attribute->getHelper()) - echo '
'; - - $found = false; - $empty_value = false; - - # If we are a required attribute, and the selection is blank, then the user cannot submit this form. - if ($attribute->isRequired() && ! count($attribute->getSelection())) - system_message(array( - 'title'=>_('Template Value Error'), - 'body'=>sprintf('This template uses a selection list for attribute [%s], however the selection list is empty.
You may need to create some dependancy entries in your LDAP server so that this attribute renders with values. Alternatively, you may be able to define the appropriate selection values in the template file.',$attribute->getName(false)), - 'type'=>'warn')); - - printf(''; - - if ($attribute->getHelper()) { - echo '
'; - $this->draw('Helper',$attribute,$i); - echo '
'; - } - } - } - - /** - * Takes a shadow* attribute and returns the date as an integer. - * - * @param array Attribute objects - * @param string A shadow attribute name - */ - private function shadow_date($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $shadowattr = array(); - $shadowattr['lastchange'] = $this->template->getAttribute('shadowlastchange'); - $shadowattr['max'] = $this->template->getAttribute('shadowmax'); - - $shadow = array(); - $shadow['lastchange'] = $shadowattr['lastchange'] ? $shadowattr['lastchange']->getValue(0) : null; - $shadow['max'] = $shadowattr['max'] ? $shadowattr['max']->getValue(0) : null; - - if (($attribute->getName() == 'shadowlastchange') && $shadow['lastchange']) - $shadow_date = $shadow['lastchange']; - - elseif (($attribute->getName() == 'shadowmax') && ($shadow['max'] > 0) && $shadow['lastchange']) - $shadow_date = $shadow['lastchange']+$shadow['max']; - - elseif (($attribute->getName() == 'shadowwarning') && ($attribute->getValue(0) > 0) - && $shadow['lastchange'] && $shadow['max'] && $shadow['max'] > 0) - $shadow_date = $shadow['lastchange']+$shadow['max']-$attribute->getValue(0); - - elseif (($attribute->getName() == 'shadowinactive') && ($attribute->getValue(0) > 0) - && $shadow['lastchange'] && $shadow['max'] && $shadow['max'] > 0) - $shadow_date = $shadow['lastchange']+$shadow['max']+$attribute->getValue(0); - - elseif (($attribute->getName() == 'shadowmin') && ($attribute->getValue(0) > 0) && $shadow['lastchange']) - $shadow_date = $shadow['lastchange']+$attribute->getValue(0); - - elseif (($attribute->getName() == 'shadowexpire') && ($attribute->getValue(0) > 0)) - $shadow_date = $shadowattr->getValue(0); - - # Couldn't interpret the shadow date (could be 0 or -1 or something) - else - return false; - - return $shadow_date*24*3600; - } - - protected function drawShadowDateShadowAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $shadow_before_today_attrs = arrayLower($attribute->shadow_before_today_attrs); - $shadow_after_today_attrs = arrayLower($attribute->shadow_after_today_attrs); - $shadow_date = $this->shadow_date($attribute); - - if (! $shadow_date) - return; - - $today = date('U'); - - echo '
'; - if (($today < $shadow_date) && in_array(strtolower($attribute->getName()),$shadow_before_today_attrs)) - printf('(%s)', - strftime($_SESSION[APPCONFIG]->getValue('appearance','date'),$shadow_date)); - - elseif (($today > $shadow_date) && in_array(strtolower($attribute->getName()),$shadow_after_today_attrs)) - printf('(%s)', - strftime($_SESSION[APPCONFIG]->getValue('appearance','date'),$shadow_date)); - - else - printf('(%s)', - strftime($_SESSION[APPCONFIG]->getValue('appearance','date'),$shadow_date)); - - echo '
'; - } - - protected function drawFormReadOnlyValueShadowAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->drawFormReadOnlyValueAttribute($attribute,$i); - $this->draw('ShadowDate',$attribute); - } - - protected function drawFormReadWriteValueShadowAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->drawFormReadWriteValueAttribute($attribute,$i); - $this->draw('ShadowDate',$attribute); - } -} -?> diff --git a/lib/Query.php b/lib/Query.php deleted file mode 100644 index 62a3d2b..0000000 --- a/lib/Query.php +++ /dev/null @@ -1,283 +0,0 @@ -getServer(); - - foreach ($xmldata['query'] as $xml_key => $xml_value) { - if (DEBUG_ENABLED) - debug_log('Foreach loop Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key,is_array($xml_value)); - - switch ($xml_key) { - - # Build our attribute list from the DN and Template. - case ('attributes'): - if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); - - if (is_array($xmldata['query'][$xml_key])) { - foreach ($xmldata['query'][$xml_key] as $tattrs) { - foreach ($tattrs as $index => $details) { - - if (DEBUG_ENABLED) - debug_log('Foreach tattrs Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__, - $index,$details); - - # If there is no schema definition for the attribute, it will be ignored. - if ($sattr = $server->getSchemaAttribute($index)) { - if (is_null($attribute = $this->getAttribute($sattr->getName()))) - $attribute = $this->addAttribute($sattr->getName(false),array('values'=>array())); - - $attribute->show(); - $attribute->setXML($details); - } - } - } - } - - break; - - # Build our bases list from the DN and Template. - case ('bases'): - if (isset($xmldata['query'][$xml_key]['base'])) - if (is_array($xmldata['query'][$xml_key]['base'])) - $this->base = $xmldata['query'][$xml_key]['base']; - else - $this->base = array($xmldata['query'][$xml_key]['base']); - else - error(sprintf(_('In the XML file (%s), [%s] contains an unknown key.'), - $this->filename,$xml_key),'error','index.php'); - - $this->base = array_unique($this->base); - break; - - default: - if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); - - # Some key definitions need to be an array, some must not be: - $allowed_arrays = array(''); - $storelower = array(''); - $storearray = array(''); - - # Items that must be stored lowercase - if (in_array($xml_key,$storelower)) - if (is_array($xml_value)) - foreach ($xml_value as $index => $value) - $xml_value[$index] = strtolower($value); - else - $xml_value = strtolower($xml_value); - - # Items that must be stored as arrays - if (in_array($xml_key,$storearray) && ! is_array($xml_value)) - $xml_value = array($xml_value); - - # Items that should not be an array - if (! in_array($xml_key,$allowed_arrays) && is_array($xml_value)) { - debug_dump(array(__METHOD__,'key'=>$xml_key,'value'=>$xml_value)); - error(sprintf(_('In the XML file (%s), [%s] is an array, it must be a string.'), - $this->filename,$xml_key),'error'); - } - - $this->$xml_key = $xml_value; - } - } - - # Check we have some manditory items. - foreach (array() as $key) { - if (! isset($this->$key) - || (! is_array($this->$key) && ! trim($this->$key))) { - - $this->setInvalid(sprintf(_('Missing %s in the XML file.'),$key)); - break; - } - } - } - - /** - * Accept will run the query and store the results in results() - */ - public function accept() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $this->getServer(); - - $query = array(); - $query['size_limit'] = get_request('size_limit','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','size_limit')); - $query['format'] = get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')); - $query['orderby'] = get_request('orderby','REQUEST',false,'dn'); - - # If this is a custom search, we need to populate are paramters - if ($this->getID() == 'none') { - $bases = get_request('base','REQUEST',false,null); - $query['filter'] = get_request('filter','REQUEST',false,'objectClass=*'); - $query['scope'] = get_request('scope','REQUEST',false,'sub'); - $attrs = get_request('display_attrs','REQUEST'); - - $attrs = preg_replace('/\s+/','',$attrs); - if ($attrs) - $query['attrs'] = explode(',',$attrs); - else - $query['attrs'] = array('*'); - - } else { - $bases = $this->base; - $query['filter'] = $this->filter; - $query['scope'] = $this->scope; - $query['attrs'] = $this->getAttributeNames(); - } - - if (! $bases) - $bases = $server->getBaseDN(); - elseif (! is_array($bases)) - $bases = explode('|',$bases); - - foreach ($bases as $base) { - $query['base'] = $base; - - $time_start = utime(); - $this->results[$base] = $server->query($query,null); - $time_end = utime(); - - $this->resultsdata[$base]['time'] = round($time_end-$time_start,2); - $this->resultsdata[$base]['scope'] = $query['scope']; - $this->resultsdata[$base]['filter'] = $query['filter']; - $this->resultsdata[$base]['attrs'] = $query['attrs']; - - if ($this->getAttrSortOrder() == 'dn') - usort($this->results[$base],'pla_compare_dns'); - elseif ($this->getAttrSortOrder()) - masort($this->results[$base],$this->getAttrSortOrder()); - } - } - - /** - * This is temporary to get around objects that use a DN for rendering, for example jpegPhoto - */ - public function setDN($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->dn = $dn; - } - - /** - * This is temporary to get around objects that use a DN for rendering, for example jpegPhoto - */ - public function getDN() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn); - - return $this->dn; - } - - public function getDNEncode($url=true) { - // @todo Be nice to do all this in 1 location - if ($url) - return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->dn)); - else - return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->dn); - } - - public function getAttrSortOrder() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = array(); - - if (count($this->attributes)) { - masort($this->attributes,'ordersort'); - - foreach ($this->attributes as $attribute) - array_push($result,$attribute->getName()); - - } else { - $display = preg_replace('/,\s+/',',',get_request('orderby','REQUEST',false,'dn')); - - if (trim($display)) - $result = explode(',',$display); - } - - return implode(',',$result); - } - - public function getAttrDisplayOrder() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = array(); - - if (count($this->attributes)) { - masort($this->attributes,'order'); - - foreach ($this->attributes as $attribute) - array_push($result,$attribute->getName()); - - } else { - $display = preg_replace('/,\s+/',',',get_request('display_attrs','REQUEST',false,'')); - - if (trim($display)) - $result = explode(',',$display); - } - - # If our display order is empty, then dynamically build it - if (! count($result)) { - foreach ($this->results as $details) - foreach ($details as $attrs) - $result = array_merge($result,array_keys(array_change_key_case($attrs))); - - $result = array_unique($result); - sort($result); - } - - # Put the DN first - array_unshift($result,'dn'); - $result = array_unique($result); - - return implode(',',$result); - } - - /** - * Test if the template is visible - * - * @return boolean - */ - public function isVisible() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->visible); - - return $this->visible; - } - - public function getDescription() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); - - return $this->description; - } -} -?> diff --git a/lib/QueryRender.php b/lib/QueryRender.php deleted file mode 100644 index 4cc1b6e..0000000 --- a/lib/QueryRender.php +++ /dev/null @@ -1,557 +0,0 @@ -%s
',__METHOD__); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [GETquery:%s]
',__METHOD__,get_request('query','REQUEST')); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Page:%s]
',__METHOD__,get_request('page','REQUEST')); - - $this->template_id = $this->getTemplateChoice(); - $this->page = get_request('page','REQUEST',false,1); - - # If we are the default template, make sure we pressed search - if ($this->template_id == 'none' && ! get_request('search','REQUEST')) - $this->drawTemplateChoice(); - - elseif ($this->template_id) { - $templates = $this->getTemplates(); - $this->template = $templates->getTemplate($this->template_id); - $this->template->accept(); - - $this->visitStart(); - $this->visitEnd(); - } - } - - /** - * Get our templates applicable for this object - */ - protected function getTemplates() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return new Queries($this->server_id); - } - - /** - * Are default queries enabled? - */ - protected function haveDefaultTemplate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $this->getServer(); - - if ($server->getValue('query','disable_default')) - return false; - else - return true; - } - - protected function drawTemplateChoice() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $server = $this->getServer(); - - $this->drawTitle(_('Search')); - $this->drawSubTitle(); - - echo "\n"; - - $baseDNs = $server->getBaseDN(); - - printf('',JSDIR); - echo '
'; - echo '
'; - echo ''; - printf('',$server->getIndex()); - echo '
'; - - echo ''; - echo ''; - - $templates = $this->getTemplates(); - - if (count($templates->getTemplates())) { - echo ''; - printf('',_('Run a predefined query'),_('Predefined Query')); - echo ''; - echo ''; - } - - echo ''; - printf('',_('The format to show the query results'),_('Display Format')); - echo ''; - echo ''; - - echo ''; - printf('',_('Entries to show per page'),_('Show Results')); - echo ''; - echo ''; - - echo ''; - - echo ''; - echo ''; - - printf('',_('Search')); - - echo '
 
%s'; - echo ''; - echo '
%s'; - echo ''; - echo '
%s'; - echo ''; - echo '
'; - printf('
','block'); - echo '
'; - echo '
'; - printf('%s',_('Custom Query')); - echo ''; - - printf('',_('Base DN')); - printf(''; - echo ''; - - echo ''; - printf('',_('The scope in which to search'),_('Search Scope')); - - echo ''; - echo ''; - - echo ''; - printf('', - htmlspecialchars(_('Standard LDAP search filter. Example: (&(sn=Smith)(givenName=David))')),_('Search Filter')); - - printf('', - 'objectClass=*'); - - echo ''; - - echo ''; - printf('', - _('A list of attributes to display in the results (comma-separated)'),_('Show Attributes')); - - printf('', - implode(', ',$_SESSION[APPCONFIG]->getValue('search','result_attributes'))); - echo ''; - - echo ''; - printf('',_('Order by'),_('Order by')); - printf('',''); - echo ''; - - echo ''; - printf('',_('Set the search results to 0 to retrieve all available records'),_('Search Results')); - printf('',$_SESSION[APPCONFIG]->getValue('search','size_limit')); - echo ''; - - echo '
%s',count($baseDNs) == 1 ? $baseDNs[0] : ''); - - draw_chooser_link('advanced_search_form','base'); - - echo '
%s'; - echo ''; - echo '
%s
%s
%s
%s
'; - echo '
'; - echo '
'; - echo '

'; - echo '
'; - } - - private function visitStart() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->drawTitle(_('Search Results')); - $this->drawSubTitle(); - echo '
'; - } - - private function visitEnd() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $this->getServer(); - $afattrs = $this->getAFAttrs(); - - # If Mass Actions Enabled - if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) { - $mass_actions = array( - _('delete') => 'mass_delete', - _('edit') => 'mass_edit' - ); - } - - $this->drawBaseTabs(); - $ado = $this->template->getAttrDisplayOrder(); - $counter = 0; - $j = 0; - - foreach ($this->template->results as $base => $results) { - $counter++; - - if (! $show = get_request('show','REQUEST')) - $show = ($counter === 1 ? $this->getAjaxRef($base) : null); - - printf('
', - $this->getAjaxRef($base), ($show == $this->getAjaxRef($base) ? 'block' : 'none')); - - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - - $this->drawResultsTable($base,count($results)); - - echo '
'; - echo '
'; - - switch(get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display'))) { - case 'list': - foreach ($results as $dndetails) { - $dndetails = array_change_key_case($dndetails); - - # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) - $this->template->setDN($dndetails['dn']); - - echo ''; - - echo ''; - printf('',IMGDIR,get_icon($server->getIndex(),$dndetails['dn'])); - - printf('', - $server->getIndex(),$this->template->getDNEncode(),htmlspecialchars(get_rdn($dndetails['dn']))); - echo ''; - - printf('', - htmlspecialchars(dn_unescape($dndetails['dn']))); - - # Iterate over each attribute for this entry - foreach (explode(',',$ado) as $attr) { - $attr = strtolower($attr); - - # Ignore DN, we've already displayed it. - if ($attr == 'dn') - continue; - - if (! isset($dndetails[$attr])) - continue; - - # Set our object with our values - $afattrs[$attr]->clearValue(); - - if (is_array($dndetails[$attr])) - $afattrs[$attr]->initValue($dndetails[$attr]); - else - $afattrs[$attr]->initValue(array($dndetails[$attr])); - - echo ''; - echo ''; - - echo ''; - - echo ''; - echo ''; - } - - echo '
icon%s
 dn%s
 '; - $this->draw('Name',$afattrs[$attr]); - echo ''; - $this->draw('CurrentValues',$afattrs[$attr]); - echo '
'; - echo '
'; - } - - break; - - # Display the results. - case 'table': - if (! $results) { - echo _('Search returned no results'); - - continue 2; - } - - printf('
',$counter); - echo '
'; - printf('',$server->getIndex()); - - foreach ($this->template->resultsdata[$base]['attrs'] as $attr) - printf('',$attr); - - echo '
'; - - echo ''; - - echo ''; - echo ''; - echo ''; - echo ''; - - foreach (explode(',',$ado) as $attr) { - echo ''; - } - - echo ''; - echo ''; - - echo ''; - foreach ($results as $dndetails) { - $j++; - $dndetails = array_change_key_case($dndetails); - - # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) - $this->template->setDN($dndetails['dn']); - - printf('', - $j%2 ? 'even' : 'odd',$j,$j); - - # Is mass action enabled. - if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) - printf('',$j,$dndetails['dn']); - - $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),$this->template->getDNEncode()); - printf('', - htmlspecialchars($href), - IMGDIR,get_icon($server->getIndex(),$dndetails['dn'])); - - # We'll clone our attribute factory attributes, since we need to add the values to them for rendering. - foreach (explode(',',$ado) as $attr) { - # If the entry is blank, we'll draw an empty box and continue. - if (! isset($dndetails[$attr])) { - echo ''; - continue; - } - - # Special case for DNs - if ($attr == 'dn') { - $dn_display = strlen($dndetails['dn']) > 40 - ? sprintf('%s...',htmlspecialchars($dndetails['dn']),htmlspecialchars(substr($dndetails['dn'],0,40))) - : htmlspecialchars($dndetails['dn']); - - printf('',htmlspecialchars($href),$dn_display); - continue; - } - - # Set our object with our values - $afattrs[$attr]->clearValue(); - if (is_array($dndetails[$attr])) - $afattrs[$attr]->initValue($dndetails[$attr]); - else - $afattrs[$attr]->initValue(array($dndetails[$attr])); - - echo ''; - } - - echo ''; - } - - # Is mass action enabled. - if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) { - printf('',++$j%2 ? 'odd' : 'even'); - printf('',$counter); - printf(''; - echo ''; - } - - echo ''; - echo '
  '; - $this->draw('Name',$afattrs[$attr]); - echo '
icon %s'; - $this->draw('CurrentValues',$afattrs[$attr]); - echo '
',2+count(explode(',',$ado))); - - foreach ($mass_actions as $display => $action) - printf('  ',$action,$display); - - echo '
'; - echo '
'; - echo "\n\n"; - - break; - - default: - printf('Have ID [%s], run this query for page [%s]',$this->template_id,$this->page); - } - - echo '
'; - echo '
'; - echo "\n\n"; - } - - if (get_request('format','REQUEST',false,'table') == 'table') - printf('',JSDIR); - } - - public function drawSubTitle($subtitle=null) { - if (is_null($subtitle)) { - $server = $this->getServer(); - - $subtitle = sprintf('%s: %s',_('Server'),$server->getName()); - - if ($this->template) { - $subtitle .= '
'; - $subtitle .= sprintf('%s: %s',('Query'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); - if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); - } - } - - parent::drawSubTitle($subtitle); - } - - private function getAFattrs() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attribute_factory = new AttributeFactory(); - $results = array(); - - foreach (explode(',',$this->template->getAttrDisplayOrder()) as $attr) - $results[strtolower($attr)] = $attribute_factory->newAttribute($attr,array('values'=>array()),$this->getServerID()); - - return $results; - } - - private function getAjaxRef($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return preg_replace('/=/','.',base64_encode($dn)); - } - - private function drawBaseTabs() { - # Setup the Javascript to show/hide our DIVs. - echo ''; - echo "\n\n"; - - echo ''; - echo ''; - $counter = 0; - foreach ($this->template->results as $base => $results) { - if (! $show = get_request('show','REQUEST')) - $show = ($counter++ === 0 ? $this->getAjaxRef($base) : null); - - printf('', - $this->getAjaxRef($base), - $this->getAjaxRef($base), - ($show == $this->getAjaxRef($base) ? '#F0F0F0' : '#E0E0E0'), - htmlspecialchars($base)); - } - echo ''; - echo '
%s
'; - echo "\n\n"; - } - - private function drawResultsTable($base,$results) { - $server = $this->getServer(); - - echo ''; - - echo ''; - printf('',_('Entries found'), - number_format($results),$this->template->resultsdata[$base]['time'],_('seconds')); - - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form')) { - $href = htmlspecialchars(sprintf('cmd.php?cmd=export_form&server_id=%s&scope=%s&dn=%s&filter=%s&attributes=%s', - $server->getIndex(),$this->template->resultsdata[$base]['scope'], - $base,rawurlencode($this->template->resultsdata[$base]['filter']), - rawurlencode(implode(', ',$this->template->resultsdata[$base]['attrs'])))); - - printf(''; - echo ''; - echo '
%s: %s

(%s %s)
[ Save %s ]', - $href,IMGDIR,_('export results')); - } - - printf('[ rename %s:',IMGDIR,_('Format')); - - foreach (array('list','table') as $f) { - echo ' '; - - if (get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')) == $f) { - printf('%s',_($f)); - - } else { - $query_string = htmlspecialchars(sprintf('%s&format=%s&show=%s&focusbase=%s',array_to_query_string($_GET,array('format','meth')),$f,$this->getAjaxRef($base),$base)); - - if (isAjaxEnabled()) - printf('%s', - $query_string,$query_string,_('Loading Search'),_($f)); - else - printf('%s',$query_string,_($f)); - } - } - - echo ' ]'; - - echo '
'; - printf('%s: %s',_('Base DN'),htmlspecialchars($base)); - - echo '
'; - printf('%s: %s',_('Filter performed'),htmlspecialchars($this->template->resultsdata[$base]['filter'])); - - echo '
'; - } -} -?> diff --git a/lib/ShadowAttribute.php b/lib/ShadowAttribute.php deleted file mode 100644 index eeb7cd1..0000000 --- a/lib/ShadowAttribute.php +++ /dev/null @@ -1,19 +0,0 @@ - diff --git a/lib/Template.php b/lib/Template.php deleted file mode 100644 index a9f7a17..0000000 --- a/lib/Template.php +++ /dev/null @@ -1,1571 +0,0 @@ -noleaf = $_SESSION[APPCONFIG]->getValue('appearance','disable_default_leaf'); - } - - public function __clone() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # We need to clone our attributes, when passing back a template with getTemplate - foreach ($this->attributes as $key => $value) - $this->attributes[$key] = clone $value; - } - - /** - * Main processing to store the template. - * - * @param xmldata Parsed xmldata from xml2array object - */ - protected function storeTemplate($xmldata) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $this->getServer(); - $objectclasses = array(); - - foreach ($xmldata['template'] as $xml_key => $xml_value) { - if (DEBUG_ENABLED) - debug_log('Foreach loop Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key,is_array($xml_value)); - - switch ($xml_key) { - # Build our object Classes from the DN and Template. - case ('objectclasses'): - if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); - - if (isset($xmldata['template'][$xml_key]['objectclass'])) - if (is_array($xmldata['template'][$xml_key]['objectclass'])) { - foreach ($xmldata['template'][$xml_key]['objectclass'] as $index => $details) { - - # XML files with only 1 objectClass dont have a numeric index. - $soc = $server->getSchemaObjectClass(strtolower($details)); - - # If we havent recorded this objectclass already, do so now. - if (is_object($soc) && ! in_array($soc->getName(),$objectclasses)) - array_push($objectclasses,$soc->getName(false)); - - elseif (! is_object($soc) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) - system_message(array( - 'title'=>_('Automatically removed objectClass from template'), - 'body'=>sprintf('%s: %s %s',$this->getTitle(),$details,_('removed from template as it is not defined in the schema')), - 'type'=>'warn')); - } - - } else { - # XML files with only 1 objectClass dont have a numeric index. - $soc = $server->getSchemaObjectClass(strtolower($xmldata['template'][$xml_key]['objectclass'])); - - # If we havent recorded this objectclass already, do so now. - if (is_object($soc) && ! in_array($soc->getName(),$objectclasses)) - array_push($objectclasses,$soc->getName(false)); - } - - break; - - # Build our attribute list from the DN and Template. - case ('attributes'): - if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); - - if (is_array($xmldata['template'][$xml_key])) { - foreach ($xmldata['template'][$xml_key] as $tattrs) - foreach ($tattrs as $index => $details) { - if (DEBUG_ENABLED) - debug_log('Foreach tattrs Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__, - $index,$details); - - # If there is no schema definition for the attribute, it will be ignored. - if ($sattr = $server->getSchemaAttribute($index)) - if (is_null($this->getAttribute($sattr->getName()))) - $this->addAttribute($sattr->getName(),$details,'XML'); - } - - masort($this->attributes,'order'); - } - - break; - - default: - if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); - - # Some key definitions need to be an array, some must not be: - $allowed_arrays = array('rdn'); - $storelower = array('rdn'); - $storearray = array('rdn'); - - # Items that must be stored lowercase - if (in_array($xml_key,$storelower)) - if (is_array($xml_value)) - foreach ($xml_value as $index => $value) - $xml_value[$index] = strtolower($value); - else - $xml_value = strtolower($xml_value); - - # Items that must be stored as arrays - if (in_array($xml_key,$storearray) && ! is_array($xml_value)) - $xml_value = array($xml_value); - - # Items that should not be an array - if (! in_array($xml_key,$allowed_arrays) && is_array($xml_value)) { - debug_dump(array(__METHOD__,'key'=>$xml_key,'value'=>$xml_value)); - error(sprintf(_('In the XML file (%s), [%s] is an array, it must be a string.'), - $this->filename,$xml_key),'error'); - } - - $this->$xml_key = $xml_value; - - if ($xml_key == 'invalid' && $xml_value) - $this->setInvalid(_('Disabled by XML configuration'),true); - } - } - - if (! count($objectclasses)) { - $this->setInvalid(_('ObjectClasses in XML dont exist in LDAP server.')); - return; - - } else { - $attribute = $this->addAttribute('objectClass',array('values'=>$objectclasses),'XML'); - $attribute->justModified(); - $attribute->setRequired(); - $attribute->hide(); - } - - $this->rebuildTemplateAttrs(); - - # Check we have some manditory items. - foreach (array('rdn','structural_oclass','visible') as $key) { - if (! isset($this->$key) - || (! is_array($this->$key) && ! trim($this->$key))) { - - $this->setInvalid(sprintf(_('Missing %s in the XML file.'),$key)); - break; - } - } - - # Mark our RDN attributes as RDN - $counter = 1; - foreach ($this->rdn as $key) { - if ((is_null($attribute = $this->getAttribute($key))) && (in_array_ignore_case('extensibleobject',$this->getObjectClasses()))) { - $attribute = $this->addAttribute($key,array('values'=>array())); - $attribute->show(); - } - - if (! is_null($attribute)) - $attribute->setRDN($counter++); - elseif ($this->isType('creation')) - $this->setInvalid(sprintf(_('Missing RDN attribute %s in the XML file.'),$key)); - } - } - - /** - * Is default templates enabled? - * This will disable the default template from the engine. - * - * @return boolean - */ - protected function hasDefaultTemplate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template')) - return false; - else - return true; - } - - /** - * Return the templates of type (creation/modification) - * - * @param $string type - creation/modification - * @return array - Array of templates of that type - */ - protected function readTemplates($type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $template_xml = new Templates($this->server_id); - return $template_xml->getTemplates($type); - } - - /** - * This function will perform the following intialisation steps: - * + If a DN is set, query the ldap and load the object - * + Read our $_REQUEST variable and set the values - * After this action, the template should self describe as to whether it is an update, create - * or delete. - * (OLD values are IGNORED, we will have got them when we build this object from the LDAP server DN.) - */ - public function accept($makeVisible=false,$nocache=false) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $this->getServer(); - - # If a DN is set, then query the LDAP server for the details. - if ($this->dn) { - if (! $server->dnExists($this->dn)) - system_message(array( - 'title'=>__METHOD__, - 'body'=>sprintf('DN (%s) didnt exist in LDAP?',$this->dn), - 'type'=>'info')); - - $rdnarray = rdn_explode(strtolower(get_rdn(dn_escape($this->dn)))); - - $counter = 1; - foreach ($server->getDNAttrValues($this->dn,null,LDAP_DEREF_NEVER,array_merge(array('*'),$server->getValue('server','custom_attrs')),$nocache) as $attr => $values) { - # We ignore DNs. - if ($attr == 'dn') - continue; - - $attribute = $this->getAttribute($attr); - - if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$values)); - else - if ($attribute->getValues()) { - # Override values to those that are defined in the XML file. - if ($attribute->getSource() != 'XML') - $attribute->setValue(array_values($values)); - else - $attribute->setOldValue(array_values($values)); - - } else - $attribute->initValue(array_values($values)); - - # Work out the RDN attributes - foreach ($attribute->getValues() as $index => $value) - if (in_array(sprintf('%s=%s', - $attribute->getName(),strtolower($attribute->getValue($index))),$rdnarray)) - $attribute->setRDN($counter++); - - if ($makeVisible) - $attribute->show(); - } - - # Get the Internal Attributes - foreach ($server->getDNAttrValues($this->dn,null,LDAP_DEREF_NEVER,array_merge(array('+'),$server->getValue('server','custom_sys_attrs'))) as $attr => $values) { - $attribute = $this->getAttribute($attr); - - if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$values)); - else - if ($attribute->getValues()) - $attribute->setValue(array_values($values)); - else - $attribute->initValue(array_values($values)); - - if (! in_array_ignore_case($attribute->getName(),$server->getValue('server','custom_attrs'))) - $attribute->setInternal(); - } - - # If this is the default template, and our $_REQUEST has defined our objectclass, then query the schema to get the attributes - } elseif ($this->container) { - if ($this->isType('default') && ! count($this->getAttributes(true)) && isset($_REQUEST['new_values']['objectclass'])) { - $attribute = $this->addAttribute('objectclass',array('values'=>$_REQUEST['new_values']['objectclass'])); - $attribute->justModified(); - $this->rebuildTemplateAttrs(); - unset($_REQUEST['new_values']['objectclass']); - } - - } elseif (get_request('create_base')) { - if (get_request('rdn')) { - $rdn = explode('=',get_request('rdn')); - $attribute = $this->addAttribute($rdn[0],array('values'=>array($rdn[1]))); - $attribute->setRDN(1); - } - - } else { - debug_dump_backtrace('No DN or CONTAINER?',1); - } - - # Read in our new values. - foreach (array('new_values') as $key) { - if (isset($_REQUEST[$key])) - foreach ($_REQUEST[$key] as $attr => $values) { - # If it isnt an array, silently ignore it. - if (! is_array($values)) - continue; - - # If _REQUEST['skip_array'] with this attr set, we'll ignore this new_value - if (isset($_REQUEST['skip_array'][$attr]) && $_REQUEST['skip_array'][$attr] == 'on') - continue; - - # Prune out entries with a blank value. - foreach ($values as $index => $value) - if (! strlen(trim($value))) - unset($values[$index]); - - $attribute = $this->getAttribute($attr); - # If the attribute is null, then no attribute exists, silently ignore it (unless this is the default template) - if (is_null($attribute) && (! $this->isType('default') && ! $this->isType(null))) - continue; - - # If it is a binary attribute, the post should have base64 encoded the value, we'll need to reverse that - if ($server->isAttrBinary($attr)) - foreach ($values as $index => $value) - $values[$index] = base64_decode($value); - - if (is_null($attribute)) { - $attribute = $this->addAttribute($attr,array('values'=>$values)); - - if (count($values)) - $attribute->justModified(); - - } else - $attribute->setValue(array_values($values)); - } - - # Read in our new binary values - if (isset($_FILES[$key]['name'])) - foreach ($_FILES[$key]['name'] as $attr => $values) { - $new_values = array(); - - foreach ($values as $index => $details) { - # Ignore empty files - if (! $_FILES[$key]['size'][$attr][$index]) - continue; - - if (! is_uploaded_file($_FILES[$key]['tmp_name'][$attr][$index])) { - if (isset($_FILES[$key]['error'][$attr][$index])) - switch($_FILES[$key]['error'][$attr][$index]) { - - # No error; possible file attack! - case 0: - $msg = _('Security error: The file being uploaded may be malicious.'); - break; - - # Uploaded file exceeds the upload_max_filesize directive in php.ini - case 1: - $msg = _('The file you uploaded is too large. Please check php.ini, upload_max_size setting'); - break; - - # Uploaded file exceeds the MAX_FILE_SIZE directive specified in the html form - case 2: - $msg = _('The file you uploaded is too large. Please check php.ini, upload_max_size setting'); - break; - - # Uploaded file was only partially uploaded - case 3: - $msg = _('The file you selected was only partially uploaded, likley due to a network error.'); - break; - - # No file was uploaded - case 4: - $msg = _('You left the attribute value blank. Please go back and try again.'); - break; - - # A default error, just in case! :) - default: - $msg = _('Security error: The file being uploaded may be malicious.'); - break; - } - - else - $msg = _('Security error: The file being uploaded may be malicious.'); - - system_message(array( - 'title'=>_('Upload Binary Attribute Error'),'body'=>$msg,'type'=>'warn')); - - } else { - $binaryfile = array(); - $binaryfile['name'] = $_FILES[$key]['tmp_name'][$attr][$index]; - $binaryfile['handle'] = fopen($binaryfile['name'],'r'); - $binaryfile['data'] = fread($binaryfile['handle'],filesize($binaryfile['name'])); - fclose($binaryfile['handle']); - - $new_values[$index] = $binaryfile['data']; - } - } - - if (count($new_values)) { - $attribute = $this->getAttribute($attr); - - if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$new_values)); - else - foreach ($new_values as $value) - $attribute->addValue($value); - - $attribute->justModified(); - } - } - } - - # If there are any single item additions (from the add_attr form for example) - if (isset($_REQUEST['single_item_attr'])) { - if (isset($_REQUEST['single_item_value'])) { - if (! is_array($_REQUEST['single_item_value'])) - $values = array($_REQUEST['single_item_value']); - else - $values = $_REQUEST['single_item_value']; - - } elseif (isset($_REQUEST['binary'])) { - /* Special case for binary attributes (like jpegPhoto and userCertificate): - * we must go read the data from the file and override $_REQUEST['single_item_value'] with the - * binary data. Secondly, we must check if the ";binary" option has to be appended to the name - * of the attribute. */ - - if ($_FILES['single_item_value']['size'] === 0) - system_message(array( - 'title'=>_('Upload Binary Attribute Error'), - 'body'=>sprintf('%s %s',_('The file you chose is either empty or does not exist.'),_('Please go back and try again.')), - 'type'=>'warn')); - - else { - if (! is_uploaded_file($_FILES['single_item_value']['tmp_name'])) { - if (isset($_FILES['single_item_value']['error'])) - switch($_FILES['single_item_value']['error']) { - - # No error; possible file attack! - case 0: - $msg = _('Security error: The file being uploaded may be malicious.'); - break; - - # Uploaded file exceeds the upload_max_filesize directive in php.ini - case 1: - $msg = _('The file you uploaded is too large. Please check php.ini, upload_max_size setting'); - break; - - # Uploaded file exceeds the MAX_FILE_SIZE directive specified in the html form - case 2: - $msg = _('The file you uploaded is too large. Please check php.ini, upload_max_size setting'); - break; - - # Uploaded file was only partially uploaded - case 3: - $msg = _('The file you selected was only partially uploaded, likley due to a network error.'); - break; - - # No file was uploaded - case 4: - $msg = _('You left the attribute value blank. Please go back and try again.'); - break; - - # A default error, just in case! :) - default: - $msg = _('Security error: The file being uploaded may be malicious.'); - break; - } - - else - $msg = _('Security error: The file being uploaded may be malicious.'); - - system_message(array( - 'title'=>_('Upload Binary Attribute Error'),'body'=>$msg,'type'=>'warn'),'index.php'); - } - - $binaryfile = array(); - $binaryfile['name'] = $_FILES['single_item_value']['tmp_name']; - $binaryfile['handle'] = fopen($binaryfile['name'],'r'); - $binaryfile['data'] = fread($binaryfile['handle'],filesize($binaryfile['name'])); - fclose($binaryfile['handle']); - - $values = array($binaryfile['data']); - } - } - - if (count($values)) { - $attribute = $this->getAttribute($_REQUEST['single_item_attr']); - - if (is_null($attribute)) - $attribute = $this->addAttribute($_REQUEST['single_item_attr'],array('values'=>$values)); - else - $attribute->setValue(array_values($values)); - - $attribute->justModified(); - } - } - - # If this is the default creation template, we need to set some additional values - if ($this->isType('default') && $this->getContext() == 'create') { - # Load our schema, based on the objectclasses that may have already been defined. - if (! get_request('create_base')) - $this->rebuildTemplateAttrs(); - - # Set the RDN attribute - $counter = 1; - foreach (get_request('rdn_attribute','REQUEST',false,array()) as $key => $value) { - $attribute = $this->getAttribute($value); - - if (! is_null($attribute)) - $attribute->setRDN($counter++); - - else { - system_message(array( - 'title'=>_('No RDN attribute'), - 'body'=>_('No RDN attribute was selected'), - 'type'=>'warn'),'index.php'); - - die(); - } - } - } - } - - /** - * Set the DN for this template, if we are editing entries - * - * @param dn The DN of the entry - */ - public function setDN($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (isset($this->container)) - system_message(array( - 'title'=>__METHOD__, - 'body'=>'CONTAINER set while setting DN', - 'type'=>'info')); - - $this->dn = $dn; - } - - /** - * Set the RDN attributes - * Given an RDN, mark the attributes as RDN attributes. If there is no defined attribute, - * then the remaining RDNs will be returned. - * - * @param RDN - * @return RDN attributes not processed - */ - public function setRDNAttributes($rdn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Setup to work out our RDN. - $rdnarray = rdn_explode($rdn); - - $counter = 1; - foreach ($this->getAttributes(true) as $attribute) - foreach ($rdnarray as $index => $rdnattr) { - list($attr,$value) = explode('=',$rdnattr); - - if (strtolower($attr) == $attribute->getName()) { - $attribute->setRDN($counter++); - unset($rdnarray[$index]); - } - } - - return $rdnarray; - } - - /** - * Display the DN for this template entry. If the DN is not set (creating a new entry), then - * a generated DN will be produced, taken from the RDN and the CONTAINER details. - * - * @return dn - */ - public function getDN() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn); - - if ($this->dn) - return $this->dn; - - # If DN is not set, our DN will be made from our RDN and Container. - elseif ($this->getRDN() && $this->getContainer()) - return sprintf('%s,%s',$this->getRDN(),$this->GetContainer()); - - # If container is not set, we're probably creating the base - elseif ($this->getRDN() && get_request('create_base')) - return $this->getRDN(); - } - - public function getDNEncode($url=true) { - // @todo Be nice to do all this in 1 location - if ($url) - return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN())); - else - return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN()); - } - - /** - * Set the container for this template, if we are creating entries - * - * @param dn The DN of the container - * @todo Trigger a query to the LDAP server and generate an error if the container doesnt exist - */ - public function setContainer($container) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (isset($this->dn)) - system_message(array( - 'title'=>__METHOD__, - 'body'=>'DN set while setting CONTAINER', - 'type'=>'info')); - - $this->container = $container; - } - - /** - * Get the DN of the container for this entry - * - * @return dn DN of the container - */ - public function getContainer() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->container); - - return $this->container; - } - - public function getContainerEncode($url=true) { - // @todo Be nice to do all this in 1 location - if ($url) - return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->container)); - else - return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->container); - } - - /** - * Copy a DN - */ - public function copy($template,$rdn,$asnew=false) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $rdnarray = rdn_explode($rdn); - - $counter = 1; - foreach ($template->getAttributes(true) as $sattribute) { - $attribute = $this->addAttribute($sattribute->getName(false),array('values'=>$sattribute->getValues())); - - # Set our new RDN, and its values - if (is_null($attribute)) { - debug_dump_backtrace('Attribute is null, it probably doesnt exist in the destination server?'); - - } else { - - # Mark our internal attributes. - if ($sattribute->isInternal()) - $attribute->setInternal(); - - $modified = false; - foreach ($rdnarray as $index => $rdnattr) { - list($attr,$value) = explode('=',$rdnattr); - if (strtolower($attr) == $attribute->getName()) { - - # If this is already marked as an RDN, then this multivalue RDN was updated on a previous loop - if (! $modified) { - $attribute->setValue(array($value)); - $attribute->setRDN($counter++); - $modified = true; - - } else { - $attribute->addValue($value); - } - - # This attribute has been taken care of, we'll drop it from our list. - unset($rdnarray[$index]); - } - } - } - - // @todo If this is a Jpeg Attribute, we need to mark it read only, since it cant be deleted like text attributes can - if (strcasecmp(get_class($attribute),'jpegAttribute') == 0) - $attribute->setReadOnly(); - } - - # If we have any RDN values left over, there werent in the original entry and need to be added. - foreach ($rdnarray as $rdnattr) { - list($attr,$value) = explode('=',$rdnattr); - - $attribute = $this->addAttribute($attr,array('values'=>array($value))); - - if (is_null($attribute)) - debug_dump_backtrace('Attribute is null, it probably doesnt exist in the destination server?'); - else - $attribute->setRDN($counter++); - } - - # If we are copying into a new entry, we need to discard all the "old values" - if ($asnew) - foreach ($this->getAttributes(true) as $sattribute) - $sattribute->setOldValue(array()); - } - - /** - * Get Attributes by LDAP type - * This function will return a list of attributes by LDAP type (MUST,MAY). - * - * @return array Array of attributes. - */ - function getAttrbyLdapType($type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = array(); - - foreach ($this->attributes as $index => $attribute) { - if ($attribute->getLDAPtype() == strtolower($type)) - array_push($result,$attribute->getName()); - } - - return $result; - } - - /** - * Return true if this is a MUST,MAY attribute - */ - function isAttrType($attr,$type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (in_array(strtolower($attr),$this->getAttrbyLdapType($type))) - return true; - else - return false; - } - - /** - * Return the attributes that comprise the RDN. - * - * @return array Array of RDN objects - */ - private function getRDNObjects() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $return = array(); - - foreach ($this->attributes as $attribute) - if ($attribute->isRDN()) - array_push($return,$attribute); - - masort($return,'rdn'); - return $return; - } - - /** - * Get all the RDNs for this template, in RDN order. - * - * @return array RDNs in order. - */ - public function getRDNAttrs() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $return = array(); - - foreach ($this->getRDNObjects() as $attribute) { - # We'll test if two RDN's have the same number (we cant test anywhere else) - if (isset($return[$attribute->isRDN()]) && $this->getType() == 'creation') - system_message(array( - 'title'=>_('RDN attribute sequence already defined'), - 'body'=>sprintf('%s %s', - sprintf(_('There is a problem in template [%s].'),$this->getName()), - sprintf(_('RDN attribute sequence [%s] is already used by attribute [%s] and cant be used by attribute [%s] also.'), - $attribute->isRDN(),$return[$attribute->isRDN()],$attribute->getName())), - 'type'=>'error'),'index.php'); - - $return[$attribute->isRDN()] = $attribute->getName(); - } - - return $return; - } - - /** - * Return the RDN for this template. If the DN is already defined, then the RDN will be calculated from it. - * If the DN is not set, then the RDN will be calcuated from the template attribute definitions - * - * @return rdn RDN for this template - */ - public function getRDN() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # If the DN is set, then the RDN will be calculated from it. - if ($this->dn) - return get_rdn($this->dn); - - $rdn = ''; - - foreach ($this->getRDNObjects() as $attribute) { - $vals = $attribute->getValues(); - - # If an RDN attribute has no values, return with an empty string. The calling script should handle this. - if (! count($vals)) - return ''; - - foreach ($vals as $val) - $rdn .= sprintf('%s=%s+',$attribute->getName(false),$val); - } - - # Chop the last plus sign off when returning - return preg_replace('/\+$/','',$rdn); - } - - /** - * Return the attribute name part of the RDN - */ - public function getRDNAttributeName() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attr = array(); - - if ($this->getDN()) { - $i = strpos($this->getDN(),','); - if ($i !== false) { - $attrs = explode('\+',substr($this->getDN(),0,$i)); - foreach ($attrs as $id => $attr) { - list ($name,$value) = explode('=',$attr); - $attrs[$id] = $name; - } - - $attr = array_unique($attrs); - } - } - - return $attr; - } - - /** - * Determine the type of template this is - */ - public function getContext() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->getContainer() && get_request('cmd','REQUEST') == 'copy') - return 'copyasnew'; - elseif ($this->getContainer() || get_request('create_base')) - return 'create'; - elseif ($this->getDN()) - return 'edit'; - else - return 'unknown'; - } - - /** - * Test if the template is visible - * - * @return boolean - */ - public function isVisible() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->visible); - - return $this->visible; - } - - public function setVisible() { - $this->visible = true; - } - - public function setInvisible() { - $this->visible = false; - } - - public function getRegExp() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->regexp); - - return $this->regexp; - } - - /** - * Test if this template has been marked as a read-only template - */ - public function isReadOnly() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ((($this->getContext() == 'edit') && $this->readonly) || $this->getServer()->isReadOnly()) - return true; - else - return false; - } - - /** - * Get the attribute entries - * - * @param boolean Include the optional attributes - * @return array Array of attributes - */ - public function getAttributes($optional=false) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($optional) - return $this->attributes; - - $result = array(); - foreach ($this->attributes as $attribute) { - if (! $attribute->isRequired()) - continue; - - array_push($result,$attribute); - } - - return $result; - } - - /** - * Return a list of attributes that should be shown - */ - public function getAttributesShown() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = array(); - - foreach ($this->attributes as $attribute) - if ($attribute->isVisible()) - array_push($result,$attribute); - - return $result; - } - - /** - * Return a list of the internal attributes - */ - public function getAttributesInternal() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = array(); - - foreach ($this->attributes as $attribute) - if ($attribute->isInternal()) - array_push($result,$attribute); - - return $result; - } - - /** - * Return the objectclasses defined in this template - * - * @return array Array of Objects - */ - public function getObjectClasses() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attribute = $this->getAttribute('objectclass'); - if ($attribute) - return $attribute->getValues(); - else - return array(); - } - - /** - * Get template icon - */ - public function getIcon() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon); - - return isset($this->icon) ? sprintf('%s/%s',IMGDIR,$this->icon) : ''; - } - - /** - * Return the template description - * - * @return string Description - */ - public function getDescription() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); - - return $this->description; - } - - /** - * Set a template as invalid - * - * @param string Message indicating the reason the template has been invalidated - */ - public function setInvalid($msg,$admin=false) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $this->invalid = true; - $this->invalid_reason = $msg; - $this->invalid_admin = $admin; - } - - /** - * Get the template validity or the reason it is invalid - * - * @return string Invalid reason, or false if not invalid - */ - public function isInValid() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->invalid) - return $this->invalid_reason; - else - return false; - } - - public function isAdminDisabled() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->invalid_admin); - - return $this->invalid_admin; - } - - /** - * Set the minimum number of values for an attribute - * - * @param object Attribute - * @param int - */ - private function setMinValueCount($attr,$value) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attribute = $this->getAttribute($attr); - - if (! is_null($attribute)) - $attribute->setMinValueCount($value); - } - - /** - * Set the LDAP type property for an attribute - * - * @param object Attribute - * @param string (MUST,MAY,OPTIONAL) - */ - private function setAttrLDAPtype($attr,$value) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attribute = $this->getAttribute($attr); - - if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>array())); - - $attribute->setLDAPtype($value); - } - - /** - * OnChangeAdd javascript processing - */ - public function OnChangeAdd($origin,$value) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $attribute = $this->getAttribute($origin); - - if (preg_match('/^=(\w+)\((.*)\)$/',$value,$matches)) { - $command = $matches[1]; - $arg = $matches[2]; - } else - return; - - switch ($command) { - /* - autoFill:string - string is a literal string, and may contain many fields like %attr|start-end/flags% - to substitute values read from other fields. - |start-end is optional, but must be present if the k flag is used. - /flags is optional. - - flags may be: - T: Read display text from selection item (drop-down list), otherwise, read the value of the field - For fields that aren't selection items, /T shouldn't be used, and the field value will always be read. - k: Tokenize: - If the "k" flag is not given: - A |start-end instruction will perform a sub-string operation upon - the value of the attr, passing character positions start-end through. - start can be 0 for first character, or any other integer. - end can be 0 for last character, or any other integer for a specific position. - If the "k" flag is given: - The string read will be split into fields, using : as a delimiter - "start" indicates which field number to pass through. - K: The string read will be split into fields, using ' ' as a delimiter "start" indicates which field number to pass through. - l: Make the result lower case. - U: Make the result upper case. - */ - case 'autoFill': - if (! preg_match('/;/',$arg)) { - system_message(array( - 'title'=>_('Problem with autoFill() in template'), - 'body'=>sprintf('%s (%s)',_('There is only 1 argument, when there should be two'),$attribute->getName(false)), - 'type'=>'warn')); - - return; - } - - list($attr,$string) = preg_split('(([^,]+);(.*))',$arg,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - preg_match_all('/%(\w+)(\|[0-9]*-[0-9]*)?(\/[KklTUA]+)?%/U',$string,$matchall); - //print"
";print_r($matchall); //0 = highlevel match, 1 = attr, 2 = subst, 3 = mod
-
-				if (! isset($attribute->js['autoFill']))
-					$attribute->js['autoFill'] = '';
-
-				$formula = $string;
-				$formula = preg_replace('/^([^%])/','\'$1',$formula);
-				$formula = preg_replace('/([^%])$/','$1\'',$formula);
-
-				# Check that our attributes match our schema attributes.
-				foreach ($matchall[1] as $index => $checkattr) {
-					$sattr = $this->getServer()->getSchemaAttribute($checkattr);
-
-					# If the attribute is the same as in the XML file, then dont need to do anything.
-					if (! $sattr || ! strcasecmp($sattr->getName(),$checkattr))
-						continue;
-
-					$formula = preg_replace("/$checkattr/",$sattr->getName(),$formula);
-					$matchall[1][$index] = $sattr->getName();
-				}
-
-				$elem_id = 0;
-
-				foreach ($matchall[0] as $index => $null) {
-					$match_attr = strtolower($matchall[1][$index]);
-					$match_subst = $matchall[2][$index];
-					$match_mod = $matchall[3][$index];
-
-					$substrarray = array();
-
-					if (! isset($varcount[$match_attr]))
-						$varcount[$match_attr] = 0;
-					else
-						$varcount[$match_attr]++;
-
-					$js_match_attr = $match_attr;
-					$match_attr = $js_match_attr.'xx'.$varcount[$match_attr];
-
-					$formula = preg_replace('/%'.$js_match_attr.'([|\/%])/i','%'.$match_attr.'$1',$formula,1);
-
-					$attribute->js['autoFill'] .= sprintf("  var %s;\n",$match_attr);
-					$attribute->js['autoFill'] .= sprintf(
-							"  var elem$elem_id = document.getElementById(pre+'%s'+suf);\n".
-							"  if (!elem$elem_id) return;\n", $js_match_attr);
-
-					if (strstr($match_mod,'T')) {
-						$attribute->js['autoFill'] .= sprintf("  %s = elem$elem_id.options[elem$elem_id.selectedIndex].text;\n",
-							$match_attr);
-					} else {
-						$attribute->js['autoFill'] .= sprintf("  %s = elem$elem_id.value;\n",$match_attr);
-					}
-
-					$elem_id++;
-
-					if (strstr($match_mod,'k')) {
-						preg_match_all('/([0-9]+)/',trim($match_subst),$substrarray);
-						if (isset($substrarray[1][0])) {
-							$tok_idx = $substrarray[1][0];
-						} else {
-							$tok_idx = '0';
-						}
-						$attribute->js['autoFill'] .= sprintf("   %s = %s.split(':')[%s];\n",$match_attr,$match_attr,$tok_idx);
-
-					} elseif (strstr($match_mod,'K')) {
-						preg_match_all('/([0-9]+)/',trim($match_subst),$substrarray); 
-						if (isset($substrarray[1][0])) { 
-							$tok_idx = $substrarray[1][0]; 
-						} else { 
-							$tok_idx = '0'; 
-						} 
-						$attribute->js['autoFill'] .= sprintf("   %s = %s.split(' ')[%s];\n",$match_attr,$match_attr,$tok_idx); 
-
-					} else {
-						preg_match_all('/([0-9]*)-([0-9]*)/',trim($match_subst),$substrarray);
-						if ((isset($substrarray[1][0]) && $substrarray[1][0]) || (isset($substrarray[2][0]) && $substrarray[2][0])) {
-							$attribute->js['autoFill'] .= sprintf("   %s = %s.substr(%s,%s);\n",
-								$match_attr,$match_attr,
-								$substrarray[1][0] ? $substrarray[1][0] : '0',
-								$substrarray[2][0] ? $substrarray[2][0] : sprintf('%s.length',$match_attr));
-						}
-					}
-
-					if (strstr($match_mod,'l')) {
-						$attribute->js['autoFill'] .= sprintf("   %s = %s.toLowerCase();\n",$match_attr,$match_attr);
-					}
-					if (strstr($match_mod,'U')) {
-						$attribute->js['autoFill'] .= sprintf("   %s = %s.toUpperCase();\n",$match_attr,$match_attr);
-					}
-					if (strstr($match_mod,'A')) {
-						$attribute->js['autoFill'] .= sprintf("   %s = toAscii(%s);\n",$match_attr,$match_attr);
-					}
-
-					# Matchfor only entry without modifiers.
-					$formula = preg_replace('/^%('.$match_attr.')%$/U','$1 + \'\'',$formula);
-					# Matchfor only entry with modifiers.
-					$formula = preg_replace('/^%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[KklTUA]+)?%$/U','$1 + \'\'',$formula);
-					# Matchfor begining entry.
-					$formula = preg_replace('/^%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[KklTUA]+)?%/U','$1 + \'',$formula);
-					# Matchfor ending entry.
-					$formula = preg_replace('/%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[KklTUA]+)?%$/U','\' + $1 ',$formula);
-					# Match for entries not at begin/end.
-					$formula = preg_replace('/%('.$match_attr.')(\|[0-9]*-[0-9]*)?(\/[:lTUA]+)?%/U','\' + $1 + \'',$formula);
-					$attribute->js['autoFill'] .= "\n";
-				}
-
-				$attribute->js['autoFill'] .= sprintf(" fillRec(pre+'%s'+suf, %s); // %s\n",strtolower($attr),$formula,$string);
-				$attribute->js['autoFill'] .= "\n";
-				break;
-
-			default: $return = '';
-		}
-	}
-
-	/**
-	 * This functions main purpose is to discover our MUST attributes based on objectclass
-	 * definitions in the template file and to discover which of the objectclasses are
-	 * STRUCTURAL - without one, creating an entry will just product an LDAP error.
-	 */
-	private function rebuildTemplateAttrs() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$server = $this->getServer();
-
-		# Collect our structural, MUST & MAY attributes.
-		$oclass_processed = array();
-		$superclasslist = array();
-		$allattrs = array('objectclass');
-
-		foreach ($this->getObjectClasses() as $oclass) {
-			# If we get some superclasses - then we'll need to go through them too.
-			$supclass = true;
-			$inherited = false;
-
-			while ($supclass) {
-				$soc = $server->getSchemaObjectClass($oclass);
-
-				if ($soc->getType() == 'structural' && (! $inherited))
-					array_push($this->structural_oclass,$oclass);
-
-				# Make sure our MUST attributes are marked as such for this template.
-				if ($soc->getMustAttrs())
-					foreach ($soc->getMustAttrs() as $index => $details) {
-						$objectclassattr = $details->getName();
-
-						# We add the 'objectClass' attribute, only if it's explicitly in the template attribute list
-						if ((strcasecmp('objectClass',$objectclassattr) != 0) ||
-								((strcasecmp('objectClass',$objectclassattr) == 0) && (! is_null($this->getAttribute($objectclassattr))))) {
-
-							# Go through the aliases, and ignore any that are already defined.
-							$ignore = false;
-							$sattr = $server->getSchemaAttribute($objectclassattr);
-							foreach ($sattr->getAliases() as $alias) {
-								if ($this->isAttrType($alias,'must')) {
-									$ignore = true;
-									break;
-								}
-							}
-
-							if ($ignore)
-								continue;
-
-							$this->setAttrLDAPtype($sattr->getName(),'must');
-							$this->setMinValueCount($sattr->getName(),1);
-
-							# We need to mark the attributes as show, except for the objectclass attribute.
-							if (strcasecmp('objectClass',$objectclassattr) != 0) {
-								$attribute = $this->getAttribute($sattr->getName());
-								$attribute->show();
-							}
-						}
-
-						if (! in_array($objectclassattr,$allattrs))
-							array_push($allattrs,$objectclassattr);
-					}
-
-				if ($soc->getMayAttrs())
-					foreach ($soc->getMayAttrs() as $index => $details) {
-						$objectclassattr = $details->getName();
-						$sattr = $server->getSchemaAttribute($objectclassattr);
-
-						# If it is a MUST attribute, skip to the next one.
-						if ($this->isAttrType($objectclassattr,'must'))
-							continue;
-
-						if (! $this->isAttrType($objectclassattr,'may'))
-							$this->setAttrLDAPtype($sattr->getName(false),'may');
-
-						if (! in_array($objectclassattr,$allattrs))
-							array_push($allattrs,$objectclassattr);
-					}
-
-				# Keep a list to objectclasses we have processed, so we dont get into a loop.
-				array_push($oclass_processed,$oclass);
-				$supoclasses = $soc->getSupClasses();
-
-				if (count($supoclasses) || count($superclasslist)) {
-					foreach ($supoclasses as $supoclass) {
-						if (! in_array($supoclass,$oclass_processed))
-							$superclasslist[] = $supoclass;
-					}
-
-					$oclass = array_shift($superclasslist);
-					if ($oclass)
-						$inherited = true;
-					else
-						$supclass = false;
-
-				} else {
-					$supclass = false;
-				}
-			}
-		}
-
-		# Check that attributes are defined by an ObjectClass
-		foreach ($this->getAttributes(true) as $index => $attribute)
-			if (! in_array($attribute->getName(),$allattrs) && (! array_intersect($attribute->getAliases(),$allattrs))
-				&& (! in_array_ignore_case('extensibleobject',$this->getObjectClasses()))
-				&& (! in_array_ignore_case($attribute->getName(),$server->getValue('server','custom_attrs')))) {
-				unset($this->attributes[$index]);
-
-				if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
-					system_message(array(
-						'title'=>_('Automatically removed attribute from template'),
-						'body'=>sprintf('%s: %s %s',$this->getTitle(),$attribute->getName(false),_('removed from template as it is not defined by an ObjectClass')),
-						'type'=>'warn'));
-			}
-	}
-
-	/**
-	 * Return an array, that can be passed to ldap_add().
-	 * Attributes with empty values will be excluded.
-	 */
-	public function getLDAPadd($attrsOnly=false) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$return = array();
-		$returnattrs = array();
-
-		if ($attrsOnly && count($returnattrs))
-			return $returnattrs;
-
-		foreach ($this->getAttributes(true) as $attribute)
-			if (! $attribute->isInternal() && count($attribute->getValues())) {
-				$return[$attribute->getName()] = $attribute->getValues();
-				$returnattrs[$attribute->getName()] = $attribute;
-			}
-
-		# Ensure that our objectclasses has "top".
-		if (isset($return['objectclass']) && ! in_array('top',$return['objectclass']))
-			array_push($return['objectclass'],'top');
-
-		if ($attrsOnly)
-			return $returnattrs;
-
-		return $return;
-	}
-
-	/**
-	 * Return an array, that can be passed to ldap_mod_replace().
-	 * Only attributes that have changed their value will be returned.
-	 *
-	 * This function will cache its results, so that it can be called with count() to see
-	 * if there are changes, and if they are, the 2nd call will just return the results
-	 *
-	 * @param boolean Return the attribute objects (useful for a confirmation process), or the modification array for ldap_modify()
-	 */
-	public function getLDAPmodify($attrsOnly=false,$index=0) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $return = array();
-		static $returnattrs = array();
-
-		if ($attrsOnly && isset($returnattrs[$index]) && count($returnattrs[$index]))
-			return $returnattrs[$index];
-
-		$returnattrs[$index] = array();
-		$return[$index] = array();
-
-		# If an objectclass is being modified, we need to remove all the orphan attributes that would result.
-		if ($this->getAttribute('objectclass')->hasBeenModified()) {
-			$attr_to_keep = array();
-			$server = $this->getServer();
-
-			# Make sure that there will be a structural object class remaining.
-			$haveStructural = false;
-			foreach ($this->getAttribute('objectclass')->getValues() as $value) {
-				$soc = $server->getSchemaObjectClass($value);
-
-				if ($soc) {
-					if ($soc->isStructural())
-						$haveStructural = true;
-
-					# While we are looping, workout which attributes these objectclasses define.
-					foreach ($soc->getMustAttrs(true) as $value)
-						if (! in_array($value->getName(),$attr_to_keep))
-							array_push($attr_to_keep,$value->getName());
-
-					foreach ($soc->getMayAttrs(true) as $value)
-						if (! in_array($value->getName(),$attr_to_keep))
-							array_push($attr_to_keep,$value->getName());
-				}
-			}
-
-			if (! $haveStructural)
-				error(_('An entry should have one structural objectClass.'),'error','index.php');
-
-			# Work out the attributes to delete.
-			foreach ($this->getAttribute('objectclass')->getRemovedValues() as $value) {
-				$soc = $server->getSchemaObjectClass($value);
-
-				foreach ($soc->getMustAttrs() as $value) {
-					$attribute = $this->getAttribute($value->getName());
-
-					if ($attribute && (! in_array($value->getName(),$attr_to_keep)) && ($value->getName() != 'objectclass'))
-						#array_push($attr_to_delete,$value->getName(false));
-						$attribute->setForceDelete();
-				}
-
-				foreach ($soc->getMayAttrs() as $value) {
-					$attribute = $this->getAttribute($value->getName());
-
-					if ($attribute && (! in_array($value->getName(),$attr_to_keep)) && ($value->getName() != 'objectclass'))
-						$attribute->setForceDelete();
-				}
-			}
-		}
-
-		foreach ($this->getAttributes(true) as $attribute)
-			if ($attribute->hasBeenModified()
-				&& (count(array_diff($attribute->getValues(),$attribute->getOldValues())) || ! count($attribute->getValues())
-					|| $attribute->isForceDelete() || (count($attribute->getValues()) != count($attribute->getOldValues()))))
-				$returnattrs[$index][$attribute->getName()] = $attribute;
-
-		if ($attrsOnly)
-			return $returnattrs[$index];
-
-		foreach ($returnattrs[$index] as $attribute)
-			$return[$index][$attribute->getName()] = $attribute->getValues();
-
-		return $return[$index];
-	}
-
-	/**
-	 * Get the attributes that are marked as force delete
-	 * We'll cache this result in the event of multiple calls.
-	 */
-	public function getForceDeleteAttrs() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $result = array();
-
-		if (count($result))
-			return $result;
-
-		foreach ($this->attributes as $attribute)
-			if ($attribute->isForceDelete())
-				array_push($result,$attribute);
-
-		return $result;
-	}
-
-	/**
-	 * Get available attributes
-	 */
-	public function getAvailAttrs() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$attributes = array();
-		$server = $this->getServer();
-
-		# Initialise the Attribute Factory.
-		$attribute_factory = new AttributeFactory();
-
-		if (in_array_ignore_case('extensibleobject',$this->getObjectClasses())) {
-			foreach ($server->SchemaAttributes() as $sattr) {
-				$attribute = $attribute_factory->newAttribute($sattr->getName(),array('values'=>array()),$server->getIndex(),null);
-				array_push($attributes,$attribute);
-			}
-
-		} else {
-			$attrs = array();
-
-			foreach ($this->getObjectClasses() as $oc) {
-				$soc = $server->getSchemaObjectClass($oc);
-				$attrs = array_merge($attrs,$soc->getMustAttrNames(true),$soc->getMayAttrNames(true));
-				$attrs = array_unique($attrs);
-			}
-
-			foreach ($attrs as $attr)
-				if (is_null($this->getAttribute($attr))) {
-					$attribute = $attribute_factory->newAttribute($attr,array('values'=>array()),$server->getIndex(),null);
-					array_push($attributes,$attribute);
-				}
-		}
-
-		masort($attributes,'name');
-		return $attributes;
-	}
-
-	public function isNoLeaf() {
-		return $this->noleaf;
-	}
-
-	public function sort() {
-		usort($this->attributes,'sortAttrs');
-	}
-}
-?>
diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php
deleted file mode 100644
index 249c7a1..0000000
--- a/lib/TemplateRender.php
+++ /dev/null
@@ -1,2533 +0,0 @@
-%s:%s
',time(),__METHOD__); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Visit-Start:%s]
',__METHOD__,get_class($this)); - - $tree = get_cached_item($this->server_id,'tree'); - if (! $tree) - $tree = Tree::getInstance($this->server_id); - - $treeitem = $tree->getEntry($this->dn); - - # If we have a DN, and no template_id, see if the tree has one from last time - if ($this->dn && is_null($this->template_id) && $treeitem && $treeitem->getTemplate()) - $this->template_id = $treeitem->getTemplate(); - - # Check that we have a valid template, or present a selection - # @todo change this so that the modification templates rendered are the ones for the objectclass of the dn. - if (! $this->template_id) - $this->template_id = $this->getTemplateChoice(); - - if ($treeitem) - $treeitem->setTemplate($this->template_id); - - $this->page = get_request('page','REQUEST',false,1); - - if ($this->template_id AND $this->template_id != 'invalid') { - if (! $this->template) - parent::accept(); - - $this->url_base = sprintf('server_id=%s&dn=%s', - $this->getServerID(),$this->template->getDNEncode()); - $this->layout['hint'] = sprintf('%s%%s', - IMGDIR,_('Hint')); - $this->layout['action'] = '%s%s'; - $this->layout['actionajax'] = '%s%s'; - - # If we don't want to render this template automatically, we'll return here. - if ($norender) - return; - - $this->visitStart(); - - foreach ($this->template->getAttributes(true) as $attribute) { - # Evaluate our defaults - if ($attribute->getAutoValue()) - $this->get('Default',$attribute, - $this->template->getContainer() ? $this->template->getContainer() : $this->getServer()->getContainerPath($this->template->getDN()), - 'autovalue'); - - # If this is the default template, we should mark all our attributes to show(). - if (($this->template->getID() == 'none') && (! $attribute->isInternal()) - && (($this->template->getContext() == 'edit' && $this->template->getID() == 'none') - || ($this->template->getContext() == 'create' && $attribute->getName() != 'objectclass'))) - $attribute->show(); - } - - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Visit-End:%s]
',__METHOD__,get_class($this)); - - $this->visitEnd(); - } - } - - protected function getDefaultAttribute($attribute,$container,$type) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - switch ($type) { - case 'autovalue': - $autovalue = $attribute->getAutoValue(); - - break; - - case 'helpervalue': - $autovalue = $attribute->getHelperValue(); - - break; - - default: - system_message(array( - 'title'=>_('Unknown Default Attribute context'), - 'body'=>sprintf('%s (%s)',_('A call was made to getDefaultAttribute() with an unkown context'),$type), - 'type'=>'warn')); - - return; - } - - $args = explode(';',$autovalue['args']); - $server = $this->getServer(); - $vals = ''; - - switch ($autovalue['function']) { - /** - * Function enables normal PHP functions to be called to evaluate a value. - * eg: =php.Function(date;dmY) - * - * All arguments will be passed to the function, and its value returned. - * If this used used in a POST context, the attribute values can be used as arguments. - * - * Mandatory Arguments: - * * arg 0 - * - php Function to call - * - * Additional arguments will be passed to the function. - */ - case 'Function': - $function = array_shift($args); - - if (count($args) && count($args) > 1) { - system_message(array( - 'title'=>_('Too many arguments'), - 'body'=>sprintf('%s (%s)',_('Function() only takes two arguments and more than two were specified'),count($args)), - 'type'=>'warn')); - - return; - } - - $function_args = explode(',',$args[0]); - - if (function_exists($function)) - $vals = call_user_func_array($function,$function_args); - - else - system_message(array( - 'title'=>_('Function doesnt exist'), - 'body'=>sprintf('%s (%s)',_('An attempt was made to call a function that doesnt exist'),$function), - 'type'=>'warn')); - - break; - - /** - * GetNextNumber will query the LDAP server and calculate the next number based on the query - * eg: - * - * Mandatory Arguments: - * * arg 0 - * - "$" => 'auto_number','search_base' in config file - * - "/",".",".." => get container parent as usual - * - * * arg 1 - * - attribute to query for - * - * Optional Arguments: - * * arg 2 (pool mechanism only) - * - "true" increments attribute by 1 - * - "false" do nothing - * - * * arg 3 (pool mechanism only) - * - ldap filter (must match one entry only in container) - * - * * arg 4 - * - calculus on number, eg: - * - *2,+1000 => number = (2*number) + 1000 - * - * * arg 5 - * - Min number - */ - case 'GetNextNumber': - # If the attribute already has values, we'll return - if ($type == 'autovalue' && $attribute->getValues()) - return; - - if ($args[0] == '$') - $args[0] = $server->getValue($this->server_id,'auto_number','search_base'); - - $container = $server->getContainerPath($container,$args[0]); - - $vals = get_next_number($container,$args[1], - (! empty($args[2]) && ($args[2] == 'false')) ? false : true, - (! empty($args[3])) ? $args[3] : false, - (! empty($args[5])) ? $args[5] : null); - - # Operate calculus on next number. - if (! empty($args[4])) { - $mod = explode(',',$args[4]); - $next_number = $vals; - - foreach ($mod as $calc) { - $operand = $calc[0]; - $operator = substr ($calc,1); - - switch ($operand) { - case '*': - $next_number = $next_number * $operator; - break; - - case '+': - $next_number = $next_number + $operator; - break; - - case '-': - $next_number = $next_number - $operator; - break; - - case '/': - $next_number = $next_number / $operator; - break; - } - } - - $vals = $next_number; - } - - break; - - /** - * PickList will query the LDAP server and provide a select list of values - * MultiList will query the LDAP server and provide a multi select list of values - * eg: - * - * eg: cn=root,nobody => cn=nobody;gidNumber;10)]]> - * - * Mandatory Arguments: - * * arg 0 - * - container, to query from current position - * - "/",".",".." => get container parent as usual - * - * * arg 1 - * - LDAP filter. May include '%attr%', it will be expanded. - * - * * arg2 - * - list attribute key - * - * Optional Arguments: - * * arg3 - * - select display (plus modifier /C: Capitalize) - * - replaced by %arg 2% if not given - * - * * arg 4 - * - the value furnished in output - must be attribute id. replaced by arg 2 if not given - * - * * arg 5 - * - container override - * - * * arg 6 - * - csv list (, separator) of added values. syntax: key => display_attribute=value, key... - * - * * arg 7 - * - csv list (, separator) of sort attributes (less to more important) - * - * * arg 8 (for MultiList) - * - size of displayed list (default: 10 lines) - */ - case 'MultiList': - case 'PickList': - # arg5 overrides our container - if (empty($args[5])) - $container = $server->getContainerPath($container,$args[0]); - else - $container = $args[5]; - - # Process filter (arg 1), eventually replace %attr% by its value set in a previous page. - preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[1],$filtermatchall); - //print_r($matchall); // -1 = highlevel match, 1 = attr, 2 = subst, 3 = mod - - if (isset($_REQUEST['form'])) { - $formvalues = array_change_key_case($_REQUEST['form']); - - foreach ($filtermatchall[1] as $arg) { - $value = $formvalues[strtolower($arg)]; - $args[1] = preg_replace("/%($arg)(\|.+)?(\/[lU])?%/U",$value,$args[1]); - } - } - - if (empty($args[3])) - $args[3] = "%{$args[2]}%"; - - preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[3],$matchall); - //print_r($matchall); // -1 = highlevel match, 1 = attr, 2 = subst, 3 = mod - - $attrs = array_unique(array_merge($matchall[1],array($args[2]))); - - # arg7 is sort attributes - if (isset($args[7])) { - $sort_attrs = explode(',',$args[7]); - $attrs = array_unique(array_merge($attrs,$sort_attrs)); - } - - $picklistvalues = return_ldap_hash($container,$args[1],$args[2],$attrs,(isset($args[7]) && ($args[7])) ? $sort_attrs : false); - - # arg6 is a set of fixed values to add to search result - if (isset($args[6])) { - $fixedvalues = explode(',',$args[6]); - - foreach ($fixedvalues as $fixedvalue) { - if (empty($fixedvalue)) - continue; - - $fixedvalue = preg_split('/=\>/',$fixedvalue); - $displayvalue = explode('=',$fixedvalue[1]); - - $newvalue[trim($fixedvalue[0])] = array($args[2]=>trim($fixedvalue[0]),trim($displayvalue[0])=>trim($displayvalue[1])); - - $picklistvalues = array_merge($picklistvalues,$newvalue); - } - } - - $vals = array(); - - foreach ($picklistvalues as $key => $values) { - $display = $args[3]; - - foreach ($matchall[1] as $key => $arg) { - if (isset($values[$arg])) - $disp_val = $values[$arg]; - else - $disp_val = ''; - - if (is_array($disp_val)) - $disp_val = $disp_val[0]; - - if ($matchall[3][$key]) - switch ($matchall[3][$key]) { - case '/l': - # lowercase - if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_LOWER,'utf-8'); - else - $disp_val = strtolower($disp_val); - - break; - - case '/U': - # uppercase - if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_UPPER,'utf-8'); - else - $disp_val = strtoupper($disp_val); - - break; - - case '/C': - # capitalize - if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_TITLE,'utf-8'); - else - $disp_val = ucfirst($disp_val); - - break; - - default: - break; - } - - # make value a substring of - preg_match_all('/^\|([0-9]*)-([0-9]*)$/',trim($matchall[2][$key]),$substrarray); - - if ((isset($substrarray[1][0]) && $substrarray[1][0]) || (isset($substrarray[2][0]) && $substrarray[2][0])) { - $begin = $substrarray[1][0] ? $substrarray[1][0] : '0'; - $end = $substrarray[2][0] ? $substrarray[2][0] : strlen($disp_val); - - if (function_exists('mb_substr')) - $disp_val = mb_substr($disp_val,$begin,$end,'utf-8'); - else - $disp_val = substr($disp_val,$begin,$end); - } - - $display = preg_replace("/%($arg)(\|.+)?(\/[lUC])?%/U",$disp_val,$display); - } - - if (! isset($picklist[$values[$args[2]]])) { - $vals[$values[$args[2]]] = $display; - $picklist[$values[$args[2]]] = true; - } - } - - break; - - /** - * PasswordEncryptionTypes will return a list of our support password encryption types - * eg: =php.PasswordEncryptionTypes() - * - * This function doesnt use any arguments - */ - case 'PasswordEncryptionTypes': - $vals = password_types(); - - break; - - /** - * RandomPassword will create a random password for the value. - * eg: =php.RandomPassword() - * - * When calling the attribute Javascript it will generate a random password. - * - * This function doesnt use any arguments - */ - case 'RandomPassword': - break; - } - - switch ($type) { - case 'autovalue': - if (! is_array($vals)) - $attribute->autoValue(array($vals)); - else - $attribute->autoValue($vals); - - break; - - case 'helpervalue': - return $vals; - } - } - - /** - * Set the mode of the TemplateRender - * Applicable modes are "create" or "edit" - */ - protected function getMode() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->dn) - return 'modification'; - elseif ($this->container) - return 'creation'; - elseif (get_request('create_base')) - return 'creation'; - else - debug_dump_backtrace(sprintf('Unknown mode for %s',__METHOD__),1); - } - - /** - * Return the container for this mode - */ - protected function getModeContainer() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - switch ($this->getMode()) { - case 'creation': - return $this->container; - break; - - case 'modification': - return $this->dn; - break; - - default: - return null; - } - } - - /** - * Is the default template enabled? - */ - protected function haveDefaultTemplate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template')) - return false; - else - return true; - } - - /** - * Present a list of available templates for creating and editing LDAP entries - */ - protected function drawTemplateChoice() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->drawTitle(); - $this->drawSubTitle(); - echo "\n"; - - switch ($this->getMode()) { - case 'creation': - $msg = _('Select a template for the creation process'); - break; - - case 'modification': - $msg = _('Select a template to edit the entry'); - break; - } - - $avail_templates = $this->getTemplates(); - $templates = $avail_templates->getTemplates($this->getMode(),$this->getModeContainer()); - printf('

%s

',$msg); - - $href_parms = array_to_query_string($_GET,array('meth')); - printf('
',htmlspecialchars($href_parms)); - echo "\n\n"; - - if (count($_POST)) { - echo '
'; - foreach ($_POST as $p => $v) - printf('',$p,$v); - echo '
'; - echo "\n\n"; - } - - echo ''; - echo ''; - printf('',_('Templates')); - echo ''; - - echo '
%s:'; - echo ''; - - $i = -1; - $nb_templates = count($templates); - - if ($this->haveDefaultTemplate()) - $nb_templates++; - - foreach ($templates as $name => $details) { - $i++; - - $isInValid = $details->isInValid(); - - # Balance the columns properly - if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || - ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { - echo '
'; - } - - echo "\n"; - echo ''; - - if ($isInValid) - printf('',IMGDIR); - - else { - if (isAjaxEnabled()) - printf('', - htmlspecialchars($details->getID()),htmlspecialchars($details->getID()),htmlspecialchars($href_parms),$details->getID(),str_replace('\'','\\\'',_('Retrieving DN'))); - else - printf('', - htmlspecialchars($details->getID()),htmlspecialchars($details->getID())); - } - - printf('', - htmlspecialchars($details->getID()),$details->getIcon()); - printf(''; - echo ''; - } - echo "\n"; - - # Default template - if ($this->haveDefaultTemplate()) { - $i++; - - # Balance the columns properly - if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || - ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { - echo '
Disabled
'; - } - - echo ''; - if (isAjaxEnabled()) - printf('', - htmlspecialchars($href_parms),'none',str_replace('\'','\\\'',_('Retrieving DN'))); - else - echo ''; - - printf('',IMGDIR); - printf('',_('Default')); - echo ''; - } - - echo '
'; - echo '
'; - echo '
'; - } - - /** VISIT METHODS **/ - - /** - * This function will setup our template object (read LDAP for current values, read $_REQUEST for new values, etc) - * so that it can be rendered. - */ - private function visitStart() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # If we have a DN, then we are an editing template - if ($this->dn) - $this->template->setDN($this->dn); - - # Else if we have a container, we are a creating template - elseif ($this->container || get_request('create_base')) - $this->template->setContainer($this->container); - - else - debug_dump_backtrace('Dont know what type of template we are - no DN or CONTAINER?',1); - - # Header - $this->drawHeader(); - } - - private function visitEnd() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - foreach ($this->template->getAttributesShown() as $attribute) - if ($attribute->getPage() > $this->pagelast) - $this->pagelast = $attribute->getPage(); - echo "\n\n"; - - if ($this->template->getContext() == 'create') { - $this->drawStepTitle($this->page); - $this->drawStepFormStart($this->page); - $this->drawStepForm($this->page); - $this->drawStepFormEnd(); - - } elseif ($this->template->getContext() == 'copyasnew') { - $this->drawStepFormStart($this->page); - printf('',$this->template->getContainer(false)); - echo '
'; - $this->drawRDNChooser(); - echo '
'; - $this->drawForm(true); - $this->drawStepFormSubmitButton($this->page); - - } else { - # Draw internal attributes - if (get_request('show_internal_attrs','REQUEST')) { - echo ''; - $this->drawInternalAttributes(); - echo '

'; - echo "\n"; - } - - $this->drawFormStart(); - - # To support our AJAX add Attribute - printf('
','none'); - - $this->drawForm(); - $this->drawStepFormEnd(); - } - } - - /** PAGE DRAWING METHODS **/ - - private function drawHeader() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Title - $this->drawTitle(); - if (get_request('create_base')) - $this->drawSubTitle(sprintf('%s: %s',_('Creating Base DN'),$this->template->getDN())); - else - $this->drawSubTitle(); - echo "\n"; - - # Menu - $this->drawMenu(); - } - - public function drawTitle($title=null) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (is_null($title)) - switch ($this->getMode()) { - case 'creation': - $title = _('Create Object'); - break; - - case 'modification': - $title = htmlspecialchars(get_rdn($this->dn)); - break; - - default: - $title = 'Title'; - } - - parent::drawTitle($title); - } - - public function drawSubTitle($subtitle=null) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($subtitle) - return parent::drawSubTitle($subtitle); - - switch ($this->getMode()) { - case 'creation': - $subtitle = sprintf('%s: %s   %s: %s', - _('Server'),$this->getServer()->getName(), - _('Container'),htmlspecialchars($this->container)); - - if ($this->template_id) { - $subtitle .= '
'; - $subtitle .= sprintf('%s: %s',_('Template'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); - if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); - } - - break; - - case 'modification': - $subtitle = sprintf('%s: %s   %s: %s', - _('Server'),$this->getServer()->getName(), - _('Distinguished Name'),htmlspecialchars($this->dn)); - - if ($this->template_id) { - $subtitle .= '
'; - $subtitle .= sprintf('%s: %s',_('Template'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); - if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); - } - - break; - } - - parent::drawSubTitle($subtitle); - } - - /** PAGE ENTRY MENU **/ - - private function drawMenu() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - # We only have a menu for editing entries. - if ($this->template->getContext() == 'edit') { - - echo ''; - echo ''; - $menuitem_number = 0; - - foreach (array('entryrefresh','showinternal','switchtemplate','entryexport','entrycopy','entrydelete','entryrename','entrycompare','childcreate','addattr','msgdel','childview','childexport','msgschema','msgro','msgmodattr') as $item) { - $item = $this->getMenuItem($item); - - if ($item) { - $endofrow = false; - $start = true; - $it = ''; // menu item - $ms = ''; // item message - - if (is_array($item) && count($item) > 0) { - $it = $item[0]; - - if (count($item) > 1) - $ms = $item[1]; - - } else { - $it = $item; - } - - if ($it) { - $menuitem_number++; - echo $it; - - if ($ms) { - if (($menuitem_number % 2) == 1) { - $menuitem_number++; - echo ''; - $endofrow = false; - $start = false; - } - - if ($endofrow) - print $ms; - else - echo "$ms"; - - echo ''; - $endofrow = true; - $start = false; - - } else { - if ($menuitem_number > 1 && ($menuitem_number % 2) == 0) { - echo ''; - $endofrow = true; - $start = false; - } - } - - } elseif ($ms) { - if (($menuitem_number % 2) == 1) { - $menuitem_number++; - echo ''; - $endofrow = false; - $start = false; - } - - if ($endofrow || $start) - print $ms; - else - echo "$ms"; - - echo ''; - $endofrow = true; - $start = false; - } - - echo "\n"; - } - } - - if (($menuitem_number % 2) == 1) - echo ''; - else - echo ''; - - echo ''; - echo ''; - } - } - - /** PAGE ENTRY MENU ITEMS **/ - - private function getMenuItem($i) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s (%s)
',__METHOD__,$i); - - switch ($i) { - case 'entryrefresh': - if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_refresh')) - return $this->getMenuItemRefresh(); - else - return ''; - - case 'switchtemplate': - if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','switch_template')) - return $this->getMenuItemSwitchTemplate(); - else - return ''; - - case 'entryexport': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) - return $this->getMenuItemExportBase(); - else - return ''; - - case 'entrycopy': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','copy_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','copy') && ! $this->template->isReadOnly()) - return $this->getMenuItemMove(); - else - return ''; - - case 'showinternal': - if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_internal_attributes_show')) - return $this->getMenuItemInternalAttributes(); - else - return ''; - - case 'entrydelete': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) - return $this->getMenuItemDelete(); - else - return ''; - - case 'entryrename': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','rename_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename') && ! $this->template->isReadOnly()) { - - # Check if any of the RDN's are read only. - $rdnro = false; - foreach ($this->template->getRDNAttributeName() as $attr) { - $attribute = $this->template->getAttribute($attr); - - if ($attribute && $attribute->isVisible() && ! $attribute->isReadOnly()) { - $rdnro = true; - break; - } - } - - if (! $rdnro) - return $this->getMenuItemRename(); - } - - return ''; - - case 'msgdel': - if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') - && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) - return array('',$this->getDeleteAttributeMessage()); - else - return ''; - - case 'entrycompare': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','compare_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','compare') && ! $this->template->isReadOnly()) - return $this->getMenuItemCompare(); - else - return ''; - - case 'childcreate': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','create') && ! $this->template->isReadOnly() && ! $this->template->isNoLeaf()) - return $this->getMenuItemCreate(); - else - return ''; - - case 'addattr': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','add_attr_form') && ! $this->template->isReadOnly()) - return $this->getMenuItemAddAttribute(); - else - return ''; - - case 'childview': - case 'childexport': - static $children_count = false; - static $more_children = false; - - $tree = get_cached_item($this->getServerID(),'tree'); - $tree_item = $tree->getEntry($this->template->getDN()); - - if (! $tree_item) { - $tree->addEntry($this->template->getDN()); - $tree_item = $tree->getEntry($this->template->getDN()); - } - - if ($children_count === false) { - # Visible children in the tree - $children_count = count($tree_item->getChildren()); - # Is there filtered children ? - $more_children = $tree_item->isSizeLimited(); - - if (! $children_count || ! $more_children) { - # All children in ldap - $all_children = $this->getServer()->getContainerContents( - $this->template->getDN(),null,$children_count+1,'(objectClass=*)',$_SESSION[APPCONFIG]->getValue('deref','view'),null); - - $more_children = (count($all_children) > $children_count); - } - } - - if ($children_count > 0 || $more_children) { - if ($children_count <= 0) - $children_count = ''; - if ($more_children) - $children_count .= '+'; - - if ($i == 'childview') - return $this->getMenuItemShowChildren($children_count); - elseif ($i == 'childexport' && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) - return $this->getMenuItemExportSub(); - else - return ''; - - } else - return ''; - - case 'msgschema': - if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') && $_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) - return array('',$this->getViewSchemaMessage()); - else - return array(); - - case 'msgro': - if ($this->template->isReadOnly()) - return array('',$this->getReadOnlyMessage()); - else - return array(); - - case 'msgmodattr': - $modified_attrs = array(); - $modified = get_request('modified_attrs','REQUEST',false,array()); - - foreach ($this->template->getAttributes(true) as $attribute) - if (in_array($attribute->getName(),$modified)) - array_push($modified_attrs,$attribute->getFriendlyName()); - - if (count($modified_attrs)) - return array('',$this->getModifiedAttributesMessage($modified_attrs)); - else - return array(); - - default: - return false; - } - } - - protected function getDeleteAttributeMessage() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr') && ! $this->template->isReadOnly()) - return sprintf($this->layout['hint'],_('Hint: To delete an attribute, empty the text field and click save.')); - else - return ''; - } - - protected function getModifiedAttributesMessage(&$modified_attributes) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - return sprintf($this->layout['hint'], - (count($modified_attributes) == 1) ? - sprintf(_('An attribute (%s) was modified and is highlighted below.'),implode('',$modified_attributes)) : - sprintf(_('Some attributes (%s) were modified and are highlighted below.'),implode(', ',$modified_attributes))); - } - - protected function getReadOnlyMessage() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - return sprintf($this->layout['hint'],_('Viewing entry in read-only mode.')); - } - - protected function getViewSchemaMessage() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - return sprintf($this->layout['hint'],_('Hint: To view the schema for an attribute, click the attribute name.')); - } - - /** PAGE ENTRY MENU ITEMS DETAILS **/ - - private function getMenuItemRefresh() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=template_engine&%s&junk=%s',$this->url_base,random_junk()); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'refresh.png',_('Refresh'), - htmlspecialchars($href),_('Refresh this entry'),htmlspecialchars($href),str_replace('\'','\\\'',_('Reloading')),_('Refresh')); - else - return sprintf($this->layout['action'],IMGDIR,'refresh.png',_('Refresh'), - htmlspecialchars($href),_('Refresh this entry'),_('Refresh')); - } - - protected function getMenuItemSwitchTemplate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $href = sprintf('cmd=template_engine&%s&template=',$this->url_base); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'switch.png',_('Switch Template'), - htmlspecialchars($href),_('Change to another template'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Switch Template')); - else - return sprintf($this->layout['action'],IMGDIR,'switch.png',_('Switch Template'), - htmlspecialchars($href),_('Change to another template'),_('Switch Template')); - } - - protected function getMenuItemExportBase() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=export_form&%s&scope=base',$this->url_base); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'export.png',_('Export'), - htmlspecialchars($href),_('Save a dump of this object'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Export')); - else - return sprintf($this->layout['action'],IMGDIR,'export.png',_('Export'), - htmlspecialchars($href),_('Save a dump of this object'),_('Export')); - } - - private function getMenuItemMove() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=copy_form&%s',$this->url_base); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'cut.png',_('Cut'), - htmlspecialchars($href),_('Copy this object to another location, a new DN, or another server'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Copy or move this entry')); - else - return sprintf($this->layout['action'],IMGDIR,'cut.png',_('Cut'), - htmlspecialchars($href),_('Copy this object to another location, a new DN, or another server'), - _('Copy or move this entry')); - } - - protected function getMenuItemInternalAttributes() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (get_request('show_internal_attrs','REQUEST')) { - $href = sprintf('cmd=template_engine&%s&junk=',$this->url_base,random_junk()); - - return sprintf($this->layout['action'],IMGDIR,'tools-no.png',_('Hide'), - htmlspecialchars($href),'',_('Hide internal attributes')); - - } else { - $href = sprintf('cmd=template_engine&show_internal_attrs=true&%s',$this->url_base); - - return sprintf($this->layout['action'],IMGDIR,'tools.png',_('Show'), - htmlspecialchars($href),'',_('Show internal attributes')); - } - } - - private function getMenuItemDelete() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=delete_form&%s',$this->url_base); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'trash.png',_('Trash'), - htmlspecialchars($href),_('You will be prompted to confirm this decision'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Delete this entry')); - else - return sprintf($this->layout['action'],IMGDIR,'trash.png',_('Trash'), - htmlspecialchars($href),_('You will be prompted to confirm this decision'),_('Delete this entry')); - } - - protected function getMenuItemRename() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=rename_form&%s&template=%s',$this->url_base,$this->template->getID()); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'rename.png',_('Rename'), - htmlspecialchars($href),_('Rename this entry'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Rename')); - else - return sprintf($this->layout['action'],IMGDIR,'rename.png',_('Rename'), - htmlspecialchars($href),_('Rename this entry'),_('Rename')); - } - - protected function getMenuItemCompare() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=compare_form&%s',$this->url_base); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'compare.png',_('Compare'), - htmlspecialchars($href),_('Compare this entry with another'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Compare with another entry')); - else - return sprintf($this->layout['action'],IMGDIR,'compare.png',_('Compare'), - htmlspecialchars($href),_('Compare this entry with another'),_('Compare with another entry')); - } - - protected function getMenuItemCreate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$this->template->getDNEncode()); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'create.png',_('Create'), - htmlspecialchars($href),_('Create a child entry'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Create a child entry')); - else - return sprintf($this->layout['action'],IMGDIR,'create.png',_('Create'), - htmlspecialchars($href),_('Create a child entry'),_('Create a child entry')); - } - - protected function getMenuItemAddAttribute() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (! $this->template->getAvailAttrs()) - return ''; - - $href = sprintf('cmd=add_attr_form&%s',$this->url_base); - $layout = '%s%s'; - - if (isAjaxEnabled()) - return sprintf($layout,IMGDIR,'add.png',_('Add'), - htmlspecialchars($href),_('Add new attribute to this object'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Add new attribute')),_('Add new attribute')); - else - return sprintf($this->layout['action'],IMGDIR,'add.png',_('Add'), - htmlspecialchars($href),_('Add new attribute to this object'),_('Add new attribute')); - } - - protected function getMenuItemShowChildren($children_count) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=one&query=none&size_limit=0&search=true', - $this->getServerID(),rawurlencode('objectClass=*'),$this->template->getDNEncode()); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'children.png',_('Children'), - htmlspecialchars($href),_('View the children of this object'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')), - ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'),$children_count)); - else - return sprintf($this->layout['action'],IMGDIR,'children.png',_('Children'), - htmlspecialchars($href),_('View the children of this object'), - ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'),$children_count)); - } - - protected function getMenuItemExportSub() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=export_form&%s&scope=%s',$this->url_base,'sub'); - - if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'export.png',_('Save'), - htmlspecialchars($href),_('Save a dump of this object and all of its children'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Export subtree')); - else - return sprintf($this->layout['action'],IMGDIR,'export.png',_('Save'), - htmlspecialchars($href),_('Save a dump of this object and all of its children'),_('Export subtree')); - } - - /** CHOOSERS **/ - - /** - * RDN Chooser - */ - protected function drawRDNChooser() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (! count($this->template->getRDNAttrs())) { - printf('%s','RDN'); - - echo ''; - - } else { - echo ''; - foreach ($this->template->getRDNAttrs() as $rdn) - printf('',htmlspecialchars($rdn)); - - if (get_request('create_base')) - echo ''; - - echo ''; - } - } - - /** - * Container Chooser - */ - protected function drawContainerChooser($default_container) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo ''; - printf('%s',_('Container')); - echo ''; - if (get_request('create_base')) - printf('%s',$default_container,htmlspecialchars($default_container)); - else { - printf('',htmlspecialchars($default_container)); - draw_chooser_link('entry_form','container'); - } - echo ''; - echo ''; - } - - /** - * Object Class Chooser - */ - protected function drawObjectClassChooser() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $socs = $this->getServer()->SchemaObjectClasses(); - if (! $socs) - $socs = array(); - - echo ''; - printf('%s',_('ObjectClasses')); - echo ''; - echo ''; - echo ''; - - if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints')) { - printf(' Hint',IMGDIR); - echo _('Hint: You must choose exactly one structural objectClass (shown in bold above)'); - echo '
'; - } - } - - /** INTERNAL ATTRIBUTES **/ - - protected function drawInternalAttributes() { - if ($this->template->getAttributesInternal()) - foreach ($this->template->getAttributesInternal() as $attribute) - $this->draw('Internal',$attribute); - else - printf('(%s)
',_('No internal attributes')); - - echo "\n"; - } - - protected function drawInternalAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->draw('Template',$attribute); - } - - /** FORM METHODS **/ - - public function drawFormStart() { - echo '
'; - - echo '
'; - if ($_SESSION[APPCONFIG]->getValue('confirm','update')) - echo ''; - else - echo ''; - echo '
'; - } - - protected function drawForm($nosubmit=false) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo '
'; - printf('',$this->getServerID()); - printf('',$this->template->getDNEncode(false)); - printf('',$this->template->getID()); - echo '
'; - - echo ''; - - $this->drawShownAttributes(); - if (! $nosubmit) - $this->drawFormSubmitButton(); - - echo '
'; - - echo '
 '; - $this->drawHiddenAttributes(); - echo '
'; - } - - public function drawFormEnd() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Include the RDN details to support creating the base - if (get_request('create_base')) { - if (get_request('rdn')) { - $rdn = explode('=',get_request('rdn')); - echo '
'; - printf('',$rdn[0],$rdn[1]); - printf('',$rdn[0]); - echo '
'; - } - } - - echo '
'; - - # Javascript - $this->drawJavascript(); - - # For debugging, show the template object. - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_debug_info') && get_request('debug','GET')) { - echo "\n\n"; - printf('Plus',IMGDIR); - echo ''; - } - } - - public function drawFormSubmitButton() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (! $this->template->isReadOnly()) - // @todo cant use AJAX here, it affects file uploads. - printf('', - _('Update Object')); - } - - /** STEP FORM METHODS **/ - - private function drawStepTitle($page) { - if (DEBUGTMP) printf('%s
',__METHOD__); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [templateNAME:%s]
',__METHOD__,$this->template->getName()); - - # The default template needs to ask the user for objectClasses. - if ($this->template->isType('default')) { - # The default template only uses 2 pages - $this->pagelast = 2; - - echo '

'; - printf('%s: ',sprintf(_('Step %s of %s'),$page,$this->pagelast)); - - if ($page == 1) - echo _('Container and ObjectClass(es)'); - else - echo _('Specify attributes and values'); - - echo '

'; - - } elseif ($this->template->getDescription()) - printf('

%s (%s)

', - _($this->template->getDescription()), - sprintf(_('Step %s of %s'),$page,$this->pagelast)); - } - - private function drawStepFormStart($page) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (($this->template->isType('default') && $this->template->getContext() == 'create' && $page == 1) || $page < $this->pagelast) { - echo '
'; - echo '
'; - - } else { - echo ''; - echo '
'; - - if ($_SESSION[APPCONFIG]->getValue('confirm','create') && ! get_request('create_base')) - echo ''; - else - echo ''; - } - } - - protected function drawStepForm($page) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - printf('',$this->getServerID()); - printf('',$this->template->getID()); - printf('',$page+1); - if (get_request('create_base')) - echo ''; - - $this->drawHiddenAttributes(); - - if ($this->template->isType('default') && $page == 1) { - echo '
'; - - echo ''; - - $this->drawContainerChooser($this->template->getContainer()); - $this->drawObjectClassChooser(); - - } else { - printf('',$this->template->getContainerEncode(false)); - echo ''; - - echo '
'; - - $this->drawRDNChooser(); - - if ($this->template->isType('default') && $this->template->getContext() == 'create') - $this->drawStepFormDefaultAttributes(); - else - $this->drawShownAttributes(); - } - - $this->drawStepFormSubmitButton($page); - - echo '
'; - } - - private function drawStepFormEnd() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->drawFormEnd(); - } - - private function drawStepFormSubmitButton($page) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo ''; - if ($page < $this->pagelast) - printf(' ',_('Proceed >>')); - else - // @todo cant use AJAX here, it affects file uploads. - printf('', - _('Create Object')); - echo ''; - } - - /** - * Given our known objectClass in the template, this will render the required MAY and optional MUST attributes - */ - private function drawStepFormDefaultAttributes() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - # Put required attributes first - $attrs = array(); - $attrs['required'] = array(); - $attrs['optional'] = array(); - foreach ($this->template->getAttributes(true) as $attribute) { - # Skip the objectclass attribute, we already know it in a default creation form. - if ($attribute->getName() == 'objectclass') - continue; - - if ($attribute->isRequired()) - array_push($attrs['required'],$attribute); - - elseif (! $attribute->getValues()) - array_push($attrs['optional'],$attribute); - } - - printf('%s',_('Required Attributes')); - if (count($attrs['required'])) - foreach ($attrs['required'] as $attribute) - $this->draw('Template',$attribute); - - else - printf('(%s)',_('none')); - - printf('%s',_('Optional Attributes')); - if (count($attrs['optional'])) - foreach ($attrs['optional'] as $attribute) - $this->draw('Template',$attribute); - - else - printf('(%s)',_('none')); - - echo "\n"; - } - - /** DRAW ATTRIBUTES **/ - - private function drawShownAttributes() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - foreach ($this->template->getAttributesShown() as $attribute) - if (($attribute->getPage() == $this->page) && ($attribute->isRequired() || $attribute->isMay())) { - $this->draw('Template',$attribute); - echo "\n"; - } - } - - /** DRAW PAGE JAVACRIPT */ - - protected function drawJavascript() { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo "\n"; - printf('',__METHOD__); - echo "\n"; - - printf('',JSDIR); - printf('',JSDIR); - printf('',JSDIR); - echo "\n"; - - printf('',__METHOD__); - echo ' -'; - echo "\n"; - printf('',__METHOD__); - echo "\n"; - - $this->drawTemplateJavascript(); - - # For DateAttributes, we need to set some defaults for the js_calendar. - echo ''."\n"; - echo ''."\n"; - echo ''."\n"; - echo "\n"; - - foreach ($this->template->getAttributesShown() as $attribute) - $this->draw('Javascript',$attribute); - - // @todo We need to sleep here a little bit, because our JS may not have loaded yet. - echo ''."\n"; - printf('',__METHOD__); - echo "\n"; - } - - /** - * Javascript Functions - */ - private function drawTemplateJavascript() { - printf('',__METHOD__); - echo "\n"; - foreach ($this->template->getAttributes(true) as $attribute) - if ($onchange = $attribute->getOnChange()) - if (is_array($onchange)) - foreach ($onchange as $value) - $this->template->OnChangeAdd($attribute->getName(),$value); - else - $this->template->OnChangeAdd($attribute->getName(),$onchange); - printf('',__METHOD__); - echo "\n"; - - printf('',__METHOD__); - - echo ' -'; - echo "\n"; - printf('',__METHOD__); - echo "\n"; - } - - /** ATTRIBUTE TITLE **/ - - protected function drawTitleAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (($this->template->getContext() == 'edit') - && ($attribute->hasBeenModified() || in_array($attribute->getName(),get_request('modified_attrs','REQUEST',false,array())))) - echo ''; - else - echo ''; - - echo ''; - $this->draw('Name',$attribute); - echo ''; - - echo ''; - - # Setup the $attr_note, which will be displayed to the right of the attr name (if any) - if ($_SESSION[APPCONFIG]->getValue('appearance','show_attribute_notes')) - $this->draw('Notes',$attribute); - - echo ''; - echo ''; - } - - /** ATTRIBUTE LINE **/ - - protected function drawStartValueLineAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (($this->template->getContext() == 'edit') - && ($attribute->hasBeenModified() || in_array($attribute->getName(),get_request('modified_attrs','REQUEST',false,array())))) - echo ''; - else - echo ''; - - echo ''; - } - - protected function drawEndValueLineAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - echo ''; - echo ''; - - if ($attribute->getSpacer()) - echo ' '; - - if (($this->template->getContext() == 'edit') - && ($attribute->hasBeenModified() || in_array($attribute->getName(),get_request('modified_attrs','REQUEST',false,array())))) - echo ''; - } - - protected function drawTemplateAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->draw('Title',$attribute); - $this->draw('TemplateValues',$attribute); - } - - protected function drawTemplateValuesAttribute($attribute) { - if (DEBUGTMP) printf('%s:%s
',time(),__METHOD__); - - $this->draw('StartValueLine',$attribute); - - # Draws values - $value_count = $attribute->getValueCount(); - for ($i=0;$i<$value_count;$i++) - $this->draw('Value',$attribute,$i); - - if (! $attribute->isInternal()) { - $blankvalue_count = $attribute->getMaxValueCount(); - if ($blankvalue_count < 0) - $blankvalue_count = 1; - - $blankvalue_count -= $value_count; - - for ($j=0;$j<$blankvalue_count;$j++) - $this->draw('Value',$attribute,$i+$j); - - if (($value_count == $blankvalue_count) || ($value_count && $blankvalue_count < 1)) - $this->draw('Menu',$attribute); - } - - $this->draw('EndValueLine',$attribute); - echo "\n"; - } - - /** DRAW ICONS FOR ATTRIBUTES VALUES **/ - - protected function drawIconAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (is_dn_string($val) || $this->getServer()->isDNAttr($attribute->getName())) - $this->draw('DnValueIcon',$attribute,$val); - elseif (is_mail_string($val)) - $this->draw('MailValueIcon',$attribute,$val); - elseif (is_url_string($val)) - $this->draw('UrlValueIcon',$attribute,$val); - - else { - if ($icon = $attribute->getIcon()) - printf('Icon ',$icon); - } - } - - protected function drawDnValueIconAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (strlen($val) <= 0) - printf('Go ',IMGDIR); - elseif ($this->getServer()->dnExists($val)) - printf('Go ', - $this->getServerID(),rawurlencode($val),_('Go to'),$val,IMGDIR); - else - printf('Go ',_('DN not available'),$val,IMGDIR); - } - - protected function drawMailValueIconAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $img = sprintf('%s',IMGDIR,_('Mail')); - if (strlen($val) <= 0) - echo $img; - else - printf('%s',htmlspecialchars($val),$img); - echo ' '; - } - - protected function drawUrlValueIconAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $img = sprintf('%s',IMGDIR,_('URL')); - $url = explode(' +',$val,2); - - if (strlen($val) <= 0) - echo $img; - else - printf('%s',htmlspecialchars($url[0]),$img); - echo ' '; - } - - /** DEFAULT ATTRIBUTE RENDERING **/ - - /** javacript */ - - protected function drawJavascriptAttribute($attribute) { - if (! $attribute->needJS()) { - printf('',$attribute->getName()); - echo "\n"; - return; - } - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - - echo ''."\n"; - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - } - - protected function getFocusJavascriptAttribute($attribute,$component) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - return ''; - } - - protected function getBlurJavascriptAttribute($attribute,$component) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $j = "\t".'fill('.$component.'.id,pla_getComponentValue('.$component.'));'."\n"; - $j .= "\t".'validate_'.$attribute->getName().'('.$component.',false);'."\n"; - - return $j; - } - - protected function drawFocusJavascriptAttribute($attribute,$component) { - echo $this->get('FocusJavascript',$attribute,$component); - } - - protected function drawBlurJavascriptAttribute($attribute,$component) { - echo $this->get('BlurJavascript',$attribute,$component); - } - - protected function drawFillJavascriptAttribute($attribute,$component_id,$component_value) { - if ($attribute->needJS('validate')) - printf("\tvalidate_%s(pla_getComponentById(%s),true);\n",$attribute->getName(),$component_id); - } - - protected function drawValidateJavascriptAttribute($attribute,$component,$silence,$var_valid) { - printf('var vals = getAttributeValues("new","%s");',$attribute->getName()); - echo 'if (vals.length <= 0) {'; - printf('%s = false;',$var_valid); - printf('alertError("%s: %s",%s);',_('This attribute is required'),$attribute->getFriendlyName(),$silence); - echo '}'; - echo "\n"; - - printf('var comp = getAttributeComponents("new","%s");',$attribute->getName()); - echo 'for (var i = 0; i < comp.length; i++) {'; - printf('comp[i].style.backgroundColor = "%s";',$var_valid ? 'white' : '#FFFFA0'); - echo '}'; - } - - /** ATTRIBUTE MENU **/ - - protected function drawMenuAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $result = ''; - $item = ''; - - foreach (array('add','modify','rename') as $action) - if ($item = $this->get('MenuItem',$attribute,$action)) - $result .= sprintf('
%s
',$item); - - if (! $result) - return; - - echo ''; - printf('',$result); - echo ''; - echo '
 %s
'; - } - - protected function getMenuItemAttribute($attribute,$action) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - # If there is no DN, then this is a creating entry. - if (($this->template->getContext() == 'create') || $this->template->isReadOnly()) - return false; - - switch ($action) { - case 'add': - if ($attribute->isVisible() && ! $attribute->isReadOnly() - && $_SESSION[APPCONFIG]->isCommandAvailable('script','add_value_form')) { - - if ($attribute->haveMoreValues()) - return $this->get('AddValueMenuItem',$attribute); - } - - return ''; - - case 'modify': - if (in_array($attribute->getName(),arrayLower($_SESSION[APPCONFIG]->getValue('modify_member','groupattr')))) { - if ($attribute->isVisible() && ! $attribute->isReadOnly() && ! $attribute->isRDN() - && $_SESSION[APPCONFIG]->isCommandAvailable('script','modify_member_form')) - return $this->get('ModifyMemberMenuItem',$attribute); - } - - return ''; - - case 'rename': - if ($attribute->isVisible() && $attribute->isRDN() && ! $attribute->isReadOnly() - && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename_form') - && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename')) - return $this->get('RenameMenuItem',$attribute); - - return ''; - - default: - return false; - } - } - - protected function getAddValueMenuItemAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href_parm = htmlspecialchars(sprintf('cmd=add_value_form&server_id=%s&dn=%s&attr=%s', - $this->getServerID(),$this->template->getDNEncode(),rawurlencode($attribute->getName(false)))); - - if (isAjaxEnabled()) - return sprintf('(%s)', - $href_parm,_('Add an additional value to attribute'),$attribute->getName(false),$attribute->getName(), - $href_parm,str_replace('\'','\\\'',_('Add Value to Attribute')),_('add value')); - else - return sprintf('(%s)', - $href_parm,_('Add an additional value to attribute'),$attribute->getName(false),_('add value')); - } - - protected function getAddValueMenuItemObjectClassAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href_parm = htmlspecialchars(sprintf('cmd=add_value_form&server_id=%s&dn=%s&attr=%s', - $this->getServerID(),$this->template->getDNEncode(),rawurlencode($attribute->getName(false)))); - - if (isAjaxEnabled()) - return sprintf('(%s)', - $href_parm,_('Add an additional value to attribute'),$attribute->getName(false), - $href_parm,str_replace('\'','\\\'',_('Add Value to Attribute')),_('add value')); - else - return sprintf('(%s)', - $href_parm,_('Add an additional value to attribute'),$attribute->getName(false),_('add value')); - } - - protected function getModifyMemberMenuItemAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd=modify_member_form&server_id=%s&dn=%s&attr=%s', - $this->getServerID(),$this->template->getDNEncode(),rawurlencode($attribute->getName())); - - if (isAjaxEnabled()) - return sprintf('(%s)', - htmlspecialchars($href),_('Modify members for'),$this->template->getDN(), - htmlspecialchars($href),str_replace('\'','\\\'',_('Modify group membership')), - _('modify group members')); - else - return sprintf('(%s)', - htmlspecialchars($href),_('Modify members for'),$this->template->getDN(),_('modify group members')); - } - - protected function getRenameMenuItemAttribute($attribute) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - $href = sprintf('cmd.php?cmd=rename_form&server_id=%s&dn=%s&template=%s', - $this->getServerID(),$this->template->getDNEncode(),$this->template->getID()); - - return sprintf('(%s)',htmlspecialchars($href),_('rename')); - } - - /** values **/ - - protected function drawValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($attribute->isMultiple() && $i > 0) - return; - - $val = $attribute->getValue($i); - - if ($attribute->isVisible()) { - echo ''; - - echo ''; - - echo '
'; - $this->draw('Icon',$attribute,$val); - echo ''; - } - - if ($attribute->isInternal()) - $this->draw('FormReadOnlyValue',$attribute,$i); - else - $this->draw('FormValue',$attribute,$i); - - if ($attribute->isVisible()) { - echo ''; - $this->draw('RequiredSymbol',$attribute); - echo '
'; - } - echo "\n"; - } - - # @todo for userPasswords, we need to capture the default value of select lists, without specifying - protected function drawHelperAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $params = $attribute->getHelper(); - - # We take the first only - $id = isset($params['id']) ? $params['id'] : ''; - if (is_array($id)) { - system_message(array( - 'title'=>_('Too many arguments'), - 'body'=>sprintf('%s (%s)',_('Helper attribute has too many ID values, only the first one is used'),count($id)), - 'type'=>'warn')); - - $id = $id[0]; - } - - # We take the first only - $display = isset($params['display']) ? $params['display'] : ''; - if (is_array($display)) { - system_message(array( - 'title'=>_('Too many arguments'), - 'body'=>sprintf('%s (%s)',_('Helper attribute has too many DISPLAY values, only the first one is used'),count($display)), - 'type'=>'warn')); - - $display = $display[0]; - } - - # We take the first only - $default = isset($params['default']) ? $params['default'] : ''; - if (is_array($default)) { - system_message(array( - 'title'=>_('Too many arguments'), - 'body'=>sprintf('%s (%s)',_('Helper attribute has too many DISPLAY values, only the first one is used'),count($default)), - 'type'=>'warn')); - - $default = $default[0]; - } - - if ($attribute->getHelperValue()) - $vals = $this->get('Default',$attribute, - $this->template->getContainer() ? $this->template->getContainer() : $this->getServer()->getContainerPath($this->template->getDN()), - 'helpervalue'); - else - $vals = isset($params['value']) ? $params['value'] : ''; - - if ($this->template->getContext() == 'create') - $dn = $this->template->getContainer(); - else - $dn = $this->template->getDN(); - - if (is_array($vals) && count($vals) > 0) { - $found = false; - - printf(''; - - } else { - # Vals must be an empty array. - if (is_array($vals)) - $vals = ''; - - printf('', - $id,htmlspecialchars($attribute->getName()),$i, - $id,htmlspecialchars($attribute->getName()),$i, - htmlspecialchars($vals)); - } - - if ($display) { - echo '
'; - printf('%s',$display); - echo '
'; - } - } - - protected function drawRequiredSymbolAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if ($attribute->isRequired() && ! $attribute->isReadOnly()) - echo '*'; - } - - /** BINARY ATTRIBUTE RENDERING **/ - - #@todo do we need a $this->drawJavascriptAttribute($attribute) here too ? - protected function drawJavascriptBinaryAttribute($attribute) { - # If there are no values, then this javascript doesnt need to be drawn. - if (! $attribute->getValues()) - return; - - static $drawn = false; - - # This JS may have been rendered by multiple Binary attributes - if ($drawn) - return; - else - $drawn = true; - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - - echo ''; - echo ''; - printf('',$this->getServerID()); - printf('',$this->template->getDNEncode(false)); - printf('',$this->template->getID()); - echo ''; - echo ''; - echo ''; - - echo ' -'; - echo "\n"; - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - } - - /** DATE ATTRIBUTE RENDERING **/ - - protected function drawJavaScriptDateAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - - $this->drawJavaScriptAttribute($attribute); - - static $drawn = false; - - # This JS may have been rendered by multiple Date attributes - if (! $drawn) { - printf('',JSDIR); - printf('',JSDIR); - printf('',JSDIR); - - $drawn = true; - } - - $config = array(); - $config['date'] = array_change_key_case($_SESSION[APPCONFIG]->getValue('appearance','date_attrs')); - $config['time'] = array_change_key_case($_SESSION[APPCONFIG]->getValue('appearance','date_attrs_showtime')); - $config['format'] = $_SESSION[APPCONFIG]->getValue('appearance','date'); - - if (isset($config['date'][$attribute->getName()])) - $config['format'] = $config['date'][$attribute->getName()]; - - for ($i=0;$i<=$attribute->getValueCount();$i++) { - printf('',$attribute->getName(),$i,$config['format']); - - if (in_array_ignore_case($attribute->getName(),array_keys($config['time'])) && ($config['time'][$attribute->getName()])) - printf('',$attribute->getName(),$i,'true'); - - echo "\n"; - } - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - } - - /** - * Draws an HTML date selector button which, when clicked, pops up a date selector dialog. - */ - protected function drawSelectorPopupDateAttribute($attribute,$i) { - printf('Calendar', - $attribute->getName(),$i,_('Click to popup a dialog to select a date graphically'),IMGDIR,$attribute->getName(),$i); - } - - /** DN ATTRIBUTES **/ - - protected function drawIconDnAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - $this->draw('DnValueIcon',$attribute,$val); - } - - /** OBJECT CLASS ATTRIBUTE **/ - - protected function drawIconObjectClassAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (! $_SESSION[APPCONFIG]->getValue('appearance','show_schema_link') || !$_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) - return; - - if (strlen($val) > 0) { - $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=objectclasses&viewvalue=%s', - $this->getServerID(),$val); - printf('Info ', - htmlspecialchars($href),_('View the schema description for this objectClass'),IMGDIR); - } - } - - /** PASSWORD ATTRIBUTES **/ - - protected function drawJavascriptPasswordAttribute($attribute) { - static $drawn = array(); - - # This JS may have been rendered by multiple Binary attributes - if (isset($drawn[$attribute->getName()]) && $drawn[$attribute->getName()]) - return; - else - $drawn[$attribute->getName()] = true; - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - - $this->drawJavascriptAttribute($attribute); - - # Add the javascript so we can call check password later. - echo ' -'; - echo "\n"; - - printf('',__METHOD__,$attribute->getName()); - echo "\n"; - } - - protected function drawCheckLinkPasswordAttribute($attribute,$component_id) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - printf('%s...
', - $component_id,$attribute->getName(),_('Check password')); - } - - /** RANDOM PASSWORD **/ - - /** - * This will draw the javascript that displays to the user the random password generated - * - * @todo This function doesnt work well if there are more than 1 RandomPasswordAttributes on the form for the same attribute (unlikely situation) - */ - protected function drawJavascriptRandomPasswordAttribute($attribute) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - printf("\n\n",__METHOD__); - $this->drawJavascriptPasswordAttribute($attribute); - - $pwd = password_generate(); - $pwd = str_replace("\\","\\\\",$pwd); - $pwd = str_replace("'","\\'",$pwd); - - printf("\n\n",__METHOD__); - echo ''; - printf("\n\n",__METHOD__); - } - - protected function drawDefaultHelperPasswordAttribute($attribute,$i) { - $id = 'enc'; - - if ($val = $attribute->getValue($i)) - $default = get_enc_type($val); - else - $default = $this->getServer()->getValue('appearance','pla_password_hash'); - - if (! $attribute->getPostValue()) - printf('',$attribute->getName(),$i); - - printf(''; - } - - protected function drawDefaultHelperSambaPasswordAttribute($attribute,$i) { - $id = 'enc'; - - if (! $attribute->getPostValue()) - printf('',$attribute->getName(),$i); - - switch ($attribute->getName()) { - case 'sambalmpassword' : $enc = 'lm'; break; - case 'sambantpassword' : $enc = 'nt'; break; - - default: - return ''; - } - - printf('', - $id,htmlspecialchars($attribute->getName()),$i, - $id,htmlspecialchars($attribute->getName()),$i,$enc); - } - - /** SELECTION ATTRIBUTE RENDERING **/ - - protected function drawIconSelectionAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
',__METHOD__); - - if (! $attribute->isMultiple() || $attribute->isReadOnly()) - $this->drawIconAttribute($attribute,$val); - } - - protected function getMenuItemSelectionAttribute($attribute,$i) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (DEBUGTMP) printf('%s
',__METHOD__); - - switch ($i) { - case 'add': - if (! $attribute->isMultiple()) - return $this->getMenuItemAttribute($attribute,$i); - else - return ''; - - case 'modify': - return ''; - - default: - return $this->getMenuItemAttribute($attribute,$i); - } - } -} -?> diff --git a/lib/createlm.php b/lib/createlm.php deleted file mode 100644 index 3dc4bb1..0000000 --- a/lib/createlm.php +++ /dev/null @@ -1,381 +0,0 @@ -permute($key, $this->perm1, 56); - - $c = array(); - $d = array(); - for ($i = 0; $i < 28; $i++) { - $c[$i] = $pk1[$i]; - $d[$i] = $pk1[28 + $i]; - } - - for ($i = 0; $i < 16; $i++) { - $c = $this->lshift($this->sc[$i], $c); - $d = $this->lshift($this->sc[$i], $d); - - $cd = $c; - for ($k = 0; $k < sizeof($d); $k++) $cd[] = $d[$k]; - $ki[$i] = $this->permute($cd, $this->perm2, 48); - } - - $pd1 = $this->permute($in, $this->perm3, 64); - - $l = array(); - $r = array(); - for ($i = 0; $i < 32; $i++) { - $l[$i] = $pd1[$i]; - $r[$i] = $pd1[32 + $i]; - } - - for ($i = 0; $i < 16; $i++) { - $er = $this->permute($r, $this->perm4, 48); - if ($forw) $erk = $this->mxor($er, $ki[$i]); - else $erk = $this->mxor($er, $ki[15 - $i]); - - for ($j = 0; $j < 8; $j++) { - for ($k = 0; $k < 6; $k++) { - $b[$j][$k] = $erk[($j * 6) + $k]; - } - } - for ($j = 0; $j < 8; $j++) { - $m = array(); - $n = array(); - $m = ($b[$j][0] << 1) | $b[$j][5]; - $n = ($b[$j][1] << 3) | ($b[$j][2] << 2) | ($b[$j][3] << 1) | $b[$j][4]; - - for ($k = 0; $k < 4; $k++) { - $b[$j][$k]=($this->sbox[$j][$m][$n] & (1 << (3-$k)))?1:0; - } - } - - for ($j = 0; $j < 8; $j++) { - for ($k = 0; $k < 4; $k++) { - $cb[($j * 4) + $k] = $b[$j][$k]; - } - } - $pcb = $this->permute($cb, $this->perm5, 32); - $r2 = $this->mxor($l, $pcb); - for ($k = 0; $k < 32; $k++) $l[$k] = $r[$k]; - for ($k = 0; $k < 32; $k++) $r[$k] = $r2[$k]; - } - $rl = $r; - for ($i = 0; $i < sizeof($l); $i++) $rl[] = $l[$i]; - return $this->permute($rl, $this->perm6, 64); - } - - /** - * str_to_key - * - * @param string $str - * @return string key - */ - private function str_to_key($str) { - $key[0] = $this->unsigned_shift_r($str[0], 1); - $key[1] = (($str[0]&0x01)<<6) | $this->unsigned_shift_r($str[1], 2); - $key[2] = (($str[1]&0x03)<<5) | $this->unsigned_shift_r($str[2], 3); - $key[3] = (($str[2]&0x07)<<4) | $this->unsigned_shift_r($str[3], 4); - $key[4] = (($str[3]&0x0F)<<3) | $this->unsigned_shift_r($str[4], 5); - $key[5] = (($str[4]&0x1F)<<2) | $this->unsigned_shift_r($str[5], 6); - $key[6] = (($str[5]&0x3F)<<1) | $this->unsigned_shift_r($str[6], 7); - $key[7] = $str[6]&0x7F; - for ($i = 0; $i < 8; $i++) { - $key[$i] = ($key[$i] << 1); - } - return $key; - } - - /** - * smb_hash - * - * @param unknown_type $in - * @param unknown_type $key - * @param unknown_type $forw - * @return unknown - */ - private function smb_hash($in, $key, $forw){ - $key2 = $this->str_to_key($key); - - for ($i = 0; $i < 64; $i++) { - $inb[$i] = ($in[$i/8] & (1<<(7-($i%8)))) ? 1:0; - $keyb[$i] = ($key2[$i/8] & (1<<(7-($i%8)))) ? 1:0; - $outb[$i] = 0; - } - $outb = $this->doHash($inb, $keyb, $forw); - for ($i = 0; $i < 8; $i++) { - $out[$i] = 0; - } - for ($i = 0; $i < 64; $i++) { - if ( $outb[$i] ) { - $out[$i/8] |= (1<<(7-($i%8))); - } - } - return $out; - } - - /** - * E_P16 - * - * @param unknown_type $in - * @return unknown - */ - private function E_P16($in) { - $p14 = array_values(unpack("C*",$in)); - $sp8 = array(0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25); - $p14_1 = array(); - $p14_2 = array(); - for ($i = 0; $i < 7; $i++) { - $p14_1[$i] = $p14[$i]; - $p14_2[$i] = $p14[$i + 7]; - } - $p16_1 = $this->smb_hash($sp8, $p14_1, true); - $p16_2 = $this->smb_hash($sp8, $p14_2, true); - $p16 = $p16_1; - for ($i = 0; $i < sizeof($p16_2); $i++) { - $p16[] = $p16_2[$i]; - } - return $p16; - } - - /** - * Calculates the LM hash of a given password. - * - * @param string $password password - * @return string hash value - */ - public function lmhash($password = "") { - $password = strtoupper($password); - $password = substr($password,0,14); - $password = str_pad($password, 14, chr(0)); - $p16 = $this->E_P16($password); - for ($i = 0; $i < sizeof($p16); $i++) { - $p16[$i] = sprintf("%02X", $p16[$i]); - } - return join("", $p16); - } - - /** - * Calculates the NT hash of a given password. - * - * @param string $password password - * @return string hash value - */ - public function nthash($password = "") { - if (function_exists('mhash')) - if (defined('MHASH_MD4')) - return strtoupper(bin2hex(mhash(MHASH_MD4,iconv('UTF-8','UTF-16LE',$password)))); - else - return strtoupper(hash('md4', iconv("UTF-8","UTF-16LE",$password))); - else - error(_('Your PHP install does not have the mhash() function. Cannot do hashes.'),'error','index.php'); - } - - /** - * Unsigned shift operation for 32bit values. - * - * PHP 4 only supports signed shifts by default. - */ - private function unsigned_shift_r($a, $b) { - $z = 0x80000000; - if ($z & $a) { - $a = ($a >> 1); - $a &= (~$z); - $a |= 0x40000000; - $a = ($a >> ($b - 1)); - } - else { - $a = ($a >> $b); - } - return $a; - } - -} - -?> diff --git a/lib/ds.php b/lib/ds.php deleted file mode 100644 index 4b27227..0000000 --- a/lib/ds.php +++ /dev/null @@ -1,735 +0,0 @@ -', any custom extra connection to ds. - */ - abstract public function login($user=null,$pass=null,$method=null); - - /** - * Query the datasource - */ - abstract public function query($query,$method,$index=null,$debug=false); - - /** - * Return error details from previous operation - */ - abstract protected function getErrorMessage(); - abstract protected function getErrorNum(); - - /** - * Functions that set and verify object configuration details - */ - public function setDefaults($defaults) { - foreach ($defaults as $key => $details) - foreach ($details as $setting => $value) - $this->default->{$key}[$setting] = $value; - } - - public function isDefaultKey($key) { - return isset($this->default->$key); - } - - public function isDefaultSetting($key,$setting) { - return array_key_exists($setting,$this->default->{$key}); - } - - /** - * Return a configuration value - */ - public function getValue($key,$setting,$fatal=true) { - if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs); - - if (isset($this->custom->{$key}[$setting])) - return $this->custom->{$key}[$setting]; - - elseif (isset($this->default->{$key}[$setting]) && array_key_exists('default',$this->default->{$key}[$setting])) - return $this->default->{$key}[$setting]['default']; - - elseif ($fatal) - debug_dump_backtrace("Error trying to get a non-existant value ($key,$setting)",1); - - else - return null; - } - - /** - * Set a configuration value - */ - public function setValue($key,$setting,$value) { - if (isset($this->custom->{$key}[$setting])) - system_message(array( - 'title'=>_('Configuration setting already defined.'), - 'body'=>sprintf('A call has been made to reset a configuration value (%s,%s,%s)', - $key,$setting,$value), - 'type'=>'info')); - - $this->custom->{$key}[$setting] = $value; - } - - /** - * Return the untested config items - */ - public function untested() { - $result = array(); - - foreach ($this->default as $option => $details) - foreach ($details as $param => $values) - if (isset($values['untested']) && $values['untested']) - array_push($result,sprintf('%s.%s',$option,$param)); - - return $result; - } - - /** - * Get the name of this datastore - */ - public function getName() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $this->getValue('server','name'); - } - - /** - * Functions that enable login and logout of the application - */ - /** - * Return the authentication type for this object - */ - public function getAuthType() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - switch ($this->getValue('login','auth_type')) { - case 'cookie': - case 'config': - case 'http': - case 'proxy': - case 'session': - case 'sasl': - return $this->getValue('login','auth_type'); - - default: - die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__, - $this->getValue('login','auth_type'))); - } - } - - /** - * Get the login name of the user logged into this datastore's connection method - * If this returns null, we are not logged in. - * If this returns '', we are logged in with anonymous - */ - public function getLogin($method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $method = $this->getMethod($method); - - # For anonymous binds - if ($method == 'anon') - if (isset($_SESSION['USER'][$this->index][$method]['name'])) - return ''; - else - return null; - - switch ($this->getAuthType()) { - case 'cookie': - if (! isset($_COOKIE[$method.'-USER'])) - # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_id')) && $method == 'login') ? $this->getValue('login','bind_id') : null; - else - return blowfish_decrypt($_COOKIE[$method.'-USER']); - - case 'config': - if (! isset($_SESSION['USER'][$this->index][$method]['name'])) - return $this->getValue('login','bind_id'); - else - return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['name']); - - case 'proxy': - if (! isset($_SESSION['USER'][$this->index][$method]['proxy'])) - return $this->getValue('login','bind_id'); - else - return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['proxy']); - - case 'http': - case 'session': - case 'sasl': - if (! isset($_SESSION['USER'][$this->index][$method]['name'])) - # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_id')) && $method == 'login') ? $this->getValue('login','bind_id') : null; - else - return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['name']); - - default: - die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); - } - } - - /** - * Set the login details of the user logged into this datastore's connection method - */ - protected function setLogin($user,$pass,$method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $method = $this->getMethod($method); - - switch ($this->getAuthType()) { - case 'cookie': - set_cookie($method.'-USER',blowfish_encrypt($user),NULL,'/'); - set_cookie($method.'-PASS',blowfish_encrypt($pass),NULL,'/'); - return true; - - case 'config': - return true; - - case 'proxy': - if (isset($_SESSION['USER'][$this->index][$method]['proxy'])) - unset($_SESSION['USER'][$this->index][$method]['proxy']); - - case 'http': - case 'session': - case 'sasl': - $_SESSION['USER'][$this->index][$method]['name'] = blowfish_encrypt($user); - $_SESSION['USER'][$this->index][$method]['pass'] = blowfish_encrypt($pass); - - return true; - - default: - die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); - } - } - - /** - * Get the login password of the user logged into this datastore's connection method - */ - protected function getPassword($method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $method = $this->getMethod($method); - - # For anonymous binds - if ($method == 'anon') - if (isset($_SESSION['USER'][$this->index][$method]['name'])) - return ''; - else - return null; - - switch ($this->getAuthType()) { - case 'cookie': - if (! isset($_COOKIE[$method.'-PASS'])) - # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_pass')) && $method == 'login') ? $this->getValue('login','bind_pass') : null; - else - return blowfish_decrypt($_COOKIE[$method.'-PASS']); - - case 'config': - case 'proxy': - if (! isset($_SESSION['USER'][$this->index][$method]['pass'])) - return $this->getValue('login','bind_pass'); - else - return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['pass']); - - case 'http': - case 'session': - case 'sasl': - if (! isset($_SESSION['USER'][$this->index][$method]['pass'])) - # If our bind_pass is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_pass')) && $method == 'login') ? $this->getValue('login','bind_pass') : null; - else - return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['pass']); - - default: - die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); - } - } - - /** - * Return if this datastore's connection method has been logged into - */ - public function isLoggedIn($method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - static $CACHE = array(); - - $method = $this->getMethod($method); - - if (isset($CACHE[$this->index][$method]) && ! is_null($CACHE[$this->index][$method])) - return $CACHE[$this->index][$method]; - - $CACHE[$this->index][$method] = null; - - # For some authentication types, we need to do the login here - switch ($this->getAuthType()) { - case 'config': - if (! $CACHE[$this->index][$method] = $this->login($this->getLogin($method),$this->getPassword($method),$method)) - system_message(array( - 'title'=>_('Unable to login.'), - 'body'=>_('Your configuration file has authentication set to CONFIG based authentication, however, the userid/password failed to login'), - 'type'=>'error')); - - break; - - case 'http': - # If our auth vars are not set, throw up a login box. - if (! isset($_SERVER['PHP_AUTH_USER'])) { - # If this server is not in focus, skip the basic auth prompt. - if (get_request('server_id','REQUEST') != $this->getIndex()) { - $CACHE[$this->index][$method] = false; - break; - } - - header(sprintf('WWW-Authenticate: Basic realm="%s %s"',app_name(),_('login'))); - - if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0') - header('HTTP/1.0 401 Unauthorized'); // http 1.0 method - else - header('Status: 401 Unauthorized'); // http 1.1 method - - # If we still dont have login details... - if (! isset($_SERVER['PHP_AUTH_USER'])) { - system_message(array( - 'title'=>_('Unable to login.'), - 'body'=>_('Your configuration file has authentication set to HTTP based authentication, however, there was none presented'), - 'type'=>'error')); - - $CACHE[$this->index][$method] = false; - } - - # Check our auth vars are valid. - } else { - if (! $this->login($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'],$method)) { - system_message(array( - 'title'=>_('Unable to login.'), - 'body'=>_('Your HTTP based authentication is not accepted by the LDAP server'), - 'type'=>'error')); - - $CACHE[$this->index][$method] = false; - - } else - $CACHE[$this->index][$method] = true; - } - - break; - - case 'proxy': - $CACHE[$this->index][$method] = $this->login($this->getValue('login','bind_id'),$this->getValue('login','bind_pass'),$method); - - break; - - case 'sasl': - # Propogate any given Kerberos credential cache location - if (isset($_ENV['REDIRECT_KRB5CCNAME'])) - putenv(sprintf('KRB5CCNAME=%s',$_ENV['REDIRECT_KRB5CCNAME'])); - elseif (isset($_SERVER['KRB5CCNAME'])) - putenv(sprintf('KRB5CCNAME=%s',$_SERVER['KRB5CCNAME'])); - - # Map the SASL auth ID to a DN - $regex = $this->getValue('login', 'sasl_dn_regex'); - $replacement = $this->getValue('login', 'sasl_dn_replacement'); - - if ($regex && $replacement) { - $userDN = preg_replace($regex, $replacement, $_SERVER['REMOTE_USER']); - - $CACHE[$this->index][$method] = $this->login($userDN, '', $method); - - # Otherwise, use the user name as is - # For GSSAPI Authentication + mod_auth_kerb and Basic Authentication - } else - $CACHE[$this->index][$method] = $this->login(isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : '', '', $method); - - break; - - default: - $CACHE[$this->index][$method] = is_null($this->getLogin($method)) ? false : true; - } - - return $CACHE[$this->index][$method]; - } - - /** - * Logout of this datastore's connection method - */ - public function logout($method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $method = $this->getMethod($method); - - unset ($_SESSION['cache'][$this->index]); - - switch ($this->getAuthType()) { - case 'cookie': - set_cookie($method.'-USER','',time()-3600,'/'); - set_cookie($method.'-PASS','',time()-3600,'/'); - - case 'config': - return true; - - case 'http': - case 'proxy': - case 'session': - case 'sasl': - if (isset($_SESSION['USER'][$this->index][$method])) - unset($_SESSION['USER'][$this->index][$method]); - - return true; - - default: - die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); - } - } - - /** - * Functions that return the condition of the datasource - */ - public function isVisible() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return $this->getValue('server','visible'); - } - - public function isReadOnly() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (! trim($this->getLogin(null)) && $_SESSION[APPCONFIG]->getValue('appearance','anonymous_bind_implies_read_only')) - return true; - else - return $this->getValue('server','read_only'); - } - - public function getIndex() { - if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->index); - - return $this->index; - } - - /** - * Work out which connection method to use. - * If a method is passed, then it will be passed back. If no method is passed, then we'll - * check to see if the user is logged in. If they are, then 'user' is used, otherwise - * 'anon' is used. - * - * @param int Server ID - * @return string Connection Method - */ - protected function getMethod($method=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - static $CACHE = array(); - - # Immediately return if method is set. - if (! is_null($method)) - return $method; - - # If we have been here already, then return our result - if (isset($CACHE[$this->index]) && ! is_null($CACHE)) - return $CACHE[$this->index]; - - $CACHE[$this->index] = 'anon'; - - if ($this->isLoggedIn('user')) - $CACHE[$this->index] = 'user'; - - return $CACHE[$this->index]; - } - - /** - * This method should be overridden in application specific ds files - */ - public function isSessionValid() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs,true); - - return true; - } - - /** - * Return the time left in seconds until this connection times out. If there is not timeout, - * this function will return null. - */ - public function inactivityTime() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if ($this->isLoggedIn() && ! in_array($this->getAuthType(),array('config','http'))) - return time()+($this->getValue('login','timeout')*60); - else - return null; - } -} - -/** - * The list of database sources - * - * @package phpLDAPadmin - * @subpackage DataStore - */ -class Datastore { - # Out DS index id - private $index; - # List of all the objects - private $objects = array(); - # Default settings - private $default; - - public function __construct() { - $this->default = new StdClass; - - $this->default->server['id'] = array( - 'desc'=>'Server ID', - 'default'=>null); - - $this->default->server['name'] = array( - 'desc'=>'Server name', - 'default'=>null); - - # Connectivity Info - $this->default->server['host'] = array( - 'desc'=>'Host Name', - 'default'=>'127.0.0.1'); - - $this->default->server['port'] = array( - 'desc'=>'Port Number', - 'default'=>null); - - # Read or write only access - $this->default->server['read_only'] = array( - 'desc'=>'Server is in READ ONLY mode', - 'default'=>false); - - $this->default->server['visible'] = array( - 'desc'=>'Whether this server is visible', - 'default'=>true); - - $this->default->server['hide_noaccess_base'] = array( - 'desc'=>'If base DNs are not accessible, hide them instead of showing create', - 'default'=>false); - - # Authentication Information - $this->default->login['auth_type'] = array( - 'desc'=>'Authentication Type', - 'default'=>'session'); - -/* - /* ID to login to this application, this assumes that there is - * application authentication on top of authentication required to - * access the data source ** - $this->default->login['auth_id'] = array( - 'desc'=>'User Login ID to login to this DS', - 'untested'=>true, - 'default'=>null); - - $this->default->login['auth_pass'] = array( - 'desc'=>'User Login Password to login to this DS', - 'untested'=>true, - 'default'=>null); -*/ - - $this->default->login['auth_text'] = array( - 'desc'=>'Text to show at the login prompt', - 'default'=>null); - - $this->default->login['bind_id'] = array( - 'desc'=>'User Login ID to bind to this DS', - 'default'=>null); - - $this->default->login['bind_dn_template'] = array( - 'desc'=>'Template string for user login DN to bind to this DS. Use \'%s\' where user input should be inserted.', - 'default'=>null); - - $this->default->login['bind_pass'] = array( - 'desc'=>'User Login Password to bind to this DS', - 'default'=>null); - - $this->default->login['timeout'] = array( - 'desc'=>'Session timout in seconds', - 'default'=>session_cache_expire()-1); - - $this->default->login['sasl_dn_regex'] = array( - 'desc'=>'SASL authorization id to user dn PCRE regular expression', - 'untested'=>true, - 'default'=>null); - - $this->default->login['sasl_dn_replacement'] = array( - 'desc'=>'SASL authorization id to user dn PCRE regular expression replacement string', - 'untested'=>true, - 'default'=>null); - - # Prefix for custom pages - $this->default->custom['pages_prefix'] = array( - 'desc'=>'Prefix name for custom pages', - 'default'=>'custom_'); - } - - /** - * Create a new database object - */ - public function newServer($type) { - if (class_exists($type)) { - $this->index = count($this->objects)+1; - $this->objects[$this->index] = new $type($this->index); - - $this->objects[$this->index]->setDefaults($this->default); - return $this->index; - - } else { - printf('ERROR: Class [%s] doesnt exist',$type); - die(); - } - } - - /** - * Set values for a database object. - */ - public function setValue($key,$setting,$value) { - if (! $this->objects[$this->index]->isDefaultKey($key)) - error("ERROR: Setting a key [$key] that isnt predefined.",'error',true); - - if (! $this->objects[$this->index]->isDefaultSetting($key,$setting)) - error("ERROR: Setting a index [$key,$setting] that isnt predefined.",'error',true); - - # Test if its should be an array or not. - if (is_array($this->objects[$this->index]->getValue($key,$setting)) && ! is_array($value)) - error("Error in configuration file, {$key}['$setting'] SHOULD be an array of values.",'error',true); - - if (! is_array($this->objects[$this->index]->getValue($key,$setting)) && is_array($value)) - error("Error in configuration file, {$key}['$setting'] should NOT be an array of values.",'error',true); - - # Store the value in the object. - $this->objects[$this->index]->setValue($key,$setting,$value); - } - - /** - * Get a list of all the configured servers. - * - * @param boolean Only show visible servers. - * @return array list of all configured servers. - */ - public function getServerList($isVisible=true) { - if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); - - static $CACHE; - - if (isset($CACHE[$isVisible])) - return $CACHE[$isVisible]; - - $CACHE[$isVisible] = array(); - - # Debugging incase objects is not set. - if (! $this->objects) { - print "
";
-			debug_print_backtrace();
-			die();
-		}
-
-		foreach ($this->objects as $id => $server)
-			if (! $isVisible || ($isVisible && $server->getValue('server','visible')))
-				$CACHE[$isVisible][$id] = $server;
-
-		masort($CACHE[$isVisible],'name');
-
-		return $CACHE[$isVisible];
-	}
-
-	/**
-	 * Return an object Instance of a configured database.
-	 *
-	 * @param int Index
-	 * @return object Datastore instance object.
-	 */
-	public function Instance($index=null) {
-		if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# If no index defined, then pick the lowest one.
-		if (is_null($index) || ! trim($index) || ! is_numeric($index))
-			$index = min($this->GetServerList())->getIndex();
-
-		if (! isset($this->objects[$index]))
-			debug_dump_backtrace(sprintf('Error: Datastore instance [%s] doesnt exist?',htmlspecialchars($index)),1);
-
-		if (defined('DEBUG_ENABLED') && DEBUG_ENABLED)
-			debug_log('Returning instance of database (%s)',3,0,__FILE__,__LINE__,__METHOD__,$index);
-
-		return $this->objects[$index];
-	}
-
-	/**
-	 * Return an object Instance of a configured database.
-	 *
-	 * @param string Name of the instance to retrieve
-	 * @return object Datastore instance object.
-	 */
-	public function InstanceName($name=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		foreach ($this->getServerList(false) as $index)
-			if ($this->objects[$index]->getName() == $name)
-				return $this->objects[$index];
-
-		# If we get here, then no object with the name exists.
-		return null;
-	}
-
-	/**
-	 * Return an object Instance of a configured database.
-	 *
-	 * @param string ID of the instance to retrieve
-	 * @return object Datastore instance object.
-	 */
-	public function InstanceId($id=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		foreach ($this->getServerList(false) as $index)
-			if ($this->objects[$index->getIndex()]->getValue('server','id') == $id)
-				return $this->objects[$index->getIndex()];
-
-		# If we get here, then no object with the name exists.
-		return null;
-	}
-}
-?>
diff --git a/lib/ds_ldap.php b/lib/ds_ldap.php
deleted file mode 100644
index e46a63b..0000000
--- a/lib/ds_ldap.php
+++ /dev/null
@@ -1,1581 +0,0 @@
-index = $index;
-		$this->type = 'ldap';
-
-		# Additional values that can go in our config.php
-		$this->custom = new StdClass;
-		$this->default = new StdClass;
-
-/*
- * Not used by PLA
-		# Database Server Variables
-		$this->default->server['db'] = array(
-			'desc'=>'Database Name',
-			'untested'=>true,
-			'default'=>null);
-*/
-
-		/* This was created for IDS - since it doesnt present STRUCTURAL against objectClasses
-		 * definitions when reading the schema.*/
-		$this->default->server['schema_oclass_default'] = array(
-			'desc'=>'When reading the schema, and it doesnt specify objectClass type, default it to this',
-			'default'=>null);
-
-		$this->default->server['base'] = array(
-			'desc'=>'LDAP Base DNs',
-			'default'=>array());
-
-		$this->default->server['tls'] = array(
-			'desc'=>'Connect using TLS',
-			'default'=>false);
-
-		# Login Details
-		$this->default->login['attr'] = array(
-			'desc'=>'Attribute to use to find the users DN',
-			'default'=>'dn');
-
-		$this->default->login['anon_bind'] = array(
-			'desc'=>'Enable anonymous bind logins',
-			'default'=>true);
-
-		$this->default->login['allowed_dns'] = array(
-			'desc'=>'Limit logins to users who match any of the following LDAP filters',
-			'default'=>array());
-
-		$this->default->login['base'] = array(
-			'desc'=>'Limit logins to users who are in these base DNs',
-			'default'=>array());
-
-		$this->default->login['class'] = array(
-			'desc'=>'Strict login to users containing a specific objectClasses',
-			'default'=>array());
-
-		$this->default->proxy['attr'] = array(
-			'desc'=>'Attribute to use to find the users DN for proxy based authentication',
-			'default'=>array());
-
-		# SASL configuration
-		$this->default->sasl['mech'] = array(
-			'desc'=>'SASL mechanism used while binding LDAP server',
-			'default'=>'GSSAPI');
-
-		$this->default->sasl['realm'] = array(
-			'desc'=>'SASL realm name',
-			'untested'=>true,
-			'default'=>null);
-
-		$this->default->sasl['authz_id'] = array(
-			'desc'=>'SASL authorization id',
-			'untested'=>true,
-			'default'=>null);
-
-		$this->default->sasl['authz_id_regex'] = array(
-			'desc'=>'SASL authorization id PCRE regular expression',
-			'untested'=>true,
-			'default'=>null);
-
-		$this->default->sasl['authz_id_replacement'] = array(
-			'desc'=>'SASL authorization id PCRE regular expression replacement string',
-			'untested'=>true,
-			'default'=>null);
-
-		$this->default->sasl['props'] = array(
-			'desc'=>'SASL properties',
-			'untested'=>true,
-			'default'=>null);
-	}
-
-	/**
-	 * Required ABSTRACT functions
-	 */
-	/**
-	 * Connect and Bind to the Database
-	 *
-	 * @param string Which connection method resource to use
-	 * @return resource|null Connection resource if successful, null if not.
-	 */
-	protected function connect($method,$debug=false,$new=false) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $CACHE = array();
-
-		$method = $this->getMethod($method);
-		$bind = array();
-
-		if (isset($CACHE[$this->index][$method]) && $CACHE[$this->index][$method])
-			return $CACHE[$this->index][$method];
-
-		# Check if we have logged in and therefore need to use those details as our bind.
-		$bind['id'] = is_null($this->getLogin($method)) && $method != 'anon' ? $this->getLogin('user') : $this->getLogin($method);
-		$bind['pass'] = is_null($this->getPassword($method)) && $method != 'anon' ? $this->getPassword('user') : $this->getPassword($method);
-
-		# If our bind id is still null, we are not logged in.
-		if (is_null($bind['id']) && ! in_array($method,array('anon','login')))
-			return null;
-
-		# If we bound to the LDAP server with these details for a different connection, return that resource
-		if (isset($CACHE[$this->index]) && ! $new)
-			foreach ($CACHE[$this->index] as $cachedmethod => $resource) {
-				if (($this->getLogin($cachedmethod) == $bind['id']) && ($this->getPassword($cachedmethod) == $bind['pass'])) {
-					$CACHE[$this->index][$method] = $resource;
-
-					return $CACHE[$this->index][$method];
-				}
-			}
-
-		$CACHE[$this->index][$method] = null;
-
-		# No identifiable connection exists, lets create a new one.
-		if (DEBUG_ENABLED)
-			debug_log('Creating NEW connection [%s] for index [%s]',16,0,__FILE__,__LINE__,__METHOD__,
-				$method,$this->index);
-
-		if (function_exists('run_hook'))
-			run_hook('pre_connect',array('server_id'=>$this->index,'method'=>$method));
-
-		if ($this->getValue('server','port'))
-			$resource = ldap_connect($this->getValue('server','host'),$this->getValue('server','port'));
-		else
-			$resource = ldap_connect($this->getValue('server','host'));
-
-		$CACHE[$this->index][$method] = $resource;
-
-		if (DEBUG_ENABLED)
-			debug_log('LDAP Resource [%s], Host [%s], Port [%s]',16,0,__FILE__,__LINE__,__METHOD__,
-				$resource,$this->getValue('server','host'),$this->getValue('server','port'));
-
-		if (! is_resource($resource))
-			debug_dump_backtrace('UNHANDLED, $resource is not a resource',1);
-
-		# Go with LDAP version 3 if possible (needed for renaming and Novell schema fetching)
-		ldap_set_option($resource,LDAP_OPT_PROTOCOL_VERSION,3);
-
-		/* Disabling this makes it possible to browse the tree for Active Directory, and seems
-		 * to not affect other LDAP servers (tested with OpenLDAP) as phpLDAPadmin explicitly
-		 * specifies deref behavior for each ldap_search operation. */
-		ldap_set_option($resource,LDAP_OPT_REFERRALS,0);
-
-		/* Enabling manageDsaIt to be able to browse through glued entries
-		 * 2.16.840.1.113730.3.4.2 :  "ManageDsaIT Control" "RFC 3296" "The client may provide
-		 * the ManageDsaIT control with an operation to indicate that the operation is intended
-		 * to manage objects within the DSA (server) Information Tree. The control causes
-		 * Directory-specific entries (DSEs), regardless of type, to be treated as normal entries
-		 * allowing clients to interrogate and update these entries using LDAP operations." */
-		ldap_set_option($resource,LDAP_OPT_SERVER_CONTROLS,array(array('oid'=>'2.16.840.1.113730.3.4.2')));
-
-		# Try to fire up TLS is specified in the config
-		if ($this->isTLSEnabled())
-			$this->startTLS($resource);
-
-		# If SASL has been configured for binding, then start it now.
-		if ($this->isSASLEnabled())
-			$bind['result'] = $this->startSASL($resource,$method,$bind['id'],$bind['pass']);
-
-		# Normal bind...
-		else
-			$bind['result'] = @ldap_bind($resource,$bind['id'],$bind['pass']);
-
-		if ($debug)
-			debug_dump(array('method'=>$method,'bind'=>$bind,'USER'=>$_SESSION['USER']));
-
-		if (DEBUG_ENABLED)
-			debug_log('Resource [%s], Bind Result [%s]',16,0,__FILE__,__LINE__,__METHOD__,$resource,$bind);
-
-		if (! $bind['result']) {
-			if (DEBUG_ENABLED)
-				debug_log('Leaving with FALSE, bind FAILed',16,0,__FILE__,__LINE__,__METHOD__);
-
-			$this->noconnect = true;
-
-			system_message(array(
-				'title'=>sprintf('%s %s',_('Unable to connect to LDAP server'),$this->getName()),
-				'body'=>sprintf('%s: %s (%s) for %s',_('Error'),$this->getErrorMessage($method),$this->getErrorNum($method),$method),
-				'type'=>'error'));
-
-			$CACHE[$this->index][$method] = null;
-
-		} else {
-			$this->noconnect = false;
-
-			# If this is a proxy session, we need to switch to the proxy user
-			if ($this->isProxyEnabled() && $bind['id'] && $method != 'anon')
-				if (! $this->startProxy($resource,$method)) {
-					$this->noconnect = true;
-					$CACHE[$this->index][$method] = null;
-				}
-		}
-
-		if (function_exists('run_hook'))
-			run_hook('post_connect',array('server_id'=>$this->index,'method'=>$method,'id'=>$bind['id']));
-
-		if ($debug)
-			debug_dump(array($method=>$CACHE[$this->index][$method]));
-
-		return $CACHE[$this->index][$method];
-	}
-
-	/**
-	 * Login to the database with the application user/password
-	 *
-	 * @return boolean true|false for successful login.
-	 */
-	public function login($user=null,$pass=null,$method=null,$new=false) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$userDN = null;
-
-		# Get the userDN from the username.
-		if (! is_null($user)) {
-			# If login,attr is set to DN, then user should be a DN
-			if (($this->getValue('login','attr') == 'dn') || $method != 'user')
-				$userDN = $this->getValue('login', 'bind_dn_template') ? $this->fillDNTemplate($user) : $user;
-			else
-				$userDN = $this->getLoginID($user,'login');
-
-			if (! $userDN && $this->getValue('login','fallback_dn') && strpos($user, '='))
-				$userDN = $user;
-
-			if (! $userDN)
-				return false;
-
-		} else {
-			if (in_array($method,array('user','anon'))) {
-				$method = 'anon';
-				$userDN = '';
-				$pass = '';
-
-			} else {
-				$userDN = $this->getLogin('user');
-				$pass = $this->getPassword('user');
-			}
-		}
-
-		if (! $this->isAnonBindAllowed() && ! trim($userDN))
-			return false;
-
-		# Temporarily set our user details
-		$this->setLogin($userDN,$pass,$method);
-
-		$connect = $this->connect($method,false,$new);
-
-		# If we didnt log in...
-		if (! is_resource($connect) || $this->noconnect || ! $this->userIsAllowedLogin($userDN)) {
-			$this->logout($method);
-
-			return false;
-
-		} else
-			return true;
-	}
-
-	/**
-	 * Perform a query to the Database
-	 *
-	 * @param string query to perform
-	 *	$query['base']
-	 *	$query['filter']
-	 *	$query['scope']
-	 *	$query['attrs'] = array();
-	 *	$query['deref']
-	 * @param string Which connection method resource to use
-	 * @param string Index items according to this key
-	 * @param boolean Enable debugging output
-	 * @return array|null Results of query.
-	 */
-	public function query($query,$method,$index=null,$debug=false) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$attrs_only = 0;
-
-		# Defaults
-		if (! isset($query['attrs']))
-			$query['attrs'] = array();
-		else
-			# Re-index the attrs, PHP throws an error if the keys are not sequential from 0.
-			$query['attrs'] = array_values($query['attrs']);
-
-		if (! isset($query['base'])) {
-			$bases = $this->getBaseDN();
-			$query['base'] = array_shift($bases);
-		}
-
-		if (! isset($query['deref']))
-			$query['deref'] = $_SESSION[APPCONFIG]->getValue('deref','search');
-		if (! isset($query['filter']))
-			$query['filter'] = '(&(objectClass=*))';
-		if (! isset($query['scope']))
-			$query['scope'] = 'sub';
-		if (! isset($query['size_limit']))
-			$query['size_limit'] = 0;
-		if (! isset($query['time_limit']))
-			$query['time_limit'] = 0;
-
-		if ($query['scope'] == 'base' && ! isset($query['baseok']))
-			system_message(array(
-				'title'=>sprintf('Dont call %s',__METHOD__),
-				'body'=>sprintf('Use getDNAttrValues for base queries [%s]',$query['base']),
-				'type'=>'info'));
-
-		if (is_array($query['base'])) {
-			system_message(array(
-				'title'=>_('Invalid BASE for query'),
-				'body'=>_('The query was cancelled because of an invalid base.'),
-				'type'=>'error'));
-
-			return array();
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('%s search PREPARE.',16,0,__FILE__,__LINE__,__METHOD__,$query['scope']);
-
-		if ($debug)
-			debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method)));
-
-		$resource = $this->connect($method,$debug);
-
-		switch ($query['scope']) {
-			case 'base':
-				$search = @ldap_read($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
-				break;
-
-			case 'one':
-				$search = @ldap_list($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
-				break;
-
-			case 'sub':
-			default:
-				$search = @ldap_search($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
-				break;
-		}
-
-		if ($debug)
-			debug_dump(array('method'=>$method,'search'=>$search,'error'=>$this->getErrorMessage()));
-
-		if (DEBUG_ENABLED)
-			debug_log('Search scope [%s] base [%s] filter [%s] attrs [%s] COMPLETE (%s).',16,0,__FILE__,__LINE__,__METHOD__,
-				$query['scope'],$query['base'],$query['filter'],$query['attrs'],is_null($search));
-
-		if (! $search)
-			return array();
-
-		$return = array();
-
-		# Get the first entry identifier
-		if ($entries = ldap_get_entries($resource,$search)) {
-			# Remove the count
-			if (isset($entries['count']))
-				unset($entries['count']);
-
-			# Iterate over the entries
-			foreach ($entries as $a => $entry) {
-				if (! isset($entry['dn']))
-					debug_dump_backtrace('No DN?',1);
-
-				# Remove the none entry references.
-				if (! is_array($entry)) {
-					unset($entries[$a]);
-					continue;
-				}
-
-				$dn = $entry['dn'];
-				unset($entry['dn']);
-
-				# Iterate over the attributes
-				foreach ($entry as $b => $attrs) {
-					# Remove the none entry references.
-					if (! is_array($attrs)) {
-						unset($entry[$b]);
-						continue;
-					}
-
-					# Remove the count
-					if (isset($entry[$b]['count']))
-						unset($entry[$b]['count']);
-				}
-
-				# Our queries always include the DN (the only value not an array).
-				$entry['dn'] = $dn;
-				$return[$dn] = $entry;
-			}
-
-			# Sort our results
-			foreach ($return as $key=> $values)
-				ksort($return[$key]);
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return);
-
-		return $return;
-	}
-
-	/**
-	 * Get the last error string
-	 *
-	 * @param string Which connection method resource to use
-	 */
-	public function getErrorMessage($method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		return ldap_error($this->connect($method));
-	}
-
-	/**
-	 * Get the last error number
-	 *
-	 * @param string Which connection method resource to use
-	 */
-	public function getErrorNum($method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		return ldap_errno($this->connect($method));
-	}
-
-	/**
-	 * Additional functions
-	 */
-	/**
-	 * Get a user ID
-	 *
-	 * @param string Which connection method resource to use
-	 */
-	public function getLoginID($user,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$query['filter'] = sprintf('(&(%s=%s)%s)',
-			$this->getValue('login','attr'),$user,
-			$this->getLoginClass() ? sprintf('(objectclass=%s)',join(')(objectclass=',$this->getLoginClass())) : '');
-		$query['attrs'] = array('dn');
-
-		$result = array();
-		foreach ($this->getLoginBaseDN() as $base) {
-			$query['base'] = $base;
-			$result = $this->query($query,$method);
-
-			if (count($result) == 1)
-				break;
-		}
-
-		if (count($result) != 1)
-			return null;
-
-		$detail = array_shift($result);
-
-		if (! isset($detail['dn']))
-			die('ERROR: DN missing?');
-		else
-			return $detail['dn'];
-	}
-
-	/**
-	 * Return the login base DNs
-	 * If no login base DNs are defined, then the LDAP server Base DNs are used.
-	 */
-	private function getLoginBaseDN() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if ($this->getValue('login','base'))
-			return $this->getValue('login','base');
-		else
-			return $this->getBaseDN();
-	}
-
-	private function fillDNTemplate($user) {
-		foreach($this->getLoginBaseDN() as $base)
-			if(substr_compare($user, $base, -strlen($base)) === 0)
-				return $user; // $user already passed as DN
-
-		// fill template
-		return sprintf($this->getValue('login', 'bind_dn_template'), preg_replace('/([,\\\\#+<>;"=])/', '\\\\$1', $user));
-	}
-
-	/**
-	 * Return the login classes that a user must have to login
-	 */
-	private function getLoginClass() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		return $this->getValue('login','class');
-	}
-
-	/**
-	 * Return if anonymous bind is allowed in the configuration
-	 */
-	public function isAnonBindAllowed() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		return $this->getValue('login','anon_bind');
-	}
-
-	/**
-	 * Fetches whether TLS has been configured for use with a certain server.
-	 *
-	 * Users may configure phpLDAPadmin to use TLS in config,php thus:
-	 * 
-	 *	$servers->setValue('server','tls',true|false);
-	 * 
-	 *
-	 * @return boolean
-	 */
-	private function isTLSEnabled() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if ($this->getValue('server','tls') && ! function_exists('ldap_start_tls')) {
-				error(_('TLS has been enabled in your config, but your PHP install does not support TLS. TLS will be disabled.'),'warn');
-			return false;
-
-		} else
-			return $this->getValue('server','tls');
-	}
-
-	/**
-	 * If TLS is configured, then start it
-	 */
-	private function startTLS($resource) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if (! $this->getValue('server','tls') || (function_exists('ldap_start_tls') && ! @ldap_start_tls($resource))) {
-			system_message(array(
-				'title'=>sprintf('%s (%s)',_('Could not start TLS.'),$this->getName()),
-				'body'=>sprintf('%s: %s',_('Error'),_('Could not start TLS. Please check your LDAP server configuration.')),
-				'type'=>'error'));
-
-			return false;
-
-		} else
-			return true;
-	}
-
-	/**
-	 * Fetches whether SASL has been configured for use with a certain server.
-	 *
-	 * Users may configure phpLDAPadmin to use SASL in config,php thus:
-	 * 
-	 *	$servers->setValue('login','auth_type','sasl');
-	 * OR
-	 *      $servers->setValue('sasl','mech','PLAIN');
-	 * 
-	 *
-	 * @return boolean
-	 */
-	private function isSASLEnabled() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if (! in_array($this->getValue('login','auth_type'), array('sasl'))) {
-			// check if SASL mech uses login from other auth_types
-			if (! in_array(strtolower($this->getValue('sasl', 'mech')), array('plain')))
-				return false;
-		}
-
-		if (! function_exists('ldap_sasl_bind')) {
-			error(_('SASL has been enabled in your config, but your PHP install does not support SASL. SASL will be disabled.'),'warn');
-
-			return false;
-		}
-
-		# If we get here, SASL must be configured.
-		return true;
-	}
-
-	/**
-	 * If SASL is configured, then start it
-	 * To be able to use SASL, PHP should have been compliled with --with-ldap-sasl=DIR
-	 *
-	 * @todo This has not been tested, please let the developers know if this function works as expected.
-	 */
-	private function startSASL($resource,$method,$login,$pass) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $CACHE = array();
-
-		# We shouldnt be doing SASL binds for anonymous queries?
-		if ($method == 'anon')
-			return false;
-
-		# At the moment, we have only implemented GSSAPI and PLAIN
-		if (! in_array(strtolower($this->getValue('sasl','mech')),array('gssapi','plain'))) {
-			system_message(array(
-				'title'=>_('SASL Method not implemented'),
-				'body'=>sprintf('%s: %s %s',_('Error'),$this->getValue('sasl','mech'),_('has not been implemented yet')),
-				'type'=>'error'));
-
-			return false;
-		}
-
-		if (strtolower($this->getValue('sasl','mech')) == 'plain') {
-			return @ldap_sasl_bind($resource,NULL,$pass,'PLAIN',
-					       $this->getValue('sasl','realm'),
-					       $login,
-					       $this->getValue('sasl','props'));
-		}
-
-		if (! isset($CACHE['login_dn']))
-			$CACHE['login_dn'] = $login;
-
-		$CACHE['authz_id'] = '';
-
-		/*
-		# Do we need to rewrite authz_id?
-		if (! isset($CACHE['authz_id']))
-			if (! trim($this->getValue('sasl','authz_id')) && strtolower($this->getValue('sasl','mech')) != 'gssapi') {
-				if (DEBUG_ENABLED)
-					debug_log('Rewriting bind DN [%s] -> authz_id with regex [%s] and replacement [%s].',9,0,__FILE__,__LINE__,__METHOD__,
-						$CACHE['login_dn'],
-						$this->getValue('sasl','authz_id_regex'),
-						$this->getValue('sasl','authz_id_replacement'));
-
-				$CACHE['authz_id'] = @preg_replace($this->getValue('sasl','authz_id_regex'),
-					$this->getValue('sasl','authz_id_replacement'),$CACHE['login_dn']);
-
-				# Invalid regex?
-				if (is_null($CACHE['authz_id']))
-					error(sprintf(_('It seems that sasl_authz_id_regex "%s" contains invalid PCRE regular expression. The error is "%s".'),
-						$this->getValue('sasl','authz_id_regex'),(isset($php_errormsg) ? $php_errormsg : '')),
-						'error','index.php');
-
-				if (DEBUG_ENABLED)
-					debug_log('Resource [%s], SASL OPTIONS: mech [%s], realm [%s], authz_id [%s], props [%s]',9,0,__FILE__,__LINE__,__METHOD__,
-						$resource,
-						$this->getValue('sasl','mech'),
-						$this->getValue('sasl','realm'),
-						$CACHE['authz_id'],
-						$this->getValue('sasl','props'));
-
-			} else
-				$CACHE['authz_id'] = $this->getValue('sasl','authz_id');
-		*/
-
-		# @todo this function is different in PHP5.1 and PHP5.2
-		return @ldap_sasl_bind($resource,NULL,'',
-			$this->getValue('sasl','mech'),
-			$this->getValue('sasl','realm'),
-			$CACHE['authz_id'],
-			$this->getValue('sasl','props'));
-	}
-
-	/**
-	 * Fetches whether PROXY AUTH has been configured for use with a certain server.
-	 *
-	 * Users may configure phpLDAPadmin to use PROXY AUTH in config,php thus:
-	 * 
-	 *	$servers->setValue('login','auth_type','proxy');
-	 * 
-	 *
-	 * @return boolean
-	 */
-	private function isProxyEnabled() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		return $this->getValue('login','auth_type') == 'proxy' ? true : false;
-	}
-
-	/**
-	 * If PROXY AUTH is configured, then start it
-	 */
-	private function startProxy($resource,$method) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$rootdse = $this->getRootDSE();
-
-		if (! (isset($rootdse['supportedcontrol']) && in_array('2.16.840.1.113730.3.4.18',$rootdse['supportedcontrol']))) {
-			system_message(array(
-				'title'=>sprintf('%s %s',_('Unable to start proxy connection'),$this->getName()),
-				'body'=>sprintf('%s: %s',_('Error'),_('Your LDAP server doesnt seem to support this control')),
-				'type'=>'error'));
-
-			return false;
-		}
-
-		$filter = '(&';
-		$dn = '';
-
-		$missing = false;
-		foreach ($this->getValue('proxy','attr') as $attr => $var) {
-			if (! isset($_SERVER[$var])) {
-				system_message(array(
-					'title'=>sprintf('%s %s',_('Unable to start proxy connection'),$this->getName()),
-					'body'=>sprintf('%s: %s (%s)',_('Error'),_('Attribute doesnt exist'),$var),
-					'type'=>'error'));
-
-				$missing = true;
-
-			} else {
-				if ($attr == 'dn') {
-					$dn = $var;
-
-					break;
-
-				} else
-					$filter .= sprintf('(%s=%s)',$attr,$_SERVER[$var]);
-			}
-		}
-
-		if ($missing)
-			return false;
-
-		$filter .= ')';
-
-		if (! $dn) {
-			$query['filter'] = $filter;
-
-			foreach ($this->getBaseDN() as $base) {
-				$query['base'] = $base;
-
-				if ($search = $this->query($query,$method))
-					break;
-			}
-
-			if (count($search) != 1) {
-				system_message(array(
-					'title'=>sprintf('%s %s',_('Unable to start proxy connection'),$this->getName()),
-					'body'=>sprintf('%s: %s (%s)',_('Error'),_('Search for DN returned the incorrect number of results'),count($search)),
-					'type'=>'error'));
-
-				return false;
-			}
-
-			$search = array_pop($search);
-			$dn = $search['dn'];
-		}
-
-		$ctrl = array(
-			'oid'=>'2.16.840.1.113730.3.4.18',
-			'value'=>sprintf('dn:%s',$dn),
-			'iscritical' => true);
-
-		if (! ldap_set_option($resource,LDAP_OPT_SERVER_CONTROLS,array($ctrl))) {
-			system_message(array(
-				'title'=>sprintf('%s %s',_('Unable to start proxy connection'),$this->getName()),
-				'body'=>sprintf('%s: %s (%s) for %s',_('Error'),$this->getErrorMessage($method),$this->getErrorNum($method),$method),
-				'type'=>'error'));
-
-			return false;
-		}
-
-		$_SESSION['USER'][$this->index][$method]['proxy'] = blowfish_encrypt($dn);
-
-		return true;
-	}
-
-	/**
-	 * Modify attributes of a DN
-	 */
-	public function modify($dn,$attrs,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# We need to supress the error here - programming should detect and report it.
-		return @ldap_mod_replace($this->connect($method),$dn,$attrs);
-	}
-
-	/**
-	 * Gets the root DN of the specified LDAPServer, or null if it
-	 * can't find it (ie, the server won't give it to us, or it isnt
-	 * specified in the configuration file).
-	 *
-	 * Tested with OpenLDAP 2.0, Netscape iPlanet, and Novell eDirectory 8.7 (nldap.com)
-	 * Please report any and all bugs!!
-	 *
-	 * Please note: On FC systems, it seems that php_ldap uses /etc/openldap/ldap.conf in
-	 * the search base if it is blank - so edit that file and comment out the BASE line.
-	 *
-	 * @param string Which connection method resource to use
-	 * @return array dn|null The root DN of the server on success (string) or null on error.
-	 * @todo Sort the entries, so that they are in the correct DN order.
-	 */
-	public function getBaseDN($method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $CACHE;
-
-		$method = $this->getMethod($method);
-		$result = array();
-
-		if (isset($CACHE[$this->index][$method]))
-			return $CACHE[$this->index][$method];
-
-		# If the base is set in the configuration file, then just return that.
-		if (count($this->getValue('server','base'))) {
-			if (DEBUG_ENABLED)
-				debug_log('Return BaseDN from Config [%s]',17,0,__FILE__,__LINE__,__METHOD__,implode('|',$this->getValue('server','base')));
-
-			$CACHE[$this->index][$method] = $this->getValue('server','base');
-
-		# We need to figure it out.
-		} else {
-			if (DEBUG_ENABLED)
-				debug_log('Connect to LDAP to find BaseDN',80,0,__FILE__,__LINE__,__METHOD__);
-
-			# Set this to empty, in case we loop back here looking for the baseDNs
-			$CACHE[$this->index][$method] = array();
-
-			$results = $this->getDNAttrValues('',$method);
-
-			if (isset($results['namingcontexts'])) {
-				if (DEBUG_ENABLED)
-					debug_log('LDAP Entries:%s',80,0,__FILE__,__LINE__,__METHOD__,implode('|',$results['namingcontexts']));
-
-				$result = $results['namingcontexts'];
-			}
-
-			$CACHE[$this->index][$method] = $result;
-		}
-
-		return $CACHE[$this->index][$method];
-	}
-
-	/**
-	 * Gets whether an entry exists based on its DN. If the entry exists,
-	 * returns true. Otherwise returns false.
-	 *
-	 * @param string The DN of the entry of interest.
-	 * @param string Which connection method resource to use
-	 * @return boolean
-	 */
-	public function dnExists($dn,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$results = $this->getDNAttrValues($dn,$method);
-
-		if ($results)
-			return $results;
-		else
-			return false;
-	}
-
-	/**
-	 * Given a DN string, this returns the top container portion of the string.
-	 *
-	 * @param string The DN whose container string to return.
-	 * @return string The container
-	 */
-	public function getContainerTop($dn) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$return = $dn;
-
-		foreach ($this->getBaseDN() as $base) {
-			if (preg_match("/${base}$/i",$dn)) {
-				$return = $base;
-				break;
-			}
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return);
-
-		return $return;
-	}
-
-	/**
-	 * Given a DN string and a path like syntax, this returns the parent container portion of the string.
-	 *
-	 * @param string The DN whose container string to return.
-	 * @param string Either '/', '.' or something like '../../'
-	 * @return string The container
-	 */
-	public function getContainerPath($dn,$path='..') {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$top = $this->getContainerTop($dn);
-
-		if ($path[0] == '/') {
-			$dn = $top;
-			$path = substr($path,1);
-
-		} elseif ($path == '.') {
-			return $dn;
-		}
-
-		$parenttree = explode('/',$path);
-
-		foreach ($parenttree as $key => $value) {
-			if ($value == '..') {
-				if ($this->getContainer($dn))
-					$dn = $this->getContainer($dn);
-
-				if ($dn == $top)
-					break;
-
-			} elseif($value)
-				$dn = sprintf('%s,%s',$value,$dn);
-
-			else
-				break;
-		}
-
-		if (! $dn) {
-			debug_dump(array(__METHOD__,'dn'=>$dn,'path'=>$path));
-			debug_dump_backtrace('Container is empty?',1);
-		}
-
-		return $dn;
-	}
-
-	/**
-	 * Given a DN string, this returns the parent container portion of the string.
-	 * For example. given 'cn=Manager,dc=example,dc=com', this function returns
-	 * 'dc=example,dc=com'.
-	 *
-	 * @param string The DN whose container string to return.
-	 * @return string The container
-	 */
-	public function getContainer($dn) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$parts = $this->explodeDN($dn);
-
-		if (count($parts) <= 1)
-			$return = null;
-
-		else {
-			$return = $parts[1];
-
-			for ($i=2;$i
-	 *	dc=example,dc=com
-	 *		ou=People
-	 *			cn=Dave
-	 *			cn=Fred
-	 *			cn=Joe
-	 *		ou=More People
-	 *			cn=Mark
-	 *			cn=Bob
-	 * 
-	 *
-	 * Calling getContainerContents("ou=people,dc=example,dc=com")
-	 * would return the following list:
-	 *
-	 * 
-	 *	cn=Dave
-	 *	cn=Fred
-	 *	cn=Joe
-	 *	ou=More People
-	 * 
-	 *
-	 * @param string The DN of the entry whose children to return.
-	 * @param string Which connection method resource to use
-	 * @param int (optional) The maximum number of entries to return.
-	 *            If unspecified, no limit is applied to the number of entries in the returned.
-	 * @param string (optional) An LDAP filter to apply when fetching children, example: "(objectClass=inetOrgPerson)"
-	 * @param constant (optional) The LDAP deref setting to use in the query
-	 * @return array An array of DN strings listing the immediate children of the specified entry.
-	 */
-	public function getContainerContents($dn,$method=null,$size_limit=0,$filter='(objectClass=*)',$deref=LDAP_DEREF_NEVER) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$return = array();
-
-		$query = array();
-		$query['base'] = $this->escapeDN($dn);
-		$query['attrs'] = array('dn');
-		$query['filter'] = $filter;
-		$query['deref'] = $deref;
-		$query['scope'] = 'one';
-		$query['size_limit'] = $size_limit;
-		$results = $this->query($query,$method);
-
-		if ($results) {
-			foreach ($results as $index => $entry) {
-				$child_dn = $entry['dn'];
-				array_push($return,$child_dn);
-			}
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return);
-
-		# Sort the results
-		asort($return);
-
-		return $return;
-	}
-
-	/**
-	 * Explode a DN into an array of its RDN parts.
-	 *
-	 * @param string The DN to explode.
-	 * @param int (optional) Whether to include attribute names (see http://php.net/ldap_explode_dn for details)
-	 *
-	 * @return array An array of RDN parts of this format:
-	 * 
-	 *	Array
-	 *		(
-	 *			[0] => uid=ppratt
-	 *			[1] => ou=People
-	 *			[2] => dc=example
-	 *			[3] => dc=com
-	 *		)
-	 * 
-	 *
-	 * NOTE: When a multivalue RDN is passed to ldap_explode_dn, the results returns with 'value + value';
-	 */
-	private function explodeDN($dn,$with_attributes=0) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $CACHE;
-
-		if (isset($CACHE['explode'][$dn][$with_attributes])) {
-			if (DEBUG_ENABLED)
-				debug_log('Return CACHED result (%s) for (%s)',1,0,__FILE__,__LINE__,__METHOD__,
-					$CACHE['explode'][$dn][$with_attributes],$dn);
-
-			return $CACHE['explode'][$dn][$with_attributes];
-		}
-
-		$dn = addcslashes($dn,'<>+";');
-
-		# split the dn
-		$result[0] = ldap_explode_dn($this->escapeDN($dn),0);
-		$result[1] = ldap_explode_dn($this->escapeDN($dn),1);
-		if (! $result[$with_attributes]) {
-			if (DEBUG_ENABLED)
-				debug_log('Returning NULL - NO result.',1,0,__FILE__,__LINE__,__METHOD__);
-
-			return array();
-		}
-
-		# Remove our count value that ldap_explode_dn returns us.
-		unset($result[0]['count']);
-		unset($result[1]['count']);
-
-		# Record the forward and reverse entries in the cache.
-		foreach ($result as $key => $value) {
-			# translate hex code into ascii for display
-			$result[$key] = $this->unescapeDN($value);
-
-			$CACHE['explode'][implode(',',$result[0])][$key] = $result[$key];
-			$CACHE['explode'][implode(',',array_reverse($result[0]))][$key] = array_reverse($result[$key]);
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$result[$with_attributes]);
-
-		return $result[$with_attributes];
-	}
-
-	/**
-	 * Parse a DN and escape any special characters
-	 */
-	protected function escapeDN($dn) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if (! trim($dn))
-			return $dn;
-
-		# Check if the RDN has a comma and escape it.
-		while (preg_match('/([^\\\\]),(\s*[^=]*\s*),/',$dn))
-			$dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/','$1\\\\2C$2,',$dn);
-
-		$dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*)([^,])$/','$1\\\\2C$2$3',$dn);
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$dn);
-
-		return $dn;
-	}
-
-	/**
-	 * Parse a DN and unescape any special characters
-	 */
-	private function unescapeDN($dn) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if (is_array($dn)) {
-			$a = array();
-			foreach ($dn as $key => $rdn) {
-				$a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return chr(hexdec('${m[1]}')); }, $rdn);
-			}
-			return $a;
-
-		} else {
-			return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return chr(hexdec('${m[1]}')); }, $dn);
-		}
-	}
-
-	/** Schema Methods **/
-
-	/**
-	 * Much like getDNAttrValues(), but only returns the values for
-	 * one attribute of an object. Example calls:
-	 *
-	 * 
-	 *	print_r(getDNAttrValue('cn=Bob,ou=people,dc=example,dc=com','sn'));
-	 *	Array (
-	 *		[0] => Smith
-	 *	)
-	 *
-	 * print_r(getDNAttrValue('cn=Bob,ou=people,dc=example,dc=com','objectClass'));
-	 *	Array (
-	 *		[0] => top
-	 *		[1] => person
-	 *	)
-	 * 
-	 *
-	 * @param string The distinguished name (DN) of the entry whose attributes/values to fetch.
-	 * @param string The attribute whose value(s) to return (ie, "objectClass", "cn", "userPassword")
-	 * @param string Which connection method resource to use
-	 * @param constant For aliases and referrals, this parameter specifies whether to
-	 *            follow references to the referenced DN or to fetch the attributes for
-	 *            the referencing DN. See http://php.net/ldap_search for the 4 valid
-	 *            options.
-	 * @return array
-	 * @see getDNAttrValues
-	 * @todo Caching these values may be problematic with multiple calls and different deref values.
-	 */
-	public function getDNAttrValue($dn,$attr,$method=null,$deref=LDAP_DEREF_NEVER) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# Ensure our attr is in lowercase
-		$attr = strtolower($attr);
-
-		$values = $this->getDNAttrValues($dn,$method,$deref);
-
-		if (isset($values[$attr]))
-			return $values[$attr];
-		else
-			return array();
-	}
-
-	/**
-	 * Gets the attributes/values of an entry. Returns an associative array whose
-	 * keys are attribute value names and whose values are arrays of values for
-	 * said attribute.
-	 *
-	 * Optionally, callers may specify true for the parameter
-	 * $lower_case_attr_names to force all keys in the associate array (attribute
-	 * names) to be lower case.
-	 *
-	 * Example of its usage:
-	 * 
-	 * print_r(getDNAttrValues('cn=Bob,ou=pepole,dc=example,dc=com')
-	 *	Array (
-	 *		[objectClass] => Array (
-	 *			[0] => person
-	 *			[1] => top
-	 *		)
-	 *		[cn] => Array (
-	 *			[0] => Bob
-	 *		)
-	 *		[sn] => Array (
-	 *			[0] => Jones
-	 *		)
-	 *		[dn] => Array (
-	 *			[0] => cn=Bob,ou=pepole,dc=example,dc=com
-	 *		)
-	 *	)
-	 * 
-	 *
-	 * @param string The distinguished name (DN) of the entry whose attributes/values to fetch.
-	 * @param string Which connection method resource to use
-	 * @param constant For aliases and referrals, this parameter specifies whether to
-	 *            follow references to the referenced DN or to fetch the attributes for
-	 *            the referencing DN. See http://php.net/ldap_search for the 4 valid
-	 *            options.
-	 * @return array
-	 * @see getDNSysAttrs
-	 * @see getDNAttrValue
-	 */
-	public function getDNAttrValues($dn,$method=null,$deref=LDAP_DEREF_NEVER,$attrs=array('*','+'),$nocache=false) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		static $CACHE;
-
-		$cacheindex = null;
-		$method = $this->getMethod($method);
-
-		if (in_array('*',$attrs) && in_array('+',$attrs))
-			$cacheindex = '&';
-		elseif (in_array('+',$attrs))
-			$cacheindex = '+';
-		elseif (in_array('*',$attrs))
-			$cacheindex = '*';
-
-		if (! $nocache && ! is_null($cacheindex) && isset($CACHE[$this->index][$method][$dn][$cacheindex])) {
-			$results = $CACHE[$this->index][$method][$dn][$cacheindex];
-
-			if (DEBUG_ENABLED)
-				debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$results);
-
-		} else {
-			$query = array();
-			$query['base'] = $this->escapeDN($dn);
-			$query['scope'] = 'base';
-			$query['deref'] = $deref;
-			$query['attrs'] = $attrs;
-			$query['baseok'] = true;
-			$results = $this->query($query,$method);
-
-			if (count($results))
-				$results = array_pop($results);
-
-			$results = array_change_key_case($results);
-
-			# Covert all our result key values to an array
-			foreach ($results as $key => $values)
-				if (! is_array($results[$key]))
-					$results[$key] = array($results[$key]);
-
-			# Finally sort the results
-			ksort($results);
-
-			if (! is_null($cacheindex) && count($results))
-				$CACHE[$this->index][$method][$dn][$cacheindex] = $results;
-		}
-
-		return $results;
-	}
-
-	/**
-	 * Returns true if the attribute specified is required to take as input a DN.
-	 * Some examples include 'distinguishedName', 'member' and 'uniqueMember'.
-	 *
-	 * @param string $attr_name The name of the attribute of interest (case insensitive)
-	 * @return boolean
-	 */
-	function isDNAttr($attr_name,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# Simple test first
-		$dn_attrs = array('aliasedObjectName');
-		foreach ($dn_attrs as $dn_attr)
-			if (strcasecmp($attr_name,$dn_attr) == 0)
-				return true;
-
-		# Now look at the schema OID
-		$sattr = $this->getSchemaAttribute($attr_name);
-		if (! $sattr)
-			return false;
-
-		$syntax_oid = $sattr->getSyntaxOID();
-		if ('1.3.6.1.4.1.1466.115.121.1.12' == $syntax_oid)
-		 	return true;
-		if ('1.3.6.1.4.1.1466.115.121.1.34' == $syntax_oid)
-			return true;
-
-		$syntaxes = $this->SchemaSyntaxes($method);
-		if (! isset($syntaxes[$syntax_oid]))
-			return false;
-
-		$syntax_desc = $syntaxes[ $syntax_oid ]->getDescription();
-		if (strpos(strtolower($syntax_desc),'distinguished name'))
-			return true;
-
-		return false;
-	}
-
-	/**
-	 * Used to determine if the specified attribute is indeed a jpegPhoto. If the
-	 * specified attribute is one that houses jpeg data, true is returned. Otherwise
-	 * this function returns false.
-	 *
-	 * @param string $attr_name The name of the attribute to test.
-	 * @return boolean
-	 * @see draw_jpeg_photo
-	 */
-	function isJpegPhoto($attr_name) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# easy quick check
-		if (! strcasecmp($attr_name,'jpegPhoto') || ! strcasecmp($attr_name,'photo'))
-			return true;
-
-		# go to the schema and get the Syntax OID
-		$sattr = $this->getSchemaAttribute($attr_name);
-		if (! $sattr)
-			return false;
-
-		$oid = $sattr->getSyntaxOID();
-		$type = $sattr->getType();
-
-		if (! strcasecmp($type,'JPEG') || ($oid == '1.3.6.1.4.1.1466.115.121.1.28'))
-			return true;
-
-		return false;
-	}
-
-	/**
-	 * Given an attribute name and server ID number, this function returns
-	 * whether the attrbiute contains boolean data. This is useful for
-	 * developers who wish to display the contents of a boolean attribute
-	 * with a drop-down.
-	 *
-	 * @param string $attr_name The name of the attribute to test.
-	 * @return boolean
-	 */
-	function isAttrBoolean($attr_name) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$type = ($sattr = $this->getSchemaAttribute($attr_name)) ? $sattr->getType() : null;
-
-		if (! strcasecmp('boolean',$type) ||
-			! strcasecmp('isCriticalSystemObject',$attr_name) ||
-			! strcasecmp('showInAdvancedViewOnly',$attr_name))
-			return true;
-
-		else
-			return false;
-	}
-
-	/**
-	 * Given an attribute name and server ID number, this function returns
-	 * whether the attribute may contain binary data. This is useful for
-	 * developers who wish to display the contents of an arbitrary attribute
-	 * but don't want to dump binary data on the page.
-	 *
-	 * @param string $attr_name The name of the attribute to test.
-	 * @return boolean
-	 *
-	 * @see isJpegPhoto
-	 */
-	function isAttrBinary($attr_name) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		/**
-		 * Determining if an attribute is binary can be an expensive operation.
-		 * We cache the results for each attr name on each server in the $attr_cache
-		 * to speed up subsequent calls. The $attr_cache looks like this:
-		 *
-		 * Array
-		 * 0 => Array
-		 *	'objectclass' => false
-		 *	'cn' => false
-		 *	'usercertificate' => true
-		 * 1 => Array
-		 *	'jpegphoto' => true
-		 *	'cn' => false
-		 */
-
-		static $attr_cache;
-
-		$attr_name = strtolower($attr_name);
-
-		if (isset($attr_cache[$this->index][$attr_name]))
-			return $attr_cache[$this->index][$attr_name];
-
-		if ($attr_name == 'userpassword') {
-			$attr_cache[$this->index][$attr_name] = false;
-			return false;
-		}
-
-		# Quick check: If the attr name ends in ";binary", then it's binary.
-		if (strcasecmp(substr($attr_name,strlen($attr_name) - 7),';binary') == 0) {
-			$attr_cache[$this->index][$attr_name] = true;
-			return true;
-		}
-
-		# See what the server schema says about this attribute
-		$sattr = $this->getSchemaAttribute($attr_name);
-		if (! is_object($sattr)) {
-
-			/* Strangely, some attributeTypes may not show up in the server
-			 * schema. This behavior has been observed in MS Active Directory.*/
-			$type = null;
-			$syntax = null;
-
-		} else {
-			$type = $sattr->getType();
-			$syntax = $sattr->getSyntaxOID();
-		}
-
-		if (strcasecmp($type,'Certificate') == 0 ||
-			strcasecmp($type,'Binary') == 0 ||
-			strcasecmp($attr_name,'usercertificate') == 0 ||
-			strcasecmp($attr_name,'usersmimecertificate') == 0 ||
-			strcasecmp($attr_name,'networkaddress') == 0 ||
-			strcasecmp($attr_name,'objectGUID') == 0 ||
-			strcasecmp($attr_name,'objectSID') == 0 ||
-			strcasecmp($attr_name,'auditingPolicy') == 0 ||
-			strcasecmp($attr_name,'jpegPhoto') == 0 ||
-			strcasecmp($attr_name,'krbExtraData') == 0 ||
-			strcasecmp($attr_name,'krbPrincipalKey') == 0 ||
-			$syntax == '1.3.6.1.4.1.1466.115.121.1.10' ||
-			$syntax == '1.3.6.1.4.1.1466.115.121.1.28' ||
-			$syntax == '1.3.6.1.4.1.1466.115.121.1.5' ||
-			$syntax == '1.3.6.1.4.1.1466.115.121.1.8' ||
-			$syntax == '1.3.6.1.4.1.1466.115.121.1.9'
-		) {
-
-			$attr_cache[$this->index][$attr_name] = true;
-			return true;
-
-		} else {
-			$attr_cache[$this->index][$attr_name] = false;
-			return false;
-		}
-	}
-
-	/**
-	 * This function will test if a user is a member of a group.
-	 *
-	 * Inputs:
-	 * @param string $user membership value that is being checked
-	 * @param dn $group DN to see if user is a member
-	 * @return bool true|false
-	 */
-	function userIsMember($user,$group) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$user = strtolower($user);
-		$group = $this->getDNAttrValues($group);
-
-		# If you are using groupOfNames objectClass
-		if (array_key_exists('member',$group) && ! is_array($group['member']))
-			$group['member'] = array($group['member']);
-
-		if (array_key_exists('member',$group) &&
-			in_array($user,arrayLower($group['member'])))
-
-			return true;
-
-		# If you are using groupOfUniqueNames objectClass
-		if (array_key_exists('uniquemember',$group) && ! is_array($group['uniquemember']))
-			$group['uniquemember'] = array($group['uniquemember']);
-
-		if (array_key_exists('uniquemember',$group) &&
-			in_array($user,arrayLower($group['uniquemember'])))
-
-			return true;
-
-		return false;
-	}
-
-	/**
-	 * This function will determine if the user is allowed to login based on a filter
-	 */
-	protected function userIsAllowedLogin($dn) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$dn = trim(strtolower($dn));
-
-		if (! $this->getValue('login','allowed_dns'))
-			return true;
-
-        foreach ($this->getValue('login','allowed_dns') as $login_allowed_dn) {
-            if (DEBUG_ENABLED)
-                debug_log('Working through (%s)',80,0,__FILE__,__LINE__,__METHOD__,$login_allowed_dn);
-
-            /* Check if $login_allowed_dn is an ldap search filter
-             * Is first occurence of 'filter=' (case ensitive) at position 0 ? */
-            if (preg_match('/^\([&|]\(/',$login_allowed_dn)) {
-				$query = array();
-                $query['filter'] = $login_allowed_dn;
-				$query['attrs'] = array('dn');
-
-                foreach($this->getBaseDN() as $base_dn) {
-					$query['base'] = $base_dn;
-
-                    $results = $this->query($query,null);
-
-                    if (DEBUG_ENABLED)
-                        debug_log('Search, Filter [%s], BaseDN [%s] Results [%s]',16,0,__FILE__,__LINE__,__METHOD__,
-                            $query['filter'],$query['base'],$results);
-
-                    if ($results) {
-                    	$dn_array = array();
-
-                        foreach ($results as $result)
-                            array_push($dn_array,$result['dn']);
-
-                        $dn_array = array_unique($dn_array);
-
-                        if (count($dn_array))
-                            foreach ($dn_array as $result_dn) {
-                                if (DEBUG_ENABLED)
-                                    debug_log('Comparing with [%s]',80,0,__FILE__,__LINE__,__METHOD__,$result_dn);
-
-                                # Check if $result_dn is a user DN
-                                if (strcasecmp($dn,trim(strtolower($result_dn))) == 0)
-                                    return true;
-
-                                # Check if $result_dn is a group DN
-                                if ($this->userIsMember($dn,$result_dn))
-                                    return true;
-                        }
-                    }
-                }
-            }
-
-            # Check if $login_allowed_dn is a user DN
-            if (strcasecmp($dn,trim(strtolower($login_allowed_dn))) == 0)
-                return true;
-
-            # Check if $login_allowed_dn is a group DN
-            if ($this->userIsMember($dn,$login_allowed_dn))
-                return true;
-        }
-
-        return false;
-	}
-}
-?>
diff --git a/lib/ds_ldap_pla.php b/lib/ds_ldap_pla.php
deleted file mode 100644
index 7631643..0000000
--- a/lib/ds_ldap_pla.php
+++ /dev/null
@@ -1,677 +0,0 @@
-default->appearance['pla_password_hash'] = array(
-			'desc'=>'Default HASH to use for passwords',
-			'default'=>'md5');
-
-		$this->default->appearance['show_create'] = array(
-			'desc'=>'Whether to show the "Create new Entry here" in the tree browser',
-			'default'=>true);
-
-		$this->default->appearance['open_tree'] = array(
-			'desc'=>'Whether to initially open each tree',
-			'default'=>false);
-
-		$this->default->appearance['show_authz'] = array(
-			'desc'=>'Enable display of authorization ID as login',
-			'default'=>false);
-
-		$this->default->login['fallback_dn'] = array(
-			'desc'=>'If the attribute base login fails, see if a DN was entered',
-			'default'=>false);
-
-		$this->default->query['disable_default'] = array(
-			'desc'=>'Configuration to disable the default query template',
-			'default'=>false);
-
-		$this->default->query['custom_only'] = array(
-			'desc'=>'Configuration to force the usage of custom query templates',
-			'default'=>false);
-
-		$this->default->server['branch_rename'] = array(
-			'desc'=>'Enable renaming of branches',
-			'default'=>false);
-
-		$this->default->server['custom_attrs'] = array(
-			'desc'=>'Custom operational attributes to be treated as regular attributes',
-			'default'=>array(''));
-
-		$this->default->server['custom_sys_attrs'] = array(
-			'desc'=>'Custom operational attributes to be treated as internal attributes',
-			'default'=>array('+'));
-
-		# This was added in case the LDAP server doesnt provide them with a base +,* query.
-		$this->default->server['root_dse_attributes'] = array(
-			'desc'=>'RootDSE attributes for use when displaying server info',
-			'default'=>array(
-				'namingContexts',
-				'subschemaSubentry',
-				'altServer',
-				'supportedExtension',
-				'supportedControl',
-				'supportedSASLMechanisms',
-				'supportedLDAPVersion',
-				'currentTime',
-				'dsServiceName',
-				'defaultNamingContext',
-				'schemaNamingContext',
-				'configurationNamingContext',
-				'rootDomainNamingContext',
-				'supportedLDAPPolicies',
-				'highestCommittedUSN',
-				'dnsHostName',
-				'ldapServiceName',
-				'serverName',
-				'supportedCapabilities',
-				'changeLog',
-				'tlsAvailableCipherSuites',
-				'tlsImplementationVersion',
-				'supportedSASLMechanisms',
-				'dsaVersion',
-				'myAccessPoint',
-				'dseType',
-				'+',
-				'*'
-			));
-
-		$this->default->server['force_may'] = array(
-			'desc'=>'Force server MUST attributes as MAY attributes',
-			'default'=>array(
-			));
-
-		# Settings for auto_number
-		$this->default->auto_number['enable'] = array(
-			'desc'=>'Enable the AUTO UID feature',
-			'default'=>true);
-
-		$this->default->auto_number['mechanism'] = array(
-			'desc'=>'Mechanism to use to search for automatic numbers',
-			'default'=>'search');
-
-		$this->default->auto_number['search_base'] = array(
-			'desc'=>'Base DN to use for search mechanisms',
-			'default'=>null);
-
-		$this->default->auto_number['min'] = array(
-			'desc'=>'Minimum number to start with',
-			'default'=>array('uidNumber'=>1000,'gidNumber'=>500));
-
-		$this->default->auto_number['dn'] = array(
-			'desc'=>'DN to use when evaluating numbers',
-			'default'=>null);
-
-		$this->default->auto_number['pass'] = array(
-			'desc'=>'Password for DN to use when evaluating numbers',
-			'default'=>null);
-
-		$this->default->unique['attrs'] = array(
-			'desc'=>'Attributes to check for uniqueness before allowing updates',
-			'default'=>array('mail','uid','uidNumber'));
-
-		$this->default->unique['dn'] = array(
-			'desc'=>'DN to use when evaluating attribute uniqueness',
-			'default'=>null);
-
-		$this->default->unique['pass'] = array(
-			'desc'=>'Password for DN to use when evaluating attribute uniqueness',
-			'default'=>null);
-	}
-
-	public function __get($key) {
-		switch ($key) {
-			case 'name':
-				return $this->getValue('server','name');
-
-			default:
-				system_message(array(
-					'title'=>_('Unknown request for Object value.'),
-					'body'=>sprintf(_('Attempt to obtain value %s from %s'),$key,get_class($this)),
-					'type'=>'error'));
-		}
-	}
-
-	/**
-	 * Gets whether the admin has configured phpLDAPadmin to show the "Create New" link in the tree viewer.
-	 * 
-	 *	$servers->setValue('appearance','show_create',true|false);
-	 * 
-	 * If NOT set, then default to show the Create New item.
-	 * If IS set, then return the value (it should be true or false).
-	 *
-	 * The entry creation command must be available.
-	 * 
-	 *	$config->custom->commands['script'] = array('create' => true);
-	 * 
-	 *
-	 * @return boolean true if the feature is enabled and false otherwise.
-	 */
-	function isShowCreateEnabled() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','create'))
-			return false;
-		else
-			return $this->getValue('appearance','show_create');
-	}
-
-	/**
-	 * Fetch whether the user has configured a certain server login to be non anonymous
-	 *
-	 * 
-	 *	$servers->setValue('login','anon_bind',true|false);
-	 * 
-	 *
-	 * @return boolean
-	 */
-	public function isAnonBindAllowed() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# If only_login_allowed_dns is set, then we cant have anonymous.
-		if (count($this->getValue('login','allowed_dns')) > 0)
-			$return = false;
-		else
-			$return = $this->getValue('login','anon_bind');
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return);
-
-		return $return;
-	}
-
-	/**
-	 * Returns true if the user has configured the specified server to enable branch (non-leaf) renames.
-	 *
-	 * This is configured in config.php thus:
-	 * 
-	 *	$servers->setValue('server','branch_rename',true|false);
-	 * 
-	 *
-	 * @return boolean
-	 */
-	function isBranchRenameEnabled() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
- 		return $this->getValue('server','branch_rename');
-	}
-
-	/**
-	 * Determines if an attribute's value can contain multiple lines. Attributes that fall
-	 * in this multi-line category may be configured in config.php. Hence, this function
-	 * accesses the global variable $_SESSION[APPCONFIG]->custom->appearance['multi_line_attributes'];
-	 *
-	 * Usage example:
-	 * 
-	 *	if ($ldapserver->isMultiLineAttr('postalAddress'))
-	 *		echo '';
-	 *	else
-	 *		echo '';
-	 * 
-	 *
-	 * @param string The name of the attribute of interested (case insensivite)
-	 * @param string (optional) The current value of the attribute (speeds up the process by searching for carriage returns already in the attribute value)
-	 * @return boolean
-	 */
-	function isMultiLineAttr($attr_name,$val=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# Set default return
-		$return = false;
-
-		# First, check the optional val param for a \n or a \r
-		if (! is_null($val) && (strpos($val,"\n") || strpos($val,"\r")))
-			$return = true;
-
-		# Next, compare strictly by name first
-		else
-			foreach ($_SESSION[APPCONFIG]->getValue('appearance','multi_line_attributes') as $multi_line_attr_name)
-				if (strcasecmp($multi_line_attr_name,$attr_name) == 0) {
-					$return = true;
-					break;
-				}
-
-		# If unfound, compare by syntax OID
-		if (! $return) {
-			$sattr = $this->getSchemaAttribute($attr_name);
-
-			if ($sattr) {
-				$syntax_oid = $sattr->getSyntaxOID();
-
-				if ($syntax_oid)
-					foreach ($_SESSION[APPCONFIG]->getValue('appearance','multi_line_syntax_oids') as $multi_line_syntax_oid)
-						if ($multi_line_syntax_oid == $syntax_oid) {
-							$return = true;
-							break;
-						}
-			}
-		}
-
-		if (DEBUG_ENABLED)
-			debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return);
-
-		return $return;
-	}
-
-	/**
-	 * Returns true if the specified attribute is configured according to
-	 * the test enabled in config.php
-	 *
-	 * @param string The name of the attribute to test.
-	 * @param array The attributes to test against.
-	 * @param dn A DN that is exempt from these tests.
-	 * @return boolean
-	 */
-	private function isAttrTest($attr,$attrs,$except_dn) {
-		$attr = trim($attr);
-		if (! trim($attr) || ! count($attrs))
-			return false;
-
-		# Is the user excluded?
-		if ($except_dn && $this->userIsMember($this->getLogin(),$except_dn))
-			return false;
-
-		foreach ($attrs as $attr_name)
-			if (strcasecmp($attr,trim($attr_name)) == 0)
-				return true;
-
-		return false;
-	}
-
-	/**
-	 * Returns true if the specified attribute is configured as read only
-	 * in config.php.
-	 * Attributes are configured as read-only in config.php thus:
-	 * 
-	 *	$config->custom->appearance['readonly_attrs'] = array('objectClass');
-	 * 
-	 *
-	 * @param string The name of the attribute to test.
-	 * @return boolean
-	 */
-	public function isAttrReadOnly($attr) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$attrs = $_SESSION[APPCONFIG]->getValue('appearance','readonly_attrs');
-		$except_dn = $_SESSION[APPCONFIG]->getValue('appearance','readonly_attrs_exempt');
-
-		return $this->isAttrTest($attr,$attrs,$except_dn);
-	}
-
-	/**
-	 * Returns true if the specified attribute is configured as hidden
-	 * in config.php.
-	 * Attributes are configured as hidden in config.php thus:
-	 * 
-	 *	$config->custom->appearance['hide_attrs'] = array('objectClass');
-	 * 
-	 *
-	 * @param string The name of the attribute to test.
-	 * @return boolean
-	 */
-	public function isAttrHidden($attr) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$attrs = $_SESSION[APPCONFIG]->getValue('appearance','hide_attrs');
-		$except_dn = $_SESSION[APPCONFIG]->getValue('appearance','hide_attrs_exempt');
-
-		return $this->isAttrTest($attr,$attrs,$except_dn);
-	}
-
-	/**
-	 * Add objects
-	 */
-	public function add($dn,$entry_array,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		foreach ($entry_array as $attr => $val)
-			$entry_array[$attr] = dn_unescape($val);
-
-		$result = false;
-
-		# Check our unique attributes.
-		if (! $this->checkUniqueAttrs($dn,$entry_array))
-			return false;
-
-		if (run_hook('pre_entry_create',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$entry_array))) {
-			$result = @ldap_add($this->connect($method),dn_escape($dn),$entry_array);
-
-			if ($result) {
-				# Update the tree
-				$tree = get_cached_item($this->index,'tree');
-
-				# If we created the base, delete it, then add it back
-				if (get_request('create_base'))
-					$tree->delEntry($dn);
-
-				$tree->addEntry($dn);
-
-				set_cached_item($this->index,'tree','null',$tree);
-
-				run_hook('post_entry_create',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$entry_array));
-
-			} else {
-				system_message(array(
-					'title'=>_('Could not add the object to the LDAP server.'),
-					'body'=>ldap_error_msg($this->getErrorMessage(null),$this->getErrorNum(null)),
-					'type'=>'error'));
-			}
-		}
-
-		return $result;
-	}
-
-	/**
-	 * Delete objects
-	 */
-	public function delete($dn,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$result = false;
-
-		if (run_hook('pre_entry_delete',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn))) {
-			$result = @ldap_delete($this->connect($method),dn_escape($dn));
-
-			if ($result) {
-				# Update the tree
-				$tree = get_cached_item($this->index,'tree');
-				$tree->delEntry($dn);
-
-				set_cached_item($this->index,'tree','null',$tree);
-
-				run_hook('post_entry_delete',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn));
-			}
-		}
-
-		return $result;
-	}
-
-	/**
-	 * Rename objects
-	 */
-	public function rename($dn,$new_rdn,$container,$deleteoldrdn,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		$result = false;
-
-		if (run_hook('pre_entry_rename',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'rdn'=>$new_rdn,'container'=>$container))) {
-			$result = @ldap_rename($this->connect($method),$dn,$new_rdn,$container,$deleteoldrdn);
-
-			if ($result) {
-				# Update the tree
-				$tree = get_cached_item($this->index,'tree');
-				$newdn = sprintf('%s,%s',$new_rdn,$container);
-				$tree->renameEntry($dn,$newdn);
-
-				set_cached_item($this->index,'tree','null',$tree);
-
-				run_hook('post_entry_rename',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'rdn'=>$new_rdn,'container'=>$container));
-			}
-		}
-
-		return $result;
-	}
-
-	/**
-	 * Modify objects
-	 */
-	public function modify($dn,$attrs,$method=null) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# Check our unique attributes.
-		if (! $this->checkUniqueAttrs($dn,$attrs))
-			return false;
-
-		$result = false;
-		$summary = array();
-		$current_attrs = $this->getDNAttrValues($dn,$method,LDAP_DEREF_NEVER,array('*'));
-
-		# Go through our attributes and call our hooks for each attribute changing its value
-		foreach ($attrs as $attr => $values) {
-			# For new attributes
-			if (count($values) && ! isset($current_attrs[$attr])) {
-				if (! run_hook('pre_attr_add',
-					array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'newvalue'=>$values))) {
-
-					unset($attrs[$attr]);
-					system_message(array(
-						'title'=>_('Attribute not added'),
-						'body'=>sprintf('%s (%s)',_('Hook pre_attr_add prevented attribute from being added'),$attr),
-						'type'=>'warn'));
-
-				} else
-					$summary['add'][$attr]['new'] = $values;
-
-			# For modify attributes
-			} elseif (count($values)) {
-				if (! run_hook('pre_attr_modify',
-					array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$current_attrs[$attr],'newvalue'=>$values))) {
-
-					unset($attrs[$attr]);
-					system_message(array(
-						'title'=>_('Attribute not modified'),
-						'body'=>sprintf('%s (%s)',_('Hook pre_attr_modify prevented attribute from being modified'),$attr),
-						'type'=>'warn'));
-
-				} else {
-					$summary['modify'][$attr]['new'] = $values;
-					$summary['modify'][$attr]['old'] = $current_attrs[$attr];
-				}
-
-			# For delete attributes
-			} else {
-				if (! run_hook('pre_attr_delete',
-					array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$current_attrs[$attr]))) {
-
-					unset($attrs[$attr]);
-					system_message(array(
-						'title'=>_('Attribute not deleted'),
-						'body'=>sprintf('%s (%s)',_('Hook pre_attr_delete prevented attribute from being deleted'),$attr),
-						'type'=>'warn'));
-
-				} else
-					$summary['delete'][$attr]['old'] = $current_attrs[$attr];
-			}
-		}
-
-		if (! count($attrs))
-			return false;
-
-		if (run_hook('pre_entry_modify',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$attrs))) {
-			$result = @ldap_modify($this->connect($method),$dn,$attrs);
-
-			if ($result) {
-				run_hook('post_entry_modify',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$attrs));
-
-				foreach (array('add','modify','delete') as $mode)
-					if (isset($summary[$mode]))
-						foreach ($summary[$mode] as $attr => $values)
-							switch ($mode) {
-								case 'add':
-									run_hook(sprintf('post_attr_%s',$mode),
-										array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'newvalue'=>$values['new']));
-									break;
-
-								case 'modify':
-									run_hook(sprintf('post_attr_%s',$mode),
-										array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$values['old'],'newvalue'=>$values['new']));
-									break;
-
-								case 'delete':
-									run_hook(sprintf('post_attr_%s',$mode),
-										array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$values['old']));
-									break;
-
-								default:
-									debug_dump_backtrace(sprintf('Unkown mode %s',$mode),1);
-							}
-			} else {
-				system_message(array(
-					'title'=>_('Could not perform ldap_modify operation.'),
-					'body'=>ldap_error_msg($this->getErrorMessage($method),$this->getErrorNum($method)),
-					'type'=>'error'));
-			}
-		}
-
-		return $result;
-	}
-
-	/**
-	 * Returns true if the specified attribute is configured as unique
-	 * in config.php.
-	 * Attributes are configured as hidden in config.php thus:
-	 * 
-	 *	$servers->setValue('unique','attrs',array('mail','uid','uidNumber'));
-	 * 
-	 *
-	 * @param string $attr The name of the attribute to test.
-	 * @return boolean
-	 */
-	public function isAttrUnique($attr) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# Should this attribute value be unique
-		if (in_array_ignore_case($attr,$this->getValue('unique','attrs')))
-			return true;
-		else
-			return false;
-	}
-
-	/**
-	 * This function will check whether the value for an attribute being changed
-	 * is already assigned to another DN.
-	 *
-	 * Returns the bad value, or null if all values are OK
-	 *
-	 * @param dn DN that is being changed
-	 * @param string Attribute being changed
-	 * @param string|array New values for the attribute
-	 */
-	public function checkUniqueAttrs($dn,$attrs) {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# If none of the attributes are defined unique, we'll return immediately;
-		if (! $checkattrs = array_intersect(arrayLower($this->getValue('unique','attrs')),array_keys(array_change_key_case($attrs))))
-			return true;
-
-		# Check see and use our alternate uid_dn and password if we have it.
-		if (! $this->login($this->getValue('unique','dn'),$this->getValue('unique','pass'),'unique')) {
-			system_message(array(
-				'title'=>_('UNIQUE invalid login/password'),
-				'body'=>sprintf('%s (%s)',_('Unable to connect to LDAP server with the unique login/password, please check your configuration.'),
-					$this->getName()),
-				'type'=>'warn'));
-
-			return false;
-		}
-
-		$query = array();
-
-		# Build our search filter to double check each attribute.
-		$query['filter'] = '(|';
-		foreach ($checkattrs as $attr)
-			foreach ($attrs[$attr] as $val)
-				if ($val)
-					$query['filter'] .= sprintf('(%s=%s)',$attr,$val);
-		$query['filter'] .= ')';
-
-		$query['attrs'] = $checkattrs;
-
-		# Search through our bases and see if we have match
-		foreach ($this->getBaseDN() as $base) {
-			$query['base'] = $base;
-
-			# Do the search
-			$results = $this->query($query,'unique');
-
-			# If we have a match.
-			if (count($results))
-				foreach ($results as $values)
-					# If one of the attributes is owned to somebody else, then we may as well die here.
-					if ($values['dn'] != $dn) {
-						$href = sprintf('cmd.php?cmd=query_engine&server_id=%s&filter=%s&scope=sub&query=none&format=list&search=true',$this->index,$query['filter']);
-
-						system_message(array(
-							'title'=>_('Attribute value would not be unique'),
-							'body'=>sprintf('%s (%s)',
-								_('This update has been or will be cancelled, it would result in an attribute value not being unique. You might like to search the LDAP server for the offending entry.'),
-								htmlspecialchars($href),
-								_('Search')),
-							'type'=>'warn'));
-
-						return false;
-					}
-		}
-
-		# If we get here, then it must be OK?
-		return true;
-	}
-
-	/**
-	 * Check if the session timeout has occured for this LDAP server.
-	 */
-	public function isSessionValid() {
-		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-			debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-		# If inactiveTime() returns a value, we need to check that it has not expired.
-		if (is_null($this->inactivityTime()) || ! $this->isLoggedIn())
-			return true;
-
-		# If session has expired
-		if ((isset($_SESSION['ACTIVITY'][$this->getIndex()])) && ($_SESSION['ACTIVITY'][$this->getIndex()] < time())) {
-			$this->logout();
-			unset($_SESSION['ACTIVITY'][$this->getIndex()]);
-
-			return false;
-		}
-
-		$_SESSION['ACTIVITY'][$this->getIndex()] = $this->inactivityTime();
-		return true;
-	}
-
-	/**
-	 * Return login, or authorization ID if show_authz enabled
-	 */
-	public function displayLogin($method=null) {
-		// check for whoami function, added in 7.2
-		if ($this->getValue('appearance', 'show_authz') && function_exists('ldap_exop_whoami')) {
-			$result = @ldap_exop_whoami($this->connect($method));
-			if ($result) // strip any dn: or u: prefix
-				$result = preg_replace('/^(u|dn):/i', '', $result);
-			else // fall back to login on error
-				$result = $this->getLogin($method);
-			return $result;
-		}
-		else {
-			return $this->getLogin($method);
-		}
-	}
-}
-?>
diff --git a/lib/functions.php b/lib/functions.php
deleted file mode 100644
index 7849228..0000000
--- a/lib/functions.php
+++ /dev/null
@@ -1,2520 +0,0 @@
-_('Generic Error'),
-			'body'=>sprintf('%s: %s [%s]',
-				__METHOD__,_('Called to load a class that cant be found'),$className),
-			'type'=>'error'));
-}
-
-if (version_compare(phpversion(), '7.0', '>=')) {
-	spl_autoload_register('pla_autoload');
-} else {
-	eval('function __autoload($className) {pla_autoload($className);}');
-}
-
-/**
- * Strips all slashes from the specified array in place (pass by ref).
- * @param Array The array to strip slashes from, typically one of
- *        $_GET, $_POST, or $_COOKIE.
- */
-function array_stripslashes(&$array) {
-	if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-		debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-	if (is_array($array))
-		while (list($key) = each($array))
-			if (is_array($array[$key]) && $key != $array)
-				array_stripslashes($array[$key]);
-			else
-				$array[$key] = stripslashes($array[$key]);
-}
-
-/**
- * Compatibility Functions
- * These functions exist, so that a standard function can be used in new applications, and they
- * map to already defined functions in older applications.
- */
-
-/**
- * If gettext is not available in PHP, then this will provide compatibility for it.
- */
-if (! function_exists('_')) {
-	function _($msg) {
-		return $msg;
-	}
-}
-
-/**
- * Generic Utility Functions
- */
-
-/**
- * Custom error handling function.
- * When a PHP error occurs, PHP will call this function rather than printing
- * the typical PHP error string. This provides the application the ability to
- * format an error message so that it looks better.
- * Optionally, it can present a link so that a user can search/submit bugs.
- * This function is not to be called directly. It is exclusively for the use of
- * PHP internally. If this function is called by PHP from within a context
- * where error handling has been disabled (ie, from within a function called
- * with "@" prepended), then this function does nothing.
- *
- * @param int The PHP error number that occurred (ie, E_ERROR, E_WARNING, E_PARSE, etc).
- * @param string The PHP error string provided (ie, "Warning index "foo" is undefined)
- * @param string The file in which the PHP error ocurred.
- * @param int The line number on which the PHP error ocurred
- * @see set_error_handler
- */
-function app_error_handler($errno,$errstr,$file,$lineno) {
-	if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
-		debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);
-
-	/**
-	 * error_reporting will be 0 if the error context occurred
-	 * within a function call with '@' preprended (ie, @ldap_bind() );
-	 * So, don't report errors if the caller has specifically
-	 * disabled them with '@'
-	 */
-	if (ini_get('error_reporting') == 0 || error_reporting() == 0)
-		return;
-
-	$file = basename($file);
-	$caller = basename($_SERVER['PHP_SELF']);
-	$errtype = '';
-
-	switch ($errno) {
-		case E_STRICT: $errtype = 'E_STRICT'; break;
-		case E_ERROR: $errtype = 'E_ERROR'; break;
-		case E_WARNING: $errtype = 'E_WARNING'; break;
-		case E_PARSE: $errtype = 'E_PARSE'; break;
-		case E_NOTICE: $errtype = 'E_NOTICE'; break;
-		case E_CORE_ERROR: $errtype = 'E_CORE_ERROR'; break;
-		case E_CORE_WARNING: $errtype = 'E_CORE_WARNING'; break;
-		case E_COMPILE_ERROR: $errtype = 'E_COMPILE_ERROR'; break;
-		case E_COMPILE_WARNING: $errtype = 'E_COMPILE_WARNING'; break;
-		case E_USER_ERROR: $errtype = 'E_USER_ERROR'; break;
-		case E_USER_WARNING: $errtype = 'E_USER_WARNING'; break;
-		case E_USER_NOTICE: $errtype = 'E_USER_NOTICE'; break;
-		case E_ALL: $errtype = 'E_ALL'; break;
-
-		default: $errtype = sprintf('%s: %s',_('Unrecognized error number'),$errno);
-	}
-
-	# Take out extra spaces in error strings.
-	$errstr = preg_replace('/\s+/',' ',$errstr);
-
-	if ($errno == E_NOTICE) {
-		$body = '';
-		$body .= sprintf('',_('Error'),$errstr,$errtype);
-		$body .= sprintf('',
-			_('File'),$file,_('line'),$lineno,_('caller'),$caller);
-		$body .= sprintf('',
-			app_version(),phpversion(),php_sapi_name());
-		$body .= sprintf('',isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'SCRIPT');
-
-		if (function_exists('get_href'))
-			$body .= sprintf('',
-				get_href('search_bug',"&summary_keyword=".rawurlencode($errstr)),
-				_('Please check and see if this bug has been reported'));
-		$body .= '
%s:%s (%s)
%s:%s %s %s, %s %s
Versions:PLA: %s, PHP: %s, SAPI: %s
Web server:%s
%s.
'; - - system_message(array( - 'title'=>_('You found a non-fatal phpLDAPadmin bug!'), - 'body'=>$body, - 'type'=>'error')); - - return; - } - - # If this is a more serious error, call the error call. - error(sprintf('%s: %s',$errtype,$errstr),'error',null,true,true); -} - -/** - * Returns the application name. - */ -function app_name() { - return 'phpLDAPadmin'; -} - -/** - * Returns the application version currently running. The version - * is read from the file named VERSION. - * - * @return string The current version as read from the VERSION file. - */ -function app_version() { - static $CACHE = null; - - if ($CACHE) - return $CACHE; - - $version_file = realpath(LIBDIR.'../VERSION'); - if (! file_exists($version_file)) - $CACHE = 'UNKNOWN'; - - else { - $version = rtrim(file_get_contents($version_file)); - - $CACHE = preg_replace('/^RELEASE-([0-9\.]+(-.*)*)$/','$1',$version); - - # Check if we are a CVS copy. - if (preg_match('/^(DEVEL)?$/',$CACHE)) - $CACHE = 'DEVEL'; - - # Check if we are special DEVEL version - elseif (preg_match('/^DEVEL-([0-9\.]+)+$/',$CACHE)) {} - - # If return is still the same as version, then the tag is not one we expect. - elseif ($CACHE == $version) - $CACHE = 'UNKNOWN'; - } - - return $CACHE; -} - -/** - * This function will convert the browser two character language into the - * default 5 character language, where the country portion should NOT be - * assumed to be upper case characters of the first two characters. - */ -function auto_lang($lang) { - switch ($lang) { - case 'ja': return 'ja_JP'; - case 'cs': return 'cs_CZ'; - default: return sprintf('%s_%s',$lang,strtoupper($lang)); - } -} - -/** - * Makes sure that the config file is properly setup. - */ -function check_config($config_file) { - # Read in config_default.php - require_once LIBDIR.'config_default.php'; - - # Make sure their PHP version is current enough - if (strcmp(phpversion(),REQUIRED_PHP_VERSION) < 0) - system_message(array( - 'title'=>_('Incorrect version of PHP'), - 'body'=>sprintf('phpLDAPadmin requires PHP version %s or greater.
(You are using %s)', - REQUIRED_PHP_VERSION,phpversion()), - 'type'=>'error')); - - $config = new Config; - - if (file_exists(LIBDIR.'config_custom.php') && is_readable(LIBDIR.'config_custom.php')) - include LIBDIR.'config_custom.php'; - - ob_start(); - require $config_file; - $str = ''; - if (ob_get_level()) { - $str = ob_get_contents(); - ob_end_clean(); - } - - if ($str) { - $str = strip_tags($str); - $matches = array(); - preg_match('/(.*):\s+(.*):.*\s+on line (\d+)/',$str,$matches); - - if (isset($matches[1]) && isset($matches[2]) && isset($matches[3])) { - $error_type = $matches[1]; - $error = $matches[2]; - $line_num = $matches[3]; - - $file = file($config_file); - - $body = '

Config file ERROR

'; - $body .= sprintf('

%s (%s) on line %s

',$error_type,$error,$line_num); - - $body .= '
'; - $body .= sprintf('Looks like your config file has an ERROR on line %s.
',$line_num); - $body .= 'Here is a snippet around that line
'; - $body .= '
'."\n"; - - $body .= '
'; - - for ($i = $line_num-9; $i<$line_num+5; $i++) { - if ($i+1 == $line_num) - $body .= '
'; - - if ($i < 0) - continue; - - $body .= sprintf('%s: %s
',$i+1,$file[$i]); - - if ($i+1 == $line_num) - $body .= '
'; - } - - $body .= '
'; - $body .= '
'; - $body .= 'Hint: Sometimes these errors are caused by lines preceding the line reported.'; - $body .= '
'; - - $block = new block(); - $block->SetBody($body); - $www['page'] = new page(); - $www['page']->block_add('body',$block); - $www['page']->display(); - - die(); - } - } - - # Check for server definitions. - if (! isset($servers) || count($servers->GetServerList()) == 0) - error(_('Your config.php is missing Server Definitions. Please see the sample file config/config.php.example.'),'error','index.php',true); - - $config->setServers($servers); - - # Check the memory limit parameter. - if ((ini_get('memory_limit') > -1) && ini_get('memory_limit') < $config->getValue('session','memorylimit')) - system_message(array( - 'title'=>_('Memory Limit low.'), - 'body'=>sprintf('Your php memory limit is low - currently %s, you should increase it to atleast %s. This is normally controlled in /etc/php.ini.', - ini_get('memory_limit'),$config->getValue('session','memorylimit')), - 'type'=>'error')); - - return $config; -} - -/** - * Commands available in the control_panel of the page - * - * @return array - */ -function cmd_control_pane($type) { - if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - switch ($type) { - case 'main' : - return array( - 'home'=>array( - 'title'=>_('Home'), - 'enable'=>true, - 'link'=>sprintf('href="index.php" title="%s"',_('Home')), - 'image'=>sprintf('%s',IMGDIR,_('Home'))), - - 'purge'=>array( - 'title'=>_('Purge caches'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('script','purge_cache') : false, - 'link'=>sprintf('href="cmd.php?cmd=purge_cache" onclick="return ajDISPLAY(\'BODY\',\'cmd=purge_cache\',\'%s\');" title="%s"', - _('Clearing cache'),_('Purge caches')), - 'image'=>sprintf('%s',IMGDIR,_('Purge caches'))), - - 'hide_debug_info'=>array( - 'title'=>_('Show Cache'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? ($_SESSION[APPCONFIG]->isCommandAvailable('script','show_cache')) && (! $_SESSION[APPCONFIG]->getValue('appearance','hide_debug_info')) : false, - 'link'=>sprintf('href="cmd.php?cmd=show_cache" onclick="return ajDISPLAY(\'BODY\',\'cmd=show_cache\',\'%s\');" title="%s"', - _('Loading'),_('Show Cache'),_('Show Cache')), - 'image'=>sprintf('%s',IMGDIR,_('Show Cache'))), - ); - - break; - - case 'top' : - return array( - 'forum'=>array( - 'title'=>_('Forum'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks') : true, - 'link'=>sprintf('href="%s" title="%s" onclick="target=\'_blank\';"',get_href('forum'),_('Forum')), - 'image'=>sprintf('%s',IMGDIR,_('Forum'))), - - 'feature'=>array( - 'title'=>_('Request feature'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks') : true, - 'link'=>sprintf('href="%s" title="%s" onclick="target=\'_blank\';"',get_href('add_rfe'),_('Request feature')), - 'image'=>sprintf('%s',IMGDIR,_('Request feature'))), - - 'bug'=>array( - 'title'=>_('Report a bug'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks') : true, - 'link'=>sprintf('href="%s" title="%s" onclick="target=\'_blank\';"',get_href('add_bug'),_('Report a bug')), - 'image'=>sprintf('%s',IMGDIR,_('Report a bug'))), - - 'donation'=>array( - 'title'=>_('Donate'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks') : true, - 'link'=>sprintf('href="%s" title="%s" onclick="target=\'_blank\';"',get_href('donate'),_('Donate')), - 'image'=>sprintf('%s',IMGDIR,_('Donate'))), - - 'help'=>array( - 'title'=>_('Help'), - 'enable'=>isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks') : true, - 'link'=>sprintf('href="%s" title="%s" onclick="target=\'_blank\';"',get_href('documentation'),_('Help')), - 'image'=>sprintf('%s',IMGDIR,_('Help'))) - ); - - break; - } -} - -/** - * This function dumps the $variable for debugging purposes - * - * @param string|array Variable to dump - * @param boolean Whether to stop execution or not. - */ -function debug_dump($variable,$die=false,$onlydebugaddr=false) { - if ($onlydebugaddr && - isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('debug','addr') && - $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SESSION[APPCONFIG]->getValue('debug','addr') && - $_SERVER['REMOTE_ADDR'] != $_SESSION[APPCONFIG]->getValue('debug','addr')) - return; - - $backtrace = debug_backtrace(); - $caller['class'] = isset($backtrace[0]['class']) ? $backtrace[0]['class'] : 'N/A'; - $caller['function'] = isset($backtrace[0]['function']) ? $backtrace[0]['function'] : 'N/A'; - $caller['file'] = isset($backtrace[0]['file']) ? $backtrace[0]['file'] : 'N/A'; - $caller['line'] = isset($backtrace[0]['line']) ? $backtrace[0]['line'] : 'N/A'; - $caller['debug'] = $variable; - - print '
';
-	print_r($caller);
-	print '
'; - - if ($die) - die(); -} - -/** - * This function generates a backtrace - * - * @param boolean Whether to stop execution or not. - */ -function debug_dump_backtrace($msg='Calling BackTrace',$die=false) { - error($msg,'note',null,$die,true); -} - -/** - * Send a debug as a sys message - */ -function debug_sysmsg($msg) { - system_message(array('title'=>_('Debug'),'body'=>$msg,'type'=>'debug')); -} - -/** - * Debug Logging - * - * The global debug level is turned on in your configuration file by setting: - * - * $config->custom->debug['level'] = 255; - * - * together with atleast one output direction (currently file and syslog are supported). - * - * $config->custom->debug['file'] = '/tmp/app_debug.log'; - * $config->custom->debug['syslog'] = true; - * - * - * The debug level is turned into binary, then if the message levels bit is on - * the message will be sent to the debug log. (Thus setting your debug level to 255, - * all bits on, will results in all messages being printed.) - * - * The message level bits are defined here. - * 0( 1) = Entry/Return results from function calls. - * 1( 2) = Configuration Processing - * 2( 4) = Template Processing - * 3( 8) = Schema Processing - * 4( 16) = LDAP Server Communication - * 5( 32) = Tree Processing - * 7( 64) = Other non generic messages - * 8(128) = Page Processing - * 9(256) = Hooks Processing - * @param string Message to send to syslog - * @param int Log bit number for this message. - * @see syslog.php - */ -function debug_log($msg,$level,$indent) { - static $debug_file; - - # In case we are called before we are fully initialised or if debugging is not set. - if (! isset($_SESSION[APPCONFIG]) - || ! ($_SESSION[APPCONFIG]->getValue('debug','file') || $_SESSION[APPCONFIG]->getValue('debug','syslog'))) - return; - - $debug_level = $_SESSION[APPCONFIG]->getValue('debug','level'); - if (! $debug_level || (! ($level & $debug_level))) - return; - - if ($_SESSION[APPCONFIG]->getValue('debug','addr')) - if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] == $_SESSION[APPCONFIG]->getValue('debug','addr')) - $debugaddr = true; - elseif ($_SERVER['REMOTE_ADDR'] == $_SESSION[APPCONFIG]->getValue('debug','addr')) - $debugaddr = true; - else - $debugaddr = false; - - else - $debugaddr = true; - - if (! $debugaddr) - return; - - # If we are limiting debug to a browser, then check that - $caller = basename($_SERVER['PHP_SELF']); - - $args = func_get_args(); - # Discard our first three arguments. - array_shift($args); - array_shift($args); - array_shift($args); - - # Pull the file/line/method - if (is_string($args[0]) && preg_match('/.php$/',$args[0])) { - $file = preg_replace('/.php$/','',array_shift($args)); - $line = array_shift($args); - $method = array_shift($args); - - } else { - $file = 'UNKNOWN'; - $line = 'UNKNOWN'; - $method = 'UNKNOWN'; - } - - # TEMP: New debuglog format - if (preg_match('/%%/',$msg) && $args[0] != 'NOARGS') - $args = array_shift($args); - - $fargs = array(); - foreach ($args as $key) { - if (is_array($key)) - array_push($fargs,serialize($key)); - elseif (is_object($key)) - array_push($fargs,sprintf('OBJECT:%s',get_class($key))); - else - array_push($fargs,$key); - } - - if (preg_match('/%%/',$msg)) - $msg = preg_replace('/%%/',join('|',$fargs),$msg); - else - $msg = vsprintf($msg,array_values($fargs)); - - if (function_exists('stopwatch')) - $timer = stopwatch(); - else - $timer = null; - - $debug_message = sprintf('[%2.3f] %15s(%04s-%03s): %s%s: %s',$timer,basename($file),$line,$level,str_repeat('.',$indent),$method,substr($msg,0,200)); - - if ($debug_file || $_SESSION[APPCONFIG]->getValue('debug','file')) { - if (! $debug_file) - $debug_file = fopen($_SESSION[APPCONFIG]->getValue('debug','file'), - $_SESSION[APPCONFIG]->getValue('debug','append') ? 'a' : 'w'); - - fwrite($debug_file,$debug_message."\n"); - } - - if ($_SESSION[APPCONFIG]->getValue('debug','syslog') && function_exists('syslog_notice')) - syslog_notice($debug_message); -} - -/** - * Display an error message in the system message panel of the page. - */ -function error($msg,$type='note',$redirect=null,$fatal=false,$backtrace=false) { - global $www; - static $counter; - - # Just a check to see that we are called right. - if (! isset($www['page']) && ! $fatal) - die("Function error called incorrectly [$msg]"); - - # If the error is fatal, we'll need to stop here. - if (! isset($www['page'])) - $www['page'] = new page(); - - if ($fatal) - $www['page']->setsysmsg(array('title'=>_('Error'),'body'=>$msg,'type'=>$type)); - else - system_message(array('title'=>_('Error'),'body'=>$msg,'type'=>$type),$redirect); - - # Spin loop detection - if ($counter++ > 20) { - debug_dump('Spin loop detection.'); - debug_dump(array('msg'=>$msg,'session'=>$_SESSION['sysmsg'],'www'=>$www),1); - } - - # Do we have a backtrace to display? - if ($backtrace) { - $backtraceblock = new block(); - $backtraceblock->SetTitle('PHP Debug Backtrace'); - - $body = ''; - $body .= "\n"; - - foreach (debug_backtrace() as $error => $line) { - $_SESSION['backtrace'][$error]['file'] = isset($line['file']) ? $line['file'] : 'unknown'; - $_SESSION['backtrace'][$error]['line'] = isset($line['line']) ? $line['line'] : 'unknown'; - $body .= sprintf('', - _('File'),isset($line['file']) ? $line['file'] : $last['file'],isset($line['line']) ? $line['line'] : ''); - - $_SESSION['backtrace'][$error]['function'] = $line['function']; - $body .= sprintf(''; - $body .= "\n"; - - if (isset($line['file'])) - $last['file'] = $line['file']; - } - - $body .= '
%s%s (%s)
 %s%s', - _('Function'),$line['function']); - - if (isset($line['args'])) { - $display = strlen(serialize($line['args'])) < 50 ? htmlspecialchars(serialize($line['args'])) : htmlspecialchars(substr(serialize($line['args']),0,50)).'...'; - $_SESSION['backtrace'][$error]['args'] = $line['args']; - if (file_exists(LIBDIR.'../tools/unserialize.php')) - $body .= sprintf(' (%s)', - '../tools/unserialize.php',$error,$display); - else - $body .= sprintf(' (%s)',$display); - } - $body .= '
'; - $body .= "\n"; - $backtraceblock->SetBody($body); - - $www['page']->block_add('body',$backtraceblock); - } - - if ($fatal) { - $www['page']->display(array('tree'=>false)); - die(); - } -} - -/** - * Return the result of a form variable, with optional default - * - * @return The form GET/REQUEST/SESSION/POST variable value or its default - */ -function get_request($attr,$type='POST',$die=false,$default=null,$preventXSS=true) { - switch($type) { - case 'GET': - $value = isset($_GET[$attr]) ? (is_array($_GET[$attr]) ? $_GET[$attr] : (empty($_GET['nodecode'][$attr]) ? rawurldecode($_GET[$attr]) : $_GET[$attr])) : $default; - break; - - case 'REQUEST': - $value = isset($_REQUEST[$attr]) ? (is_array($_REQUEST[$attr]) ? $_REQUEST[$attr] : (empty($_REQUEST['nodecode'][$attr]) ? rawurldecode($_REQUEST[$attr]) : $_REQUEST[$attr])) : $default; - break; - - case 'SESSION': - $value = isset($_SESSION[$attr]) ? (is_array($_SESSION[$attr]) ? $_SESSION[$attr] : (empty($_SESSION['nodecode'][$attr]) ? rawurldecode($_SESSION[$attr]) : $_SESSION[$attr])) : $default; - break; - - case 'POST': - default: - $value = isset($_POST[$attr]) ? (is_array($_POST[$attr]) ? $_POST[$attr] : (empty($_POST['nodecode'][$attr]) ? rawurldecode($_POST[$attr]) : $_POST[$attr])) : $default; - break; - } - - if ($die && is_null($value)) - system_message(array( - 'title'=>_('Generic Error'), - 'body'=>sprintf('%s: Called "%s" without "%s" using "%s"', - basename($_SERVER['PHP_SELF']),get_request('cmd','REQUEST'),preventXSS($attr),preventXSS($type)), - 'type'=>'error'), - 'index.php'); - if($preventXSS && !is_null($value)) - $value = preventXSS($value); - return $value; -} -/** -* Prevent XSS function. This function can usage has preventXSS(get_request('cmd','REQUEST')) -* Return valor escape XSS. -*/ - function preventXSS($data){ - if (gettype($data) == 'array') { - foreach ($data as $key => $value) { - if (gettype($value) == 'array') - $data[$key] = preventXSS($value); - else - $data[$key] = htmlspecialchars($value); - } - return $data; - } - return htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); -} - -/* - * Record a system message. - * This function can be used as an alternative to generate a system message, if page hasnt yet been defined. - */ -function system_message($msg,$redirect=null) { - if (! is_array($msg)) - return null; - - if (! isset($msg['title']) && ! isset($msg['body'])) - return null; - - if (! isset($msg['type'])) - $msg['type'] = 'info'; - - if (! isset($_SESSION['sysmsg']) || ! is_array($_SESSION['sysmsg'])) - $_SESSION['sysmsg'] = array(); - - # Try and detect if we are in a redirect loop - if (get_request('redirect','GET') && $msg['type'] != 'debug') { - foreach ($_SESSION['sysmsg'] as $detail) { - if ($msg == $detail && ! isset($detail['special'])) { - debug_dump(array('Incoming MSG'=>$msg,'existing'=>$_SESSION['sysmsg'])); - debug_dump_backtrace('Redirect Loop Detected',true); - } - } - } - - array_push($_SESSION['sysmsg'],$msg); - - if ($redirect) { - if (preg_match('/\?/',$redirect)) - $redirect .= '&'; - else - $redirect .= '?'; - $redirect .= 'redirect=true'; - - # Check if we were an ajax request, and only render the ajax message - if (get_request('meth','REQUEST') == 'ajax') - $redirect .= '&meth=ajax'; - - header("Location: $redirect"); - die(); - } -} - -/** - * Other Functions - */ - -/** - * String padding - * - * @param string Input string - * @param integer Length of the result - * @param string The filling string - * @param integer Padding mode - * @return string The padded string - */ -function full_str_pad($input,$pad_length,$pad_string='',$pad_type=0) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $str = ''; - $length = $pad_length - strlen($input); - - if ($length > 0) { // str_repeat doesn't like negatives - if ($pad_type == STR_PAD_RIGHT) { // STR_PAD_RIGHT == 1 - $str = $input.str_repeat($pad_string, $length); - } elseif ($pad_type == STR_PAD_BOTH) { // STR_PAD_BOTH == 2 - $str = str_repeat($pad_string, floor($length/2)); - $str .= $input; - $str .= str_repeat($pad_string, ceil($length/2)); - } else { // defaults to STR_PAD_LEFT == 0 - $str = str_repeat($pad_string, $length).$input; - } - - } else { // if $length is negative or zero we don't need to do anything - $str = $input; - } - return $str; -} - -/** - * Returns the cached array of LDAP resources. - * - * Note that internally, this function utilizes a two-layer cache, - * one in memory using a static variable for multiple calls within - * the same page load, and one in a session for multiple calls within - * the same user session (spanning multiple page loads). - * - * @return Returns the cached attributed requested, - * or null if there is nothing cached.. - */ -function get_cached_item($index,$item,$subitem='null') { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Set default return - $return = null; - - # Check config to make sure session-based caching is enabled. - if ($_SESSION[APPCONFIG]->getValue('cache',$item) && isset($_SESSION['cache'][$index][$item][$subitem])) - $return = $_SESSION['cache'][$index][$item][$subitem]; - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * Caches the specified $item for the specified $index. - * - * Returns true on success of false on failure. - */ -function set_cached_item($index,$item,$subitem='null',$data) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Check config to make sure session-based caching is enabled. - if ($_SESSION[APPCONFIG]->getValue('cache',$item)) { - global $CACHE; - - $CACHE[$index][$item][$subitem] = $data; - $_SESSION['cache'][$index][$item][$subitem] = $data; - - return true; - - } else - return false; -} - -/** - * Deletes the cache for a specified $item for the specified $index - */ -function del_cached_item($index,$item,$subitem='null') { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - global $CACHE; - - # Check config to make sure session-based caching is enabled. - if (isset($_SESSION['cache'][$index][$item][$subitem])) - unset($_SESSION['cache'][$index][$item][$subitem]); - - if (isset($CACHE[$index][$item][$subitem])) - unset($CACHE[$index][$item][$subitem]); -} - -/** - * Utility wrapper for setting cookies, which takes into consideration - * application configuration values. On success, true is returned. On - * failure, false is returned. - * - * @param string The name of the cookie to set. - * @param string The value of the cookie to set. - * @param int (optional) The duration in seconds of this cookie. If unspecified, $cookie_time is used from config.php - * @param string (optional) The directory value of this cookie (see php.net/setcookie) - * @return boolean - */ -function set_cookie($name,$val,$expire=null,$dir=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Set default return - $return = false; - - if ($expire == null) { - $cookie_time = $_SESSION[APPCONFIG]->getValue('session','cookie_time'); - $expire = $cookie_time == 0 ? null : time() + $cookie_time; - } - - if ($dir == null) - $dir = dirname($_SERVER['PHP_SELF']); - - if (@setcookie($name,$val,$expire,$dir)) { - $_COOKIE[$name] = $val; - $return = true; - } - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * Get a customized file for a server - * We don't need any caching, because it's done by PHP - * - * @param int The ID of the server - * @param string The requested filename - * - * @return string The customized filename, if exists, or the standard one - */ -function get_custom_file($index,$filename,$path) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Set default return - $return = $path.$filename; - $server = $_SESSION[APPCONFIG]->getServer($index); - - $custom = $server->getValue('custom','pages_prefix'); - if (! is_null($custom) && is_file(realpath($path.$custom.$filename))) - $return = $path.$custom.$filename; - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * Replacement for create_function() which is deprecated as of php 7.2 - * - * @param string The function arguments - * @param string The function code - */ -function pla_create_function($args, $code) { - if (version_compare(phpversion(),'7.0','>=')) { - # anonymous functions were introduced in PHP 5.3.0 - return eval("return function(".$args."){".$code."};"); - - } else { - # create_function is deprecated in php 7.2 - return create_function($args, $code); - } -} - -/** - * Sort a multi dimensional array. - * - * @param array Multi demension array passed by reference - * @param string Comma delimited string of sort keys. - * @param boolean Whether to reverse sort. - * @return array Sorted multi demension array. - */ -function masort(&$data,$sortby,$rev=0) { - if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # if the array to sort is null or empty, or if we have some nasty chars - if (! preg_match('/^[a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\))?$/',$sortby) || ! $data) - return; - - static $CACHE = array(); - - if (empty($CACHE[$sortby])) { - $code = "\$c=0;\n"; - - foreach (explode(',',$sortby) as $key) { - $code .= "if (is_object(\$a) || is_object(\$b)) {\n"; - - $code .= " if (is_array(\$a->$key)) {\n"; - $code .= " asort(\$a->$key);\n"; - $code .= " \$aa = array_shift(\$a->$key);\n"; - $code .= " } else\n"; - $code .= " \$aa = \$a->$key;\n"; - - $code .= " if (is_array(\$b->$key)) {\n"; - $code .= " asort(\$b->$key);\n"; - $code .= " \$bb = array_shift(\$b->$key);\n"; - $code .= " } else\n"; - $code .= " \$bb = \$b->$key;\n"; - - $code .= " if (\$aa != \$bb)"; - if ($rev) - $code .= " return (\$aa < \$bb ? 1 : -1);\n"; - else - $code .= " return (\$aa > \$bb ? 1 : -1);\n"; - - $code .= "} else {\n"; - - $code .= " \$a = array_change_key_case(\$a);\n"; - $code .= " \$b = array_change_key_case(\$b);\n"; - - $key = strtolower($key); - - $code .= " if ((! isset(\$a['$key'])) && isset(\$b['$key'])) return 1;\n"; - $code .= " if (isset(\$a['$key']) && (! isset(\$b['$key']))) return -1;\n"; - - $code .= " if ((isset(\$a['$key'])) && (isset(\$b['$key']))) {\n"; - $code .= " if (is_array(\$a['$key'])) {\n"; - $code .= " asort(\$a['$key']);\n"; - $code .= " \$aa = array_shift(\$a['$key']);\n"; - $code .= " } else\n"; - $code .= " \$aa = \$a['$key'];\n"; - - $code .= " if (is_array(\$b['$key'])) {\n"; - $code .= " asort(\$b['$key']);\n"; - $code .= " \$bb = array_shift(\$b['$key']);\n"; - $code .= " } else\n"; - $code .= " \$bb = \$b['$key'];\n"; - - $code .= " if (\$aa != \$bb)\n"; - $code .= " if (is_numeric(\$aa) && is_numeric(\$bb)) {\n"; - - if ($rev) - $code .= " return (\$aa < \$bb ? 1 : -1);\n"; - else - $code .= " return (\$aa > \$bb ? 1 : -1);\n"; - - $code .= " } else {\n"; - - if ($rev) - $code .= " if ( (\$c = strcasecmp(\$bb,\$aa)) != 0 ) return \$c;\n"; - else - $code .= " if ( (\$c = strcasecmp(\$aa,\$bb)) != 0 ) return \$c;\n"; - - $code .= " }\n"; - $code .= " }\n"; - $code .= "}\n"; - } - - $code .= 'return $c;'; - - $CACHE[$sortby] = pla_create_function('$a, $b',$code); - } - - uasort($data,$CACHE[$sortby]); -} - -/** - * Is compression enabled for output - */ -function isCompress() { - return (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','compress') - && ! ini_get('zlib.output_compression') - && preg_match('/gzip/',$_SERVER['HTTP_ACCEPT_ENCODING'])); -} - -/** - * PLA specific Functions - */ - -/** - * Returns an HTML-beautified version of a DN. - * Internally, this function makes use of pla_explode_dn() to break the - * the DN into its components. It then glues them back together with - * "pretty" HTML. The returned HTML is NOT to be used as a real DN, but - * simply displayed. - * - * @param string The DN to pretty-print. - * @return string - */ -function pretty_print_dn($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $dn_save = $dn; - $dn = pla_explode_dn($dn); - - if (! $dn) - return $dn_save; - - foreach ($dn as $i => $element) { - $element = htmlspecialchars($element); - $element = explode('=',$element,2); - $element = implode('=',$element); - $dn[$i] = $element; - } - - $dn = implode(',',$dn); - - return $dn; -} - -/** - * Given a string, this function returns true if the string has the format - * of a DN (ie, looks like "cn=Foo,dc=example,dc=com"). Returns false otherwise. - * The purpose of this function is so that developers can examine a string and - * know if it looks like a DN, and draw a hyperlink as needed. - * - * (See unit_test.php for test cases) - * - * @param string The attribute to examine for "DNness" - * @return boolean - */ -function is_dn_string($str) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - /* Try to break the string into its component parts if it can be done - ie, "uid=Manager" "dc=example" and "dc=com" */ - $parts = pla_explode_dn($str); - if (! is_array($parts) || ! count($parts)) - return false; - - /* Foreach of the "parts", look for an "=" character, - and make sure neither the left nor the right is empty */ - foreach ($parts as $part) { - if (! strpos($part,"=")) - return false; - - $sub_parts = explode('=',$part,2); - $left = $sub_parts[0]; - $right = $sub_parts[1]; - - if ( ! strlen(trim($left)) || ! strlen(trim($right))) - return false; - - if (strpos($left,'#') !== false) - return false; - } - - # We survived the above rigor. This is a bonified DN string. - return true; -} - -/** - * Get whether a string looks like an email address (user@example.com). - * - * @param string The string to analyze. - * @return boolean Returns true if the specified string looks like an email address or false otherwise. - */ -function is_mail_string($str) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $mail_regex = "/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/"; - - if (preg_match($mail_regex,$str)) - return true; - else - return false; -} - -/** - * Get whether a string looks like a web URL (http://www.example.com/) - * - * @param string The string to analyze. - * @return boolean Returns true if the specified string looks like a web URL or false otherwise. - */ -function is_url_string($str) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $url_regex = '/^(ftp|https?):\/\/+[\w\.\-\/\?\=\&]*\w+/'; - - if (preg_match($url_regex,$str)) - return true; - else - return false; -} - -/** - * Compares 2 DNs. If they are equivelant, returns 0, otherwise, - * returns their sorting order (similar to strcmp()): - * Returns < 0 if dn1 is less than dn2. - * Returns > 0 if dn1 is greater than dn2. - * - * The comparison is performed starting with the top-most element - * of the DN. Thus, the following list: - * - * ou=people,dc=example,dc=com - * cn=Admin,ou=People,dc=example,dc=com - * cn=Joe,ou=people,dc=example,dc=com - * dc=example,dc=com - * cn=Fred,ou=people,dc=example,dc=org - * cn=Dave,ou=people,dc=example,dc=org - * - * Will be sorted thus using usort( $list, "pla_compare_dns" ): - * - * dc=com - * dc=example,dc=com - * ou=people,dc=example,dc=com - * cn=Admin,ou=People,dc=example,dc=com - * cn=Joe,ou=people,dc=example,dc=com - * cn=Dave,ou=people,dc=example,dc=org - * cn=Fred,ou=people,dc=example,dc=org - * - * - * @param string The first of two DNs to compare - * @param string The second of two DNs to compare - * @return int - */ -function pla_compare_dns($dn1,$dn2) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # If pla_compare_dns is passed via a tree, then we'll just get the DN part. - if (is_array($dn1)) - if (isset($dn1['dn'])) - $dn1 = $dn1['dn']; - else - $dn1 = implode('+',$dn1); - if (is_array($dn2)) - if (isset($dn2['dn'])) - $dn2 = $dn2['dn']; - else - $dn2 = implode('+',$dn2); - - # If they are obviously the same, return immediately - if (! strcasecmp($dn1,$dn2)) - return 0; - - $dn1_parts = pla_explode_dn(pla_reverse_dn($dn1)); - $dn2_parts = pla_explode_dn(pla_reverse_dn($dn2)); - assert(is_array($dn1_parts)); - assert(is_array($dn2_parts)); - - # Foreach of the "parts" of the smaller DN - for ($i=0; $i < count($dn1_parts) && $i < count($dn2_parts); $i++) { - /* dnX_part is of the form: "cn=joe" or "cn = joe" or "dc=example" - ie, one part of a multi-part DN. */ - $dn1_part = $dn1_parts[$i]; - $dn2_part = $dn2_parts[$i]; - - /* Each "part" consists of two sub-parts: - 1. the attribute (ie, "cn" or "o") - 2. the value (ie, "joe" or "example") */ - $dn1_sub_parts = explode('=',$dn1_part,2); - $dn2_sub_parts = explode('=',$dn2_part,2); - - $dn1_sub_part_attr = trim($dn1_sub_parts[0]); - $dn2_sub_part_attr = trim($dn2_sub_parts[0]); - - if (0 != ($cmp = strcasecmp($dn1_sub_part_attr,$dn2_sub_part_attr))) - return $cmp; - - $dn1_sub_part_val = trim($dn1_sub_parts[1]); - $dn2_sub_part_val = trim($dn2_sub_parts[1]); - if (0 != ($cmp = strcasecmp($dn1_sub_part_val,$dn2_sub_part_val))) - return $cmp; - } - - /* If we iterated through all entries in the smaller of the two DNs - (ie, the one with fewer parts), and the entries are different sized, - then, the smaller of the two must be "less than" than the larger. */ - if (count($dn1_parts) > count($dn2_parts)) { - return 1; - - } elseif (count($dn2_parts) > count($dn1_parts)) { - return -1; - - } else { - return 0; - } -} - -/** - * For LDAP servers with auto_number enabled, this function will get the next - * available number using the host's preferred mechanism (pool or search). - * - * This is configured in config.php by server: - * - * - * $servers->setValue('auto_number','enable',true|false); - * - * - * The available mechanisms are: - * pool: - * The pool mechanism uses a user-configured entry in the LDAP server to - * store the last used "number". This mechanism simply fetches and increments - * and returns that value. - * - * search: - * The search mechanism will search the LDAP server that has the attribute - * set. It will then find the smallest value and "fills in the gaps" by - * incrementing the smallest attribute until an unused value is found. - * - * NOTE: Both mechanisms do NOT prevent race conditions or toe-stomping, so - * care must be taken when actually creating the entry to check that the number - * returned here has not been used in the mean time. Note that the two different - * mechanisms may (will!) return different values as they use different algorithms - * to arrive at their result. Do not be alarmed if (when!) this is the case. - * - * See config.php.example for more notes on the two mechanisms. - * - * @param string Base to start the search from - * @param string Attribute to query - * @param boolean Increment the result (for pool searches) - * @param string LDAP filter to use (for pool searches) - * @return int - */ -function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); - $attr = strtolower($attr); - $query = array(); - - if (! $server->getValue('auto_number','enable')) { - system_message(array( - 'title'=>_('AUTO_NUMBER is disabled for this server'), - 'body'=>sprintf('%s (%s)',_('A call was made to get_next_number(), however, it is disabled for this server'),$attr), - 'type'=>'warn')); - - return false; - } - - # Check see and use our alternate uid_dn and password if we have it. - if (! $server->login($server->getValue('auto_number','dn'),$server->getValue('auto_number','pass'),'auto_number')) { - system_message(array( - 'title'=>_('AUTO_NUMBER invalid login/password'), - 'body'=>sprintf('%s (%s)',_('Unable to connect to LDAP server with the auto_number login/password, please check your configuration.'), - $server->getName()), - 'type'=>'warn')); - - return false; - } - - # Some error checking - if (! $base) { - $query['base'] = $server->getValue('auto_number','search_base'); - - if (! trim($query['base'])) { - system_message(array( - 'title'=>_('No AUTO_NUMBER search_base configured for this server'), - 'body'=>_('A call was made to get_next_number(), however, the base to search is empty.'), - 'type'=>'warn')); - - return false; - } - - } else - $query['base'] = $base; - - if (! $server->dnExists($query['base'])) { - system_message(array( - 'title'=>_('No AUTO_NUMBER search_base exists for this server'), - 'body'=>sprintf('%s (%s)',_('A call was made to get_next_number(), however, the base to search does not exist for this server.'),$query['base']), - 'type'=>'warn')); - - return false; - } - - if (! is_string($attr) || ! $server->getSchemaAttribute($attr)) { - system_message(array( - 'title'=>_('AUTO_NUMBER search attribute invalid'), - 'body'=>sprintf('%s (%s)',_('The search attribute for AUTO_NUMBER is invalid, expecting a single valid attribute.'),$attr), - 'type'=>'warn')); - - return false; - } - - $query['attrs'] = array($attr); - - # Based on the configured mechanism, go get the next available uidNumber! - switch ($server->getValue('auto_number','mechanism')) { - case 'search': - $query['filter'] = sprintf('(%s=*)',$attr); - $search = $server->query($query,'auto_number'); - - # Construct a list of used numbers - $autonum = array(0); - - foreach ($search as $dn => $values) { - $values = array_change_key_case($values); - foreach ($values[$attr] as $value) - array_push($autonum,$value); - } - - $autonum = array_unique($autonum); - sort($autonum); - - # Start with the least existing autoNumber and add 1 - $minNumber = is_null($startmin) ? intval($autonum[0])+1 : $startmin; - - # Override our minNumber by the configuration if it exists. - if (count($server->getValue('auto_number','min'))) { - $min = array_change_key_case($server->getValue('auto_number','min')); - - if (isset($min[$attr])) - $minNumber = $min[$attr] > $minNumber ? $min[$attr] : $minNumber; - } - - for ($i=0;$i $num+1) - return $autonum[$i] >= $num ? $num+1 : $num; - } - - # If we didnt find a suitable gap and are all above the minNumber, we'll just return the $minNumber - return $minNumber; - - break; - - case 'pool': - switch ($attr) { - case 'gidnumber': - $query['filter'] = '(objectClass=gidPool)'; - - break; - - case 'uidnumber': - $query['filter'] = '(objectClass=uidPool)'; - - break; - } - - # If we are called with a filter, we'll use the one from the configuration. - if (! empty($filter)) - $query['filter'] = $filter; - - $search = $server->query($query,'auto_number'); - - switch (count($search)) { - case '1': - break; - - case '0': - system_message(array( - 'title'=>_('AUTO_NUMBER pool filter didnt return any DNs'), - 'body'=>sprintf('%s (%s)',_('Please change your filter parameter, or check your auto_number,search_base configuration'),$query['filter']), - 'type'=>'warn')); - - return false; - - default: - system_message(array( - 'title'=>_('AUTO_NUMBER pool filter returned too many DNs'), - 'body'=>sprintf('%s (%s)',_('Please change your filter parameter, or check your auto_number,search_base configuration'),$query['filter']), - 'type'=>'warn')); - - return false; - } - - # This should only iterate once. - foreach ($search as $dn => $values) { - $values = array_change_key_case($values); - - $autonum = $values[$attr][0]; - $poolDN = $values['dn']; - } - - if ($increment) { - $updatedattr = array($attr=>$autonum+1); - $server->modify($poolDN,$updatedattr); - } - - return $autonum; - - # No other cases allowed. The user has an error in the configuration - default: - system_message(array( - 'title'=>_('Invalid AUTO_NUMBER mechanism'), - 'body'=>sprintf('%s (%s)',_('Your config file specifies an unknown AUTO_NUMBER search mechanism.'),$server->getValue('auto_number','mechanism')), - 'type'=>'warn')); - - return false; - } -} - -/** - * Given a DN and server ID, this function reads the DN's objectClasses and - * determines which icon best represents the entry. The results of this query - * are cached in a session variable so it is not run every time the tree - * browser changes, just when exposing new DNs that were not displayed - * previously. That means we can afford a little bit of inefficiency here - * in favor of coolness. :) - * - * This function returns a string like "country.png". All icon files are assumed - * to be contained in the /images/ directory of phpLDAPadmin. - * - * Developers are encouraged to add new icons to the images directory and modify - * this function as needed to suit their types of LDAP entries. If the modifications - * are general to an LDAP audience, the phpLDAPadmin team will gladly accept them - * as a patch. - * - * @param string The DN of the entry whose icon you wish to fetch. - * @return string - */ -function get_icon($server_id,$dn,$object_classes=array()) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $_SESSION[APPCONFIG]->getServer($server_id); - - # Fetch and lowercase all the objectClasses in an array - if (! count($object_classes)) - $object_classes = $server->getDNAttrValue($dn,'objectClass'); - - foreach ($object_classes as $index => $value) - $object_classes[$index] = strtolower($value); - - $rdn = get_rdn($dn); - $rdn_parts = explode('=',$rdn,2); - $rdn_value = isset($rdn_parts[0]) ? $rdn_parts[0] : null; - $rdn_attr = isset($rdn_parts[1]) ? $rdn_parts[1] : null; - unset($rdn_parts); - - # Return icon filename based upon objectClass value - if (in_array('sambaaccount',$object_classes) && - '$' == $rdn[ strlen($rdn) - 1 ]) - return 'nt_machine.png'; - - if (in_array('sambaaccount',$object_classes)) - return 'nt_user.png'; - - elseif (in_array('organizationalrole',$object_classes)) - return 'ldap-uid.png'; - - elseif (in_array('jammvirtualdomain',$object_classes)) - return 'mail.png'; - - elseif (in_array('locality',$object_classes)) - return 'locality.png'; - - elseif (in_array('applicationprocess',$object_classes)) - return 'process.png'; - - elseif (in_array('groupofuniquenames',$object_classes)) - return 'ldap-uniquegroup.png'; - - elseif (in_array('nlsproductcontainer',$object_classes)) - return 'n.png'; - - elseif (in_array('ndspkikeymaterial',$object_classes)) - return 'lock.png'; - - elseif (in_array('volume',$object_classes)) - return 'hard-drive.png'; - - elseif (in_array('ndscatcatalog',$object_classes)) - return 'catalog.png'; - - elseif (in_array('resource',$object_classes)) - return 'n.png'; - - elseif (in_array('ldapgroup',$object_classes)) - return 'ldap-server.png'; - - elseif (in_array('ldapserver',$object_classes)) - return 'ldap-server.png'; - - elseif (in_array('nisserver',$object_classes)) - return 'ldap-server.png'; - - elseif (in_array('rbscollection',$object_classes)) - return 'ldap-ou.png'; - - elseif (in_array('dfsconfiguration',$object_classes)) - return 'nt_machine.png'; - - elseif (in_array('applicationsettings',$object_classes)) - return 'server-settings.png'; - - elseif (in_array('aspenalias',$object_classes)) - return 'mail.png'; - - elseif (in_array('container',$object_classes)) - return 'folder.png'; - - elseif (in_array('ipnetwork',$object_classes)) - return 'network.png'; - - elseif (in_array('samserver',$object_classes)) - return 'server-small.png'; - - elseif (in_array('lostandfound',$object_classes)) - return 'find.png'; - - elseif (in_array('infrastructureupdate',$object_classes)) - return 'server-small.png'; - - elseif (in_array('filelinktracking',$object_classes)) - return 'files.png'; - - elseif (in_array('automountmap',$object_classes) || - in_array('automount',$object_classes)) - - return 'hard-drive.png'; - - elseif (strpos($rdn_value,'ipsec') === 0 || - strcasecmp($rdn_value,'IP Security') == 0|| - strcasecmp($rdn_value,'MSRADIUSPRIVKEY Secret') == 0 || - strpos($rdn_value,'BCKUPKEY_') === 0) - - return 'lock.png'; - - elseif (strcasecmp($rdn_value,'MicrosoftDNS') == 0) - return 'ldap-dc.png'; - - # Oh well, I don't know what it is. Use a generic icon. - else - return 'ldap-default.png'; -} - -/** - * Appends a servers base to a "sub" dn or returns the base. - * - * @param string The baseDN to be added if the DN is relative - * @param string The DN to be made absolute - * @return string|null Returns null if both base is null and sub_dn is null or empty - */ -function expand_dn_with_base($base,$sub_dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $empty_str = (is_null($sub_dn) || (($len=strlen(trim($sub_dn))) == 0)); - - if ($empty_str) - return $base; - - # If we have a string which doesn't need a base - elseif ($sub_dn[$len-1] != ',') - return $sub_dn; - - else - return sprintf('%s%s',$sub_dn,$base); -} - -/** - * Split an RDN into its attributes - */ -function rdn_explode($rdn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - # Setup to work out our RDN. - $rdnarray = explode('\+',$rdn); - - # Capture items that have +, but are not an attribute - foreach ($rdnarray as $index => $val) { - if (preg_match('/=/',$val)) - $validindex = $index; - - if (! preg_match('/=/',$val)) { - $rdnarray[$validindex] .= '+'.$val; - unset($rdnarray[$index]); - } - } - - return $rdnarray; -} - -/** - * Given an LDAP error number, returns a verbose description of the error. - * This function parses ldap_error_codes.txt and looks up the specified - * ldap error number, and returns the verbose message defined in that file. - * - * - * Array ( - * [title] => "Invalid Credentials" - * [description] => "An invalid username and/or password was supplied to the LDAP server." - * ) - * - * - * @param string The hex error number (ie, "0x42") of the LDAP error of interest. - * @return array An associative array contianing the error title and description like so: - */ -function pla_verbose_error($key) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - static $CACHE = array(); - - if (! count($CACHE)) { - $source_file = LIBDIR.'ldap_error_codes.txt'; - - if (! file_exists($source_file) || ! is_readable($source_file) || ! ($f = fopen($source_file,'r'))) - return false; - - $contents = fread($f,filesize($source_file)); - fclose($f); - $entries = array(); - preg_match_all("/0x[A-Fa-f0-9][A-Za-z0-9]\s+[0-9A-Za-z_]+\s+\"[^\"]*\"\n/", - $contents,$entries); - - foreach ($entries[0] as $values) { - $entry = array(); - preg_match("/(0x[A-Za-z0-9][A-Za-z0-9])\s+([0-9A-Za-z_]+)\s+\"([^\"]*)\"/",$values,$entry); - - $hex_code = isset($entry[1]) ? $entry[1] : null; - $title = isset($entry[2]) ? $entry[2] : null; - $desc = isset($entry[3]) ? $entry[3] : null; - $desc = preg_replace('/\s+/',' ',$desc); - $CACHE[$hex_code] = array('title'=>$title,'desc'=>$desc); - } - } - - if (isset($CACHE[$key])) - return $CACHE[$key]; - else - return array('title' => null,'desc' => null); -} - -/** - * Print an LDAP error message - */ -function ldap_error_msg($msg,$errnum) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $body = ''; - - $errnum = ('0x'.str_pad(dechex($errnum),2,0,STR_PAD_LEFT)); - $verbose_error = pla_verbose_error($errnum); - - $body .= sprintf('',_('LDAP said'),$msg); - - if ($verbose_error) { - $body .= sprintf('',_('Error number'),$errnum,$verbose_error['title']); - $body .= sprintf('',_('Description'),$verbose_error['desc']); - - } else { - $body .= sprintf('',_('Error number'),$errnum); - $body .= sprintf('',_('Description'),_('no description available')); - } - - $body .= '
%s:%s
%s:%s (%s)
%s:%s
%s:%s
%s:(%s)
'; - - return $body; -} - -/** - * Draw the jpegPhoto image(s) for an entry wrapped in HTML. Many options are available to - * specify how the images are to be displayed. - * - * Usage Examples: - * - * draw_jpeg_photo(0,'cn=Bob,ou=People,dc=example,dc=com',"jpegPhoto",0,true,array('img_opts'=>"border: 1px; width: 150px")); - * draw_jpeg_photo(1,'cn=Fred,ou=People,dc=example,dc=com',null,1); - * - * - * @param object The Server to get the image from. - * @param string The DN of the entry that contains the jpeg attribute you want to draw. - * @param string The name of the attribute containing the jpeg data (usually 'jpegPhoto'). - * @param int Index of the attribute to draw - * @param boolean If true, draws a button beneath the image titled 'Delete' allowing the user - * to delete the jpeg attribute by calling JavaScript function deleteAttribute() provided - * in the default modification template. - * @param array Specifies optional image and CSS style attributes for the table tag. Supported keys are - * fixed_width, fixed_height, img_opts. - */ -function draw_jpeg_photo($server,$dn,$attr_name='jpegphoto',$index,$draw_delete_buttons=false,$options=array()) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $fixed = array(); - $fixed['width'] = isset($options['fixed_width']) ? $options['fixed_width'] : false; - $fixed['height'] = isset($options['fixed_height']) ? $options['fixed_height'] : false; - - if (is_null($server)) - $jpeg_data = $_SESSION['tmp']; - else - $jpeg_data = $server->getDNAttrValues($dn,null,LDAP_DEREF_NEVER,array($attr_name)); - - if (! isset($jpeg_data[$attr_name][$index]) || ! $jpeg_data[$attr_name][$index]) { - system_message(array( - 'title'=>_('Unable to retrieve image'), - 'body'=>sprintf('%s %s', - _('Could not fetch jpeg data for attribute'),$attr_name), - 'type'=>'warn')); - - # This should atleast generate some text that says "Image not available" - printf('Photo',$attr_name); - - return; - } - - $width = 0; - $height = 0; - - if (function_exists('getimagesize')) { - $jpeg_temp_dir = realpath($_SESSION[APPCONFIG]->getValue('jpeg','tmpdir').'/'); - if (! is_writable($jpeg_temp_dir)) - system_message(array( - 'title'=>_('Unable to write to jpeg tmp directory'), - 'body'=>_('Please set jpeg,tmpdir to a writable directory in the phpLDAPadmin config.php'), - 'type'=>'warn')); - - else { - # We have an image to display - $jpeg_filename = tempnam($jpeg_temp_dir.'/','pla'); - $outjpeg = @file_put_contents($jpeg_filename,$jpeg_data[$attr_name][$index]); - - if (! $outjpeg) { - system_message(array( - 'title'=>_('Error writing to jpeg tmp directory'), - 'body'=>sprintf(_('Please check jpeg,tmpdir is a writable directory in the phpLDAPadmin config.php'),$jpeg_temp_dir), - 'type'=>'warn')); - - } elseif ($outjpeg < 6) { - system_message(array( - 'title'=>sprintf('%s %s',$attr_name,_('contains errors')), - 'body'=>_('It appears that the jpeg image may not be a jpeg image'), - 'type'=>'warn')); - - } else { - $jpeg_dimensions = getimagesize($jpeg_filename); - $width = $jpeg_dimensions[0]; - $height = $jpeg_dimensions[1]; - } - - unlink($jpeg_filename); - } - } - - if ($width > 300) { - $scale_factor = 300 / $width; - $img_width = 300; - $img_height = intval($height * $scale_factor); - - } else { - $img_width = $width; - $img_height = $height; - } - - $href = sprintf('view_jpeg_photo.php?dn=%s&index=%s&attr=%s',rawurlencode($dn),$index,$attr_name); - - printf('',number_format($outjpeg),_('bytes'),$width,$height,_('pixels')); - - printf('Photo', - htmlspecialchars($href), - is_null($server) ? 'location=session' : sprintf('server_id=%s',$server->getIndex()), - (! $img_width || $fixed['width'] ? '' : sprintf('width="%s"',$img_width)), - (! $img_height || $fixed['height'] ? '' : sprintf('height="%s"',$img_height)), - (isset($options['img_opts']) ? $options['img_opts'] : '')); - - echo ''; - - if ($draw_delete_buttons) - # - printf('
%s', - $attr_name,_('Delete photo')); -} - -/** - * Draws an HTML browse button which, when clicked, pops up a DN chooser dialog. - * @param string The name of the form element to which this chooser - * dialog will publish the user's choice. The form element must be a member - * of a form with the "name" or "id" attribute set in the form tag, and the element - * must also define "name" or "id" for JavaScript to uniquely identify it. - * Example $form_element values may include "creation_form.container" or - * "edit_form.member_uid". See /templates/modification/default.php for example usage. - * @param boolean (optional) If true, the function draws the localized text "choose" to the right of the button. - */ -function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none') { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $href = sprintf("javascript:dnChooserPopup('%s','%s','%s');",$form,$element,$rdn == 'none' ? '' : rawurlencode($rdn)); - $title = _('Click to popup a dialog to select an entry (DN) graphically'); - - printf('Find',$href,$title,IMGDIR); - - if ($include_choose_text) - printf('%s',$href,$title,_('browse')); -} - -/** - * http://php.net/manual/en/function.ldap-explode-dn.php#34724 - * fixed for: - * Keep attention on UTF8 encoded DNs. Since openLDAP >=2.1.2 - * ldap_explode_dn turns unprintable chars (in the ASCII sense, UTF8 - * encoded) into \. - */ -function ldap_explode_dn_patch($dn,$with_attrib) { - $result = ldap_explode_dn($dn,$with_attrib); - if (! $result) - return null; - - # translate hex code into ascii again - foreach ($result as $key => $value) { - $result[$key] = preg_replace_callback( - "/\\\([0-9A-Fa-f]{2})/", - function ($matches) { - return chr(hexdec($matches[1])); - }, - $value - ); - } - - return $result; -} - -/** - * Explode a DN into an array of its RDN parts. - * - * NOTE: When a multivalue RDN is passed to ldap_explode_dn, the results returns with 'value + value'; - * - * - * Array ( - * [0] => uid=ppratt - * [1] => ou=People - * [2] => dc=example - * [3] => dc=com - * ) - * - * - * @param string The DN to explode. - * @param int (optional) Whether to include attribute names (see http://php.net/ldap_explode_dn for details) - * @return array An array of RDN parts of this format: - */ -function pla_explode_dn($dn,$with_attributes=0) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - global $CACHE; - - if (isset($CACHE['explode'][$dn][$with_attributes])) { - if (DEBUG_ENABLED) - debug_log('Return CACHED result (%s) for (%s)',1,0,__FILE__,__LINE__,__METHOD__, - $CACHE['explode'][$dn][$with_attributes],$dn); - - return $CACHE['explode'][$dn][$with_attributes]; - } - - $dn = addcslashes($dn,'<>+";'); - - # split the dn - $result[0] = ldap_explode_dn_patch(dn_escape($dn),0); - $result[1] = ldap_explode_dn_patch(dn_escape($dn),1); - if (! $result[$with_attributes]) { - if (DEBUG_ENABLED) - debug_log('Returning NULL - NO result.',1,0,__FILE__,__LINE__,__METHOD__); - - return array(); - } - - # Remove our count value that ldap_explode_dn returns us. - unset($result[0]['count']); - unset($result[1]['count']); - - # Record the forward and reverse entries in the cache. - foreach ($result as $key => $value) { - # translate hex code into ascii for display - $result[$key] = dn_unescape($value); - - $CACHE['explode'][implode(',',$result[0])][$key] = $result[$key]; - $CACHE['explode'][implode(',',array_reverse($result[0]))][$key] = array_reverse($result[$key]); - } - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$result[$with_attributes]); - - return $result[$with_attributes]; -} - -/** - * Parse a DN and escape any special characters - */ -function dn_escape($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $olddn = $dn; - - # Check if the RDN has a comma and escape it. - while (preg_match('/([^\\\\]),(\s*[^=]*\s*),/',$dn)) - $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/','$1\\\\2C$2,',$dn); - - $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*)([^,])$/','$1\\\\2C$2$3',$dn); - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$dn); - - return $dn; -} - -/** - * Parse a DN and unescape any special characters - */ -function dn_unescape($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (is_array($dn)) { - $a = array(); - - foreach ($dn as $key => $rdn) - $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', - function ($r) { - return chr(hexdec($r[1])); - }, - $rdn - ); - - return $a; - - } else { - return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', - function ($r) { - return chr(hexdec($r[1])); - }, - $dn - ); - } -} - -/** - * Fetches the URL for the specified item. This is a convenience function for - * fetching project HREFs (like bugs) - * - * @param string One of "open_bugs", "add_bug", "donate", or "add_rfe" - * (rfe = request for enhancement) - * @return string The URL to the requested item. - */ -function get_href($type,$extra_info='') { - $pla = 'http://phpldapadmin.sourceforge.net'; - - switch($type) { - case 'add_bug': - return 'https://github.com/leenooks/phpLDAPadmin/issues'; - case 'add_rfe': - return 'https://github.com/leenooks/phpLDAPadmin/issues'; - case 'credits': - return sprintf('%s/Credits',$pla); - case 'documentation': - return sprintf('%s/Documentation',$pla); - case 'donate': - return 'https://sourceforge.net/donate/index.php?group_id=61828'; - case 'forum': - return 'https://stackoverflow.com/questions/tagged/phpldapadmin'; - case 'web': - return sprintf('%s',$pla); - default: - return null; - } -} - -/** - * Returns the current time as a double (including micro-seconds). - * - * @return double The current time in seconds since the beginning of the UNIX epoch (Midnight Jan. 1, 1970) - */ -function utime() { - $time = explode(' ',microtime()); - $usec = (double)$time[0]; - $sec = (double)$time[1]; - return $sec + $usec; -} - -/** - * Converts an array to a query-string with the option to exclude certain variables - * from the returned query string. This is convenient if callers want to convert the - * current GET query string or POST array into a string and replace certain - * variables with their own. - * - * @param array The associate array to convert whose form is such that the keys are the - * names of the variables and the values are said variables' values like this: - * - * Array ( - * [server_id] = 0, - * [dn] = "dc=example,dc=com", - * [attr] = "sn" - * ) - * - * This will produce a string like this: "server_id=0&dn=dc=example,dc=com&attr=sn" - * @param array (optional) An array of variables to exclude in the resulting string - * @return string The string created from the array. - */ -function array_to_query_string($array,$exclude_vars=array()) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (! is_array($array) || ! count($array)) - return ''; - - $str = ''; - $i = 0; - foreach ($array as $name => $val) - if (! in_array($name,$exclude_vars)) - if (is_array($val)) - foreach ($val as $v) { - if ($i++ > 0) - $str .= '&'; - - $str .= sprintf('%s[]=%s',rawurlencode($name),rawurlencode($v)); - } - - else { - if ($i++ > 0) - $str .= '&'; - - $str .= sprintf('%s=%s',rawurlencode($name),rawurlencode($val)); - } - - return $str; -} - -/** - * Reverses a DN such that the top-level RDN is first and the bottom-level RDN is last - * For example: - * - * cn=Brigham,ou=People,dc=example,dc=com - * - * Becomes: - * - * dc=com,dc=example,ou=People,cn=Brigham - * - * This makes it possible to sort lists of DNs such that they are grouped by container. - * - * @param string The DN to reverse - * @return string The reversed DN - * - * @see pla_compare_dns - * @see pla_explode_dns - */ -function pla_reverse_dn($dn) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - return (implode(',',array_reverse(pla_explode_dn($dn)))); -} - -/** - * Reads an array and returns the array values back in lower case - * - * @param array $array The array to convert the values to lowercase. - * @returns array Array with values converted to lowercase. - */ -function arrayLower($array) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (! is_array($array)) - return $array; - - $newarray = array(); - foreach ($array as $key => $value) - $newarray[$key] = strtolower($value); - - return $newarray; -} - -/** - * Checks if a string exists in an array, ignoring case. - * - * @param string What you are looking for - * @param array The array that you think it is in. - * @return boolean True if its there, false if its not. - */ -function in_array_ignore_case($needle,$haystack) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (! is_array($haystack)) - return false; - - if (! is_string($needle)) - return false; - - $return = false; - - foreach ($haystack as $element) { - if (is_string($element) && (strcasecmp($needle,$element) == 0)) { - $return = true; - break; - } - } - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * Gets a DN string using the user-configured tree_display_format string to format it. - */ -function draw_formatted_dn($server,$entry) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $dn = $entry->getDn(); - - $formats = $_SESSION[APPCONFIG]->getValue('appearance','tree_display_format'); - - foreach ($formats as $format) { - $has_none = false; - preg_match_all('/%[a-zA-Z_0-9]+/',$format,$tokens); - $tokens = $tokens[0]; - - if (DEBUG_ENABLED) - debug_log('The tokens are (%s)',1,0,__FILE__,__LINE__,__METHOD__,$tokens); - - foreach ($tokens as $token) { - if (strcasecmp($token,'%dn') == 0) - $format = str_replace($token,pretty_print_dn($dn),$format); - - elseif (strcasecmp($token,'%rdn') == 0) - $format = str_replace($token,pretty_print_dn($entry->getRDN()),$format); - - elseif (strcasecmp($token,'%rdnvalue') == 0) { - $rdn = get_rdn($dn,0,true); - $rdn_value = explode('=',$rdn,2); - $rdn_value = $rdn_value[1]; - $format = str_replace($token,$rdn_value,$format); - - } else { - $attr_name = str_replace('%','',$token); - $attr_values = $server->getDNAttrValue($dn,$attr_name); - - if (is_null($attr_values) || (count($attr_values) <= 0)) { - $display = '<'._('none').'>'; - $has_none = true; - - } elseif (is_array($attr_values)) - $display = implode(', ',$attr_values); - - else - $display = $attr_values; - - $format = str_replace($token,$display,$format); - } - } - - # If this format has all values available, use it. Otherwise, try the next one - if (!$has_none) - return $format; - } - - return $format; -} - -/** - * Server html select list - */ -function server_select_list($selected=null,$logged_on=false,$name='index',$isVisible=true,$js=null) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $count = 0; - $server_menu_html = sprintf(''; - - if ($count > 1) - return $server_menu_html; - - elseif ($count) - return sprintf('%s ', - $selected_server->getName(),$name,$selected_server->getIndex()); - - else - return ''; -} - -/** - * Converts a little-endian hex-number to one, that 'hexdec' can convert - */ -function littleEndian($hex) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $result = ''; - - for ($x=strlen($hex)-2;$x>= 0;$x=$x-2) - $result .= substr($hex,$x,2); - - return $result; -} - -function binSIDtoText($binsid) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $hex_sid = bin2hex($binsid); - $rev = hexdec(substr($hex_sid,0,2)); // Get revision-part of SID - $subcount = hexdec(substr($hex_sid,2,2)); // Get count of sub-auth entries - $auth = hexdec(substr($hex_sid,4,12)); // SECURITY_NT_AUTHORITY - - $result = "$rev-$auth"; - - for ($x=0;$x<$subcount;$x++) { - $subauth[$x] = hexdec(littleEndian(substr($hex_sid,16+($x*8),8))); // get all SECURITY_NT_AUTHORITY - $result .= sprintf('-%s',$subauth[$x]); - } - - return $result; -} - -/** - * Query LDAP and return a hash. - * - * @param string The base DN to use. - * @param string LDAP Query filter. - * @param string LDAP attribute to use as key. - * @param array Attributes to use as values. - * @param boolean Specify false to not sort results by DN - * or true to have the returned array sorted by DN (uses ksort) - * or an array of attribute names to sort by attribute values - * @return array Array of values keyed by $key. - */ -function return_ldap_hash($base,$filter,$key,$attrs,$sort=true) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); - $key = strtolower($key); - - $query = array(); - $query['base'] = $base; - $query['filter'] = $filter; - $query['attrs'] = $attrs; - $search = $server->query($query,null); - - $results = array(); - - foreach ($search as $dn => $values) - if (isset($values[$key])) - if (is_array($values[$key])) - foreach ($values[$key] as $i => $k) - foreach ($attrs as $attr) { - $lattr = strtolower($attr); - if (isset($values[$lattr])) { - $v = ''; - - if (is_array($values[$lattr]) && isset($values[$lattr][$i])) - $v = $values[$lattr][$i]; - - if (is_string($v) && (strlen($v) > 0)) - $results[$k][$attr] = $v; - } - } - - else - foreach ($attrs as $attr) { - $lattr = strtolower($attr); - if (isset($values[$lattr])) - $results[$values[$key]][$attr] = $values[$lattr]; - } - - if ($sort) - masort($results,is_array($sort) ? implode(',',$sort) : 'dn'); - - return $results; -} - -/** - * This function returns a string automatically generated - * based on the criteria defined in the array $criteria in config.php - */ -function password_generate() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - $no_use_similiar = ! $_SESSION[APPCONFIG]->getValue('password','use_similar'); - $lowercase = $_SESSION[APPCONFIG]->getValue('password','lowercase'); - $uppercase = $_SESSION[APPCONFIG]->getValue('password','uppercase'); - $digits = $_SESSION[APPCONFIG]->getValue('password','numbers'); - $punctuation = $_SESSION[APPCONFIG]->getValue('password','punctuation'); - $length = $_SESSION[APPCONFIG]->getValue('password','length'); - - $outarray = array(); - - if ($no_use_similiar) { - $raw_lower = 'a b c d e f g h k m n p q r s t u v w x y z'; - $raw_numbers = '2 3 4 5 6 7 8 9'; - $raw_punc = '# $ % ^ & * ( ) _ - + = . , [ ] { } :'; - - } else { - $raw_lower = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'; - $raw_numbers = '1 2 3 4 5 6 7 8 9 0'; - $raw_punc = '# $ % ^ & * ( ) _ - + = . , [ ] { } : |'; - } - - $llower = explode(' ',$raw_lower); - shuffle($llower); - $lupper = explode(' ',strtoupper($raw_lower)); - shuffle($lupper); - $numbers = explode(' ',$raw_numbers); - shuffle($numbers); - $punc = explode(' ',$raw_punc); - shuffle($punc); - - if ($lowercase > 0) - $outarray = array_merge($outarray,a_array_rand($llower,$lowercase)); - - if ($uppercase > 0) - $outarray = array_merge($outarray,a_array_rand($lupper,$uppercase)); - - if ($digits > 0) - $outarray = array_merge($outarray,a_array_rand($numbers,$digits)); - - if ($punctuation > 0) - $outarray = array_merge($outarray,a_array_rand($punc,$punctuation)); - - $num_spec = $lowercase + $uppercase + $digits + $punctuation; - - if ($num_spec < $length) { - $leftover = array(); - if ($lowercase > 0) - $leftover = array_merge($leftover,$llower); - if ($uppercase > 0) - $leftover = array_merge($leftover,$lupper); - if ($digits > 0) - $leftover = array_merge($leftover,$numbers); - if ($punctuation > 0) - $leftover = array_merge($leftover,$punc); - - if (count($leftover) == 0) - $leftover = array_merge($leftover,$llower,$lupper,$numbers,$punc); - - shuffle($leftover); - $outarray = array_merge($outarray,a_array_rand($leftover,$length-$num_spec)); - } - - shuffle($outarray); - $return = implode('',$outarray); - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * This function returns an array of $num_req values - * randomly picked from the $input array - * - * @param array Array of values - * @param integer Number of values in returned array - * @return string The padded string - */ -function a_array_rand($input,$num_req) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (count($input) == 0) - return array(); - - if ($num_req < 1) - return array(); - - $return = array(); - if ($num_req > count($input)) { - for($i = 0; $i < $num_req; $i++) { - $idx = array_rand($input,1); - $return[] = $input[$idx]; - } - - } else { - $idxlist = array_rand($input,$num_req); - if ($num_req == 1) - $idxlist = array($idxlist); - - for($i = 0; $i < count($idxlist); $i++) - $return[] = $input[$idxlist[$i]]; - } - - if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); - - return $return; -} - -/** - * This is for Opera. By putting "random junk" in the query string, it thinks - * that it does not have a cached version of the page, and will thus - * fetch the page rather than display the cached version - */ -function random_junk() { - $time = gettimeofday(); - return md5(strtotime('now').$time['usec']); -} - -/** - * Returns a HTML id that can be used in the URL after the #. - * - * @param string The DN to pretty-print. - * @return string - */ -function htmlid($sid,$dn) { - return sprintf('SID%s:%s',$sid,preg_replace('/[\ =,]/','_',$dn)); -} - -/** - * Is PLA configured for AJAX display - */ -function isAjaxEnabled() { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); - - if (isset($_SESSION[APPCONFIG])) - return ($_SESSION[APPCONFIG]->getValue('appearance','tree') == 'AJAXTree'); - else - return false; -} -/** -* Check if user is a robot with reCAPTCHA -**/ -function IsRobot($gResponse){ - $isRobot = true; - $url = 'https://www.google.com/recaptcha/api/siteverify'; - $data = array( - 'secret' => $_SESSION[APPCONFIG]->getValue('session','reCAPTCHA-key-server'), - 'response' => $gResponse - ); - $options = array( - 'http' => array ( - 'method' => 'POST','header' => - 'Content-Type: application/x-www-form-urlencoded', - 'content' => http_build_query($data) - ) - ); - $context = stream_context_create($options); - $verify = file_get_contents($url, false, $context); - $captcha_success = json_decode($verify); - if ($captcha_success->success) { - $isRobot = false; - } - return $isRobot; - -} -?> diff --git a/lib/ldap_error_codes.txt b/lib/ldap_error_codes.txt deleted file mode 100644 index 8d4a2cc..0000000 --- a/lib/ldap_error_codes.txt +++ /dev/null @@ -1,94 +0,0 @@ -0x00 LDAP_SUCCESS "The operation completed successfully." -0x01 LDAP_OPERATIONS_ERROR "An operations error occurred. This is - typically the result of an internal error on your LDAP server." -0x02 LDAP_PROTOCOL_ERROR "A protocol violation was detected." -0x03 LDAP_TIMELIMIT_EXCEEDED "The operation timed out waiting to complete." -0x04 LDAP_SIZELIMIT_EXCEEDED "The LDAP server refused to serve such a large result set." -0x05 LDAP_COMPARE_FALSE "A compare operation returned false." -0x06 LDAP_COMPARE_TRUE "A compare operation returned true." -0x07 LDAP_AUTH_METHOD_NOT_SUPPORTED "The authentication method you specified is not supported by - the LDAP server." -0x08 LDAP_STRONG_AUTH_REQUIRED "This LDAP server requires strong (encrypted) authentication, - not clear text." -0x09 LDAP_PARTIAL_RESULTS "The result set received is a partial result set." -0x0a LDAP_REFERRAL "" -0x0b LDAP_ADMINLIMIT_EXCEEDED "" -0x0c LDAP_UNAVAILABLE_CRITICAL_EXTENSION "" -0x0d LDAP_CONFIDENTIALITY_REQUIRED "" -0x0e LDAP_SASL_BIND_INPROGRESS "" -0x10 LDAP_NO_SUCH_ATTRIBUTE "That entry does not contain the attribute specified." -0x11 LDAP_UNDEFINED_TYPE "The attribute type specified is invalid." -0x12 LDAP_INAPPROPRIATE_MATCHING "This usually means that your LDAP server has not defined an equality rule - for the attribute you are trying to alter. This is not phpLDAPadmin's fault as the - LDAP server has refused to perform the operation (as well it should if there is - no equality rule for it to use for the operation). This generally applies when - adding a new value to a binary attribute, or removing a single value from a - multi-valued binary attribute." -0x13 LDAP_CONSTRAINT_VIOLATION "Some constraint would be violated by performing the action. This can happen when - you try to add a second value to a single-valued attribute, for example." -0x14 LDAP_TYPE_OR_VALUE_EXISTS "An attribute type or attribute value - specified already exists in the entry" -0x15 LDAP_INVALID_SYNTAX "An invalid attribute value was specified." -0x20 LDAP_NO_SUCH_OBJECT "That object does not exist." -0x21 LDAP_ALIAS_PROBLEM "An alias in the directory points to a - non-existent entry." -0x22 LDAP_INVALID_DN_SYNTAX "You used an invalid syntax in the specified DN." -0x23 LDAP_IS_LEAF "The object specified is a leaf" -0x24 LDAP_ALIAS_DEREF_PROBLEM "A problem was encountereed when - dereferencing an alias" -0x30 LDAP_INAPPROPRIATE_AUTH "Inappropriate authentication was - specified (e.g. LDAP_AUTH_SIMPLE was - specified and the entry does not have - a userPassword attribute)." -0x31 LDAP_INVALID_CREDENTIALS "Incorrect login DN and/or password." -0x32 LDAP_INSUFFICIENT_ACCESS "You do not have sufficient permissions - to perform that operation." -0x33 LDAP_BUSY "The LDAP server is busy." -0x34 LDAP_UNAVAILABLE "The LDAP server is unavailable." -0x35 LDAP_UNWILLING_TO_PERFORM "The LDAP server refused to perform the operation." -0x36 LDAP_LOOP_DETECT "A loop was detected." -0x3C LDAP_SORT_CONTROL_MISSING "" -0x3D LDAP_INDEX_RANGE_ERROR "" -0x40 LDAP_NAMING_VIOLATION "A naming violation occurred. This usually - means that you tried to change the value of an attribute that is used in the - DN. For example, if you change the 'cn' value of an entry whose DN is 'cn=Bob - Jones,dc=example,dc=com', you must also rename the entry to reflect the - change." -0x41 LDAP_OBJECT_CLASS_VIOLATION "You tried to perform an operation that would cause an undefined attribute - to exist or that would remove a required attribute, given the current list - of ObjectClasses. This can also occur if you do not - specify a structural objectClass when creating an entry, or if you specify - more than one structural objectClass." -0x42 LDAP_NOT_ALLOWED_ON_NONLEAF "The entry you tried to operate on has children. Usually this means you - tried to delete or rename the entry, which you cannot do to an entry - with children." -0x43 LDAP_NOT_ALLOWED_ON_RDN "You cannot preform that operation on a the relative distinguished name - (RDN) of an object." -0x44 LDAP_ALREADY_EXISTS "The object already exists. Usually you are trying to create a new object - on top of an existing one." -0x45 LDAP_NO_OBJECT_CLASS_MODS "ObjectClass modifications are not allowed." -0x46 LDAP_RESULTS_TOO_LARGE "" -0x47 LDAP_AFFECTS_MULTIPLE_DSAS "" -0x50 LDAP_OTHER "" -0x51 LDAP_SERVER_DOWN "The LDAP server is down." -0x52 LDAP_LOCAL_ERROR "" -0x53 LDAP_ENCODING_ERROR "" -0x54 LDAP_DECODING_ERROR "" -0x55 LDAP_TIMEOUT "" -0x56 LDAP_AUTH_UNKNOWN "" -0x57 LDAP_FILTER_ERROR "The LDAP search filter specified is inavlid." -0x58 LDAP_USER_CANCELLED "The user cancelled the LDAP operation." -0x59 LDAP_PARAM_ERROR "An ldap routine was called with a bad - parameter." -0x5a LDAP_NO_MEMORY "A memory allocation (e.g., malloc(3) - or other dynamic memory allocator) - call failed in an ldap library rou- - tine." -0x5b LDAP_CONNECT_ERROR "" -0x5c LDAP_NOT_SUPPORTED "The requested operation is not supported by the LDAP server." -0x5d LDAP_CONTROL_NOT_FOUND "" -0x5e LDAP_NO_RESULTS_RETURNED "The search came back empty." -0x5f LDAP_MORE_RESULTS_TO_RETURN "The LDAP server has more results that it would like to return." -0x60 LDAP_CLIENT_LOOP "" -0x61 LDAP_REFERRAL_LIMIT_EXCEEDED "This means that a search was performed that required the LDAP - server to follow a chain of referrals that was too lengthy." diff --git a/lib/query_functions.php b/lib/query_functions.php deleted file mode 100644 index de47630..0000000 --- a/lib/query_functions.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/lib/template_functions.php b/lib/template_functions.php deleted file mode 100644 index bb3b606..0000000 --- a/lib/template_functions.php +++ /dev/null @@ -1,23 +0,0 @@ - diff --git a/templates/creation/alias.xml b/templates/creation/alias.xml deleted file mode 100644 index 3c803d1..0000000 --- a/templates/creation/alias.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - diff --git a/templates/creation/courierMailAccount.xml b/templates/creation/courierMailAccount.xml deleted file mode 100644 index b7602ab..0000000 --- a/templates/creation/courierMailAccount.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - diff --git a/templates/creation/courierMailAlias.xml b/templates/creation/courierMailAlias.xml deleted file mode 100644 index 9a53196..0000000 --- a/templates/creation/courierMailAlias.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - diff --git a/templates/creation/dNSDomain.xml b/templates/creation/dNSDomain.xml deleted file mode 100644 index 4a98054..0000000 --- a/templates/creation/dNSDomain.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - diff --git a/templates/creation/example.xml b/templates/creation/example.xml deleted file mode 100644 index 812b707..0000000 --- a/templates/creation/example.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - diff --git a/templates/creation/inetOrgPerson.xml b/templates/creation/inetOrgPerson.xml deleted file mode 100644 index 6469221..0000000 --- a/templates/creation/inetOrgPerson.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - diff --git a/templates/creation/kolabPerson.xml b/templates/creation/kolabPerson.xml deleted file mode 100644 index 8be2e6b..0000000 --- a/templates/creation/kolabPerson.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - diff --git a/templates/creation/mozillaOrgPerson.xml b/templates/creation/mozillaOrgPerson.xml deleted file mode 100644 index dc39a73..0000000 --- a/templates/creation/mozillaOrgPerson.xml +++ /dev/null @@ -1,161 +0,0 @@ - - - - diff --git a/templates/creation/organizationalRole.xml b/templates/creation/organizationalRole.xml deleted file mode 100644 index 85e595a..0000000 --- a/templates/creation/organizationalRole.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - diff --git a/templates/creation/ou.xml b/templates/creation/ou.xml deleted file mode 100644 index 6e0f45a..0000000 --- a/templates/creation/ou.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/templates/creation/posixAccount.xml b/templates/creation/posixAccount.xml deleted file mode 100644 index 19f1f31..0000000 --- a/templates/creation/posixAccount.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - diff --git a/templates/creation/posixGroup.xml b/templates/creation/posixGroup.xml deleted file mode 100644 index 6f8d26b..0000000 --- a/templates/creation/posixGroup.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - diff --git a/templates/creation/sambaDomain.xml b/templates/creation/sambaDomain.xml deleted file mode 100644 index 563828e..0000000 --- a/templates/creation/sambaDomain.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - diff --git a/templates/creation/sambaGroupMapping.xml b/templates/creation/sambaGroupMapping.xml deleted file mode 100644 index c93745c..0000000 --- a/templates/creation/sambaGroupMapping.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - diff --git a/templates/creation/sambaMachine.xml b/templates/creation/sambaMachine.xml deleted file mode 100644 index fe5e5d3..0000000 --- a/templates/creation/sambaMachine.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - diff --git a/templates/creation/sambaSamAccount.xml b/templates/creation/sambaSamAccount.xml deleted file mode 100644 index d44fad8..0000000 --- a/templates/creation/sambaSamAccount.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - diff --git a/templates/creation/sendmailMTAAliasObject.xml b/templates/creation/sendmailMTAAliasObject.xml deleted file mode 100644 index 86688b6..0000000 --- a/templates/creation/sendmailMTAAliasObject.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - diff --git a/templates/creation/sendmailMTAClass.xml b/templates/creation/sendmailMTAClass.xml deleted file mode 100644 index 9bbde8e..0000000 --- a/templates/creation/sendmailMTAClass.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - diff --git a/templates/creation/sendmailMTACluster.xml b/templates/creation/sendmailMTACluster.xml deleted file mode 100644 index 08bba5c..0000000 --- a/templates/creation/sendmailMTACluster.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - diff --git a/templates/creation/sendmailMTAMapObject.xml b/templates/creation/sendmailMTAMapObject.xml deleted file mode 100644 index 5f4afd5..0000000 --- a/templates/creation/sendmailMTAMapObject.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - diff --git a/templates/creation/sendmailVirtualDomain.xml b/templates/creation/sendmailVirtualDomain.xml deleted file mode 100644 index b2c1047..0000000 --- a/templates/creation/sendmailVirtualDomain.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - diff --git a/templates/creation/sendmailVirtualUser.xml b/templates/creation/sendmailVirtualUser.xml deleted file mode 100644 index c046991..0000000 --- a/templates/creation/sendmailVirtualUser.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - diff --git a/templates/creation/simpleSecurityObject.xml b/templates/creation/simpleSecurityObject.xml deleted file mode 100644 index 2cb2000..0000000 --- a/templates/creation/simpleSecurityObject.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - diff --git a/templates/modification/inetOrgPerson.xml b/templates/modification/inetOrgPerson.xml deleted file mode 100644 index b7f17e9..0000000 --- a/templates/modification/inetOrgPerson.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - diff --git a/templates/modification/posixGroup.xml b/templates/modification/posixGroup.xml deleted file mode 100644 index f761c3a..0000000 --- a/templates/modification/posixGroup.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - diff --git a/templates/template.dtd b/templates/template.dtd deleted file mode 100644 index 64ed786..0000000 --- a/templates/template.dtd +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -