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