Code

Added some logging
[gosa.git] / plugins / admin / users / class_userManagement.inc
index d118a64c07630a73585739cf6048bb248b56472c..d11e22d654f7f57f63139e151413e461c0e37e69 100644 (file)
@@ -31,7 +31,6 @@ class userManagement extends plugin
   /* Dialog attributes */
   var $usertab              = NULL;
   var $ui                   = NULL;
-  var $acl                  = "";
   var $templates            = array();
   var $got_uid              = false;
   var $CopyPasteHandler     = NULL;
@@ -52,8 +51,6 @@ class userManagement extends plugin
     /* Creat dialog object */
     $this->DivListUsers = new divListUsers($this->config,$this);
 
-    /* LOCK MESSAGE Vars */
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
   }
 
 
@@ -62,6 +59,9 @@ class userManagement extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    /* LOCK MESSAGE Vars */
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
+
     $smarty       = get_smarty();                 // Smarty instance
     $s_action     = "";                           // Contains the action to be taken
     $s_entry      = "";                           // The value for s_action
@@ -79,6 +79,7 @@ class userManagement extends plugin
       foreach(array("del"       => "user_del",    "edit"      => "user_edit",
                     "new"       => "user_new",
                     "new_tpl"   => "user_tplnew",
+                    "del_multiple" => "^remove_multiple_users",
                     "create_user_from_tpl"          => "userfrom_tpl",
                     "change_pw" => "user_chgpw", 
                     "editPaste" => "editPaste",   "copy"      => "copy",
@@ -104,6 +105,10 @@ class userManagement extends plugin
       $s_tab= "user";
     }
 
+    if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
+      $s_tab = "user";
+    }
+
     /* Display the copy & paste dialog, if it is currently open */
     $ret = $this->copyPasteHandling($s_action,$s_entry);
     if($ret){
@@ -139,7 +144,7 @@ class userManagement extends plugin
       $this->usertab->current = $s_tab;
 
       /* Set ACL and move DN to the headline */
-      $this->usertab->set_acl_base();
+      $this->usertab->set_acl_base($this->dn);
       $_SESSION['objectinfo']= $this->dn;
     }
 
@@ -180,8 +185,7 @@ class userManagement extends plugin
 
       /* Load permissions for selected 'dn' and check if
          we're allowed to remove this 'dn' */
-      $ui = get_userinfo();
-      if (preg_match("/w/",$ui->get_permissions($this->dn,"users/password"))){
+      if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
 
         /* User is allowed to change passwords, save 'dn' and 'acl' for next
            dialog. */
@@ -203,11 +207,9 @@ class userManagement extends plugin
     if (isset($_POST['password_finish'])){
 
       /* For security reasons, check if user is allowed to set password again */
-      $ui  = get_userinfo();
-      $dn  = $this->usertab->dn;
-      $acl = $ui->get_permissions($dn, "users/password");
-      $cacl= $ui->get_permissions($dn, "users/user");
-
+      $dn  = $this->dn;
+      $acl = $this->ui->get_permissions($dn, "users/password");
+      $cacl= $this->ui->get_permissions($dn, "users/user");
 
       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
 
@@ -286,6 +288,88 @@ class userManagement extends plugin
     }
 
 
+    /********************
+      Delete MULTIPLE entries requested, display confirm dialog
+     ********************/
+
+    if ($s_action=="del_multiple"){
+      $ids = $this->list_get_selected_items();
+
+      if(count($ids)){
+
+        foreach($ids as $id){
+          $dn = $this->list[$id]['dn'];
+          if (($user= get_lock($dn)) != ""){
+            return(gen_locked_message ($user, $dn));
+          }
+          $this->dns[$id] = $dn; 
+        }
+
+        $dns_names = "<br><pre>";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="</pre>";
+
+        /* Lock the current entry, so nobody will edit it during deletion */
+        if (count($this->dns) == 1){
+          $smarty->assign("info",     sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
+        } else {
+          $smarty->assign("info",     sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
+        }
+        $smarty->assign("multiple", true);
+        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries confirmed 
+     ********************/
+
+      /* Confirmation for deletion has been passed. Users should be deleted. */
+      if (isset($_POST['delete_multiple_user_confirm'])){
+
+        /* Remove user by user and check acls before removeing them */
+        foreach($this->dns as $key => $dn){
+
+          $acl = $this->ui->get_permissions($dn, "users/user"); 
+          if (preg_match('/d/', $acl)){
+
+            /* Delete request is permitted, perform LDAP action */
+            $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
+            $this->usertab->set_acl_base();
+            $this->usertab->delete ();
+            gosa_log ("User object '".$dn."' has been removed");
+            unset ($this->usertab);
+            $this->usertab= NULL;
+          } else {
+            print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
+            if(isset($this->ui->uid)){
+              gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
+            }
+          }
+          /* Remove lock file after successfull deletion */
+          del_lock ($dn);
+          unset($this->dns[$key]);
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries Canceled 
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_user_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+  
+
     /********************
       Delete entry requested, display confirm dialog
      ********************/
@@ -308,6 +392,7 @@ class userManagement extends plugin
       /* Lock the current entry, so nobody will edit it during deletion */
       add_lock ($this->dn, $this->ui->dn);
       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
+      $smarty->assign("multiple", false);
       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
     }
 
@@ -322,8 +407,7 @@ class userManagement extends plugin
       /* Some nice guy may send this as POST, so we've to check
          for the permissions again. */
 
-      $ui  = get_userinfo();
-      $acl = $ui->get_permissions($this->dn, "users/user"); 
+      $acl = $this->ui->get_permissions($this->dn, "users/user"); 
  
       if (preg_match('/d/', $acl)){
 
@@ -401,6 +485,7 @@ class userManagement extends plugin
 
           /* In case of new users, ask for a password, skip this for templates */
           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
+            $this->dn = $this->usertab->dn;
             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
           }
 
@@ -430,11 +515,10 @@ class userManagement extends plugin
       foreach ($this->config->departments as $key => $value){
     
         /* Get acls from different ou's */
-        $ui  = get_userinfo();
-        $acl = $ui->get_permissions("cn=dummy,".$this->DivListUsers->selectedBase,"users/user")       ; 
+        $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
  
         /* If creation of a new user is allowed, append this template */
-        if (preg_match("/r/",$acl)){
+        if (preg_match("/c/",$acl)){
           
           /* Search all templates from the current dn */
           $ldap->cd (get_people_ou().$value);
@@ -674,7 +758,7 @@ class userManagement extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListUsers->SubSearch){
-      $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
+      $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
     }
     $this->reload();
     $this->DivListUsers->setEntries($this->list);
@@ -751,16 +835,25 @@ class userManagement extends plugin
     $SortTemp = array();
     $List = array();
     foreach($ListTemp as $Key => $Entry){
-       // Generate caption for rows
-      if (isset($Entry["sn"]) && isset($Entry["givenName"])){
-        $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
-      } else {
-        $display= "[".$Entry["uid"][0]."]";
-      }
 
-      $display = strtolower($display);
-      $List[$display] = $Entry;
-      $SortTemp[$display] = $display;
+      /* Skip entries that are not located under the people ou (normaly 'ou=people,')
+       * Else winstations will be listed too, if you use the subtree flag. 
+       */
+      if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
+        continue;
+      }else{
+
+        // Generate caption for rows
+        if (isset($Entry["sn"]) && isset($Entry["givenName"])){
+          $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
+        } else {
+          $display= "[".$Entry["uid"][0]."]";
+        }
+
+        $display = strtolower($display);
+        $List[$display] = $Entry;
+        $SortTemp[$display] = $display;
+      }
     }
     sort($SortTemp);
     reset($SortTemp);
@@ -803,6 +896,9 @@ class userManagement extends plugin
 
         /* Use the last dn to search for it's ID in the newly generated list. */
         $dn= $this->CopyPasteHandler->lastdn;
+
+        /* Get new user list */
+        $this->reload();
         foreach($this->list as $id => $entry){
           if($entry['dn'] == $dn){
             $s_entry= $id;
@@ -822,9 +918,20 @@ class userManagement extends plugin
       if($s_action == "copy"){
         $this->CopyPasteHandler->Clear();
         $dn= $this->list[trim($s_entry)]['dn'];
-        $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
-        $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
-        $this->CopyPasteHandler->Copy($obj,$objNew);
+
+        /* Check acl */
+        $ui = get_userinfo();
+        $acl_all  = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
+        if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+          $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
+          $obj->set_acl_base($dn);
+          $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
+          $objNew->set_acl_base($dn);
+
+          $this->CopyPasteHandler->Copy($obj,$objNew);
+        }else{
+          print_red("You are not allowed to copy this entry.");
+        }
       }
 
       /* Cut selected object. 
@@ -832,8 +939,16 @@ class userManagement extends plugin
       if($s_action == "cut"){
         $this->CopyPasteHandler->Clear();
         $dn= $this->list[trim($s_entry)]['dn'];
-        $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
-        $this->CopyPasteHandler->Cut($obj);
+
+        /* Check acl */
+        $acl_all  = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
+        if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+          $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
+          $obj->set_acl_base($dn);
+          $this->CopyPasteHandler->Cut($obj);
+        }else{
+          print_red("You are not allowed to cut this entry.");
+        }
       }
     }
   }
@@ -846,6 +961,20 @@ class userManagement extends plugin
     }
   }
 
+    
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[0-9]*$/",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
+      }
+    }
+    return($ids);
+  }
+  
+
   /* A set of disabled and therefore overloaded functions. They are
      not needed in this class. */
   function remove_from_parent() { }