Code

Closes #237 Just a test commit
[gosa.git] / plugins / personal / password / class_password.inc
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         msg_dialog::display(_("User password"),
78                             _("You need to specify your current password in order to proceed."),WARNING_DIALOG);
79       }elseif ($_POST['new_password'] != $_POST['repeated_password']){
80         msg_dialog::display(_("User password"),
81                             _("The passwords you've entered as 'New password' and 'Repeated new password' do not match."),WARNING_DIALOG);
82       } elseif ($_POST['new_password'] == ""){
83         msg_dialog::display(_("User password"),
84                             _("The password you've entered as 'New password' is empty."),WARNING_DIALOG);
85       }elseif($check_differ && (substr($_POST['current_password'], 0, $differ) == substr($_POST['new_password'], 0, $differ))){
86         msg_dialog::display(_("User password"),
87                             _("The password used as new and current are too similar."),WARNING_DIALOG);
88       }elseif($check_length && (strlen($_POST['new_password']) < $length)){
89         msg_dialog::display(_("User password"),
90                             _("The password used as new is to short."),WARNING_DIALOG);
91       }elseif($check_hook && $check_hook_output != ""){
92         msg_dialog::display(_("User password"),
93                     sprintf(_("External password changer reported a problem: %s."),$check_hook_output),WARNING_DIALOG);
94       }else{
96         /* Try to connect via current password */
97         $tldap = new LDAP(
98             $ui->dn, 
99             $_POST['current_password'],
100             $this->config->current['SERVER'],
101             isset($this->config->current['RECURSIVE'])  && preg_match("/true/i",$this->config->current['RECURSIVE']),
102             isset($this->config->current['TLS'])        && preg_match("/true/i",$this->config->current['TLS']));
104         /* connection Successfull ? */
105         if ($tldap->error != "Success"){
106           msg_dialog::display(_("User password"),
107                               _("The password you've entered as your current password doesn't match the real one."),WARNING_DIALOG);
108         }else{
110           /* Check GOsa permissions */
111           if (!preg_match("/w/i",$password_ACLS)){
112             msg_dialog::display(_("User password"),
113                                 _("You have no permissions to change your password."),WARNING_DIALOG);
114           }else{
115             change_password ($ui->dn, $_POST['new_password']);
116             gosa_log ("User/password has been changed");
117             $ui->password= $_POST['new_password'];
118             $_SESSION['ui']= $ui;
119 #$this->handle_post_events("modify",array("userPassword" => $_POST['new_password']));
120             return($smarty->fetch(get_template_path("changed.tpl", TRUE)));
121           }
122         }
123       }
124     }
125     return($smarty->fetch(get_template_path("password.tpl", TRUE)));
126   } 
128   function remove_from_parent()
129   {
130     $this->handle_post_events("remove");
131   }
133   function save()
134   {
135   }
137   function plInfo()
138   {
139     return (array(
140           "plDescription"     => _("User password"),
141           "plSelfModify"      => TRUE,
142           "plDepends"         => array("user"),
143           "plPriority"        => 10,
144           "plSection"     => array("personal" => _("My account")),
145           "plCategory"    => array("users"),
146           "plOptions"         => array(),
148           "plProvidedAcls"  => array())
149         );
150   }
153 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
154 ?>