Code

c2a0449b5d21f660c01df305ef1e6da5d2f39181
[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 $mail       = "none";
37   var $theme      = "default"; 
38   var $errorlvl   = FALSE;
39   var $cyrusunixstyle = FALSE;
41   var $pwd_rules  = array("pwminlen" => 6, 
42                           "pwminlen_active" => FALSE,
43                           "pwdiffer" => 5,
44                           "pwdiffer_active" => FALSE,
45                           "externalpwdhook" => "/path/to/your/script username oldpassword newpassword",
46                           "externalpwdhook_active" => FALSE);
48   var $mail_settings = array("vacationdir"        => "/etc/gosa/vacation",
49                              "vacationdir_active" => FALSE);
50  
51   var $crypt_methods  = array();
52   var $mail_methods   = array();
55   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","mail","theme","errorlvl","cyrusunixstyle",
56                           "base_hook","base_hook_active");
58   function Step_Config1()
59   {
60     $this->update_strings();
62     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
63     foreach($tmp['name'] as $name){
64       $this->crypt_methods[$name] = $name;
65     }
66     $tmp = $this->get_available_mail_classes();
67     foreach($tmp['name'] as $name){
68       $this->mail_methods[$name] = $name;
69     }
70   }
73   function update_strings()
74   {
75     $this->s_title      = _("GOsa settings 1/3");
76     $this->s_title_long = _("GOsa settings 1/3");
77     $this->s_info       = _("GOsa generic settings");
78   }
80   
81   function execute()
82   {
83     $smarty = get_smarty();
84     $smarty->assign("peopledns",array("uid","cn"));
85     $smarty->assign("crypt_methods",$this->crypt_methods);
86     $smarty->assign("mail_methods",$this->mail_methods);
87     $smarty->assign("themes",$this->get_themes());
88     $smarty->assign("pwd_rules",$this->pwd_rules);
89     $smarty->assign("mail_settings",$this->mail_settings);
90     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
91     foreach($this->attributes as $attr){
92       $smarty->assign($attr,$this->$attr);
93     }
94     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
95   }
98   /* Returns the classnames auf the mail classes */
99   function get_available_mail_classes()
100   {
101     $dir = opendir( "../include");
102     $methods = array();
103     $suffix = "class_mail-methods-";
104     $lensuf = strlen($suffix);
105     $prefix = ".inc";
106     $lenpre = strlen($prefix);
107     $i = 0;
108     while (($file = readdir($dir)) !== false){
110       if(stristr($file,$suffix)) {
111         $lenfile = strlen($file);
112         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
113         $methods['file'][$i] = $file;
114         $methods[$i]['file'] = $file;
115         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
116         $i++;
117       }
118     }
119     return($methods); 
120   }
122   function get_themes()
123   {
124     $dir = opendir( "../ihtml/themes/");
125     $themes = array();
126     while (($file = readdir($dir)) !== false){
127       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
128         $themes[$file] = $file;
129       }      
130     }
131     return($themes);
132   }
134   function check()
135   {
136     $message = array();
138     if(preg_match("/,$/",$this->peopleou)){
139       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
140     }
142     if(preg_match("/,$/",$this->groupou)){
143       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
144     }
146     if(!is_numeric($this->uidbase)){
147       $message[] = _("Uid base must be numeric");
148     }
150     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
151       $message[] = _("The given password minimum length is not numeric.");
152     }
153     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
154       $message[] = _("The given password differ value is not numeric.");
155     }
156     return($message);
157   }
159   function save_object()
160   {
161     if(isset($_POST['step5_posted'])){
163       /* Get attributes */
164       foreach($this->attributes as $attr){
165         if(isset($_POST[$attr])){
166           $this->$attr = validate($_POST[$attr]);
167         }
168       }
170       /* Get password settings */ 
171       if(isset($_POST['pwdiffer_active'])){
172         $this->pwd_rules['pwdiffer_active'] = TRUE;
173         if(isset($_POST['pwdiffer'])){
174           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
175         }
176       }else{
177         $this->pwd_rules['pwdiffer_active'] = FALSE;
178       }
180       /* Get password minimum length posts */
181       if(isset($_POST['pwminlen_active'])){
182         $this->pwd_rules['pwminlen_active'] = TRUE;
183         if(isset($_POST['pwminlen'])){
184           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
185         }
186       }else{
187         $this->pwd_rules['pwminlen_active'] = FALSE;
188       }
190       /* Mail settings */
191       if(isset($_POST['vacationdir_active'])){
192         $this->mail_settings['vacationdir_active'] = TRUE;
193         if(isset($_POST['vacationdir'])){
194           $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
195         }
196       }else{
197         $this->mail_settings['vacationdir_active'] = FALSE;
198       }
200       /* Mail settings */
201       if(isset($_POST['externalpwdhook_active'])){
202         $this->pwd_rules['externalpwdhook_active'] = TRUE;
203         if(isset($_POST['externalpwdhook'])){
204           $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
205         }
206       }else{
207         $this->pwd_rules['externalpwdhook_active'] = FALSE;
208       }
210       /* Mail settings */
211       if(isset($_POST['base_hook_active'])){
212         $this->pwd_rules['base_hook_active'] = TRUE;
213         if(isset($_POST['base_hook'])){
214           $this->pwd_rules['base_hook'] = $_POST['base_hook'];
215         }
216       }else{
217         $this->pwd_rules['base_hook_active'] = FALSE;
218       }
219     }
221     $tmp = $this->check(); 
222     if(count($tmp) == 0){
223       $this->is_completed = TRUE;
224     }else{
225       $this->is_completed = FALSE;
226     }
227   }// if tempalte posted 
230   /* Attributes that are interesting for configuration generation */
231   function get_attributes()
232   {
233     $tmp = setup_step::get_attributes();
234     foreach(array("pwd_rules","mail_settings") as $attr){
235       $tmp[$attr]= $this->$attr;
236     }
237     return($tmp);
238   }
239 }// CLass
241 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
242 ?>