Code

Updated several service dialogs, fixed typos, string, html, post handling and more.
[gosa.git] / gosa-plugins / mit-krb5 / admin / systems / services / kerberos / class_krb5_policy.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2008 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 krb5_policy extends plugin
22 {
23     var $name   = "";
24     var $data   = array();
25     var $is_new = TRUE;
26     var $init_name ="";
27     var $parent ;
28     var $config ;
29     var $attributes = array("MASK","POLICY_REFCNT","PW_HISTORY_NUM","PW_MAX_LIFE",
30             "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE");
33     /*! \brief Initializes the policy class.
34       @param Object The GOsa configuration object. 
35       @param Array  The policy data array to edit or an empty array()
36       @param Object The parent object.
37      */
38     public function __construct($config,$entry,$parent)
39     {
40         $this->config = $config;
41         $this->parent = $parent;
42         if(count($entry)){
43             $this->is_new =FALSE;
44             $this->name = $entry['NAME'];
45             $this->data = $entry['DATA'];
46         }else{
47             $this->data['MASK']           = 0;
48             $this->data['POLICY_REFCNT']  = 0;
49             $this->data['PW_HISTORY_NUM'] = 5;
50             $this->data['PW_MAX_LIFE']    = 604800;
51             $this->data['PW_MIN_CLASSES'] = 3;
52             $this->data['PW_MIN_LENGTH']  = 6;
53             $this->data['PW_MIN_LIFE']    = 36000;
54         }
55         $this->init_name = $this->name;
56     }
59     /*! \brief  Returns a HTML ui which allows 
60       configuring this policy 
61       @return String a HTML interface.
62      */
63     public function execute()
64     {
65         $display = plugin::execute();
66         $smarty = get_smarty();    
68         $smarty->assign("name", set_post($this->name));
69         foreach($this->attributes as $attr){
70             $smarty->assign($attr, set_post($this->data[$attr]));
71         }
73         $smarty->assign("POLICY_REFCNT", sprintf("<i>"._("This policy is referenced %d times.")."</i>", $this->data["POLICY_REFCNT"]));
74         return($smarty->fetch(get_template_path("krb5_policy.tpl",TRUE,dirname(__FILE__))));
75     }
78     /*! \brief  Saves the HTML posted variables 
79      */
80     public function save_object()
81     {
82         if(isset($_POST['Policy_Posted'])){
83             if(isset($_POST['name'])){
84                 $this->name = get_post("name");
85             }
86             foreach($this->attributes as $attr){
87                 if(isset($_POST[$attr])){
88                     $this->data[$attr] = get_post($attr);
89                 }
90             }
91         }
92     }
95     /*! \brief Checks the given input 
96       @return Array   Containing errors about incorrect values.
97      */ 
98     public function check()
99     {
100         $message = array();
101         $names = $this->parent->getPolicyNames();
102         if($this->name != $this->init_name && in_array($this->name,$names)){
103             $message[] = msgPool::duplicated(_("Policy name"));
104         }
105         if(empty($this->name)){
106             $message[] = msgPool::required(_("Policy name"));
107         }
109         if(!preg_match("/^[a-z0-9\@\.\-_]*$/i",$this->name)){
110             $message[] = msgPool::invalid(_("Policy name"),$this->name,"/[a-z0-9]/i");
111         }
113         /* Check password history */
114         if(!is_numeric($this->data['PW_HISTORY_NUM'])){
115             $message[] = msgPool::invalid(_("Password history size"));
116         }elseif($this->data['PW_HISTORY_NUM'] <= 0){
117             $message[] = msgPool::toosmall(_("Password history size"));
118         }
120         /* Check password minimum length */
121         if(!is_numeric($this->data['PW_MIN_LENGTH'])){
122             $message[] = msgPool::invalid(_("Minimum password length"));
123         }elseif($this->data['PW_MIN_LENGTH'] <= 0){
124             $message[] = msgPool::toosmall(_("Minimum password length"));
125         }
127         /* Check password different character classes */
128         if(!is_numeric($this->data['PW_MIN_CLASSES'])){
129             $message[] = msgPool::invalid(_("Required different characters"));
130         }elseif($this->data['PW_MIN_CLASSES'] <= 0){
131             $message[] = msgPool::toosmall(_("Required different characters"));
132         }elseif($this->data['PW_MIN_CLASSES'] > $this->data['PW_MIN_LENGTH']){
133             $message[] = sprintf(_("The value specified for '%s' must be smaller than the value specified for '%s'!"),
134                     _("Required different characters"),_("Minimum password length"));
135         }
137         /* Check password min lifetime */
138         if(!is_numeric($this->data['PW_MIN_LIFE'])){
139             $message[] = msgPool::invalid(_("Minimum password lifetime"));
140         }elseif($this->data['PW_MIN_LIFE'] <= 0){
141             $message[] = msgPool::toosmall(_("Minimum password lifetime"));
142         }
144         /* Check password lifetime */
145         if(!is_numeric($this->data['PW_MAX_LIFE'])){
146             $message[] = msgPool::invalid(_("Password lifetime"));
147         }elseif($this->data['PW_MAX_LIFE'] <= 0){
148             $message[] = msgPool::toosmall(_("Password lifetime"));
149         }elseif($this->data['PW_MAX_LIFE'] < $this->data['PW_MIN_LIFE']){
150             $message[] = sprintf(_("The value specified for '%s' must be smaller than the value specified for '%s'!"),
151                     _("Minimum password lifetime"),_("Password lifetime"));
152         }
154         return($message);
155     }
158     /*! \brief  Returns object data of the currently edited policy 
159       @return Array   A multidimensional array containing policy informations.
160      */
161     public function save()
162     {
163         $ret = array();
164         $ret['NAME']        = $this->name;
165         $ret['DATA']        = $this->data;
166         return($ret);
167     }
170 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
171 ?>