X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_plugin.inc;h=8e992dccc33c03b894848d7fe53767a16b168040;hb=8b2de39692985b42a1c3c4e2ce655a9ff21d18fd;hp=9d7de4e59ff66c58dd69c003e8ca18b90a35a51d;hpb=ec2413db23159069935684bc98a051c9aa0f7478;p=gosa.git diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 9d7de4e59..8e992dccc 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -83,6 +83,11 @@ class plugin */ var $attrs= array(); + /* Keep set of conflicting plugins */ + var $conflicts= array(); + + /* Save unit tags */ + var $gosaUnitTag= ""; /*! \brief Used standard values @@ -102,6 +107,9 @@ class plugin var $new= TRUE; var $saved_attributes= array(); + /* This can be set to render the tabulators in another stylesheet */ + var $pl_notify= FALSE; + /*! \brief plugin constructor If 'dn' is set, the node loads the given 'dn' from LDAP @@ -109,7 +117,7 @@ class plugin \param dn Distinguished name to initialize plugin from \sa plugin() */ - function plugin ($config, $dn= NULL) + function plugin ($config, $dn= NULL, $parent= NULL) { /* Configuration is fine, allways */ $this->config= $config; @@ -125,18 +133,26 @@ class plugin if ($dn != NULL){ /* Load data to 'attrs' and save 'dn' */ - $ldap->cat ($dn); - $this->attrs= $ldap->fetch(); + if ($parent != NULL){ + $this->attrs= $parent->attrs; + } else { + $ldap->cat ($dn); + $this->attrs= $ldap->fetch(); + } /* Copy needed attributes */ foreach ($this->attributes as $val){ - #if (isset($this->attrs["$val"][0])){ $found= array_key_ics($val, $this->attrs); if ($found != ""){ $this->$val= $this->attrs["$found"][0]; } } + /* gosaUnitTag loading... */ + if (isset($this->attrs['gosaUnitTag'][0])){ + $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0]; + } + /* Set the template flag according to the existence of objectClass gosaUserTemplate */ if (isset($this->attrs['objectClass'])){ @@ -255,7 +271,7 @@ class plugin foreach ($this->attributes as $val){ if (chkacl ($this->acl, "$val") == "" && isset ($_POST["$val"])){ /* Check for modifications */ - if (get_magic_quotes_gpc()) { + if ((get_magic_quotes_gpc()) && !is_array($_POST["$val"])) { $data= stripcslashes($_POST["$val"]); } else { $data= $this->$val = $_POST["$val"]; @@ -367,6 +383,11 @@ class plugin } } } + + /* Update saved attributes and ensure that next cleanups will be successful too */ + foreach($this->attrs as $name => $value){ + $this->saved_attributes[$name] = $value; + } } /* Check formular input */ @@ -493,15 +514,20 @@ class plugin /* Show header message for tab dialogs */ function show_header($button_text, $text, $disabled= FALSE) { + $state = "disabled"; + if($this->is_account && $this->acl == "#all#"){ + $state= ""; + }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){ + $state= ""; + } + if ($disabled == TRUE){ $state= "disabled"; - } else { - $state= ""; } + $display= "\n

$text

\n"; - $display.= "acl, "all")." ".$state. - ">

 

"; + $display.= "". + "

 

"; return($display); } @@ -515,6 +541,12 @@ class plugin } if ($command != ""){ + + /* Additional attributes */ + foreach ($add_attrs as $name => $value){ + $command= preg_replace("/%$name/", $value, $command); + } + /* Walk through attribute list */ foreach ($this->attributes as $attr){ if (!is_array($this->$attr)){ @@ -523,11 +555,6 @@ class plugin } $command= preg_replace("/%dn/", $this->dn, $command); - /* Additional attributes */ - foreach ($add_attrs as $name => $value){ - $command= preg_replace("/%$name/", $value, $command); - } - if (check_command($command)){ @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); @@ -549,6 +576,12 @@ class plugin } if ($command != ""){ + + /* Additional attributes */ + foreach ($add_attrs as $name => $value){ + $command= preg_replace("/%$name/", $value, $command); + } + /* Walk through attribute list */ foreach ($this->attributes as $attr){ if (!is_array($this->$attr)){ @@ -557,11 +590,6 @@ class plugin } $command= preg_replace("/%dn/", $this->dn, $command); - /* Additional attributes */ - foreach ($add_attrs as $name => $value){ - $command= preg_replace("/%$name/", $value, $command); - } - if (check_command($command)){ @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); @@ -583,6 +611,12 @@ class plugin } if ($command != ""){ + + /* Additional attributes */ + foreach ($add_attrs as $name => $value){ + $command= preg_replace("/%$name/", $value, $command); + } + /* Walk through attribute list */ foreach ($this->attributes as $attr){ if (!is_array($this->$attr)){ @@ -616,7 +650,7 @@ class plugin /* Try to use plain entry first */ $dn= "$attribute=".$this->$attribute.",$base"; - $ldap->cat ($dn); + $ldap->cat ($dn, array('dn')); if (!$ldap->fetch()){ return ($dn); } @@ -628,7 +662,7 @@ class plugin } $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base"; - $ldap->cat ($dn); + $ldap->cat ($dn, array('dn')); if (!$ldap->fetch()){ return ($dn); } @@ -657,7 +691,7 @@ class plugin { /* Rename dn in possible object groups */ $ldap= $this->config->get_ldap_link(); - $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.$src_dn.'))', + $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($src_dn).'))', array('cn')); while ($attrs= $ldap->fetch()){ $og= new ogroup($this->config, $ldap->getDN()); @@ -669,16 +703,15 @@ class plugin $ldap->cat($dst_dn); $attrs= $ldap->fetch(); if (count($attrs)){ - trigger_error("Trying to overwrite $dst_dn, which already exists.", + trigger_error("Trying to overwrite ".@LDAP::fix($dst_dn).", which already exists.", E_USER_WARNING); return (FALSE); } $ldap->cat($src_dn); - $attrs= array(); $attrs= $ldap->fetch(); if (!count($attrs)){ - trigger_error("Trying to move $src_dn, which does not seem to exist.", + trigger_error("Trying to move ".@LDAP::fix($src_dn).", which does not seem to exist.", E_USER_WARNING); return (FALSE); } @@ -692,7 +725,7 @@ class plugin $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']); error_reporting (0); - $sr=ldap_read($ds, $ldap->fix($src_dn), "objectClass=*"); + $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*"); /* Fill data from LDAP */ $new= array(); @@ -720,20 +753,28 @@ class plugin /* Adapt naming attribute */ $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn); $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn); - $new[$dst_name]= $dst_val; + $new[$dst_name]= @LDAP::fix($dst_val); /* Check if this is a department. * If it is a dep. && there is a , override in his ou * change \2C to , again, else this entry can't be saved ... */ - if((isset($new['ou'])) &&( preg_match("/\\\\2C/",$new['ou']))){ - $new['ou'] = preg_replace("/\\\\2C/",",",$new['ou']); + if((isset($new['ou'])) &&( preg_match("/\\,/",$new['ou']))){ + $new['ou'] = preg_replace("/\\\\,/",",",$new['ou']); } /* Save copy */ $ldap->connect(); $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn)); + + /* FAIvariable=.../..., cn=.. + could not be saved, because the attribute FAIvariable was different to + the dn FAIvariable=..., cn=... */ + if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){ + $new['FAIvariable'] = $ldap->fix($new['FAIvariable']); + } $ldap->cd($dst_dn); $ldap->add($new); @@ -774,7 +815,7 @@ class plugin $ldap= $this->config->get_ldap_link(); /* Check if destination exists - abort */ - $ldap->cat($dst_dn); + $ldap->cat($dst_dn, array('dn')); if ($ldap->fetch()){ trigger_error("recursive_move $dst_dn already exists.", E_USER_WARNING); @@ -844,27 +885,131 @@ class plugin } $todo[] = "is_account"; foreach($todo as $var){ - $this->$var = $source->$var; + if (isset($source->$var)){ + $this->$var= $source->$var; + } } } - function handle_object_tagging() + function handle_object_tagging($dn= "", $tag= "", $show= false) { - /* Watch out for an administrative unit below own base */ - echo "handle_object_tagging()
";
-    echo "DN  : ".$this->dn."\n";
-    echo "Base: ".$this->config->current['BASE']."\n";
-    echo "
"; + //FIXME: How to optimize this? We have at least two + // LDAP accesses per object. It would be a good + // idea to have it integrated. + + /* No dn? Self-operation... */ + if ($dn == ""){ + $dn= $this->dn; + + /* No tag? Find it yourself... */ + if ($tag == ""){ + $len= strlen($dn); - /* Make a base search on every department */ - //FIXME: evaluate if these informations should be cached, too - #$parts= split(',', preg_replace("/,".normalizePreg($this->config->current['BASE'])."$/", '', $this->dn)); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging"); + $relevant= array(); + foreach ($this->config->adepartments as $key => $ntag){ - /* Set objectclass and attribute */ + /* 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; + } + } + } + + + /* Set tag? */ + if ($tag != ""){ + /* Set objectclass and attribute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); + $attrs= $ldap->fetch(); + if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ + if ($show) { + echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."
"; + flush(); + } + return; + } + if (count($attrs)){ + if ($show){ + echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."
"; + flush(); + } + $nattrs= array("gosaUnitTag" => $tag); + $nattrs['objectClass']= array(); + for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ + $oc= $attrs['objectClass'][$i]; + if ($oc != "gosaAdministrativeUnitTag"){ + $nattrs['objectClass'][]= $oc; + } + } + $nattrs['objectClass'][]= "gosaAdministrativeUnitTag"; + $ldap->cd($dn); + $ldap->modify($nattrs); + show_ldap_error($ldap->get_error(), _("Handle object tagging failed")); + } else { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging"); + } + + } else { + /* Remove objectclass and attribute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); + $attrs= $ldap->fetch(); + if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging"); + return; + } + if (count($attrs)){ + if ($show){ + echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."
"; + flush(); + } + $nattrs= array("gosaUnitTag" => array()); + $nattrs['objectClass']= array(); + for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ + $oc= $attrs['objectClass'][$i]; + if ($oc != "gosaAdministrativeUnitTag"){ + $nattrs['objectClass'][]= $oc; + } + } + $ldap->cd($dn); + $ldap->modify($nattrs); + show_ldap_error($ldap->get_error(), _("Handle object tagging failed")); + } else { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging"); + } + } } + + /* Add possibility to stop remove process */ + function allow_remove() + { + $reason= ""; + return $reason; + } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>