Code

Added acls for password change
[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   $password_ACLS = "cmdr";
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){
78         /* Show error message and continue editing */
79         show_errors($message);
80       } else {
82         /* Passed quality check, just try to change the password now */
83         $output= "";
84         if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
85           exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".
86                $_POST['current_password']." ".$_POST['new_password'], $resarr);
87           if(count($resarr) > 0) {
88             $output= join('\n', $resarr);
89           }
90         }
91         if ($output != ""){
92           $message[]= _("External password changer reported a problem: ".$output);
93           show_errors($message);
94         } else {                
95           change_password ($ui->dn, $_POST['new_password']);
96           gosa_log ("User/password has been changed");
97           $ui->password= $_POST['new_password'];
98           $_SESSION['ui']= $ui;
99           $display= $smarty->fetch(get_template_path("changed.tpl", TRUE));
100         }
101       }
102     }
103   }
105   if ($display == ""){
106     if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
107       !preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
108       $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
109     }else{
110       $expired= ldap_expired_account($config, $ui->dn, $ui->username);
111      
112       if($expired == 4){
113         $display= $smarty->fetch(get_template_path("nochange.tpl", TRUE));
114       }else{
115         $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
116       }
117     }
118   }
121 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
122 ?>