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 setup_step_5 extends setup_step
24 {
26 var $peopleou = "ou=people";
27 var $groupou = "ou=groups";
28 var $peopledn = "cn";
29 var $uidbase = 1000;
30 var $encryption = "crypt";
31 var $mail = "none";
32 var $theme = "default";
33 var $errorlvl = TRUE;
34 var $cyrusunixstyle = FALSE;
36 var $pwd_rules = array("pwminlen" => 6,
37 "pwminlen_active" => FALSE,
38 "pwdiffer" => 5,
39 "pwdiffer_active" => FALSE,
40 "externalpwdhook" => "/usr/bin/sudo myscript",
41 "externalpwdhook_active" => FALSE);
43 var $mail_settings = array("vacationdir" => "/etc/gosa/vacation",
44 "vacationdir_active" => FALSE);
46 var $crypt_methods = array();
47 var $mail_methods = array();
50 var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","mail","theme","errorlvl","cyrusunixstyle");
52 function setup_step_5()
53 {
54 $this->update_strings();
56 $tmp = @passwordMethod::get_available_methods_if_not_loaded();
57 foreach($tmp['name'] as $name){
58 $this->crypt_methods[$name] = $name;
59 }
60 $tmp = $this->get_available_mail_classes();
61 foreach($tmp['name'] as $name){
62 $this->mail_methods[$name] = $name;
63 }
64 }
67 function update_strings()
68 {
69 $this->s_title = _("GOsa settings 1/3");
70 $this->s_title_long = _("GOsa generic settings, page 1/3");
71 $this->s_info = _("This dialog allows you to setup GOsa behaviour");
72 }
75 function execute()
76 {
77 $smarty = get_smarty();
78 $smarty->assign("peopledns",array("uid","cn"));
79 $smarty->assign("crypt_methods",$this->crypt_methods);
80 $smarty->assign("mail_methods",$this->mail_methods);
81 $smarty->assign("themes",$this->get_themes());
82 $smarty->assign("pwd_rules",$this->pwd_rules);
83 $smarty->assign("mail_settings",$this->mail_settings);
84 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
85 $smarty->assign("warnings" ,$this->check());
86 $smarty->assign("warnings_cnt" ,count($this->check()));
87 foreach($this->attributes as $attr){
88 $smarty->assign($attr,$this->$attr);
89 }
90 return($smarty -> fetch (get_template_path("../setup/setup_step5.tpl")));
91 }
94 /* Returns the classnames auf the mail classes */
95 function get_available_mail_classes()
96 {
97 $dir = opendir( "../include");
98 $methods = array();
99 $suffix = "class_mail-methods-";
100 $lensuf = strlen($suffix);
101 $prefix = ".inc";
102 $lenpre = strlen($prefix);
103 $i = 0;
104 while (($file = readdir($dir)) !== false){
106 if(stristr($file,$suffix)) {
107 $lenfile = strlen($file);
108 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
109 $methods['file'][$i] = $file;
110 $methods[$i]['file'] = $file;
111 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
112 $i++;
113 }
114 }
115 return($methods);
116 }
118 function get_themes()
119 {
120 $dir = opendir( "../ihtml/themes/");
121 $themes = array();
122 while (($file = readdir($dir)) !== false){
123 if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
124 $themes[$file] = $file;
125 }
126 }
127 return($themes);
128 }
130 function check()
131 {
132 $message = array();
134 if(preg_match("/,$/",$this->peopleou)){
135 $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
136 }
138 if(preg_match("/,$/",$this->groupou)){
139 $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
140 }
142 if(!is_numeric($this->uidbase)){
143 $message[] = _("Uid base must be numeric");
144 }
146 if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
147 $message[] = _("The given password minimum length is not numeric.");
148 }
149 if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
150 $message[] = _("The given password differ value is not numeric.");
151 }
152 return($message);
154 }
156 function save_object()
157 {
158 if(isset($_POST['step5_posted'])){
160 /* Get attributes */
161 foreach($this->attributes as $attr){
162 if(isset($_POST[$attr])){
163 $this->$attr = validate($_POST[$attr]);
164 }
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 /* Mail settings */
188 if(isset($_POST['vacationdir_active'])){
189 $this->mail_settings['vacationdir_active'] = TRUE;
190 if(isset($_POST['vacationdir'])){
191 $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
192 }
193 }else{
194 $this->mail_settings['vacationdir_active'] = FALSE;
195 }
197 /* Mail settings */
198 if(isset($_POST['externalpwdhook_active'])){
199 $this->pwd_rules['externalpwdhook_active'] = TRUE;
200 if(isset($_POST['externalpwdhook'])){
201 $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
202 }
203 }else{
204 $this->pwd_rules['externalpwdhook_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","mail_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 ?>