Code

Replaced in_array calls with in_array_strict
[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->initTime = microtime(TRUE);
41         $this->config = $config;
42         $this->parent = $parent;
43         if(count($entry)){
44             $this->is_new =FALSE;
45             $this->name = $entry['NAME'];
46             $this->data = $entry['DATA'];
47         }else{
48             $this->data['MASK']           = 0;
49             $this->data['POLICY_REFCNT']  = 0;
50             $this->data['PW_HISTORY_NUM'] = 5;
51             $this->data['PW_MAX_LIFE']    = 604800;
52             $this->data['PW_MIN_CLASSES'] = 3;
53             $this->data['PW_MIN_LENGTH']  = 6;
54             $this->data['PW_MIN_LIFE']    = 36000;
55         }
56         $this->init_name = $this->name;
58         // Create statistic table entry
59         stats::log('plugin', $class = get_class($this), $category = array($this->acl_category),  $action = 'open',
60                 $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
62     }
65     /*! \brief  Returns a HTML ui which allows 
66       configuring this policy 
67       @return String a HTML interface.
68      */
69     public function execute()
70     {
71         $display = plugin::execute();
72         $smarty = get_smarty();    
74         $smarty->assign("name", set_post($this->name));
75         foreach($this->attributes as $attr){
76             $smarty->assign($attr, set_post($this->data[$attr]));
77         }
79         $smarty->assign("POLICY_REFCNT", sprintf("<i>"._("This policy is referenced %d times.")."</i>", $this->data["POLICY_REFCNT"]));
80         return($smarty->fetch(get_template_path("krb5_policy.tpl",TRUE,dirname(__FILE__))));
81     }
84     /*! \brief  Saves the HTML posted variables 
85      */
86     public function save_object()
87     {
88         if(isset($_POST['Policy_Posted'])){
89             if(isset($_POST['name'])){
90                 $this->name = get_post("name");
91             }
92             foreach($this->attributes as $attr){
93                 if(isset($_POST[$attr])){
94                     $this->data[$attr] = get_post($attr);
95                 }
96             }
97         }
98     }
101     /*! \brief Checks the given input 
102       @return Array   Containing errors about incorrect values.
103      */ 
104     public function check()
105     {
106         $message = array();
107         $names = $this->parent->getPolicyNames();
108         if($this->name != $this->init_name && in_array_strict($this->name,$names)){
109             $message[] = msgPool::duplicated(_("Policy name"));
110         }
111         if(empty($this->name)){
112             $message[] = msgPool::required(_("Policy name"));
113         }
115         if(!preg_match("/^[a-z0-9\@\.\-_]*$/i",$this->name)){
116             $message[] = msgPool::invalid(_("Policy name"),$this->name,"/[a-z0-9]/i");
117         }
119         /* Check password history */
120         if(!is_numeric($this->data['PW_HISTORY_NUM'])){
121             $message[] = msgPool::invalid(_("Password history size"));
122         }elseif($this->data['PW_HISTORY_NUM'] <= 0){
123             $message[] = msgPool::toosmall(_("Password history size"));
124         }
126         /* Check password minimum length */
127         if(!is_numeric($this->data['PW_MIN_LENGTH'])){
128             $message[] = msgPool::invalid(_("Minimum password length"));
129         }elseif($this->data['PW_MIN_LENGTH'] <= 0){
130             $message[] = msgPool::toosmall(_("Minimum password length"));
131         }
133         /* Check password different character classes */
134         if(!is_numeric($this->data['PW_MIN_CLASSES'])){
135             $message[] = msgPool::invalid(_("Required different characters"));
136         }elseif($this->data['PW_MIN_CLASSES'] <= 0){
137             $message[] = msgPool::toosmall(_("Required different characters"));
138         }elseif($this->data['PW_MIN_CLASSES'] > $this->data['PW_MIN_LENGTH']){
139             $message[] = sprintf(_("The value specified for '%s' must be smaller than the value specified for '%s'!"),
140                     _("Required different characters"),_("Minimum password length"));
141         }
143         /* Check password min lifetime */
144         if(!is_numeric($this->data['PW_MIN_LIFE'])){
145             $message[] = msgPool::invalid(_("Minimum password lifetime"));
146         }elseif($this->data['PW_MIN_LIFE'] <= 0){
147             $message[] = msgPool::toosmall(_("Minimum password lifetime"));
148         }
150         /* Check password lifetime */
151         if(!is_numeric($this->data['PW_MAX_LIFE'])){
152             $message[] = msgPool::invalid(_("Password lifetime"));
153         }elseif($this->data['PW_MAX_LIFE'] <= 0){
154             $message[] = msgPool::toosmall(_("Password lifetime"));
155         }elseif($this->data['PW_MAX_LIFE'] < $this->data['PW_MIN_LIFE']){
156             $message[] = sprintf(_("The value specified for '%s' must be smaller than the value specified for '%s'!"),
157                     _("Minimum password lifetime"),_("Password lifetime"));
158         }
160         return($message);
161     }
164     /*! \brief  Returns object data of the currently edited policy 
165       @return Array   A multidimensional array containing policy informations.
166      */
167     public function save()
168     {
169         $ret = array();
170         $ret['NAME']        = $this->name;
171         $ret['DATA']        = $this->data;
172         return($ret);
173     }
176 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
177 ?>