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