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 function password(&$config, $dn= NULL, $parent= NULL)
30 {
31 plugin::plugin($config, $dn, $parent);
32 }
35 function execute()
36 {
37 plugin::execute();
38 $smarty = get_smarty();
39 $ui = get_userinfo();
41 /* Get acls */
42 $password_ACLS = $ui->get_permissions($ui->dn,"users/password");
43 $smarty->assign("ChangeACL" , $password_ACLS);
44 $smarty->assign("NotAllowed" , !preg_match("/w/i",$password_ACLS));
46 /* Display expiration template */
47 if ($this->config->get_cfg_value("handleExpiredAccounts") == "true"){
48 $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
49 if($expired == 4){
50 return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
51 }
52 }
54 /* Pwd change requested */
55 if (isset($_POST['password_finish'])){
57 /* Should we check different characters in new password */
58 $check_differ = $this->config->get_cfg_value("passwordMinDiffer") != "";
59 $differ = $this->config->get_cfg_value("passwordMinDiffer", 0);
61 /* Enable length check ? */
62 $check_length = $this->config->get_cfg_value("passwordMinLength") != "";
63 $length = $this->config->get_cfg_value("passwordMinLength", 0);
65 /* Call external password quality hook ?*/
66 $check_hook = $this->config->get_cfg_value("passwordHook") != "";
67 $hook = $this->config->get_cfg_value("passwordHook")." ".$ui->username." ".$_POST['current_password']." ".$_POST['new_password'];
68 if($check_hook){
69 exec($hook,$resarr);
70 $check_hook_output = "";
71 if(count($resarr) > 0) {
72 $check_hook_output= join('\n', $resarr);
73 }
74 }
76 /* Check given values */
77 if(!isset($_POST['current_password']) || empty($_POST['current_password'])){
78 msg_dialog::display(_("Password change"),
79 _("You need to specify your current password in order to proceed."),WARNING_DIALOG);
80 }elseif ($_POST['new_password'] != $_POST['repeated_password']){
81 msg_dialog::display(_("Password change"),
82 _("The passwords you've entered as 'New password' and 'Repeated new password' do not match."),WARNING_DIALOG);
83 } elseif ($_POST['new_password'] == ""){
84 msg_dialog::display(_("Password change"),
85 _("The password you've entered as 'New password' is empty."),WARNING_DIALOG);
86 }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
87 msg_dialog::display(_("Password change"),
88 _("The password used as new and current are too similar."),WARNING_DIALOG);
89 }elseif($check_length && (strlen($_POST['new_password']) < $length)){
90 msg_dialog::display(_("Password change"),
91 _("The password used as new is to short."),WARNING_DIALOG);
92 }elseif($check_hook && $check_hook_output != ""){
93 msg_dialog::display(_("Password change"),
94 sprintf(_("External password changer reported a problem: %s."),$check_hook_output),WARNING_DIALOG);
95 }else{
97 /* Try to connect via current password */
98 $tldap = new LDAP(
99 $ui->dn,
100 $_POST['current_password'],
101 $this->config->current['SERVER'],
102 $this->config->get_cfg_value("ldapFollowReferrals") == "true",
103 $this->config->get_cfg_value("ldapTLS") == "true");
105 /* connection Successfull ? */
106 if (!$tldap->success()){
107 msg_dialog::display(_("Password change"),
108 _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
109 }else{
111 /* Check GOsa permissions */
112 if (!preg_match("/w/i",$password_ACLS)){
113 msg_dialog::display(_("Password change"),
114 _("You have no permission to change your password."),WARNING_DIALOG);
115 }else{
116 change_password ($ui->dn, $_POST['new_password']);
117 gosa_log ("User/password has been changed");
118 $ui->password= $_POST['new_password'];
119 session::global_set('ui',$ui);
120 #$this->handle_post_events("modify",array("userPassword" => $_POST['new_password']));
121 return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
122 }
123 }
124 }
125 }
126 return($smarty->fetch(get_template_path("password.tpl", TRUE)));
127 }
129 function remove_from_parent()
130 {
131 $this->handle_post_events("remove");
132 }
134 function save()
135 {
136 }
138 static function plInfo()
139 {
140 return (array(
141 "plDescription" => _("User password"),
142 "plSelfModify" => TRUE,
143 "plDepends" => array("user"),
144 "plPriority" => 10,
145 "plSection" => array("personal" => _("My account")),
146 "plCategory" => array("users"),
147 "plOptions" => array(),
149 "plProvidedAcls" => array())
150 );
151 }
153 }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>