Code

I've accidentally submitted the last few changes to tag/2.6 instead of /branches/2.6
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 13 Sep 2010 07:56:31 +0000 (07:56 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 13 Sep 2010 07:56:31 +0000 (07:56 +0000)
- Ported the changes to branches 2.6

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19611 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/personal/generic/class_user.inc
gosa-core/plugins/personal/generic/generic.tpl
gosa-core/plugins/personal/generic/generic_picture.tpl
gosa-core/plugins/personal/password/class_password.inc

index 8681b44fa6bb61bc69d649f4590519b71d4c7dc0..b75e3efeac7a55cf630ca6df50840e79790a0c38 100644 (file)
@@ -986,72 +986,57 @@ class user extends plugin
     /* Special handling for attribute jpegPhote needed, scale image via
        image magick to 147x200 pixels and inject resulting data. */
     if ($this->jpegPhoto == "*removed*"){
-    
-      /* Reset attribute to avoid writing *removed* as value */    
-      $this->attrs["jpegPhoto"] = array();
-
-    } else {
-
-      /* Fallback if there's no image magick inside PHP */
-      if (!function_exists("imagick_blob2image")){
-        /* Get temporary file name for conversation */
-        $fname = tempnam (TEMP_DIR, "GOsa");
-  
-        /* Open file and write out photoData */
-        $fp = fopen ($fname, "w");
-        fwrite ($fp, $this->photoData);
-        fclose ($fp);
-
-        /* Build conversation query. Filename is generated automatically, so
-           we do not need any special security checks. Exec command and save
-           output. For PHP safe mode, you'll need a configuration which respects
-           image magick as executable... */
-        $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
-        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
-            $query, "Execute");
-  
-        /* Read data written by convert */
-        $output= "";
-        $sh= popen($query, 'r');
-        while (!feof($sh)){
-          $output.= fread($sh, 4096);
-        }
-        pclose($sh);
-
-        unlink($fname);
 
-        /* Save attribute */
-        $this->attrs["jpegPhoto"] = $output;
-
-      } else {
+        /* Reset attribute to avoid writing *removed* as value */    
+        $this->attrs["jpegPhoto"] = array();
 
-        /* Load the new uploaded Photo */
-        if(!$handle  =  imagick_blob2image($this->photoData))  {
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
-        }
+    } else {
 
-        /* Resizing image to 147x200 and blur */
-        if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
-        }
+       if(class_exists('Imagick')){
+
+            $im = new Imagick();
+            $im->readImageBlob($this->photoData);
+            $im->setImageOpacity(1.0);
+            $im->resizeImage(147,200,Imagick::FILTER_UNDEFINED,0.5,TRUE);
+            $im->setCompressionQuality(90);
+            $im->setImageFormat('jpeg');
+            $this->attrs["jpegPhoto"] = $im->getImageBlob();
+
+        }elseif(exec('convert')){
+
+            /* Get temporary file name for conversation */
+            $fname = tempnam (TEMP_DIR, "GOsa");
+
+            /* Open file and write out photoData */
+            $fp = fopen ($fname, "w");
+            fwrite ($fp, $this->photoData);
+            fclose ($fp);
+
+            /* Build conversation query. Filename is generated automatically, so
+               we do not need any special security checks. Exec command and save
+               output. For PHP safe mode, you'll need a configuration which respects
+               image magick as executable... */
+            $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
+            @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+                    $query, "Execute");
+
+            /* Read data written by convert */
+            $output= "";
+            $sh= popen($query, 'r');
+            while (!feof($sh)){
+                $output.= fread($sh, 4096);
+            }
+            pclose($sh);
 
-        /* Converting image to JPEG */
-        if(!imagick_convert($handle,"JPEG")) {
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
-        }
+            unlink($fname);
 
-        /* Creating binary Code for the Image */
-        if(!$dump = imagick_image2blob($handle)){
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
+            /* Save attribute */
+            $this->attrs["jpegPhoto"] = $output;
+        }else{
+            msg_dialog::display(_("Error"), 
+                    _("Cannot save user picture, GOsa requires the package 'imagemagick' or 'php5-imagick' to be installed!"), 
+                    ERROR_DIALOG);
         }
-
-        /* Sending Image */
-        $output=  $dump;
-
-        /* Save attribute */
-        $this->attrs["jpegPhoto"] = $output;
-      }
-
     }
 
     /* This only gets called when user is renaming himself */
index 517218efbd0434698a472201c50bcb64e8d353b6..985cc80ea18360ac5bc232d822d31b3559be9002 100644 (file)
        <td style="vertical-align:top">
          <table>
           <tr>
-               <td width="147" height="200" bgcolor="gray">
+        <td style='width:147px; height:200px; background-color:gray; vertical-align: middle; text-align: center;'>
+
                {if !$userPicture_is_readable}
                        <img class='center' border="0" width="100%" src="plugins/users/images/default.jpg" alt="{t}Personal picture{/t}">
                {else}
-                       <img class='center' border="0" width="100%" src="getbin.php?rand={$rand}" alt="{t}Personal picture{/t}">
+            <img  src="getbin.php?rand={$rand}" alt='' style='max-width:147px; max-height: 200px; vertical-align: middle;'
+              alt="{t}Personal picture{/t}" >
                {/if}
                </td>
           </tr>
index de72255090d590f571a57be2568e8bd84c58962d..dbf04d3eba1d04ef1122003e52dfb06bb7b1e64d 100644 (file)
@@ -11,8 +11,8 @@
   <td>
    <table>
     <tr>
-     <td width="147" height="200" bgcolor="gray">
-      <img class="center" border="0" width="100%" src="getbin.php?rand={$rand}" alt="{t}Personal picture{/t}">
+     <td style='width:147px; height:200px; background-color:gray; vertical-align: middle; text-align: center;'>
+      <img  src="getbin.php?rand={$rand}" alt='' style='max-width:147px; max-height: 200px; vertical-align: middle;' >
      </td>
     </tr>
    </table>
index cb3b43fcd3bffb6c1deb11d0a8ec06e577f71156..aa18925bca9001e2c8b475d6c7394a81b7441cb5 100644 (file)
 
 class password extends plugin
 {
-  /* Definitions */
-  var $plHeadline     = "Password";
-  var $plDescription  = "Change user password";
-
-  var $proposal = "";
-  var $proposalEnabled = FALSE;
-  var $proposalSelected = 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;
-      }
-  }
-
-  function forceHash($hash)
-  {
-      $this->forcedHash = $hash;
-  }
-
-  function refreshProposal()
-  {
-      $this->proposal = passwordMethod::getPasswordProposal($this->config);
-      $this->proposalEnabled = (!empty($this->proposal));
-  }
-
-  function execute()
-  {
-    plugin::execute();
-    $smarty = get_smarty();
-    $smarty->assign("usePrototype", "true");
-    $ui = get_userinfo();
-
-    /* Get acls */
-    $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
-    $smarty->assign("ChangeACL" ,  $password_ACLS);
-    $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
-
-    /* Display expiration template */
-    $smarty->assign("passwordExpired", FALSE);
-    if ($this->config->get_cfg_value("handleExpiredAccounts") == "true"){
-      $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
-      $smarty->assign("passwordExpired", $expired & POSIX_FORCE_PASSWORD_CHANGE);
-      if($expired == POSIX_DISALLOW_PASSWORD_CHANGE){
-        return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
-      }
-    }
+    /* Definitions */
+    var $plHeadline     = "Password";
+    var $plDescription  = "Change user password";
 
+    function password(&$config, $dn= NULL, $parent= NULL)
+    {
+        plugin::plugin($config, $dn, $parent);
+    }
 
-    // Refresh proposal if requested
-    if(isset($_POST['refreshProposal'])) $this->refreshProposal();
-    if(isset($_POST['proposalSelected'])) $this->proposalSelected = get_post('proposalSelected') == 1;
-    $smarty->assign("proposal" , $this->proposal);
-    $smarty->assign("proposalEnabled" , $this->proposalEnabled);
-    $smarty->assign("proposalSelected" , $this->proposalSelected);
 
-    /* Pwd change requested */
-    if (isset($_POST['password_finish'])){
+    function execute()
+    {
+        plugin::execute();
+        $smarty = get_smarty();
+        $ui = get_userinfo();
 
+        /* Get acls */
+        $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
+        $smarty->assign("ChangeACL" ,  $password_ACLS);
+        $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
 
-        if($this->proposalSelected){
-            $current_password = get_post('current_password');
-            $new_password = $this->proposal;
-            $repeated_password = $this->proposal;
-        }else{
-            $current_password = get_post('current_password');
-            $new_password = get_post('new_password');
-            $repeated_password = get_post('repeated_password');
+        /* Display expiration template */
+        if ($this->config->get_cfg_value("handleExpiredAccounts") == "true"){
+            $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
+            if($expired == 4){
+                return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
+            }
         }
 
+        /* Pwd change requested */
+        if (isset($_POST['password_finish'])){
+
+            /* Should we check different characters in new password */
+            $check_differ = $this->config->get_cfg_value("passwordMinDiffer") != "";
+            $differ       = $this->config->get_cfg_value("passwordMinDiffer", 0);
+
+            /* Enable length check ? */
+            $check_length = $this->config->get_cfg_value("passwordMinLength") != "";
+            $length       = $this->config->get_cfg_value("passwordMinLength", 0);
+
+            // Validate input
+            $message = array();
+            if(!isset($_POST['current_password']) || empty($_POST['current_password'])){
+                $message[] = _("You need to specify your current password in order to proceed.");
+            }elseif ($_POST['new_password'] != $_POST['repeated_password']){
+                $message[] = _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
+            } elseif ($_POST['new_password'] == ""){
+                $message[] = _("The password you've entered as 'New password' is empty.");
+            }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
+                $message[] = _("The password used as new and current are too similar.");
+            }elseif($check_length && (strlen($_POST['new_password']) < $length)){
+                $message[] = _("The password used as new is to short.");
+            }
+            
+            // No errors yet, so call the external password hook.
+            if(!count($message)){
+                $check_hook   = $this->config->get_cfg_value("passwordHook") != "";
+                $hook         = $this->config->get_cfg_value("passwordHook")." ".
+                    $ui->username." ".$_POST['current_password']." ".$_POST['new_password'];
+                if($check_hook){
+                    exec($hook,$resarr);
+                    $check_hook_output = "";
+                    if(count($resarr) > 0) {
+                        $check_hook_output= join('\n', $resarr);
+                    }
+                    $check_hook_output= sprintf(_("External password changer reported a problem: %s."),$check_hook_output);
+                    if(!empty($check_hook_output))  $message[] = $check_hook_output;
+                }
+            }
+
+            if(count($message)){
+                msg_dialog::displayChecks($message);
+            }else{
+
+                /* Try to connect via current password */
+                $tldap = new LDAP(
+                        $ui->dn, 
+                        $_POST['current_password'],
+                        $this->config->current['SERVER'],
+                        $this->config->get_cfg_value("ldapFollowReferrals") == "true",
+                        $this->config->get_cfg_value("ldapTLS") == "true");
+
+                /* connection Successfull ? */
+                if (!$tldap->success()){
+                    msg_dialog::display(_("Password change"),
+                            _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
+                }else{
+
+                    /* Check GOsa permissions */
+                    if (!preg_match("/w/i",$password_ACLS)){
+                        msg_dialog::display(_("Password change"),
+                                _("You have no permission to change your password."),WARNING_DIALOG);
+                    }else{
+                        change_password ($ui->dn, $_POST['new_password']);
+                        gosa_log ("User/password has been changed");
+                        $ui->password= $_POST['new_password'];
+                        session::set('ui',$ui);
+                        return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
+                    }
+                }
+            }
+        }
+        return($smarty->fetch(get_template_path("password.tpl", TRUE)));
+    } 
 
-      /* Should we check different characters in new password */
-      $check_differ = $this->config->get_cfg_value("passwordMinDiffer") != "";
-      $differ       = $this->config->get_cfg_value("passwordMinDiffer", 0);
+    function remove_from_parent()
+    {
+        $this->handle_post_events("remove");
+    }
 
-      /* Enable length check ? */
-      $check_length = $this->config->get_cfg_value("passwordMinLength") != "";
-      $length       = $this->config->get_cfg_value("passwordMinLength", 0);
+    function save()
+    {
+    }
 
-      /* Call external password quality hook ?*/
-      $check_hook   = $this->config->get_cfg_value("passwordHook") != "";
-      $hook         = $this->config->get_cfg_value("passwordHook")." ".
-          escapeshellarg($ui->username)." ".escapeshellarg($current_password)." ".escapeshellarg($new_password);
-      if($check_hook){
-        exec($hook,$resarr);
-        $check_hook_output = "";
-        if(count($resarr) > 0) {
-          $check_hook_output= join('\n', $resarr);
-        }
-      }
-
-      /* Check given values */    
-      if(!isset($current_password) || empty($current_password)){
-        msg_dialog::display(_("Password change"),
-                            _("You need to specify your current password in order to proceed."),WARNING_DIALOG);
-      }elseif ($new_password != $repeated_password){
-        msg_dialog::display(_("Password change"),
-                            _("The passwords you've entered as 'New password' and 'Repeated new password' do not match."),WARNING_DIALOG);
-      } elseif ($new_password == ""){
-        msg_dialog::display(_("Password change"),
-                            _("The password you've entered as 'New password' is empty."),WARNING_DIALOG);
-      }elseif($check_differ && (substr($current_password, 0, $differ) == substr($new_password, 0, $differ))){
-        msg_dialog::display(_("Password change"),
-                            _("The password used as new and current are too similar."),WARNING_DIALOG);
-      }elseif($check_length && (strlen($new_password) < $length)){
-        msg_dialog::display(_("Password change"),
-                            _("The password used as new is to short."),WARNING_DIALOG);
-      }elseif($check_hook && $check_hook_output != ""){
-        msg_dialog::display(_("Password change"),
-                    sprintf(_("External password changer reported a problem: %s."),$check_hook_output),WARNING_DIALOG);
-      }else{
-
-        /* Try to connect via current password */
-        $tldap = new LDAP(
-            $ui->dn, 
-            $current_password,
-            $this->config->current['SERVER'],
-            $this->config->get_cfg_value("ldapFollowReferrals") == "true",
-            $this->config->get_cfg_value("ldapTLS") == "true");
-
-        /* connection Successfull ? */
-        if (!$tldap->success()){
-          msg_dialog::display(_("Password change"),
-                              _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
-        }else{
-
-          /* Check GOsa permissions */
-          if (!preg_match("/w/i",$password_ACLS)){
-            msg_dialog::display(_("Password change"),
-                                _("You have no permission to change your password."),WARNING_DIALOG);
-          }else{
-            $this->change_password($ui->dn, $new_password,$this->forcedHash);
-            gosa_log ("User/password has been changed");
-            $ui->password= $new_password;
-            session::set('ui',$ui);
-#$this->handle_post_events("modify",array("userPassword" => $new_password));
-            return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
-          }
-        }
-      }
+    static function plInfo()
+    {
+        return (array(
+                    "plDescription"     => _("User password"),
+                    "plSelfModify"      => TRUE,
+                    "plDepends"         => array("user"),
+                    "plPriority"        => 10,
+                    "plSection"     => array("personal" => _("My account")),
+                    "plCategory"    => array("users"),
+                    "plOptions"         => array(),
+
+                    "plProvidedAcls"  => array())
+               );
     }
-    return($smarty->fetch(get_template_path("password.tpl", TRUE)));
-  } 
-
-  function change_password($dn, $pwd, $hash)
-  {
-      if(!$hash){
-          change_password ($dn, $pwd);
-      }else{
-          change_password ($dn, $pwd,0, $hash);
-      }
-  }
-
-
-  function remove_from_parent()
-  {
-    $this->handle_post_events("remove");
-  }
-
-  function save()
-  {
-  }
-
-  static function plInfo()
-  {
-    return (array(
-          "plDescription"     => _("User password"),
-          "plSelfModify"      => TRUE,
-          "plDepends"         => array("user"),
-          "plPriority"        => 10,
-          "plSection"     => array("personal" => _("My account")),
-          "plCategory"    => array("users"),
-          "plOptions"         => array(),
-
-          "plProvidedAcls"  => array())
-        );
-  }
 
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: