Code

Added snmp-community to gosa setup
[gosa.git] / setup / class_setupStep_Config2.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_Config2 extends setup_step
24 {
25   var $governmentmode = FALSE;
26   var $sambaidmapping = FALSE;
27   var $header_image = "images/ldapserver.png";
29   var $cyrusunixstyle = FALSE;
30   var $mail       = "none";
31   var $mail_methods   = array();
32   var $mail_settings = array("vacationdir"        => "/etc/gosa/vacation",
33                              "vacationdir_active" => FALSE);
35   var $generic_settings  = array( 
36                                   "enableCopyPaste" => false,
37                                   "enableDNS"      => false,
38                                   "enableDHCP"      => false,
39                                   "wws_ou"          => "ou=winstations",
40                                   "wws_ou_active"   => FALSE);
42   var $samba_settings    = array( "samba_sid"        => "0-815-4711",
43                                   "samba_sid_active" => FALSE,
44                                   "samba_rid"        => 1000,
45                                   "smbhash"          => 'SMBHASH',
46                                   "samba_rid_active" => FALSE); 
48   var $sambaDomain_found    = FALSE;
49   var $use_netatalk         = FALSE;
50   var $enableFAI_management = FALSE;
51   var $enableMimeType       = FALSE;
53   var $timezone       = "Europe/Berlin";
54   var $timezones      = array();
56   var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
57   var $called = FALSE;
59   function Step_Config2()
60   {
61     $this->update_strings();
62     $tmp = $this->get_available_mail_classes();
63     foreach($tmp['name'] as $name){
64       $this->mail_methods[$name] = $name;
65     }
67     /* Look for samba password generation method */
68     if(file_exists("/usr/bin/mkntpasswd")){
69       $pwdhash  = "/usr/bin/mkntpasswd";
70     } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
71       $pwdhash= "mkntpwd";
72     } else {
73       $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
74     }
76     $this->timezones = _get_tz_zones();
77     $this->samba_settings['smbhash'] = $pwdhash;
78   }
80  
81   function update_strings()
82   {
83     $this->s_title      = _("GOsa settings 2/3");
84     $this->s_title_long = _("GOsa settings 2/3");
85     $this->s_info       = _("Customize special parameters");
86   }
88  
89   function execute()
90   {
91     /* On first call check for rid/sid base */
92     $cv = $this->parent->captured_values;
93     $ldap = new LDAP($cv['admin'],
94         $cv['password'],
95         $cv['connection'],
96         FALSE,
97         $cv['tls']);
99     $ldap->cd($cv['base']);
100     $ldap->search("(objectClass=sambaDomain)",array("dn"));
101     if($ldap->count()){
102       $this->sambaDomain_found =TRUE;
103     }else{
104       $this->sambaDomain_found =FALSE;
105     }
107     if(!$this->called){
108       if(!$this->sambaDomain_found){
109         $this->samba_settings['samba_sid_active'] = TRUE;
110         $this->samba_settings['samba_rid_active'] = TRUE;
111       }
112   
113       /* Check if we can enable netatalk plugin */
114       $tmp = $ldap->get_objectclasses();
115       if(is_array($tmp) && isset($tmp['apple-user'])) {
116         $this->use_netatalk = TRUE;
117       }
119       /* Check the FAI schema is used */
120       if(is_array($tmp) && isset($tmp['FAIclass'])){
121 #        $this->enableFAI_management = TRUE;
122       }
124       /* Check the MimeType schema is used */
125       if(is_array($tmp) && isset($tmp['gotoMimeType'])){
126         $this->enableMimeType = TRUE;
127       }
129       if(is_array($tmp) && isset($tmp['dhcpClass'])){
130         $this->generic_settings['enableDHCP'] = TRUE;
131       }
133       if(is_array($tmp) && isset($tmp['dNSZone'])){
134         $this->generic_settings['enableDNS'] = TRUE;
135       }
137       $this->called = TRUE;
138     }
140     $smarty = get_smarty();
141     $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
142     $smarty->assign("generic_settings",$this->generic_settings);
143     $smarty->assign("mail_settings",$this->mail_settings);
144     $smarty->assign("mail_methods",$this->mail_methods);
145     $smarty->assign("samba_settings",$this->samba_settings);
146     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
147         foreach($this->attributes as $attr){
148       $smarty->assign($attr,$this->$attr);
149     }
150     $smarty->assign("timezone"     ,$this->timezone);
151     $smarty->assign("timezones"    ,$this->timezones);
152     return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
153   }
155   function save_object()
156   {
157     if(isset($_POST['step6_posted'])){
159       if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
160         $this->timezone = $_POST['timezone'];
161       }
163       /* Get attributes */
164       foreach($this->attributes as $attr){
165         if(isset($_POST[$attr])){
166           $this->$attr = validate(get_post($attr));
167         }
168       }
170       /* Mail settings */
171       if(isset($_POST['vacationdir_active'])){
172         $this->mail_settings['vacationdir_active'] = TRUE;
173         if(isset($_POST['vacationdir'])){
174           $this->mail_settings['vacationdir'] = get_post('vacationdir');
175         }
176       }else{
177         $this->mail_settings['vacationdir_active'] = FALSE;
178       }
180       if(isset($_POST['enableCopyPaste'])){
181         $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
182       }
183       if(isset($_POST['enableDNS'])){
184         $this->generic_settings['enableDNS'] = get_post('enableDNS');
185       }
186       if(isset($_POST['enableDHCP'])){
187         $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
188       }
190       if(isset($_POST['wws_ou_active'])){
191         $this->generic_settings['wws_ou_active'] = TRUE;
192         if(isset($_POST['wws_ou'])){
193           $this->generic_settings['wws_ou'] = get_post('wws_ou');
194         }
195       }else{
196         $this->generic_settings['wws_ou_active'] = FALSE;
197       }
199       /* Samba settings */
200       if(isset($_POST['samba_sid_active'])){
201         $this->samba_settings['samba_sid_active'] = TRUE;
202         if(isset($_POST['samba_sid'])){
203           $this->samba_settings['samba_sid'] = get_post('samba_sid');
204         }
205       }else{
206         $this->samba_settings['samba_sid_active'] = FALSE;
207       }
208       if(isset($_POST['samba_rid_active'])){
209         $this->samba_settings['samba_rid_active'] = TRUE;
210         if(isset($_POST['samba_rid'])){
211           $this->samba_settings['samba_rid'] = get_post('samba_rid');
212         }
213       }else{
214         $this->samba_settings['samba_rid_active'] = FALSE;
215       }
216       if(isset($_POST['smbhash'])){
217         $this->samba_settings['smbhash'] = get_post('smbhash');
218       }
220       if(!$this->sambaDomain_found){
221         $this->samba_settings['samba_sid_active'] = TRUE;
222         $this->samba_settings['samba_rid_active'] = TRUE;
223       }
224     }
226     $tmp = $this->check();
227     if(count($tmp) == 0){
228       $this->is_completed = TRUE;
229     }else{
230       $this->is_completed = FALSE;
231     }
232   }
235   function check()
236   {
237     $message = array();
238     return($message);
239   }
240   
242   /* Attributes that are interesting for configuration generation */
243   function get_attributes()
244   {
245     $tmp = setup_step::get_attributes();
246     foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
247       $tmp[$attr]= $this->$attr;
248     }
249     return($tmp);
250   }
252 /* Returns the classnames auf the mail classes */
253   function get_available_mail_classes()
254   {
255     $dir = opendir( "../include");
256     $methods = array();
257     $suffix = "class_mail-methods-";
258     $lensuf = strlen($suffix);
259     $prefix = ".inc";
260     $lenpre = strlen($prefix);
261     $i = 0;
262     while (($file = readdir($dir)) !== false){
264       if(stristr($file,$suffix)) {
265         $lenfile = strlen($file);
266         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
267         $methods['file'][$i] = $file;
268         $methods[$i]['file'] = $file;
269         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
270         $i++;
271       }
272     }
273     return($methods);
274   }
278 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
279 ?>