From f6e4d295bf041f03b2822c6583468dce99094df8 Mon Sep 17 00:00:00 2001 From: cajus Date: Tue, 15 Jan 2008 16:28:27 +0000 Subject: [PATCH] Simplified the way we handle tags. This *may* break tagging. Needs testing. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@8370 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_plugin.inc | 57 +++++++++++++++++++ include/functions.inc | 39 +++++++++++++ .../admin/applications/tabs_application.inc | 4 -- .../departments/class_departmentGeneric.inc | 9 +-- plugins/admin/fai/class_faiHook.inc | 7 +-- plugins/admin/fai/class_faiPackage.inc | 11 +--- plugins/admin/fai/class_faiPartitionTable.inc | 24 ++------ plugins/admin/fai/class_faiProfile.inc | 4 -- plugins/admin/fai/class_faiScript.inc | 17 +----- plugins/admin/fai/class_faiTemplate.inc | 17 +----- plugins/admin/fai/class_faiVariable.inc | 17 +----- plugins/admin/groups/tabs_group.inc | 4 -- plugins/admin/mimetypes/tabs_mimetypes.inc | 5 -- plugins/admin/ogroups/tabs_ogroups.inc | 6 +- plugins/admin/systems/class_printGeneric.inc | 3 - plugins/admin/systems/tabs_component.inc | 3 - plugins/admin/systems/tabs_phone.inc | 3 - plugins/admin/systems/tabs_printers.inc | 3 - plugins/admin/systems/tabs_server.inc | 3 - plugins/admin/systems/tabs_terminal.inc | 2 - plugins/admin/systems/tabs_winstation.inc | 3 - plugins/admin/systems/tabs_workstation.inc | 3 - plugins/personal/generic/class_user.inc | 3 - 23 files changed, 116 insertions(+), 131 deletions(-) diff --git a/include/class_plugin.inc b/include/class_plugin.inc index e84ddec65..d66789930 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -335,6 +335,8 @@ class plugin } } + /* Handle tagging */ + $this->tag_attrs(&$this->attrs); } @@ -892,6 +894,61 @@ class plugin } + function tag_attrs($at, $dn= "", $tag= "", $show= false) + { + /* No dn? Self-operation... */ + if ($dn == ""){ + $dn= $this->dn; + + /* No tag? Find it yourself... */ + if ($tag == ""){ + $len= strlen($dn); + + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging"); + $relevant= array(); + foreach ($this->config->adepartments as $key => $ntag){ + + /* This one is bigger than our dn, its not relevant... */ + if ($len <= strlen($key)){ + continue; + } + + /* This one matches with the latter part. Break and don't fix this entry */ + if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging"); + $relevant[strlen($key)]= $ntag; + continue; + } + + } + + /* If we've some relevant tags to set, just get the longest one */ + if (count($relevant)){ + ksort($relevant); + $tmp= array_keys($relevant); + $idx= end($tmp); + $tag= $relevant[$idx]; + $this->gosaUnitTag= $tag; + } + } + } + + /* Remove tags that may already be here... */ + remove_objectClass("gosaAdministrativeUnitTag", &$at); + if (isset($at['gosaUnitTag'])){ + unset($at['gosaUnitTag']); + } + + /* Set tag? */ + if ($tag != ""){ + add_objectClass("gosaAdministrativeUnitTag", &$at); + $at['gosaUnitTag']= $tag; + } + + return ($at); + } + + function handle_object_tagging($dn= "", $tag= "", $show= false) { //FIXME: How to optimize this? We have at least two diff --git a/include/functions.inc b/include/functions.inc index e83805413..70ab363ac 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2604,6 +2604,45 @@ function is_in_network($network, $netmask, $address) } +/* Add a given objectClass to an attrs entry */ +function add_objectClass($classes, &$attrs) +{ + if (is_array($classes)){ + $list= $classes; + } else { + $list= array($classes); + } + + foreach ($list as $class){ + $attrs['objectClass'][]= $class; + } +} + + +/* Removes a given objectClass from the attrs entry */ +function remove_objectClass($classes, &$attrs) +{ + if (isset($attrs['objectClass'])){ + /* Array? */ + if (is_array($classes)){ + $list= $classes; + } else { + $list= array($classes); + } + + $tmp= array(); + foreach ($attrs['objectClass'] as $oc) { + foreach ($list as $class){ + if ($oc != $class){ + $tmp[]= $oc; + } + } + } + $attrs['objectClass']= $tmp; + } +} + + /* Returns contents of the given POST variable and check magic quotes settings */ function get_post($name) { diff --git a/plugins/admin/applications/tabs_application.inc b/plugins/admin/applications/tabs_application.inc index 859218e04..b8863a7a4 100644 --- a/plugins/admin/applications/tabs_application.inc +++ b/plugins/admin/applications/tabs_application.inc @@ -44,10 +44,6 @@ class apptabs extends tabs } tabs::save(); - - /* Fix tagging if needed */ - $baseobject->dn= $this->dn; - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index 9aecbccdf..18f8db4ab 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -296,7 +296,7 @@ class department extends plugin $tmp= array(); /* Remove gosaAdministrativeUnit from this plugin */ - $has_unit_tag= false; + $has_unit_tag= false; foreach($this->attrs['objectClass'] as $oc){ if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){ $tmp[]= $oc; @@ -333,11 +333,6 @@ class department extends plugin This will be done later */ $this->tag_objects(true); - /* Fix tagging if needed */ - if (!$this->is_administrational_unit){ - $this->handle_object_tagging(); - } - /* Optionally execute a command after we're done */ $this->postcreate(); return(true); @@ -421,7 +416,7 @@ class department extends plugin $this->must_be_tagged =true; return; } - $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); + $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); echo "" ; } } diff --git a/plugins/admin/fai/class_faiHook.inc b/plugins/admin/fai/class_faiHook.inc index 0ad7dba9e..c00c14dc3 100644 --- a/plugins/admin/fai/class_faiHook.inc +++ b/plugins/admin/fai/class_faiHook.inc @@ -432,9 +432,6 @@ class faiHook extends plugin } show_ldap_error($ldap->get_error(), _("Saving FAI hook base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); - $ldap->cd($this->dn); /* Prepare FAIscriptEntry to write it to ldap @@ -516,6 +513,9 @@ class faiHook extends plugin } } + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); + if($obj['status'] == "delete"){ $ldap->cd($sub_dn); $ldap->rmdir_recursive($sub_dn); @@ -538,7 +538,6 @@ class faiHook extends plugin $this->handle_post_events("add"); show_ldap_error($ldap->get_error(), _("Saving FAI hook failed")); } - $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); } } diff --git a/plugins/admin/fai/class_faiPackage.inc b/plugins/admin/fai/class_faiPackage.inc index 32a26f91b..18a7aeae7 100644 --- a/plugins/admin/fai/class_faiPackage.inc +++ b/plugins/admin/fai/class_faiPackage.inc @@ -507,8 +507,6 @@ class faiPackage extends plugin } show_ldap_error($ldap->get_error(), _("Saving FAI package base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); $ldap->cd($this->dn); /* Save Package configurations */ @@ -533,11 +531,8 @@ class faiPackage extends plugin /* cehck if object already exists */ $ldap->cat($pkgdn,array("objectClass")); - /* Workaround for missing "gosaAdministrativeUnitTag" */ - $attrs = $ldap->fetch(); - if((isset($attrs['objectClass'])) && (in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass']))){ - $pkgattrs['objectClass'][] = "gosaAdministrativeUnitTag"; - } + /* Tag object */ + $this->tag_attrs(&$pkgattrs, $sub_dn, $this->gosaUnitTag); if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){ if($ldap->count()!=0){ @@ -554,8 +549,6 @@ class faiPackage extends plugin show_ldap_error($ldap->get_error(), _("Saving FAI package entry failed")); } - /* Handle tagging */ - $this->handle_object_tagging($pkgdn, $this->gosaUnitTag); } } } diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index c85cf9ab3..a627dfd6f 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -367,9 +367,6 @@ class faiPartitionTable extends plugin } show_ldap_error($ldap->get_error(), _("Saving FAI partition table base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); - /* Sort entries, because we must delete entries with status="delete" first */ $order = array(); foreach($this->disks as $key => $disk){ @@ -402,13 +399,9 @@ class faiPartitionTable extends plugin } } - /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for disks */ - $ldap->cat($disk_dn,array("objectClass")); - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $disk_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; - } - + /* Do object tagging */ + $this->tag_attrs(&$disk_attrs, $disk_dn, $this->gosaUnitTag); + if($disk['status'] == "delete"){ $ldap->cd($disk_dn); $ldap->rmdir_recursive($disk_dn); @@ -434,8 +427,6 @@ class faiPartitionTable extends plugin print_red("unknown status while saving disks"); } - $this->handle_object_tagging($disk_dn, $this->gosaUnitTag); - /* Collect all opperations. Delete first than add new entries .*/ $Todo['delete'] = array(); $Todo['rest'] = array(); @@ -512,11 +503,9 @@ class faiPartitionTable extends plugin $ldap->cat($partition_dn); if($ldap->count()){ - /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */ - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; - } + /* Tag object */ + $this->tag_attrs(&$partition_attrs, $partition_dn, $this->gosaUnitTag); + if(empty($partition_attrs['description'])){ $partition_attrs['description']=array(); } @@ -548,7 +537,6 @@ class faiPartitionTable extends plugin $ldap->add($partition_attrs); show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); } - $this->handle_object_tagging($partition_dn, $this->gosaUnitTag); } } $this->handle_post_events("add"); diff --git a/plugins/admin/fai/class_faiProfile.inc b/plugins/admin/fai/class_faiProfile.inc index 84e5b40b1..8f70c88a3 100644 --- a/plugins/admin/fai/class_faiProfile.inc +++ b/plugins/admin/fai/class_faiProfile.inc @@ -457,10 +457,6 @@ class faiProfile extends plugin $ldap->add($this->attrs); } show_ldap_error($ldap->get_error(), _("Saving FAI profile failed")); - - /* Do object tagging */ - $this->handle_object_tagging(); - show_ldap_error($ldap->get_error()); } diff --git a/plugins/admin/fai/class_faiScript.inc b/plugins/admin/fai/class_faiScript.inc index ac945d890..c4a84f381 100644 --- a/plugins/admin/fai/class_faiScript.inc +++ b/plugins/admin/fai/class_faiScript.inc @@ -464,9 +464,6 @@ class faiScript extends plugin } show_ldap_error($ldap->get_error(), _("Creating FAI script base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); - /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -531,16 +528,8 @@ class faiScript extends plugin $tmp['FAIpriority'] ="0"; } - /* Check if gosaAdministrativeUnitTag is required as object class */ - if($obj['status'] == "edited"){ - $ldap->cat($sub_dn,array("objectClass")); - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass'])){ - if(in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $tmp['objectClass'][] = "gosaAdministrativeUnitTag"; - } - } - } + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); if($obj['status'] == "delete"){ $ldap->cd($sub_dn); @@ -567,8 +556,6 @@ class faiScript extends plugin $this->handle_post_events("add"); show_ldap_error($ldap->get_error(), _("Saving FAI script failed")); } - - $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); } } diff --git a/plugins/admin/fai/class_faiTemplate.inc b/plugins/admin/fai/class_faiTemplate.inc index bb552443c..6a27eeca4 100644 --- a/plugins/admin/fai/class_faiTemplate.inc +++ b/plugins/admin/fai/class_faiTemplate.inc @@ -402,9 +402,6 @@ class faiTemplate extends plugin } show_ldap_error($ldap->get_error(), _("Saving FAI template base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); - /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -463,16 +460,8 @@ class faiTemplate extends plugin } } - /* Check if gosaAdministrativeUnitTag is required as object class */ - if($obj['status'] == "edited"){ - $ldap->cat($sub_dn,array("objectClass")); - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass'])){ - if(in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $tmp['objectClass'][] = "gosaAdministrativeUnitTag"; - } - } - } + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); if($obj['status'] == "delete"){ $ldap->cd($sub_dn); @@ -498,8 +487,6 @@ class faiTemplate extends plugin $this->handle_post_events("add"); show_ldap_error($ldap->get_error(), _("Creating FAI template entry failed")); } - - $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); } } diff --git a/plugins/admin/fai/class_faiVariable.inc b/plugins/admin/fai/class_faiVariable.inc index 171ad312d..a2f36897f 100644 --- a/plugins/admin/fai/class_faiVariable.inc +++ b/plugins/admin/fai/class_faiVariable.inc @@ -314,9 +314,6 @@ class faiVariable extends plugin } show_ldap_error($ldap->get_error(), _("Saving FAI variable base failed")); - /* Do object tagging */ - $this->handle_object_tagging(); - /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -363,16 +360,8 @@ class faiVariable extends plugin } } - /* Check if gosaAdministrativeUnitTag is required as object class */ - if($obj['status'] == "edited"){ - $ldap->cat($sub_dn,array("objectClass")); - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass'])){ - if(in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $tmp['objectClass'][] = "gosaAdministrativeUnitTag"; - } - } - } + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); if($obj['status'] == "delete"){ $ldap->cd($sub_dn); @@ -399,8 +388,6 @@ class faiVariable extends plugin $this->handle_post_events("add"); show_ldap_error($ldap->get_error(), _("Saving FAI variable failed")); } - - $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); } } diff --git a/plugins/admin/groups/tabs_group.inc b/plugins/admin/groups/tabs_group.inc index 7adb0c305..c83e87628 100644 --- a/plugins/admin/groups/tabs_group.inc +++ b/plugins/admin/groups/tabs_group.inc @@ -77,10 +77,6 @@ class grouptabs extends tabs $ret= tabs::save(); - /* Fix tagging if needed */ - $baseobject->dn= $new_dn; - $baseobject->handle_object_tagging(); - return $ret; } diff --git a/plugins/admin/mimetypes/tabs_mimetypes.inc b/plugins/admin/mimetypes/tabs_mimetypes.inc index eb4368ce9..cab01e147 100644 --- a/plugins/admin/mimetypes/tabs_mimetypes.inc +++ b/plugins/admin/mimetypes/tabs_mimetypes.inc @@ -49,11 +49,6 @@ class mimetabs extends tabs } tabs::save(); - - /* Fix tagging if needed */ - $baseobject->dn= $this->dn; - $baseobject->handle_object_tagging(); - $this->by_object['mimetype'] = $baseobject; } } diff --git a/plugins/admin/ogroups/tabs_ogroups.inc b/plugins/admin/ogroups/tabs_ogroups.inc index 33c6ae98c..496e84c44 100644 --- a/plugins/admin/ogroups/tabs_ogroups.inc +++ b/plugins/admin/ogroups/tabs_ogroups.inc @@ -273,14 +273,10 @@ class ogrouptabs extends tabs } if ($this->dn == "new"){ - $this->dn= 'cn='.$baseobject->cn.','.get_groups_ou().$baseobject->base; + $this->dn= $new_dn; } tabs::save(); - - /* Fix tagging if needed */ - $baseobject->dn= $new_dn; - $baseobject->handle_object_tagging(); } function saveCopyDialog() diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc index d2f3b6bea..9fd41e31b 100644 --- a/plugins/admin/systems/class_printGeneric.inc +++ b/plugins/admin/systems/class_printGeneric.inc @@ -851,9 +851,6 @@ class printgeneric extends plugin $this->netConfigDNS->dn = $this->dn; $this->netConfigDNS->save($this->dn); } - - /* This is a multi object. Handle tagging here... */ - $this->handle_object_tagging(); } function generateList(){ diff --git a/plugins/admin/systems/tabs_component.inc b/plugins/admin/systems/tabs_component.inc index 60facee5a..55cb008cf 100644 --- a/plugins/admin/systems/tabs_component.inc +++ b/plugins/admin/systems/tabs_component.inc @@ -27,9 +27,6 @@ class componenttabs extends tabs } tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_phone.inc b/plugins/admin/systems/tabs_phone.inc index cae0a2493..7328c86d1 100644 --- a/plugins/admin/systems/tabs_phone.inc +++ b/plugins/admin/systems/tabs_phone.inc @@ -27,9 +27,6 @@ class phonetabs extends tabs } tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_printers.inc b/plugins/admin/systems/tabs_printers.inc index 0fbbccc22..fd255199c 100644 --- a/plugins/admin/systems/tabs_printers.inc +++ b/plugins/admin/systems/tabs_printers.inc @@ -45,9 +45,6 @@ class printtabs extends tabs } tabs::save(FALSE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_server.inc b/plugins/admin/systems/tabs_server.inc index 037aa8501..68a0f7b21 100644 --- a/plugins/admin/systems/tabs_server.inc +++ b/plugins/admin/systems/tabs_server.inc @@ -33,9 +33,6 @@ class servtabs extends tabs $config= $_SESSION['config']; $config->load_servers(); $_SESSION['config']= $config; - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_terminal.inc b/plugins/admin/systems/tabs_terminal.inc index cac248e2e..0395906ad 100644 --- a/plugins/admin/systems/tabs_terminal.inc +++ b/plugins/admin/systems/tabs_terminal.inc @@ -64,8 +64,6 @@ class termtabs extends tabs } } - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_winstation.inc b/plugins/admin/systems/tabs_winstation.inc index 3f03437fa..b04f89f98 100644 --- a/plugins/admin/systems/tabs_winstation.inc +++ b/plugins/admin/systems/tabs_winstation.inc @@ -33,9 +33,6 @@ class wintabs extends tabs } tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/systems/tabs_workstation.inc b/plugins/admin/systems/tabs_workstation.inc index 8716247cd..80c789ee8 100644 --- a/plugins/admin/systems/tabs_workstation.inc +++ b/plugins/admin/systems/tabs_workstation.inc @@ -59,9 +59,6 @@ class worktabs extends tabs $this->by_object['printgeneric']->remove_from_parent(); } } - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 410933631..79cda297b 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -985,9 +985,6 @@ class user extends plugin $this->handle_post_events("modify",array("uid" => $this->uid)); } - /* Fix tagging if needed */ - $this->handle_object_tagging(); - return (0); } -- 2.30.2