Code

Updated password change.
[gosa.git] / gosa-core / include / class_plugin.inc
index 580be7939ac143b284262d3860afcc144e22683a..588a9e0bef73c33fd103395fa4d766b48527dd65 100644 (file)
@@ -215,13 +215,18 @@ class plugin
           unset($this->saved_attributes[$index]);
           continue;
         }
-        if (isset($this->saved_attributes[$index][0]) && $this->saved_attributes[$index]["count"] == 1){
-          $tmp= $this->saved_attributes[$index][0];
-          unset($this->saved_attributes[$index]);
-          $this->saved_attributes[$index]= $tmp;
-          continue;
-        }
 
+        if (isset($this->saved_attributes[$index][0])){
+          if(!isset($this->saved_attributes[$index]["count"])){
+            $this->saved_attributes[$index]["count"] = count($this->saved_attributes[$index]);
+          }
+          if($this->saved_attributes[$index]["count"] == 1){
+            $tmp= $this->saved_attributes[$index][0];
+            unset($this->saved_attributes[$index]);
+            $this->saved_attributes[$index]= $tmp;
+            continue;
+          }
+        }
         unset($this->saved_attributes["$index"]["count"]);
       }
       if(isset($this->attrs['gosaUnitTag'])){
@@ -608,18 +613,25 @@ 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)){
-          $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
+          $add_attrs[$attr] = $this->$attr;
         }
       }
-      $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
+      $add_attrs['dn']=$this->dn;
+
+      $tmp = array();
+      foreach($add_attrs as $name => $value){
+        $tmp[$name] =  strlen($name);
+      }
+      arsort($tmp);
+      
+      /* Additional attributes */
+      foreach ($tmp as $name => $len){
+        $value = $add_attrs[$name];
+        $command= preg_replace("/%$name/", "$value", $command);
+      }
 
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
@@ -627,7 +639,7 @@ class plugin
 
         exec($command);
       } else {
-        $message[]= msgPool::cmdnotfound("POSTCREATE", get_class($this));
+        $message= msgPool::cmdnotfound("POSTCREATE", get_class($this));
         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
       }
     }
@@ -640,26 +652,31 @@ 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)){
-          $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
+          $add_attrs[$attr] = $this->$attr;
         }
       }
-      $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
+      $add_attrs['dn']=$this->dn;
 
-      if (check_command($command)){
-        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
-            $command, "Execute");
+      $tmp = array();
+      foreach($add_attrs as $name => $value){
+        $tmp[$name] =  strlen($name);
+      }
+      arsort($tmp);
+      
+      /* Additional attributes */
+      foreach ($tmp as $name => $len){
+        $value = $add_attrs[$name];
+        $command= preg_replace("/%$name/", "$value", $command);
+      }
 
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,$command, "Execute");
         exec($command);
       } else {
-        $message[]= msgPool::cmdnotfound("POSTMODIFY", get_class($this));
+        $message= msgPool::cmdnotfound("POSTMODIFY", get_class($this));
         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
       }
     }
@@ -671,18 +688,25 @@ class plugin
     $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
     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)){
-          $command= preg_replace("/%$attr( |$)/", $this->$attr." ", $command);
+          $add_attrs[$attr] = $this->$attr;
         }
       }
-      $command= preg_replace("/%dn( |$)/", $this->dn." ", $command);
+      $add_attrs['dn']=$this->dn;
+
+      $tmp = array();
+      foreach($add_attrs as $name => $value){
+        $tmp[$name] =  strlen($name);
+      }
+      arsort($tmp);
+      
+      /* Additional attributes */
+      foreach ($tmp as $name => $len){
+        $value = $add_attrs[$name];
+        $command= preg_replace("/%$name/", "$value", $command);
+      }
 
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
@@ -690,7 +714,7 @@ class plugin
 
         exec($command);
       } else {
-        $message[]= msgPool::cmdnotfound("POSTREMOVE", get_class($this));
+        $message= msgPool::cmdnotfound("POSTREMOVE", get_class($this));
         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
       }
     }
@@ -992,7 +1016,7 @@ class plugin
         foreach ($this->config->adepartments as $key => $ntag){
 
           /* This one is bigger than our dn, its not relevant... */
-          if ($len <= strlen($key)){
+          if ($len < strlen($key)){
             continue;
           }
 
@@ -1076,7 +1100,7 @@ class plugin
       $password       = $tmp['SNAPSHOT_PASSWORD'];
       $snapldapbase   = $tmp['SNAPSHOT_BASE'];
 
-      $ldap_to        = new ldapMultipelxer(new LDAP($user,$password, $server));
+      $ldap_to        = new ldapMultiplexer(new LDAP($user,$password, $server));
       $ldap_to -> cd($snapldapbase);
 
       if (!$ldap_to->success()){
@@ -1348,6 +1372,7 @@ class plugin
     $data  = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
 
     /* Import the given data */
+    $err = "";
     $ldap->import_complete_ldif($data,$err,false,false);
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, "", get_class()));