From: <mi...@us...> - 2003-12-31 19:14:48
|
Update of /cvsroot/egroupware/eldaptir/inc In directory sc8-pr-cvs1:/tmp/cvs-serv13546 Added Files: class.at.inc.php class.oc.inc.php Log Message: Add code ported from phpldapadmin --- NEW FILE: class.at.inc.php --- <?php /**************************************************************************\ * eGroupWare - eLDAPtir - LDAP Administration * * Written by Miles Lott <mi...@gr...> * * Provide common vars/functions for schema-aware LDAP Administration * * Most if not all of this code is from phpldapadmin: * * http://phpldapadmin.sf.net * * ------------------------------------------------------------------------ * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id: class.at.inc.php,v 1.1 2003/12/31 19:14:44 milosch Exp $ */ /* * Represents an LDAP AttributeType */ class at { /* The OID of this attributeType: ie, 1.2.3.4*/ var $oid; /* The name of this attributeType */ var $name; /* string: the description */ var $description; /* boolean: is it obsoloete */ var $is_obsolete; /* The attribute from which this attribute inherits (if any) */ var $sup_attribute; /* The equality rule used */ var $equality; /* The ordering of the attributeType */ var $ordering; /* Boolean: supports substring matching? */ var $sub_str; /* The full syntax string, ie 1.2.3.4{16} */ var $syntax; /* boolean: is single valued only? */ var $is_single_value; /* boolean: is collective? */ var $is_collective; /* boolean: can use modify? */ var $is_no_user_modification; /* The usage string set by the LDAP schema */ var $usage; /* An array of alias attribute names, strings */ var $aliases; /* The max number of characters this attribute can be */ var $max_length; /* A string description of the syntax type (taken from the LDAPSyntaxes) */ var $type; /* An array of objectClasses which use this attributeType (must be set by caller) */ var $used_in_object_classes; /* * Initialize the class' member variables */ function initVars() { $this->oid = null; $this->name = null; $this->description = null; $this->is_obsolete = false; $this->sup_attribute = null; $this->equality = null; $this->ordering = null; $this->sub_str = null; $this->syntax_oid = null; $this->syntax = null; $this->max_length = null; $this->is_single_value= false; $this->is_collective = false; $this->is_no_user_modification = false; $this->usage = null; $this->aliases = array(); $this->type = null; $this->used_in_object_classes = array(); } /* * Parses a raw LDAP objectClass string into this object's $this vars */ function at($raw_ldap_attr_string) { //echo "<nobr>$raw_ldap_attr_string</nobr><Br />"; $this->initVars(); $attr = $raw_ldap_attr_string; $strings = preg_split("/[\s,]+/", $attr, -1,PREG_SPLIT_DELIM_CAPTURE); for($i=0; $i<count($strings); $i++) { switch($strings[$i]) { case '(': break; case 'NAME': if($strings[$i+1]!="(") { do { $i++; if(strlen($this->name)==0) { $this->name = $strings[$i]; } else { $this->name .= " " . $strings[$i]; } }while(!preg_match("/\'$/s", $strings[$i])); // this attribute has no aliases $this->aliases = array(); } else { $i++; do { $i++; if(strlen($this->name) == 0) { $this->name = $strings[$i]; } else { $this->name .= " " . $strings[$i]; } } while(!preg_match("/\'$/s", $strings[$i])); // add alias names for this attribute while($strings[++$i]!=")") { $alias = $strings[$i]; $alias = preg_replace("/^\'/", "", $alias ); $alias = preg_replace("/\'$/", "", $alias ); $this->aliases[] = $alias; } } break; case 'DESC': do { $i++; if(strlen($this->description)==0) { $this->description=$this->description . $strings[$i]; } else { $this->description=$this->description . " " . $strings[$i]; } }while(!preg_match("/\'$/s", $strings[$i])); break; case 'OBSOLETE': $this->is_obsolete = TRUE; break; case 'SUP': $i++; $this->sup_attribute = $strings[$i]; break; case 'EQUALITY': $i++; $this->equality = $strings[$i]; break; case 'ORDERING': $i++; $this->ordering = $strings[$i]; break; case 'SUBSTR': $i++; $this->sub_str = $strings[$i]; break; case 'SYNTAX': $i++; $this->syntax = $strings[$i]; $this->syntax_oid = preg_replace("/{\d+}$/", "", $this->syntax); // does this SYNTAX string specify a max length (ie, 1.2.3.4{16}) if(preg_match("/{(\d+)}$/", $this->syntax, $this->max_length)) { $this->max_length = $this->max_length[1]; } else { $this->max_length = null; } if($strings[$i+1]=="{") { do { $i++; $this->name .= " " . $strings[$i]; } while($strings[$i]!="}"); } break; case 'SINGLE-VALUE': $this->is_single_value = TRUE; break; case 'COLLECTIVE': $this->is_collective = TRUE; break; case 'NO-USER-MODIFICATION': $this->is_no_user_modification = TRUE; break; case 'USAGE': $i++; $this->usage = $strings[$i]; break; default: if(preg_match("/[\d\.]+/i",$strings[$i])) { $this->oid = $strings[$i]; } } } $this->name = preg_replace("/^\'/", "", $this->name); $this->name = preg_replace("/\'$/", "", $this->name); $this->description = preg_replace("/^\'/", "", $this->description); $this->description = preg_replace("/\'$/", "", $this->description); } /* Getters */ function getOID() { return $this->oid; } function getName() { return $this->name; } function getDescription() { return $this->description; } function getIsObsolete() { return $this->is_obsolete; } function getUsage() { return $this->usage; } function getSupAttribute() { return $this->sup_attribute; } function getEquality() { return $this->equality; } function getOrdering() { return $this->ordering; } function getSubstr() { return $this->sub_str; } function getAliases() { return $this->aliases; } /* * Returns the entire raw syntax string for this attr, for example: 1.2.3.4{16} */ function getSyntaxString() { return $this->syntax; } /* * Differs from getSyntaxString() in that it only returns the actual OID with any length * specification removed. Ie, if the syntax string is 1.2.3.4{16}, this retruns * 1.2.3.4. */ function getSyntaxOID() { return $this->syntax_oid; } /* * Returns the maximum length specified by this attribute (ie, "16" in 1.2.3.4{16}) */ function getMaxLength() { return $this->max_length; } function getIsSingleValue() { return $this->is_single_value; } function getIsCollective() { return $this->is_collective; } function getIsNoUserModification() { return $this->is_no_user_modification; } function getType() { return $this->type; } /* * Removes an attribute name from the alias array. */ function removeAlias($remove_alias_name) { foreach($this->aliases as $i => $alias_name ) { if(0 == strcasecmp($alias_name, $remove_alias_name)) { unset($this->aliases[ $i ]); $this->aliases = array_values($this->aliases); return true; } } return false; } /* * Adds an attribute name to the alias array. */ function addAlias($new_alias_name) { $this->aliases[] = $new_alias_name; } function setName($new_name) { $this->name = $new_name; } function setDescription($new_desc) { $this->description = $new_desc; } function setSupAttribute($new_sup_attr) { $this->sup_attribute = $new_sup_attr; } function setAliases($new_aliases) { $this->aliases = $new_aliases; } function setType($new_type) { $this->type = $new_type; } function addUsedInObjectClass($object_class_name) { if(!in_array($object_class_name, $this->used_in_object_classes)) { $this->used_in_object_classes[] = $object_class_name; } } function getUsedInObjectClasses() { return $this->used_in_object_classes; } } ?> --- NEW FILE: class.oc.inc.php --- <?php /**************************************************************************\ * eGroupWare - eLDAPtir - LDAP Administration * * Written by Miles Lott <mi...@gr...> * * Provide common vars/functions for schema-aware LDAP Administration * * Most if not all of this code is from phpldapadmin: * * http://phpldapadmin.sf.net * * ------------------------------------------------------------------------ * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id: class.oc.inc.php,v 1.1 2003/12/31 19:14:44 milosch Exp $ */ /* * Represents an LDAP objectClass */ class oc { /* This objectClass' OID, ie "2.16.840.1.113730.3.2.2" */ var $oid; /* This objectClass' name, ie "inetOrgPerson" */ var $name; /* This objectClass' description */ var $description; /* array of objectClass names from which this objectClass inherits */ var $sup_classes; /* one of STRUCTURAL, ABSTRACT, or AUXILIARY */ var $type; /* arrays of attribute names that this objectClass requires */ var $must_attrs; /* arrays of attribute names that this objectClass allows, but does not require */ var $may_attrs; /* boolean value indicating whether this objectClass is obsolete */ var $is_obsolete; /* Initialize the class' member variables */ function initVars() { $this->oid = null; $this->name = null; $this->description = null; $this->sup_classes = array(); $this->type = null; $this->must_attrs = array(); $this->may_attrs = array(); $this->is_obsolete = false; } /* * Parses a raw LDAP objectClass string into this object's $this vars */ function oc($raw_ldap_schema_string) { $this->initVars(); $class = $raw_ldap_schema_string; $strings = preg_split("/[\s,]+/", $class, -1,PREG_SPLIT_DELIM_CAPTURE); for($i=0; $i<count($strings); $i++) { switch($strings[$i]) { case '(': break; case 'NAME': if($strings[$i+1] != '(') { do { $i++; if(strlen($this->name)==0) { $this->name = $strings[$i]; } else { $this->name .= ' ' . $strings[$i]; } }while(!preg_match("/\'$/s", $strings[$i])); } else { $i++; do { $i++; if(strlen($this->name) == 0) { $this->name = $strings[$i]; } else { $this->name .= ' ' . $strings[$i]; } } while(!preg_match("/\'$/s", $strings[$i])); do { $i++; }while($strings[$i] != ')'); } break; case 'DESC': do { $i++; if(strlen($this->description)==0) { $this->description=$this->description . $strings[$i]; } else { $this->description=$this->description . ' ' . $strings[$i]; } }while(!preg_match("/\'$/s", $strings[$i])); break; case 'OBSOLETE': $this->is_obsolete = TRUE; break; case 'SUP': if($strings[$i+1] != '(') { $i++; array_push($this->sup_classes, $strings[$i]); } else { $i++; do { $i++; if($strings[$i]!="$") { array_push($this->sup_classes, $strings[$i]); } }while($strings[$i+1] != ')'); } break; case 'ABSTRACT': $this->type='abstract'; break; case 'STRUCTURAL': $this->type='structural'; break; case 'AUXILIARY': $this->type='auxiliary'; break; case 'MUST': if($strings[$i+1] != '(') { $i++; array_push($this->must_attrs, $strings[$i]); } else { $i++; do { $i++; if($strings[$i] != "$") { array_push($this->must_attrs, $strings[$i]); } }while($strings[$i+1] != ')'); } sort($this->must_attrs); break; case 'MAY': if($strings[$i+1] != '(') { $i++; array_push($this->may_attrs, $strings[$i]); } else { $i++; do { $i++; if($strings[$i] != "$") { array_push($this->may_attrs, $strings[$i]); } }while($strings[$i+1] != ')'); } sort($this->may_attrs); break; default: if(preg_match("/[\d\.]+/i",$strings[$i])) { $this->oid = $strings[$i]; } } } $this->name = preg_replace("/^\'/", '', $this->name); $this->name = preg_replace("/\'$/", '', $this->name); $this->description = preg_replace("/^\'/", '', $this->description); $this->description = preg_replace("/\'$/", '', $this->description); } /* Getters */ function getMustAttrs() { return $this->must_attrs; } function getMayAttrs() { return $this->may_attrs; } function getName() { return $this->name; } function getDescription() { return $this->description; } function getSupClasses() { return $this->sup_classes; } function getType() { return $this->type; } function getIsObsolete() { return $this->is_obsolete; } /* * Adds the specified array of attributes to this objectClass' list of * MUST attributes. The resulting array of must attributes will contain * unique members. */ function addMustAttrs($new_must_attrs) { if(!is_array($new_must_attrs)) { return; } if(0 == count($new_must_attrs)) { return; } $this->must_attrs = array_values(array_unique(array_merge($this->must_attrs, $new_must_attrs))); } /* * Behaves identically to addMustAttrs, but it operates on the MAY * attributes of this objectClass. */ function addMayAttrs($new_may_attrs) { if(!is_array($new_may_attrs)) { return; } if(0 == count($new_may_attrs)) { return; } $this->may_attrs = array_values(array_unique(array_merge($this->may_attrs, $new_may_attrs))); } /* * Returns an associative array of this objectClass. * This exists for backwards compatibility for portions of PLA * that have not yet been made aware of the new object oriented * ObjectClass code. */ function toAssoc() { return array( 'oid' => $this->oid, 'name' => $this->name, 'description' => $this->description, 'sup' => $this->sup_classes, 'type' => $this->type, 'must_attrs' => $this->must_attrs, 'may_attrs' => $this->may_attrs, 'is_obsolete' => $this->is_obsolete ); } } ?> |