Code

Updated macro class. Added check -> Empty macros can't be saved.
[gosa.git] / setup / class_setupStep_Config3.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_Config3 extends setup_step
24 {
25   var $optional = array(
26               "enableCopyPaste" => false,
27               "strict_units" => false,
28               "forceglobals" => true,
29               "forcessl" => false,
30               "warnssl" => true,
31               "ppd_path" => "/var/spool/ppd/",
32               "ppd_path_active" => FALSE,
33               "compile" =>  "/var/spool/gosa",
34               "debuglevel" => 0,
35               "session_lifetime" => 7200,
36               "max_ldap_query_time" => "5.0",
37               "max_ldap_query_time_active" => FALSE,
39               "mailQueueScriptPath" => "/usr/bin/sudo /usr/local/sbin/mailqueue %action %id %server",
40               "mailQueueScriptPath_active" => FALSE,
42               "auto_network_hook" => "/etc/gosa/net-resolv.sh",
43               "auto_network_hook_active" => FALSE,
45               "notifydir" => "",
46               "notifydir_active" => FALSE,
48               "noprimarygroup"  => FALSE,
49               "smbhash" => 'SMBHASH');
52   function Step_Config3()
53   {
54     $this->update_strings();
56     /* Look for samba password generation method */
57     if(file_exists("/usr/bin/mkntpasswd")){
58       $pwdhash  = "/usr/bin/mkntpasswd";
59     } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
60       $pwdhash= "mkntpwd";
61     } else {
62       $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
63     }
65     $this->optional['smbhash'] = $pwdhash;
66   }
69   function update_strings()
70   {
71     $this->s_title      = _("GOsa settings 3/3");
72     $this->s_title_long = _("GOsa generic settings, page 3/3");
73     $this->s_info       = _("This dialog allows you to setup GOsa behaviour");
74   }
75   
77   function execute()
78   {
79     $smarty = get_smarty();
80     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
81     $smarty->assign("optional", $this->optional);
82     foreach($this->attributes as $attr){
83       $smarty->assign($attr,$this->$attr);
84     }
86     $smarty->assign("warnings" ,$this->check());
87     $smarty->assign("warnings_cnt" ,count($this->check()));
89     return($smarty -> fetch (get_template_path("../setup/setup_config3.tpl")));
90   }
93   function save_object()
94   {
95     if(isset($_POST['step6a_posted'])){
97       /* Get attributes */
98       foreach($this->attributes as $attr){
99         if(isset($_POST[$attr])){
100           $this->$attr = validate($_POST[$attr]);
101         }
102       }
103       
104       foreach(array("strict_units","noprimarygroup","enableCopyPaste","forceglobals","forcessl","warnssl","compile","debuglevel","session_lifetime","smbhash") as $name){
105         if(isset($_POST[$name])){
106           $this->optional[$name] = stripslashes($_POST[$name]);
107         }
108       } 
110       if(isset($_POST['ppd_path_active'])){
111         $this->optional['ppd_path_active'] = TRUE;
112         if(isset($_POST['ppd_path'])){
113           $this->optional['ppd_path'] = $_POST['ppd_path'];
114         }
115       }else{
116         $this->optional['ppd_path_active'] = FALSE;
117       }
119       if(isset($_POST['max_ldap_query_time_active'])){
120         $this->optional['max_ldap_query_time_active'] = TRUE;
121         if(isset($_POST['max_ldap_query_time'])){
122           $this->optional['max_ldap_query_time'] = $_POST['max_ldap_query_time'];
123         }
124       }else{
125         $this->optional['max_ldap_query_time_active'] = FALSE;
126       }
128       if(isset($_POST['mailQueueScriptPath_active'])){
129         $this->optional['mailQueueScriptPath_active'] = TRUE;
130         if(isset($_POST['mailQueueScriptPath'])){
131           $this->optional['mailQueueScriptPath'] = $_POST['mailQueueScriptPath'];
132         }
133       }else{
134         $this->optional['mailQueueScriptPath_active'] = FALSE;
135       }
137       if(isset($_POST['auto_network_hook_active'])){
138         $this->optional['auto_network_hook_active'] = TRUE;
139         if(isset($_POST['auto_network_hook'])){
140           $this->optional['auto_network_hook'] = $_POST['auto_network_hook'];
141         }
142       }else{
143         $this->optional['auto_network_hook_active'] = FALSE;
144       }
146       if(isset($_POST['notifydir_active'])){
147         $this->optional['notifydir_active'] = TRUE;
148         if(isset($_POST['notifydir'])){
149           $this->optional['notifydir'] = $_POST['notifydir'];
150         }
151       }else{
152         $this->optional['notifydir_active'] = FALSE;
153       }
154     }
156     $tmp = $this->check();
157     if(count($tmp) == 0){
158       $this->is_completed = TRUE;
159     }else{
160       $this->is_completed = FALSE;
161     }
162   }
165   function check()
166   {
167     $message = array();
169     if(!is_numeric( $this->optional['session_lifetime'])){
170       $message[] = _("Session lifetime must be a numeric value.");
171     }
173     if(!is_numeric( $this->optional['max_ldap_query_time'])){
174       $message[] = _("Maximal ldap query time must be a numeric value. ");
175     }
176   
177     return($message);
178   }
179   
181   /* Attributes that are interesting for configuration generation */
182   function get_attributes()
183   {
184     $tmp = setup_step::get_attributes();
185     foreach(array("optional") as $attr){
186       $tmp[$attr]= $this->$attr;
187     }
188     return($tmp);
189   }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>