Code

Added additional ip/domain checks
[gosa.git] / include / class_plugin.inc
index 69a537cff0390d85e1be89e08882e9e0ad6b5574..3ebd529b95ce2d1bbddeb48fe9fdb8ae579d3335 100644 (file)
@@ -83,6 +83,9 @@ class plugin
    */
   var $attrs= array();
 
+  /* Keep set of conflicting plugins */
+  var $conflicts= array();
+
   /* Save unit tags */
   var $gosaUnitTag= "";
 
@@ -663,7 +666,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());
@@ -675,7 +678,7 @@ 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);
     }
@@ -683,7 +686,7 @@ class plugin
     $ldap->cat($src_dn);
     $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);
     }
@@ -697,7 +700,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();
@@ -725,20 +728,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);
 
@@ -854,7 +865,7 @@ class plugin
   }
 
 
-  function handle_object_tagging($dn= "", $tag= "")
+  function handle_object_tagging($dn= "", $tag= "", $show= false)
   {
     //FIXME: How to optimize this? We have at least two
     //       LDAP accesses per object. It would be a good
@@ -905,14 +916,18 @@ class plugin
       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
       $attrs= $ldap->fetch();
       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
-        echo sprintf(_("Processing: Object '%s' is already tagged"), $dn);
-        flush();
+        if ($show) {
+          echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
+          flush();
+        }
         return;
       }
       if (count($attrs)){
-        echo sprintf(_("Processing: Adding tag (%s) to object '%s'"), $dn);
-        flush();
-        $nattrs= array("gosaUnitTag" => $this->gosaUnitTag);
+        if ($show){
+          echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
+          flush();
+        }
+        $nattrs= array("gosaUnitTag" => $tag);
         $nattrs['objectClass']= array();
         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
           $oc= $attrs['objectClass'][$i];
@@ -923,6 +938,7 @@ class plugin
         $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");
       }
@@ -937,8 +953,10 @@ class plugin
         return;
       }
       if (count($attrs)){
-        echo sprintf(_("Processing: Removing tag from object '%s'"), $dn);
-        flush();
+        if ($show){
+          echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
+          flush();
+        }
         $nattrs= array("gosaUnitTag" => array());
         $nattrs['objectClass']= array();
         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
@@ -949,7 +967,7 @@ class plugin
         }
         $ldap->cd($dn);
         $ldap->modify($nattrs);
-        show_ldap_error($ldap->get_error());
+        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");
       }
@@ -957,6 +975,14 @@ class plugin
     
   }
 
+
+  /* Add possibility to stop remove process */
+  function allow_remove()
+  {
+    $reason= "";
+    return $reason;
+  }
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>