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 class password extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "Password";
25 var $plDescription = "This does something";
27 function password($config, $dn= NULL, $parent= NULL)
28 {
29 plugin::plugin($config, $dn, $parent);
30 }
33 function execute()
34 {
35 plugin::execute();
36 $smarty = get_smarty();
37 $ui = get_userinfo();
39 /* Display expiration template */
40 if((isset($this->config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
41 preg_match('/true/i', $this->config->data['MAIN']['ACCOUNT_EXPIRATION'])){
42 $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
43 if($expired == 4){
44 return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
45 }
46 }
48 /* Pwd change requested */
49 if (isset($_POST['password_finish'])){
51 /* Should we check different characters in new password */
52 $check_differ = isset($this->config->data['MAIN']['PWDIFFER']);
53 $differ = @$this->config->data['MAIN']['PWDIFFER'];
55 /* Enable length check ? */
56 $check_length = isset($this->config->data['MAIN']['PWMINLEN']);
57 $length = @$this->config->data['MAIN']['PWMINLEN'];
59 /* Call external password quality hook ?*/
60 $check_hook = isset($this->config->data['MAIN']['EXTERNALPWDHOOK']);
61 $hook = @$this->config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".$_POST['current_password']." ".$_POST['new_password'];
62 if($check_hook){
63 exec($hook,$resarr);
64 $check_hook_output = "";
65 if(count($resarr) > 0) {
66 $check_hook_output= join('\n', $resarr);
67 }
68 }
70 /* Check given values */
71 if(!isset($_POST['current_password']) || empty($_POST['current_password'])){
72 print_red(_("You need to specify your current password in order to proceed."));
73 }elseif ($_POST['new_password'] != $_POST['repeated_password']){
74 print_red(_("The passwords you've entered as 'New password' and 'Repeated new password' do not match."));
75 } elseif ($_POST['new_password'] == ""){
76 print_red(_("The password you've entered as 'New password' is empty."));
77 }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
78 print_red(_("The password used as new and current are too similar."));
79 }elseif($check_length && (strlen($_POST['new_password']) < $length)){
80 print_red(_("The password used as new is to short."));
81 }elseif($check_hook && $check_hook_output != ""){
82 print_red(_("External password changer reported a problem: ".$check_hook_output));
83 }else{
85 /* Try to connect via current password */
86 $tldap = new LDAP(
87 $ui->dn,
88 $_POST['current_password'],
89 $this->config->current['SERVER'],
90 isset($this->config->current['RECURSIVE']) && preg_match("/true/i",$this->config->current['RECURSIVE']),
91 isset($this->config->current['TLS']) && preg_match("/true/i",$this->config->current['TLS']));
93 /* connection Successfull ? */
94 if ($tldap->error != "Success"){
95 print_red(_("The password you've entered as your current password doesn't match the real one."));
96 }else{
98 /* Check GOsa permissions */
99 $ca= get_permissions ($ui->dn, $ui->subtreeACL);
100 $ca= get_module_permission($ca, "user", $ui->dn);
101 if (chkacl($ca, "password") != ""){
102 print_red(_("You have no permissions to change your password."));
103 }else{
104 change_password ($ui->dn, $_POST['new_password']);
105 gosa_log ("User/password has been changed");
106 $ui->password= $_POST['new_password'];
107 $_SESSION['ui']= $ui;
108 #$this->handle_post_events("modify",array("pwd" => $_POST['new_password']));
109 return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
110 }
111 }
112 }
113 }
114 return($smarty->fetch(get_template_path("password.tpl", TRUE)));
115 }
117 function remove_from_parent()
118 {
119 $this->handle_post_events("remove");
120 }
122 function save()
123 {
124 }
125 }
128 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
129 ?>