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