Code

Applied in_array strict patches from trunk
[gosa.git] / gosa-core / plugins / personal / posix / class_posixAccount.inc
index a0ef484c66baea3a80d08e3da13316f4d28c4120..88b1c132d08449faa8cbf3c422d229c635acfa7f 100644 (file)
@@ -34,7 +34,7 @@
 class posixAccount extends plugin
 {
   /* Definitions */
-  var $plHeadline= "UNIX";
+  var $plHeadline= "POSIX";
   var $plDescription= "Edit users POSIX settings";
 
   /* Plugin specific values */
@@ -75,10 +75,6 @@ class posixAccount extends plugin
   var $ssh= null;
   var $sshAcl= "";
 
-  var $GroupRegex= "*";
-  var $GroupUserRegex= "*";
-  var $SubSearch= false;
-
   var $view_logged= false;
 
   /* attribute list for save action */
@@ -109,7 +105,7 @@ class posixAccount extends plugin
     /* Load bases attributes */
     plugin::plugin($config, $dn, $parent);
 
-    $this->trustModeDialog = new trustModeDialog($this->config, $this->dn, $parent, 'users/posixAccount');
+    $this->trustModeDialog = new trustModeDialog($this->config, $this->dn, $parent);
     $this->trustModeDialog->setAcl('users/posixAccount');
 
     /*  If gotoLastSystemLogin is available read it from ldap and create a readable
@@ -132,7 +128,7 @@ class posixAccount extends plugin
 
       /* Correct is_account. shadowAccount is not required. */
       if (isset($this->attrs['objectClass']) &&
-          in_array ('posixAccount', $this->attrs['objectClass'])){
+          in_array_strict('posixAccount', $this->attrs['objectClass'])){
 
         $this->is_account= TRUE;
       }
@@ -221,7 +217,7 @@ class posixAccount extends plugin
     }
 
     /* Insert possibly missing loginShell */
-    if ($this->loginShell != "" && !in_array($this->loginShell, $this->loginShellList)){
+    if ($this->loginShell != "" && !in_array_strict($this->loginShell, $this->loginShellList)){
       $this->loginShellList[]= $this->loginShell;
     }
 
@@ -251,6 +247,7 @@ class posixAccount extends plugin
       $this->view_logged = TRUE;
       new log("view","users/".get_class($this),$this->dn);
     }
+    $this->dialog = FALSE;
 
     if($this->multiple_support_active){
       $this->is_account = TRUE;
@@ -304,13 +301,11 @@ class posixAccount extends plugin
     // Display dialog to allow selection of groups
     if (isset($_POST['edit_groupmembership'])){
       $this->groupSelect = new groupSelect($this->config,get_userinfo());
-      $this->dialog= TRUE;
     }
 
     // Cancel group dialog
     if (isset($_POST['add_groups_cancel'])){
       $this->groupSelect= NULL;
-      $this->dialog= FALSE;
     }
 
     // Add groups selected in groupSelect dialog to ours.
@@ -321,19 +316,18 @@ class posixAccount extends plugin
         $this->is_modified= TRUE;
       }
       $this->groupSelect= NULL;
-      $this->dialog= FALSE;
     }
 
     // Remove groups from currently selected groups.
     if (isset($_POST['delete_groupmembership']) && 
         isset($_POST['group_list']) && count($_POST['group_list'])){
 
-      $this->delGroup ($_POST['group_list']);
+      $this->delGroup (get_post('group_list'));
     }
 
     /* Templates now! */
     $smarty= get_smarty();
-    $smarty->assign("usePrototype", "true");
+
 
 
     // Handle trust mode dialog
@@ -343,12 +337,12 @@ class posixAccount extends plugin
         return($trustModeDialog);
         
     }
-    $this->dialog = FALSE;
     $smarty->assign("trustModeDialog" , $trustModeDialog);
 
 
     /* Manage group add dialog */
     if ($this->groupSelect){
+      $this->dialog = TRUE;
 
       // Build up blocklist
       session::set('filterBlacklist', array('dn' => array_keys($this->groupMembership)));
@@ -357,19 +351,18 @@ class posixAccount extends plugin
 
     // Handle ssh dialog?
     if ($this->ssh instanceOf sshPublicKey && preg_match('/[rw]/', $this->getacl("sshPublicKey"))) {
-      $smarty->assign("usePrototype", "false");
+
       if ($result= $this->ssh->execute()) {
         $this->dialog= true;
         pathNavigator::registerPlugin("SSH keys");
         return $result;
       }
-      $this->dialog= false;
     }
 
 
     /* Show main page */
     $smarty= get_smarty();
-    $smarty->assign("usePrototype", "true");
+
 
     $smarty->assign("sshPublicKeyACL", $this->getacl("sshPublicKey"));
 
@@ -407,22 +400,23 @@ class posixAccount extends plugin
     }
 
     // Set last system login
-    $smarty->assign("gotoLastSystemLogin",$this->gotoLastSystemLogin);
+    $smarty->assign("gotoLastSystemLogin", set_post($this->gotoLastSystemLogin));
 
     /* Fill arrays */
-    $smarty->assign("shells", $this->loginShellList);
+    $smarty->assign("shells", set_post($this->loginShellList));
     $smarty->assign("secondaryGroups", $this->secondaryGroups);
-    $smarty->assign("primaryGroup", $this->primaryGroup);
+    $smarty->assign("primaryGroup", set_post($this->primaryGroup));
     if(!$this->multiple_support_active){
       if (!count($this->groupMembership)){
         $smarty->assign("groupMembership", array(" "));
       } else {
-        $smarty->assign("groupMembership", $this->groupMembership);
+        $smarty->assign("groupMembership", set_post($this->groupMembership));
       }
     }else{
-      $smarty->assign("groupMembership", $this->groupMembership);
-      $smarty->assign("groupMembership_some", $this->groupMembership_some);
+      $smarty->assign("groupMembership", set_post($this->groupMembership));
+      $smarty->assign("groupMembership_some", set_post($this->groupMembership_some));
     }
+
     if (count($this->groupMembership) > 16){
       $smarty->assign("groups", "too_many_for_nfs");
     } else {
@@ -458,7 +452,7 @@ class posixAccount extends plugin
     $smarty->assign("force_idsACL", $this->getacl("uidNumber").$this->getacl("gidNumber"));
 
     foreach(array("primaryGroup","activate_shadowWarning","activate_shadowInactive","activate_shadowMin","activate_shadowMax","activate_shadowExpire","mustchangepassword") as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
@@ -468,12 +462,12 @@ class posixAccount extends plugin
 
     /* Load attributes and acl's */
     foreach($this->attributes as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
       }
-      $smarty->assign("$val", $this->$val);
+      $smarty->assign("$val", set_post($this->$val));
     }
 
     $tmp = $this->plInfo();                                                                                    
@@ -497,7 +491,6 @@ class posixAccount extends plugin
     // Add SSH button if available
     $smarty->assign("sshPublicKey", $this->ssh?1:0);
 
-    $smarty->assign("apply", apply_filter());
     $smarty->assign("multiple_support" , $this->multiple_support_active);
     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
     return($display);
@@ -576,11 +569,11 @@ class posixAccount extends plugin
 
       /*Save primary group settings */
       if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
-        $data= $_POST['primaryGroup'];
+        $data= get_post('primaryGroup');
         if ($this->primaryGroup != $data){
           $this->is_modified= TRUE;
         }
-        $this->primaryGroup= $_POST['primaryGroup'];
+        $this->primaryGroup= get_post('primaryGroup');
       }
 
       /* Get seelcted shadow checkboxes */
@@ -589,7 +582,7 @@ class posixAccount extends plugin
           $activate_var = "activate_".$var;
           if(isset($_POST['activate_'.$var])){
             $this->$activate_var  = true;
-            $this->$var      = $_POST[$var];
+            $this->$var      = get_post($var);
           }else{
             $this->$activate_var  = false;
             if ($var != "shadowExpire") {
@@ -606,29 +599,6 @@ class posixAccount extends plugin
         $this->mustchangepassword = FALSE;
       }
     }
-
-    /* Get regex from alphabet */
-    if(isset($_GET['search'])){
-      $this->GroupRegex = $_GET['search']."*";
-    }
-
-    /* Check checkboxes and regexes */
-    if(isset($_POST["PosixGroupDialogPosted"])){
-
-      if(isset($_POST['SubSearch']) && ($_POST['SubSearch'])){
-        $this->SubSearch = true;
-      }else{
-        $this->SubSearch = false;
-      }
-      if(isset($_POST['guser'])){
-        $this->GroupUserRegex = $_POST['guser'];
-      }
-      if(isset($_POST['regex'])){
-        $this->GroupRegex = $_POST['regex'];
-      }
-    }
-    $this->GroupRegex = preg_replace("/\*\**/","*",$this->GroupRegex);
-    $this->GroupUserRegex = preg_replace("/\*\**/","*",$this->GroupUserRegex);
   }
 
 
@@ -650,7 +620,7 @@ class posixAccount extends plugin
     if ($this->mustchangepassword){
       $this->shadowLastChange= (int)(date("U") / 86400) - $this->shadowMax - 1;
     } else {
-      $this->shadowLastChange= (int)(date("U") / 86400);
+#      $this->shadowLastChange= (int)(date("U") / 86400);
     }
     if (!$this->activate_shadowWarning){
       $this->shadowWarning= "0";
@@ -711,7 +681,7 @@ class posixAccount extends plugin
       if ($ldap->count() == 0){
 
         $groupcn = $this->uid;
-        $pri_attr = $this->config->get_cfg_value("accountPrimaryAttribute");
+        $pri_attr = $this->config->get_cfg_value("core","accountPrimaryAttribute");
         $groupdn= preg_replace ('/^'.preg_quote($pri_attr,'/').'=[^,]+,'.preg_quote(get_people_ou(),'/').'/i',
             'cn='.$groupcn.','.get_groups_ou(), $this->dn);
 
@@ -790,8 +760,6 @@ class posixAccount extends plugin
     }
     /* Call parents save to prepare $this->attrs */
     plugin::save();
-    $this->trustModeDialog->dn = $this->dn;
-    $this->trustModeDialog->save();
 
     /* include global link_info */
     $this->cleanup();
@@ -832,6 +800,9 @@ class posixAccount extends plugin
       $this->ssh->save();
     }
 
+    $this->trustModeDialog->dn = $this->dn;
+    $this->trustModeDialog->save();
+
     /* Take care about groupMembership values: add to groups */
     foreach ($this->groupMembership as $key => $value){
       if (!isset($this->savedGroupMembership[$key])){
@@ -897,15 +868,15 @@ class posixAccount extends plugin
       if (!tests::is_id($this->uidNumber)){
         $message[]= msgPool::invalid(_("UID"), $this->uidNumber, "/[0-9]/");
       } else {
-        if ($this->uidNumber < $this->config->get_cfg_value("minId")){
-          $message[]= msgPool::toosmall(_("UID"), $this->config->get_cfg_value("minId"));
+        if ($this->uidNumber < $this->config->get_cfg_value("core","minId")){
+          $message[]= msgPool::toosmall(_("UID"), $this->config->get_cfg_value("core","minId"));
         }
       }
       if (!tests::is_id($this->gidNumber)){
         $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
       } else {
-        if ($this->gidNumber < $this->config->get_cfg_value("minId")){
-          $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
+        if ($this->gidNumber < $this->config->get_cfg_value("core","minId")){
+          $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("core","minId"));
         }
       }
     }
@@ -961,47 +932,47 @@ class posixAccount extends plugin
   function multiple_check()
   {
     $message = plugin::multiple_check();
-    if ($this->homeDirectory == "" && in_array("homeDirectory",$this->multi_boxes)){
+    if ($this->homeDirectory == "" && in_array_strict("homeDirectory",$this->multi_boxes)){
       $message[]= msgPool::required(_("Home directory"));
     }
-    if (!tests::is_path($this->homeDirectory) && in_array("homeDirectory",$this->multi_boxes)){
+    if (!tests::is_path($this->homeDirectory) && in_array_strict("homeDirectory",$this->multi_boxes)){
       $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
     }
 
     /* Check shadow settings, well I like spaghetties... */
-    if ($this->activate_shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+    if ($this->activate_shadowMin && in_array_strict("activate_shadowMin",$this->multi_boxes)){
       if (!tests::is_id($this->shadowMin)){
         $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
       }
     }
-    if ($this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+    if ($this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
       if (!tests::is_id($this->shadowMax)){
         $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
       }
     }
-    if ($this->activate_shadowWarning && in_array("activate_shadowWarning",$this->multi_boxes)){
+    if ($this->activate_shadowWarning && in_array_strict("activate_shadowWarning",$this->multi_boxes)){
       if (!tests::is_id($this->shadowWarning)){
         $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
       }
-      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+      if (!$this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
         $message[]= msgPool::depends("shadowWarning", "shadowMax");
       }
-      if ($this->shadowWarning > $this->shadowMax && in_array("activate_shadowWarning",$this->multi_boxes)){
+      if ($this->shadowWarning > $this->shadowMax && in_array_strict("activate_shadowWarning",$this->multi_boxes)){
         $message[]= msgPool::toobig("shadowWarning", "shadowMax");
       }
-      if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+      if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array_strict("activate_shadowMin",$this->multi_boxes)){
         $message[]= msgPool::tosmall("shadowWarning", "shadowMin");
       }
     }
-    if ($this->activate_shadowInactive && in_array("activate_shadowInactive",$this->multi_boxes)){
+    if ($this->activate_shadowInactive && in_array_strict("activate_shadowInactive",$this->multi_boxes)){
       if (!tests::is_id($this->shadowInactive)){
         $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
       }
-      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+      if (!$this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
         $message[]= msgPool::depends("shadowInactive", "shadowMax");
       }
     }
-    if ($this->activate_shadowMin && $this->activate_shadowMax && in_array("activate_shadowMin",$this->multi_boxes)){
+    if ($this->activate_shadowMin && $this->activate_shadowMax && in_array_strict("activate_shadowMin",$this->multi_boxes)){
       if ($this->shadowMin > $this->shadowMax){
         $message[]= msgPool::toobig("shadowMin", "shadowMax");
       }
@@ -1108,21 +1079,17 @@ class posixAccount extends plugin
       }
     }
 
-    /* FIXME: NEED review of this section */
-    /* Need to check shadowExpire separately */
-
-    /* 
-     * If shadowExpire is not enabled in the template, it's a UNIX timestamp - so don't convert it to seconds.
-     * The check is a hack - if difference between timestamp generated above and here is max 1 day.
-     */
-    if(abs($this->shadowExpire - time())>86400) {
-      $this->shadowExpire= $this->convertToSeconds($this->shadowExpire);
-    }
-
     /* Only enable checkbox, if shadowExpire is in the future */
     if($this->shadowExpire > time()) {
       $this->activate_shadowExpire= "1";
     }
+
+    /* Convert shadowExpire for usage */
+    if ($this->shadowExpire == 0){
+      $this->shadowExpire= "";
+    } else {
+      $this->shadowExpire= date('d.m.Y', $this->shadowExpire * 60 * 60 * 24);
+    }
   }
 
   function convertToSeconds($val)
@@ -1157,11 +1124,11 @@ class posixAccount extends plugin
   function saveCopyDialog()
   {
     if(isset($_POST['homeDirectory'])){
-      $this->homeDirectory = $_POST['homeDirectory'];
+      $this->homeDirectory = get_post('homeDirectory');
       if (isset ($_POST['force_ids'])){
         $data= 1;
-        $this->gidNumber = $_POST['gidNumber'];
-        $this->uidNumber = $_POST['uidNumber'];
+        $this->gidNumber = get_post('gidNumber');
+        $this->uidNumber = get_post('uidNumber');
       } else {
         $data= 0;
       }
@@ -1169,11 +1136,11 @@ class posixAccount extends plugin
         $this->is_modified= TRUE;
       }
       $this->force_ids= $data;
-      $data= $_POST['primaryGroup'];
+      $data= get_post('primaryGroup');
       if ($this->primaryGroup != $data){
         $this->is_modified= TRUE;
       }
-      $this->primaryGroup= $_POST['primaryGroup'];
+      $this->primaryGroup= get_post('primaryGroup');
     }
   }
 
@@ -1226,18 +1193,18 @@ class posixAccount extends plugin
 
     /* Assigned informations to smarty */
     $smarty = get_smarty();
-    $smarty->assign("homeDirectory",$this->homeDirectory);
+    $smarty->assign("homeDirectory",set_post($this->homeDirectory));
     $smarty->assign("secondaryGroups",$this->secondaryGroups);
-    $smarty->assign("primaryGroup",$this->primaryGroup);
+    $smarty->assign("primaryGroup",set_post($this->primaryGroup));
 
-    $smarty->assign("uidNumber",$this->uidNumber);
-    $smarty->assign("gidNumber",$this->gidNumber);
-    $smarty->assign("forceMode",$forceMode);
-    $smarty->assign("force_ids",$force_ids);
+    $smarty->assign("uidNumber",set_post($this->uidNumber));
+    $smarty->assign("gidNumber",set_post($this->gidNumber));
+    $smarty->assign("forceMode",set_post($forceMode));
+    $smarty->assign("force_ids",set_post($force_ids));
     if (!count($this->groupMembership)){
       $smarty->assign("groupMembership", array("&nbsp;"));
     } else {
-      $smarty->assign("groupMembership", $this->groupMembership);
+      $smarty->assign("groupMembership", set_post($this->groupMembership));
     }
 
     /* Display wars message if there are more than 16 group members */
@@ -1259,6 +1226,8 @@ class posixAccount extends plugin
   {
     plugin::PrepareForCopyPaste($source);
 
+    $this->trustModeDialog->PrepareForCopyPaste($source);
+
     /* Avoid using the same gid/uid number as source user 
        empty numbers to enforce new ones. */
     $this->savedUidNumber = "";
@@ -1285,6 +1254,30 @@ class posixAccount extends plugin
       $this->primaryGroup= $source['gidNumber'][0];
     }
 
+
+    /* Adjust shadow checkboxes */
+    foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
+                "shadowExpire") as $val){
+
+        if ($this->$val != 0){
+            $oval= "activate_".$val;
+            $this->$oval= "1";
+        }
+    }
+
+    /* Convert shadowExpire for usage */
+    if ($this->shadowExpire == 0){
+      $this->shadowExpire= "";
+    } else {
+      $this->shadowExpire= date('d.m.Y', $this->shadowExpire * 60 * 60 * 24);
+    }
+
+    $tmp = new trustModeDialog($this->config, $source['dn']);
+    $this->trustModeDialog = new trustModeDialog($this->config, $this->dn);
+    $this->trustModeDialog->trustModel = $tmp->trustModel;
+    $this->trustModeDialog->accessTo = $tmp->accessTo;
+    $this->trustModeDialog->setAcl('users/posixAccount');
+
   }
 
 
@@ -1304,6 +1297,10 @@ class posixAccount extends plugin
           "plSection"         => array("personal" => _("My account")),
           "plCategory"        => array("users"),
           "plOptions"         => array(),
+          "plRequirements"=> array(
+              'ldapSchema' => array('posixAccount' => ''),
+              'onFailureDisablePlugin' => array(get_class(), 'sambaAccount','netatalk','environment')
+              ),
 
           "plProvidedAcls"  => array(
 
@@ -1336,17 +1333,17 @@ class posixAccount extends plugin
     $ret['groupMembership']     = $this->groupMembership;
     $ret['groupMembership_some']= $this->groupMembership_some;
 
-    if(in_array("primaryGroup",$this->multi_boxes)){
+    if(in_array_strict("primaryGroup",$this->multi_boxes)){
       $ret['primaryGroup'] = $this->primaryGroup;
     }
     foreach(array("shadowWarning","shadowInactive","shadowMin","shadowMax", "shadowExpire") as $entry){
       $active = "activate_".$entry;
-      if(in_array($active,$this->multi_boxes)){
+      if(in_array_strict($active,$this->multi_boxes)){
         $ret[$entry] = $this->$entry;
         $ret[$active] = $this->$active;
       }
     }
-    if(in_array("mustchangepassword",$this->multi_boxes)){
+    if(in_array_strict("mustchangepassword",$this->multi_boxes)){
       $ret['mustchangepassword'] = $this->mustchangepassword;
     }
     return($ret);
@@ -1378,10 +1375,10 @@ class posixAccount extends plugin
       foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning") as $var) {
         if($this->acl_is_writeable($var)){
           $activate_var = "activate_".$var;
-          if(in_array($activate_var, $this->multi_boxes)){
+          if(in_array_strict($activate_var, $this->multi_boxes)){
             if(isset($_POST['activate_'.$var])){
               $this->$activate_var  = true;
-              $this->$var      = $_POST[$var];
+              $this->$var      = get_post($var);
             }else{
               $this->$activate_var  = false;
               $this->$var      = 0;
@@ -1391,7 +1388,7 @@ class posixAccount extends plugin
       }
 
       /* Restore shadow value, if the shadow attribute isn't used */
-      if(!in_array("activate_shadowExpire",$this->multi_boxes)){
+      if(!in_array_strict("activate_shadowExpire",$this->multi_boxes)){
         $this->shadowExpire = $expire_tmp;
       }
 
@@ -1404,11 +1401,11 @@ class posixAccount extends plugin
 
       /* Save primary group settings */
       if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
-        $data= $_POST['primaryGroup'];
+        $data= get_post('primaryGroup');
         if ($this->primaryGroup != $data){
           $this->is_modified= TRUE;
         }
-        $this->primaryGroup= $_POST['primaryGroup'];
+        $this->primaryGroup= get_post('primaryGroup');
       }
     }
   }
@@ -1450,7 +1447,7 @@ class posixAccount extends plugin
     $groups_all = $groups_some;
     foreach($groups_all as $id => $group){
       foreach($uids as $uid){
-        if(!in_array($uid,$groups_uid[$id])){
+        if(!in_array_strict($uid,$groups_uid[$id])){
           unset($groups_all[$id]);
           break;
         }