Code

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