Code

Some backport from trunk
[gosa.git] / gosa-core / plugins / personal / password / class_password.inc
index a436e941f263ba89df9ddfc37e9e9a613ce7e292..df056069a208217c2a050b75408712b1fa1031b0 100644 (file)
@@ -28,20 +28,14 @@ class password extends plugin
 
     var $proposal = "";
     var $proposalEnabled = FALSE;
-    var $proposalSelected = TRUE;
+    var $proposalSelected = FALSE;
+    var $proposalInitialized = FALSE;
 
     var $forcedHash = NULL;
 
     function password(&$config, $dn= NULL, $parent= NULL)
     {
         plugin::plugin($config, $dn, $parent);
-
-        // Try to generate a password proposal, if this is successfull 
-        //  then preselect the proposal usage. 
-        $this->refreshProposal();
-        if($this->proposal != ""){
-            $this->proposalSelected = TRUE;
-        }
     }
 
     
@@ -64,6 +58,17 @@ class password extends plugin
         $smarty = get_smarty();
         $ui = get_userinfo();
 
+
+        // Try to generate a password proposal, if this is successfull 
+        //  then preselect the proposal usage. 
+        if(!$this->proposalInitialized){
+            $this->refreshProposal();
+            if($this->proposal != ""){
+                $this->proposalSelected = TRUE;
+            }
+            $this->proposalInitialized = TRUE;
+        }
+
         /* Get acls */
         $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
         $smarty->assign("ChangeACL" ,  $password_ACLS);
@@ -111,8 +116,8 @@ class password extends plugin
 
             // Call the check hook
             $attrs = array();
-            $attrs['current_password'] = escapeshellarg($current_password);
-            $attrs['new_password'] = escapeshellarg($new_password);
+            $attrs['current_password'] = ($current_password);
+            $attrs['new_password'] = ($new_password);
 
             // Perform GOsa password policy checks 
             if(empty($current_password)){
@@ -131,7 +136,7 @@ class password extends plugin
 
             // Call external check hook to validate the password change
             if(!count($message)){
-                $checkRes = $this->callCheckHook($attrs);
+                $checkRes = $this->callCheckHook($this->config,$this->dn,$attrs);
                 if(count($checkRes)){
                     $message[] = sprintf(_("Check-hook reported a problem: %s. Password change canceled!"),implode($checkRes));
                 }
@@ -179,13 +184,13 @@ class password extends plugin
     {
     }
 
-    function callCheckHook($attrs = array())
+    static function callCheckHook($config,$dn,$attrs = array())
     {
-        $command = $this->config->configRegistry->getPropertyValue(get_class($this),"check");
+        $command = $config->configRegistry->getPropertyValue("password","check");
         if (!empty($command)){
 
             // Build up ldif to send to the check hook
-            $ldif= "dn: $this->dn\n";
+            $ldif= "dn: $dn\n";
             foreach ($attrs as $name => $value){
                 $ldif.= "{$name}: {$value}\n";
             }
@@ -206,10 +211,8 @@ class password extends plugin
                 if($returnCode !== 0){
                     @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execution failed code: ".$returnCode);
                     @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Result: ".$err);
-                    if($displayErrors){
-                        $message= msgPool::cmdexecfailed($cmd,$command, get_class($plugin));
-                        msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
-                    }
+                    $message= msgPool::cmdexecfailed($err,$command, "password");
+                    msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
                 }else{
                     @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Result: ".$arr);
                     return(preg_split("/\n/", $arr,0,PREG_SPLIT_NO_EMPTY));
@@ -222,14 +225,52 @@ class password extends plugin
     static function plInfo()
     {
         return (array(
-                    "plDescription"     => _("User password"),
-                    "plSelfModify"      => TRUE,
-                    "plDepends"         => array("user"),
-                    "plPriority"        => 10,
+                    "plDescription" => _("User password"),
+                    "plSelfModify"  => TRUE,
+                    "plDepends"     => array("user"),
+                    "plPriority"    => 10,
                     "plSection"     => array("personal" => _("My account")),
                     "plCategory"    => array("users"),
-                    "plOptions"         => array(),
+                    "plOptions"     => array(),
 
+                    "plProperties" => array(
+                        array(
+                            "name"          => "PRELOCK",
+                            "type"          => "command",
+                            "default"       => "",
+                            "description"   => _("Script to be called before a password gets locked."),
+                            "check"         => "gosaProperty::isCommand",
+                            "migrate"       => "",
+                            "group"         => "password",
+                            "mandatory"     => FALSE),
+                        array(
+                            "name"          => "POSTLOCK",
+                            "type"          => "command",
+                            "default"       => "",
+                            "description"   => _("Script to be called after a password gets locked."),
+                            "check"         => "gosaProperty::isCommand",
+                            "migrate"       => "",
+                            "group"         => "password",
+                            "mandatory"     => FALSE),
+                        array(
+                            "name"          => "PREUNLOCK",
+                            "type"          => "command",
+                            "default"       => "",
+                            "description"   => _("Script to be called before a password gets unlocked."),
+                            "check"         => "gosaProperty::isCommand",
+                            "migrate"       => "",
+                            "group"         => "password",
+                            "mandatory"     => FALSE),
+                        array(
+                            "name"          => "POSTUNLOCK",
+                            "type"          => "command",
+                            "default"       => "",
+                            "description"   => _("Script to be called after a password gets unlocked."),
+                            "check"         => "gosaProperty::isCommand",
+                            "migrate"       => "",
+                            "group"         => "password",
+                            "mandatory"     => FALSE)
+                        ),
                     "plProvidedAcls"  => array())
                );
     }