Code

10e7806698d5bd8543dcf153be3e5477fdcb3bdb
[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;
30   var $header_image = "images/ldapserver.png";
32   var $base_hook         = "/usr/bin/sudo myscript"; 
33   var $base_hook_active  = FALSE; 
35   var $encryption = "crypt";
36   var $theme      = "default"; 
37   var $errorlvl   = FALSE;
39   var $pwd_rules  = array("pwminlen" => 6, 
40                           "pwminlen_active" => FALSE,
41                           "pwdiffer" => 5,
42                           "pwdiffer_active" => FALSE,
43                           "externalpwdhook" => "/path/to/your/script username oldpassword newpassword",
44                           "externalpwdhook_active" => FALSE);
46   var $id_settings = array(       "idgen"         => "{%sn}-{%givenName[2-4]}",
47                                   "idgen_active"  => FALSE,
48                                   "minid"         => "100",
49                                   "minid_active"  => FALSE);
51   var $crypt_methods  = array();
53   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","theme","errorlvl",
54                           "base_hook","base_hook_active");
56   function Step_Config1()
57   {
58     $this->update_strings();
60     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
61     foreach($tmp['name'] as $name){
62       $this->crypt_methods[$name] = $name;
63     }
64   }
67   function update_strings()
68   {
69     $this->s_title      = _("GOsa settings 1/3");
70     $this->s_title_long = _("GOsa settings 1/3");
71     $this->s_info       = _("GOsa generic settings");
72   }
74   
75   function execute()
76   {
77     $smarty = get_smarty();
78     $smarty->assign("peopledns",array("uid","cn"));
79     $smarty->assign("id_settings",$this->id_settings);
80     $smarty->assign("crypt_methods",$this->crypt_methods);
81     $smarty->assign("themes",$this->get_themes());
82     $smarty->assign("pwd_rules",$this->pwd_rules);
83     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
84     foreach($this->attributes as $attr){
85       $smarty->assign($attr,$this->$attr);
86     }
87     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
88   }
91   function get_themes()
92   {
93     $dir = opendir( "../ihtml/themes/");
94     $themes = array();
95     while (($file = readdir($dir)) !== false){
96       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
97         $themes[$file] = $file;
98       }      
99     }
100     return($themes);
101   }
103   function check()
104   {
105     $message = array();
107     if(isset($this->id_settings['minid_active']) && !is_numeric($this->id_settings['minid'])){
108       $message[] = sprintf(_("The specified value for '%s' must be a numeric value"),_("GID / UID min id"));
109     }
111     if(preg_match("/,$/",$this->peopleou)){
112       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
113     }
115     if(preg_match("/,$/",$this->groupou)){
116       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
117     }
119     if(!is_numeric($this->uidbase)){
120       $message[] = _("Uid base must be numeric");
121     }
123     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
124       $message[] = _("The given password minimum length is not numeric.");
125     }
126     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
127       $message[] = _("The given password differ value is not numeric.");
128     }
129     return($message);
130   }
132   function save_object()
133   {
134     if(isset($_POST['step5_posted'])){
136       /* Get attributes */
137       foreach($this->attributes as $attr){
138         if(isset($_POST[$attr])){
139           $this->$attr = validate($_POST[$attr]);
140         }
141       }
143       if(isset($_POST['minid_active'])){
144         $this->id_settings['minid_active'] = TRUE;
145         if(isset($_POST['minid'])){
146           $this->id_settings['minid'] = $_POST['minid'];
147         }
148       }else{
149         $this->id_settings['minid_active'] = FALSE;
150       }
152       /* Generic settings */
153       if(isset($_POST['idgen_active'])){
154         $this->id_settings['idgen_active'] = TRUE;
155         if(isset($_POST['idgen'])){
156           $this->id_settings['idgen'] = $_POST['idgen'];
157         }
158       }else{
159         $this->id_settings['idgen_active'] = FALSE;
160       }
162       /* Get password settings */ 
163       if(isset($_POST['pwdiffer_active'])){
164         $this->pwd_rules['pwdiffer_active'] = TRUE;
165         if(isset($_POST['pwdiffer'])){
166           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
167         }
168       }else{
169         $this->pwd_rules['pwdiffer_active'] = FALSE;
170       }
172       /* Get password minimum length posts */
173       if(isset($_POST['pwminlen_active'])){
174         $this->pwd_rules['pwminlen_active'] = TRUE;
175         if(isset($_POST['pwminlen'])){
176           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
177         }
178       }else{
179         $this->pwd_rules['pwminlen_active'] = FALSE;
180       }
182       /* External pwd settings */
183       if(isset($_POST['externalpwdhook_active'])){
184         $this->pwd_rules['externalpwdhook_active'] = TRUE;
185         if(isset($_POST['externalpwdhook'])){
186           $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
187         }
188       }else{
189         $this->pwd_rules['externalpwdhook_active'] = FALSE;
190       }
192       /* base hook settings */
193       if(isset($_POST['base_hook_active'])){
194         $this->pwd_rules['base_hook_active'] = TRUE;
195         if(isset($_POST['base_hook'])){
196           $this->pwd_rules['base_hook'] = $_POST['base_hook'];
197         }
198       }else{
199         $this->pwd_rules['base_hook_active'] = FALSE;
200       }
201     }
203     $tmp = $this->check(); 
204     if(count($tmp) == 0){
205       $this->is_completed = TRUE;
206     }else{
207       $this->is_completed = FALSE;
208     }
209   }// if tempalte posted 
212   /* Attributes that are interesting for configuration generation */
213   function get_attributes()
214   {
215     $tmp = setup_step::get_attributes();
216     foreach(array("pwd_rules","id_settings") as $attr){
217       $tmp[$attr]= $this->$attr;
218     }
219     return($tmp);
220   }
221 }// CLass
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>