Code

Fixed bug #20
[gosa.git] / plugins / personal / password / main.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 if (!$remove_lock){
23   /* Assign headline image */
24   $smarty->assign ('headimage', get_template_path('images/password.png'));
25   $display= "";
27   $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
28   $smarty->assign("ChangeACL" ,  $password_ACLS);   
29   $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));   
31   /* Check for interaction */
32   if ($_SERVER["REQUEST_METHOD"] == "POST"){
33     if (isset($_POST['password_finish'])){
34       $message= array();
36       /* Is current password correct? */
37       if ($_POST['current_password'] != ""){
38         $tldap = new LDAP($ui->dn, $_POST['current_password'],
39             $config->current['SERVER'],
40             isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
41             isset($config->current['TLS'])
42             && $config->current['TLS'] == "true");
43         if ($tldap->error != "Success"){
44           $message[]= _("The password you've entered as your current password doesn't match the real one.");
45         }
46       } else {
47         $message[]= _("You need to specify your current password in order to proceed.");
48       }
50       /* Do new and repeated password fields match? */
51       if ($_POST['new_password'] != $_POST['repeated_password']){
52         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
53       } else {
54         if ($_POST['new_password'] == ""){
55           $message[]= _("The password you've entered as 'New password' is empty.");
56         }
57       }
59       /* Password policy fulfilled? */
60       if (isset($config->data['MAIN']['PWDIFFER'])){
61         $l= $config->data['MAIN']['PWDIFFER'];
62         if (substr($_POST['current_password'], 0, $l) == substr($_POST['new_password'], 0, $l)){
63           $message[]= _("The password used as new and current are too similar.");
64         }
65       }
66       if (isset($config->data['MAIN']['PWMINLEN'])){
67         if (strlen($_POST['new_password']) < $config->data['MAIN']['PWMINLEN']){
68           $message[]= _("The password used as new is to short.");
69         }
70       }
72       if(!preg_match("/w/i",$password_ACLS)){
73         $message[]= _("You have no permissions to change your password.");
74       }
76       if (count ($message) != 0){
77         /* Show error message and continue editing */
78         show_errors($message);
79       } else {
81         /* Passed quality check, just try to change the password now */
82         $output= "";
83         if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
84           exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".
85                $_POST['current_password']." ".$_POST['new_password'], $resarr);
86           if(count($resarr) > 0) {
87             $output= join('\n', $resarr);
88           }
89         }
90         if ($output != ""){
91           $message[]= _("External password changer reported a problem: ".$output);
92           show_errors($message);
93         } else {                
94           change_password ($ui->dn, $_POST['new_password']);
95           gosa_log ("User/password has been changed");
96           $ui->password= $_POST['new_password'];
97           $_SESSION['ui']= $ui;
98           $display= $smarty->fetch(get_template_path("changed.tpl", TRUE));
99         }
100       }
101     }
102   }
104   if ($display == ""){
105     if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
106       !preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
107       $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
108     }else{
109       $expired= ldap_expired_account($config, $ui->dn, $ui->username);
110      
111       if($expired == 4){
112         $display= $smarty->fetch(get_template_path("nochange.tpl", TRUE));
113       }else{
114         $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
115       }
116     }
117   }
120 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
121 ?>