1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2007 Fabian Hickert
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 /* Get acls */
40 $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
41 $smarty->assign("ChangeACL" , $password_ACLS);
42 $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
44 /* Display expiration template */
45 if((isset($this->config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
46 preg_match('/true/i', $this->config->data['MAIN']['ACCOUNT_EXPIRATION'])){
47 $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
48 if($expired == 4){
49 return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
50 }
51 }
53 /* Pwd change requested */
54 if (isset($_POST['password_finish'])){
56 /* Should we check different characters in new password */
57 $check_differ = isset($this->config->data['MAIN']['PWDIFFER']);
58 $differ = @$this->config->data['MAIN']['PWDIFFER'];
60 /* Enable length check ? */
61 $check_length = isset($this->config->data['MAIN']['PWMINLEN']);
62 $length = @$this->config->data['MAIN']['PWMINLEN'];
64 /* Call external password quality hook ?*/
65 $check_hook = isset($this->config->data['MAIN']['EXTERNALPWDHOOK']);
66 $hook = @$this->config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".$_POST['current_password']." ".$_POST['new_password'];
67 if($check_hook){
68 exec($hook,$resarr);
69 $check_hook_output = "";
70 if(count($resarr) > 0) {
71 $check_hook_output= join('\n', $resarr);
72 }
73 }
75 /* Check given values */
76 if(!isset($_POST['current_password']) || empty($_POST['current_password'])){
77 print_red(_("You need to specify your current password in order to proceed."));
78 }elseif ($_POST['new_password'] != $_POST['repeated_password']){
79 print_red(_("The passwords you've entered as 'New password' and 'Repeated new password' do not match."));
80 } elseif ($_POST['new_password'] == ""){
81 print_red(_("The password you've entered as 'New password' is empty."));
82 }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
83 print_red(_("The password used as new and current are too similar."));
84 }elseif($check_length && (strlen($_POST['new_password']) < $length)){
85 print_red(_("The password used as new is to short."));
86 }elseif($check_hook && $check_hook_output != ""){
87 print_red(_("External password changer reported a problem: ".$check_hook_output));
88 }else{
90 /* Try to connect via current password */
91 $tldap = new LDAP(
92 $ui->dn,
93 $_POST['current_password'],
94 $this->config->current['SERVER'],
95 isset($this->config->current['RECURSIVE']) && preg_match("/true/i",$this->config->current['RECURSIVE']),
96 isset($this->config->current['TLS']) && preg_match("/true/i",$this->config->current['TLS']));
98 /* connection Successfull ? */
99 if ($tldap->error != "Success"){
100 print_red(_("The password you've entered as your current password doesn't match the real one."));
101 }else{
103 /* Check GOsa permissions */
104 if (!preg_match("/w/i",$password_ACLS)){
105 print_red(_("You have no permissions to change your password."));
106 }else{
107 change_password ($ui->dn, $_POST['new_password']);
108 gosa_log ("User/password has been changed");
109 $ui->password= $_POST['new_password'];
110 $_SESSION['ui']= $ui;
111 #$this->handle_post_events("modify",array("userPassword" => $_POST['new_password']));
112 return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
113 }
114 }
115 }
116 }
117 return($smarty->fetch(get_template_path("password.tpl", TRUE)));
118 }
120 function remove_from_parent()
121 {
122 $this->handle_post_events("remove");
123 }
125 function save()
126 {
127 }
129 function plInfo()
130 {
131 return (array(
132 "plDescription" => _("User password"),
133 "plSelfModify" => TRUE,
134 "plDepends" => array("user"),
135 "plPriority" => 10,
136 "plSection" => array("personal" => _("My account")),
137 "plCategory" => array("users"),
138 "plOptions" => array(),
140 "plProvidedAcls" => array())
141 );
142 }
144 }
145 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
146 ?>