2ff63b318ba7029ce8edbfbfc343495ae0205c56
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class password extends plugin
24 {
25 /* Definitions */
26 var $plHeadline = "Password";
27 var $plDescription = "Change user password";
29 var $proposal = "";
30 var $proposalEnabled = FALSE;
31 var $proposalSelected = FALSE;
33 var $forcedHash = NULL;
36 function password(&$config, $dn= NULL, $parent= NULL)
37 {
38 plugin::plugin($config, $dn, $parent);
40 // Try to generate a password proposal, if this is successfull
41 // then preselect the proposal usage.
42 $this->refreshProposal();
43 if($this->proposal != ""){
44 $this->proposalSelected = TRUE;
45 }
46 }
48 function forceHash($hash)
49 {
50 $this->forcedHash = $hash;
51 }
53 function refreshProposal()
54 {
55 $this->proposal = passwordMethod::getPasswordProposal($this->config);
56 $this->proposalEnabled = (!empty($this->proposal));
57 }
59 function execute()
60 {
61 plugin::execute();
62 $smarty = get_smarty();
63 $smarty->assign("usePrototype", "true");
64 $ui = get_userinfo();
66 /* Get acls */
67 $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
68 $smarty->assign("ChangeACL" , $password_ACLS);
69 $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
71 /* Display expiration template */
72 $smarty->assign("passwordExpired", FALSE);
73 if ($this->config->get_cfg_value("handleExpiredAccounts") == "true"){
74 $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
75 $smarty->assign("passwordExpired", $expired & POSIX_FORCE_PASSWORD_CHANGE);
76 if($expired == POSIX_DISALLOW_PASSWORD_CHANGE){
77 return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
78 }
79 }
82 // Refresh proposal if requested
83 if(isset($_POST['refreshProposal'])) $this->refreshProposal();
84 if(isset($_POST['proposalSelected'])) $this->proposalSelected = get_post('proposalSelected') == 1;
85 $smarty->assign("proposal" , $this->proposal);
86 $smarty->assign("proposalEnabled" , $this->proposalEnabled);
87 $smarty->assign("proposalSelected" , $this->proposalSelected);
89 /* Pwd change requested */
90 if (isset($_POST['password_finish'])){
93 if($this->proposalSelected){
94 $current_password = get_post('current_password');
95 $new_password = $this->proposal;
96 $repeated_password = $this->proposal;
97 }else{
98 $current_password = get_post('current_password');
99 $new_password = get_post('new_password');
100 $repeated_password = get_post('repeated_password');
101 }
104 /* Should we check different characters in new password */
105 $check_differ = $this->config->get_cfg_value("passwordMinDiffer") != "";
106 $differ = $this->config->get_cfg_value("passwordMinDiffer", 0);
108 /* Enable length check ? */
109 $check_length = $this->config->get_cfg_value("passwordMinLength") != "";
110 $length = $this->config->get_cfg_value("passwordMinLength", 0);
112 // Perform GOsa password policy checks
113 $message = array();
114 if(empty($current_password)){
115 $message[] = _("You need to specify your current password in order to proceed.");
116 }elseif($new_password != $repeated_password){
117 $message[] = _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
118 }elseif($new_password == ""){
119 $message[] = _("The password you've entered as 'New password' is empty.");
120 }elseif($check_differ && (substr($current_password, 0, $differ) == substr($new_password, 0, $differ))){
121 $message[] = _("The password used as new and current are too similar.");
122 }elseif($check_length && (strlen($new_password) < $length)){
123 $message[] = _("The password used as new is to short.");
124 #}elseif(!passwordMethod::is_harmless($new_password)){
125 # $message[] = _("The password contains possibly problematic Unicode characters!");
126 }
128 /* Call external password quality hook ?*/
129 if(!count($message)){
130 $check_hook = $this->config->get_cfg_value("passwordHook") != "";
131 $hook = $this->config->get_cfg_value("passwordHook")." ".
132 escapeshellarg($ui->username)." ".escapeshellarg($current_password)." ".escapeshellarg($new_password);
133 if($check_hook){
134 exec($hook,$resarr);
135 $check_hook_output = "";
136 if(count($resarr) > 0) {
137 $check_hook_output= join('\n', $resarr);
138 }
139 if(!empty($check_hook_output)){
140 $message[] = sprintf(_("Check-hook reported a problem: %s. Password change canceled!"),$check_hook_output);
141 }
142 }
143 }
145 // Some errors/warning occured, display them and abort password change.
146 if(count($message)){
147 msg_dialog::displayChecks($message);
148 }else{
150 /* Try to connect via current password */
151 $tldap = new LDAP(
152 $ui->dn,
153 $current_password,
154 $this->config->current['SERVER'],
155 $this->config->get_cfg_value("ldapFollowReferrals") == "true",
156 $this->config->get_cfg_value("ldapTLS") == "true");
158 /* connection Successfull ? */
159 if (!$tldap->success()){
160 msg_dialog::display(_("Password change"),
161 _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
162 }else{
164 /* Check GOsa permissions */
165 if (!preg_match("/w/i",$password_ACLS)){
166 msg_dialog::display(_("Password change"),
167 _("You have no permission to change your password."),WARNING_DIALOG);
168 }else{
169 $this->change_password($ui->dn, $new_password,$this->forcedHash);
170 gosa_log ("User/password has been changed");
171 $ui->password= $new_password;
172 session::set('ui',$ui);
173 #$this->handle_post_events("modify",array("userPassword" => $new_password));
174 return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
175 }
176 }
177 }
178 }
179 return($smarty->fetch(get_template_path("password.tpl", TRUE)));
180 }
182 function change_password($dn, $pwd, $hash)
183 {
184 if(!$hash){
185 change_password ($dn, $pwd);
186 }else{
187 change_password ($dn, $pwd,0, $hash);
188 }
189 }
192 function remove_from_parent()
193 {
194 $this->handle_post_events("remove");
195 }
197 function save()
198 {
199 }
201 static function plInfo()
202 {
203 return (array(
204 "plDescription" => _("User password"),
205 "plSelfModify" => TRUE,
206 "plDepends" => array("user"),
207 "plPriority" => 10,
208 "plSection" => array("personal" => _("My account")),
209 "plCategory" => array("users"),
210 "plOptions" => array(),
212 "plProvidedAcls" => array())
213 );
214 }
216 }
217 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
218 ?>