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 $crypt_methods = array();
48 var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","theme","errorlvl",
49 "base_hook","base_hook_active");
51 function Step_Config1()
52 {
53 $this->update_strings();
55 $tmp = @passwordMethod::get_available_methods_if_not_loaded();
56 foreach($tmp['name'] as $name){
57 $this->crypt_methods[$name] = $name;
58 }
59 }
62 function update_strings()
63 {
64 $this->s_title = _("GOsa settings 1/3");
65 $this->s_title_long = _("GOsa settings 1/3");
66 $this->s_info = _("GOsa generic settings");
67 }
70 function execute()
71 {
72 $smarty = get_smarty();
73 $smarty->assign("peopledns",array("uid","cn"));
74 $smarty->assign("crypt_methods",$this->crypt_methods);
75 $smarty->assign("themes",$this->get_themes());
76 $smarty->assign("pwd_rules",$this->pwd_rules);
77 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
78 foreach($this->attributes as $attr){
79 $smarty->assign($attr,$this->$attr);
80 }
81 return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
82 }
85 function get_themes()
86 {
87 $dir = opendir( "../ihtml/themes/");
88 $themes = array();
89 while (($file = readdir($dir)) !== false){
90 if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
91 $themes[$file] = $file;
92 }
93 }
94 return($themes);
95 }
97 function check()
98 {
99 $message = array();
101 if(preg_match("/,$/",$this->peopleou)){
102 $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
103 }
105 if(preg_match("/,$/",$this->groupou)){
106 $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
107 }
109 if(!is_numeric($this->uidbase)){
110 $message[] = _("Uid base must be numeric");
111 }
113 if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
114 $message[] = _("The given password minimum length is not numeric.");
115 }
116 if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
117 $message[] = _("The given password differ value is not numeric.");
118 }
119 return($message);
120 }
122 function save_object()
123 {
124 if(isset($_POST['step5_posted'])){
126 /* Get attributes */
127 foreach($this->attributes as $attr){
128 if(isset($_POST[$attr])){
129 $this->$attr = validate($_POST[$attr]);
130 }
131 }
133 /* Get password settings */
134 if(isset($_POST['pwdiffer_active'])){
135 $this->pwd_rules['pwdiffer_active'] = TRUE;
136 if(isset($_POST['pwdiffer'])){
137 $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
138 }
139 }else{
140 $this->pwd_rules['pwdiffer_active'] = FALSE;
141 }
143 /* Get password minimum length posts */
144 if(isset($_POST['pwminlen_active'])){
145 $this->pwd_rules['pwminlen_active'] = TRUE;
146 if(isset($_POST['pwminlen'])){
147 $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
148 }
149 }else{
150 $this->pwd_rules['pwminlen_active'] = FALSE;
151 }
153 /* External pwd settings */
154 if(isset($_POST['externalpwdhook_active'])){
155 $this->pwd_rules['externalpwdhook_active'] = TRUE;
156 if(isset($_POST['externalpwdhook'])){
157 $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
158 }
159 }else{
160 $this->pwd_rules['externalpwdhook_active'] = FALSE;
161 }
163 /* base hook settings */
164 if(isset($_POST['base_hook_active'])){
165 $this->pwd_rules['base_hook_active'] = TRUE;
166 if(isset($_POST['base_hook'])){
167 $this->pwd_rules['base_hook'] = $_POST['base_hook'];
168 }
169 }else{
170 $this->pwd_rules['base_hook_active'] = FALSE;
171 }
172 }
174 $tmp = $this->check();
175 if(count($tmp) == 0){
176 $this->is_completed = TRUE;
177 }else{
178 $this->is_completed = FALSE;
179 }
180 }// if tempalte posted
183 /* Attributes that are interesting for configuration generation */
184 function get_attributes()
185 {
186 $tmp = setup_step::get_attributes();
187 foreach(array("pwd_rules") as $attr){
188 $tmp[$attr]= $this->$attr;
189 }
190 return($tmp);
191 }
192 }// CLass
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>