Code

Added rfc2307bis
[gosa.git] / setup / class_setupStep_Config1.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
23 class Step_Config1 extends setup_step
24 {
26   var $peopleou   = "ou=people";
27   var $groupou    =  "ou=groups";
28   var $peopledn   = "cn";
29   var $uidbase    = 1000;
31   var $strict     = TRUE;
33   var $header_image = "images/ldapserver.png";
34   var $account_expiration  =FALSE;
35   var $base_hook         = "/usr/bin/sudo myscript"; 
36   var $base_hook_active  = FALSE; 
38   var $encryption = "crypt";
39   var $theme      = "default"; 
40   var $errorlvl   = FALSE;
42   var $include_personal_title = FALSE;
43   var $rfc2307bis             = FALSE;
45   var $pwd_rules  = array("pwminlen" => 6, 
46                           "pwminlen_active" => FALSE,
47                           "pwdiffer" => 5,
48                           "pwdiffer_active" => FALSE,
49                           "externalpwdhook" => "/path/to/your/script username oldpassword newpassword",
50                           "externalpwdhook_active" => FALSE);
52   var $id_settings = array(       "idgen"         => "{%sn}-{%givenName[2-4]}",
53                                   "idgen_active"  => FALSE,
54                                   "minid"         => "100",
55                                   "minid_active"  => FALSE);
57   var $crypt_methods  = array();
59   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","theme","errorlvl","rfc2307bis",
60                           "base_hook","base_hook_active","account_expiration","strict","include_personal_title");
62   function Step_Config1()
63   {
64     $this->update_strings();
66     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
67     foreach($tmp['name'] as $name){
68       $this->crypt_methods[$name] = $name;
69     }
70   }
73   function update_strings()
74   {
75     $this->s_title      = _("GOsa settings 1/3");
76     $this->s_title_long = _("GOsa settings 1/3");
77     $this->s_info       = _("GOsa generic settings");
78   }
80   
81   function execute()
82   {
83     $smarty = get_smarty();
84     $smarty->assign("peopledns",array("uid","cn"));
85     $smarty->assign("id_settings",$this->id_settings);
86     $smarty->assign("crypt_methods",$this->crypt_methods);
87     $smarty->assign("themes",$this->get_themes());
88     $smarty->assign("pwd_rules",$this->pwd_rules);
89     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
90     foreach($this->attributes as $attr){
91       $smarty->assign($attr,$this->$attr);
92     }
93     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
94   }
97   function get_themes()
98   {
99     $dir = opendir( "../ihtml/themes/");
100     $themes = array();
101     while (($file = readdir($dir)) !== false){
102       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
103         $themes[$file] = $file;
104       }      
105     }
106     return($themes);
107   }
109   function check()
110   {
111     $message = array();
113     if(isset($this->id_settings['minid_active']) && !is_numeric($this->id_settings['minid'])){
114       $message[] = sprintf(_("The specified value for '%s' must be a numeric value"),_("GID / UID min id"));
115     }
117     if(preg_match("/,$/",$this->peopleou)){
118       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
119     }
121     if(preg_match("/,$/",$this->groupou)){
122       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
123     }
125     if(!is_numeric($this->uidbase)){
126       $message[] = _("Uid base must be numeric");
127     }
129     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
130       $message[] = _("The given password minimum length is not numeric.");
131     }
132     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
133       $message[] = _("The given password differ value is not numeric.");
134     }
135     return($message);
136   }
138   function save_object()
139   {
140     if(isset($_POST['step5_posted'])){
142       /* Get attributes */
143       foreach($this->attributes as $attr){
144         if(isset($_POST[$attr])){
145           $this->$attr = validate($_POST[$attr]);
146         }
147       }
149       if(isset($_POST['minid_active'])){
150         $this->id_settings['minid_active'] = TRUE;
151         if(isset($_POST['minid'])){
152           $this->id_settings['minid'] = $_POST['minid'];
153         }
154       }else{
155         $this->id_settings['minid_active'] = FALSE;
156       }
158       /* Generic settings */
159       if(isset($_POST['idgen_active'])){
160         $this->id_settings['idgen_active'] = TRUE;
161         if(isset($_POST['idgen'])){
162           $this->id_settings['idgen'] = $_POST['idgen'];
163         }
164       }else{
165         $this->id_settings['idgen_active'] = FALSE;
166       }
168       /* Get password settings */ 
169       if(isset($_POST['pwdiffer_active'])){
170         $this->pwd_rules['pwdiffer_active'] = TRUE;
171         if(isset($_POST['pwdiffer'])){
172           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
173         }
174       }else{
175         $this->pwd_rules['pwdiffer_active'] = FALSE;
176       }
178       /* Get password minimum length posts */
179       if(isset($_POST['pwminlen_active'])){
180         $this->pwd_rules['pwminlen_active'] = TRUE;
181         if(isset($_POST['pwminlen'])){
182           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
183         }
184       }else{
185         $this->pwd_rules['pwminlen_active'] = FALSE;
186       }
188       /* External pwd settings */
189       if(isset($_POST['externalpwdhook_active'])){
190         $this->pwd_rules['externalpwdhook_active'] = TRUE;
191         if(isset($_POST['externalpwdhook'])){
192           $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
193         }
194       }else{
195         $this->pwd_rules['externalpwdhook_active'] = FALSE;
196       }
198       /* base hook settings */
199       if(isset($_POST['base_hook_active'])){
200         $this->pwd_rules['base_hook_active'] = TRUE;
201         if(isset($_POST['base_hook'])){
202           $this->pwd_rules['base_hook'] = $_POST['base_hook'];
203         }
204       }else{
205         $this->pwd_rules['base_hook_active'] = FALSE;
206       }
207     }
209     $tmp = $this->check(); 
210     if(count($tmp) == 0){
211       $this->is_completed = TRUE;
212     }else{
213       $this->is_completed = FALSE;
214     }
215   }// if tempalte posted 
218   /* Attributes that are interesting for configuration generation */
219   function get_attributes()
220   {
221     $tmp = setup_step::get_attributes();
222     foreach(array("pwd_rules","id_settings") as $attr){
223       $tmp[$attr]= $this->$attr;
224     }
225     return($tmp);
226   }
227 }// CLass
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>