Code

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