Code

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