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 $display = "";
22 if (!$remove_lock){
24 /* Assign headline image */
25 $smarty->assign ('headimage',"");
26 $display= "";
28 $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
29 $smarty->assign("ChangeACL" , $password_ACLS);
30 $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
32 /* Check for interaction */
33 if ($_SERVER["REQUEST_METHOD"] == "POST"){
34 if (isset($_POST['password_finish'])){
35 $message= array();
37 /* Is current password correct? */
38 if ($_POST['current_password'] != ""){
39 $tldap = new LDAP($ui->dn, $_POST['current_password'],
40 $config->current['SERVER'],
41 isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
42 isset($config->current['TLS'])
43 && $config->current['TLS'] == "true");
44 if ($tldap->error != "Success"){
45 $message[]= _("The password you've entered as your current password doesn't match the real one.");
46 }
47 } else {
48 $message[]= _("You need to specify your current password in order to proceed.");
49 }
51 /* Do new and repeated password fields match? */
52 if ($_POST['new_password'] != $_POST['repeated_password']){
53 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
54 } else {
55 if ($_POST['new_password'] == ""){
56 $message[]= _("The password you've entered as 'New password' is empty.");
57 }
58 }
60 /* Password policy fulfilled? */
61 if (isset($config->data['MAIN']['PWDIFFER'])){
62 $l= $config->data['MAIN']['PWDIFFER'];
63 if (substr($_POST['current_password'], 0, $l) == substr($_POST['new_password'], 0, $l)){
64 $message[]= _("The password used as new and current are too similar.");
65 }
66 }
67 if (isset($config->data['MAIN']['PWMINLEN'])){
68 if (strlen($_POST['new_password']) < $config->data['MAIN']['PWMINLEN']){
69 $message[]= _("The password used as new is to short.");
70 }
71 }
73 if(!preg_match("/w/i",$password_ACLS)){
74 $message[]= _("You have no permissions to change your password.");
75 }
77 if (count ($message) != 0){
79 /* Show error message and continue editing */
80 show_errors($message);
82 } else {
84 /* Passed quality check, just try to change the password now */
85 $output= "";
86 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
87 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".
88 $_POST['current_password']." ".$_POST['new_password'], $resarr);
89 if(count($resarr) > 0) {
90 $output= join('\n', $resarr);
91 }
92 }
93 if ($output != ""){
94 $message[]= _("External password changer reported a problem: ".$output);
95 show_errors($message);
96 } else {
97 change_password ($ui->dn, $_POST['new_password']);
98 gosa_log ("User/password has been changed");
99 $ui->password= $_POST['new_password'];
100 $_SESSION['ui']= $ui;
101 $display= $smarty->fetch(get_template_path("changed.tpl", TRUE));
102 }
103 }
104 }
105 }
107 if ($display == ""){
108 if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
109 !preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
110 $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
111 }else{
112 $expired= ldap_expired_account($config, $ui->dn, $ui->username);
114 if($expired == 4){
115 $display= $smarty->fetch(get_template_path("nochange.tpl", TRUE));
116 }else{
117 $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
118 }
119 }
120 }
121 }
123 $display = print_header(get_template_path('images/password.png'),_("Change password"), "").$display;
126 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
127 ?>