Code

Language cleanup
[gosa.git] / gosa-core / plugins / personal / password / class_password.inc
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((isset($this->config->data['MAIN']['ACCOUNT_EXPIRATION'])) &&
48         preg_match('/true/i', $this->config->data['MAIN']['ACCOUNT_EXPIRATION'])){
49       $expired= ldap_expired_account($this->config, $ui->dn, $ui->username);
50       if($expired == 4){
51         return($smarty->fetch(get_template_path("nochange.tpl", TRUE)));
52       }
53     }
55     /* Pwd change requested */
56     if (isset($_POST['password_finish'])){
58       /* Should we check different characters in new password */
59       $check_differ = isset($this->config->data['MAIN']['PWDIFFER']);
60       $differ       = @$this->config->data['MAIN']['PWDIFFER'];
62       /* Enable length check ? */
63       $check_length = isset($this->config->data['MAIN']['PWMINLEN']);
64       $length       = @$this->config->data['MAIN']['PWMINLEN'];
66       /* Call external password quality hook ?*/
67       $check_hook   = isset($this->config->data['MAIN']['EXTERNALPWDHOOK']);
68       $hook         = @$this->config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".$_POST['current_password']." ".$_POST['new_password'];
69       if($check_hook){
70         exec($hook,$resarr);
71         $check_hook_output = "";
72         if(count($resarr) > 0) {
73           $check_hook_output= join('\n', $resarr);
74         }
75       }
77       /* Check given values */    
78       if(!isset($_POST['current_password']) || empty($_POST['current_password'])){
79         msg_dialog::display(_("Password change"),
80                             _("You need to specify your current password in order to proceed."),WARNING_DIALOG);
81       }elseif ($_POST['new_password'] != $_POST['repeated_password']){
82         msg_dialog::display(_("Password change"),
83                             _("The passwords you've entered as 'New password' and 'Repeated new password' do not match."),WARNING_DIALOG);
84       } elseif ($_POST['new_password'] == ""){
85         msg_dialog::display(_("Password change"),
86                             _("The password you've entered as 'New password' is empty."),WARNING_DIALOG);
87       }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
88         msg_dialog::display(_("Password change"),
89                             _("The password used as new and current are too similar."),WARNING_DIALOG);
90       }elseif($check_length && (strlen($_POST['new_password']) < $length)){
91         msg_dialog::display(_("Password change"),
92                             _("The password used as new is to short."),WARNING_DIALOG);
93       }elseif($check_hook && $check_hook_output != ""){
94         msg_dialog::display(_("Password change"),
95                     sprintf(_("External password changer reported a problem: %s."),$check_hook_output),WARNING_DIALOG);
96       }else{
98         /* Try to connect via current password */
99         $tldap = new LDAP(
100             $ui->dn, 
101             $_POST['current_password'],
102             $this->config->current['SERVER'],
103             isset($this->config->current['RECURSIVE'])  && preg_match("/true/i",$this->config->current['RECURSIVE']),
104             isset($this->config->current['TLS'])        && preg_match("/true/i",$this->config->current['TLS']));
106         /* connection Successfull ? */
107         if (!$tldap->success()){
108           msg_dialog::display(_("Password change"),
109                               _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
110         }else{
112           /* Check GOsa permissions */
113           if (!preg_match("/w/i",$password_ACLS)){
114             msg_dialog::display(_("Password change"),
115                                 _("You have no permission to change your password."),WARNING_DIALOG);
116           }else{
117             change_password ($ui->dn, $_POST['new_password']);
118             gosa_log ("User/password has been changed");
119             $ui->password= $_POST['new_password'];
120             session::set('ui',$ui);
121 #$this->handle_post_events("modify",array("userPassword" => $_POST['new_password']));
122             return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
123           }
124         }
125       }
126     }
127     return($smarty->fetch(get_template_path("password.tpl", TRUE)));
128   } 
130   function remove_from_parent()
131   {
132     $this->handle_post_events("remove");
133   }
135   function save()
136   {
137   }
139   static function plInfo()
140   {
141     return (array(
142           "plDescription"     => _("User password"),
143           "plSelfModify"      => TRUE,
144           "plDepends"         => array("user"),
145           "plPriority"        => 10,
146           "plSection"     => array("personal" => _("My account")),
147           "plCategory"    => array("users"),
148           "plOptions"         => array(),
150           "plProvidedAcls"  => array())
151         );
152   }
155 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
156 ?>