Code

Updated layout
[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     $smarty->assign("warnings" ,$this->check());
92     $smarty->assign("warnings_cnt" ,count($this->check()));
93     foreach($this->attributes as $attr){
94       $smarty->assign($attr,$this->$attr);
95     }
96     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
97   }
100   /* Returns the classnames auf the mail classes */
101   function get_available_mail_classes()
102   {
103     $dir = opendir( "../include");
104     $methods = array();
105     $suffix = "class_mail-methods-";
106     $lensuf = strlen($suffix);
107     $prefix = ".inc";
108     $lenpre = strlen($prefix);
109     $i = 0;
110     while (($file = readdir($dir)) !== false){
112       if(stristr($file,$suffix)) {
113         $lenfile = strlen($file);
114         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
115         $methods['file'][$i] = $file;
116         $methods[$i]['file'] = $file;
117         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
118         $i++;
119       }
120     }
121     return($methods); 
122   }
124   function get_themes()
125   {
126     $dir = opendir( "../ihtml/themes/");
127     $themes = array();
128     while (($file = readdir($dir)) !== false){
129       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
130         $themes[$file] = $file;
131       }      
132     }
133     return($themes);
134   }
136   function check()
137   {
138     $message = array();
140     if(preg_match("/,$/",$this->peopleou)){
141       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
142     }
144     if(preg_match("/,$/",$this->groupou)){
145       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
146     }
148     if(!is_numeric($this->uidbase)){
149       $message[] = _("Uid base must be numeric");
150     }
152     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
153       $message[] = _("The given password minimum length is not numeric.");
154     }
155     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
156       $message[] = _("The given password differ value is not numeric.");
157     }
158     return($message);
160   }
162   function save_object()
163   {
164     if(isset($_POST['step5_posted'])){
166       /* Get attributes */
167       foreach($this->attributes as $attr){
168         if(isset($_POST[$attr])){
169           $this->$attr = validate($_POST[$attr]);
170         }
171       }
173       /* Get password settings */ 
174       if(isset($_POST['pwdiffer_active'])){
175         $this->pwd_rules['pwdiffer_active'] = TRUE;
176         if(isset($_POST['pwdiffer'])){
177           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
178         }
179       }else{
180         $this->pwd_rules['pwdiffer_active'] = FALSE;
181       }
183       /* Get password minimum length posts */
184       if(isset($_POST['pwminlen_active'])){
185         $this->pwd_rules['pwminlen_active'] = TRUE;
186         if(isset($_POST['pwminlen'])){
187           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
188         }
189       }else{
190         $this->pwd_rules['pwminlen_active'] = FALSE;
191       }
193       /* Mail settings */
194       if(isset($_POST['vacationdir_active'])){
195         $this->mail_settings['vacationdir_active'] = TRUE;
196         if(isset($_POST['vacationdir'])){
197           $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
198         }
199       }else{
200         $this->mail_settings['vacationdir_active'] = FALSE;
201       }
203       /* Mail settings */
204       if(isset($_POST['externalpwdhook_active'])){
205         $this->pwd_rules['externalpwdhook_active'] = TRUE;
206         if(isset($_POST['externalpwdhook'])){
207           $this->pwd_rules['externalpwdhook'] = $_POST['externalpwdhook'];
208         }
209       }else{
210         $this->pwd_rules['externalpwdhook_active'] = FALSE;
211       }
213       /* Mail settings */
214       if(isset($_POST['base_hook_active'])){
215         $this->pwd_rules['base_hook_active'] = TRUE;
216         if(isset($_POST['base_hook'])){
217           $this->pwd_rules['base_hook'] = $_POST['base_hook'];
218         }
219       }else{
220         $this->pwd_rules['base_hook_active'] = FALSE;
221       }
222     }
224     $tmp = $this->check(); 
225     if(count($tmp) == 0){
226       $this->is_completed = TRUE;
227     }else{
228       $this->is_completed = FALSE;
229     }
230   }// if tempalte posted 
233   /* Attributes that are interesting for configuration generation */
234   function get_attributes()
235   {
236     $tmp = setup_step::get_attributes();
237     foreach(array("pwd_rules","mail_settings") as $attr){
238       $tmp[$attr]= $this->$attr;
239     }
240     return($tmp);
241   }
242 }// CLass
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
245 ?>