Code

6531f36859060297949bf38f57c7e3b6df2d2619
[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;
44   var $pwd_rules  = array("pwminlen" => 6, 
45                           "pwminlen_active" => FALSE,
46                           "pwdiffer" => 5,
47                           "pwdiffer_active" => FALSE,
48                           "externalpwdhook" => "/path/to/your/script username oldpassword newpassword",
49                           "externalpwdhook_active" => FALSE);
51   var $id_settings = array(       "idgen"         => "{%sn}-{%givenName[2-4]}",
52                                   "idgen_active"  => FALSE,
53                                   "minid"         => "100",
54                                   "minid_active"  => FALSE);
56   var $crypt_methods  = array();
58   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","theme","errorlvl",
59                           "base_hook","base_hook_active","account_expiration","strict","include_personal_title");
61   function Step_Config1()
62   {
63     $this->update_strings();
65     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
66     foreach($tmp['name'] as $name){
67       $this->crypt_methods[$name] = $name;
68     }
69   }
72   function update_strings()
73   {
74     $this->s_title      = _("GOsa settings 1/3");
75     $this->s_title_long = _("GOsa settings 1/3");
76     $this->s_info       = _("GOsa generic settings");
77   }
79   
80   function execute()
81   {
82     $smarty = get_smarty();
83     $smarty->assign("peopledns",array("uid","cn"));
84     $smarty->assign("id_settings",$this->id_settings);
85     $smarty->assign("crypt_methods",$this->crypt_methods);
86     $smarty->assign("themes",$this->get_themes());
87     $smarty->assign("pwd_rules",$this->pwd_rules);
88     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
89     foreach($this->attributes as $attr){
90       $smarty->assign($attr,$this->$attr);
91     }
92     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
93   }
96   function get_themes()
97   {
98     $dir = opendir( "../ihtml/themes/");
99     $themes = array();
100     while (($file = readdir($dir)) !== false){
101       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
102         $themes[$file] = $file;
103       }      
104     }
105     return($themes);
106   }
108   function check()
109   {
110     $message = array();
112     if(isset($this->id_settings['minid_active']) && !is_numeric($this->id_settings['minid'])){
113       $message[] = sprintf(_("The specified value for '%s' must be a numeric value"),_("GID / UID min id"));
114     }
116     if(preg_match("/,$/",$this->peopleou)){
117       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
118     }
120     if(preg_match("/,$/",$this->groupou)){
121       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
122     }
124     if(!is_numeric($this->uidbase)){
125       $message[] = _("Uid base must be numeric");
126     }
128     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
129       $message[] = _("The given password minimum length is not numeric.");
130     }
131     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
132       $message[] = _("The given password differ value is not numeric.");
133     }
134     return($message);
135   }
137   function save_object()
138   {
139     if(isset($_POST['step5_posted'])){
141       /* Get attributes */
142       foreach($this->attributes as $attr){
143         if(isset($_POST[$attr])){
144           $this->$attr = validate($_POST[$attr]);
145         }
146       }
148       if(isset($_POST['minid_active'])){
149         $this->id_settings['minid_active'] = TRUE;
150         if(isset($_POST['minid'])){
151           $this->id_settings['minid'] = $_POST['minid'];
152         }
153       }else{
154         $this->id_settings['minid_active'] = FALSE;
155       }
157       /* Generic settings */
158       if(isset($_POST['idgen_active'])){
159         $this->id_settings['idgen_active'] = TRUE;
160         if(isset($_POST['idgen'])){
161           $this->id_settings['idgen'] = $_POST['idgen'];
162         }
163       }else{
164         $this->id_settings['idgen_active'] = FALSE;
165       }
167       /* Get password settings */ 
168       if(isset($_POST['pwdiffer_active'])){
169         $this->pwd_rules['pwdiffer_active'] = TRUE;
170         if(isset($_POST['pwdiffer'])){
171           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
172         }
173       }else{
174         $this->pwd_rules['pwdiffer_active'] = FALSE;
175       }
177       /* Get password minimum length posts */
178       if(isset($_POST['pwminlen_active'])){
179         $this->pwd_rules['pwminlen_active'] = TRUE;
180         if(isset($_POST['pwminlen'])){
181           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
182         }
183       }else{
184         $this->pwd_rules['pwminlen_active'] = FALSE;
185       }
187       /* External pwd settings */
188       if(isset($_POST['externalpwdhook_active'])){
189         $this->pwd_rules['externalpwdhook_active'] = TRUE;
190         if(isset($_POST['externalpwdhook'])){
191           $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
192         }
193       }else{
194         $this->pwd_rules['externalpwdhook_active'] = FALSE;
195       }
197       /* base hook settings */
198       if(isset($_POST['base_hook_active'])){
199         $this->pwd_rules['base_hook_active'] = TRUE;
200         if(isset($_POST['base_hook'])){
201           $this->pwd_rules['base_hook'] = $_POST['base_hook'];
202         }
203       }else{
204         $this->pwd_rules['base_hook_active'] = FALSE;
205       }
206     }
208     $tmp = $this->check(); 
209     if(count($tmp) == 0){
210       $this->is_completed = TRUE;
211     }else{
212       $this->is_completed = FALSE;
213     }
214   }// if tempalte posted 
217   /* Attributes that are interesting for configuration generation */
218   function get_attributes()
219   {
220     $tmp = setup_step::get_attributes();
221     foreach(array("pwd_rules","id_settings") as $attr){
222       $tmp[$attr]= $this->$attr;
223     }
224     return($tmp);
225   }
226 }// CLass
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>