Code

Updated layout - it's not complete yet, though
[gosa.git] / plugins / admin / systems / class_servKolab.inc
1 <?php
3 class servkolab extends plugin {
4   /* CLI vars */
5   var $cli_summary = "Manage server basic objects";
6   var $cli_description = "Some longer text\nfor help";
7   var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
10   var $postfix_mydomain                 = "";
11   var $postfix_mydestination            = "";
12   var $postfix_mynetworks               = "";
13   var $postfix_enable_virus_scan        = "";
14   var $cyrus_autocreatequota            = "";
15   var $cyrus_quotawarn                  = "";//ok
16   var $cyrus_admins                     = "";
17   var $cyrus_imap                       = "";//ok
18   var $cyrus_pop3                       = "";//ok
19   var $cyrus_imaps                      = "";//ok
20   var $cyrus_pop3s                      = "";//ok
21   var $cyrus_sieve                      = "";//ok
22   var $apache_allow_unauthenticated_fb  = "";//doing now
23   var $proftpd_ftp                      = "";
24   var $apache_http                      = "";
25   var $kolabHost                        = array("");
26   var $postfix_relayhost                = "";
27   var $templ                            = ""; // This variable saves the whole plugin, before loading any Kolab settings,
28                                               // So we can rereate this class again at the end of this script
29                                               // This is needed because some scripts won's save their settings correct
31   var $attributes =  array("postfix_mydomain", "postfix_mydestination",
32         "postfix_mynetworks", "postfix_enable_virus_scan","postfix_relayhost",
33         "cyrus_autocreatequota", "cyrus_admins", "cyrus_imap",
34         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
35         "apache_allow_unauthenticated_fb", "proftpd_ftp",
36         "apache_http", "cyrus_quotawarn", "kolabHost");
38   var $objectclasses = array("top", "kolab");
40   function servkolab($config, $dn = NULL) 
41   {
42     plugin::plugin($config,$dn);
43     $templ = false;
44     $this->dn = $dn;
45     $templ = $this; 
46     $this->templ = $templ;
47     $this->dn = "k=kolab,".$config->current['BASE'];
48     
49     plugin::plugin($config, $this->dn);
50     $this->dn = $dn;
52     /* Copy needed attributes */
53     foreach($this->attributes as $val) {
54       $name = preg_replace('/_/', '-', $val);
55       if (isset($this->attrs["$name"][0])) {
56         $this->$val = $this->attrs["$name"][0];
57       }
58     }
59   }
64   /* If the Button remove Kolab extension is clicked, this will be called */
65   function RemoveAccount() 
66   {
67   
68   gosa_log("Remove function");
69     
70     $ldap = $this->config->get_ldap_link();
71     $ldap->cd($this->dn);
73     if ($ldap->dn_exists($this->dn)) {
74       $ldap->rmdir($this->dn);
75       show_ldap_error($ldap->get_error());
76     }
77   }
83   /* this fucntion generates all needed attributes to start a new kolab extension */
84   function AddAccount() 
85   {
87     /* get the Ldap link, to test if there is an obeject with the same dn */
88     $ldap = $this->config->get_ldap_link();
89     
90     gosa_log("Add function");
92     /* test */
93     if (!$ldap->dn_exists($this->dn)) {
94       /* Object Classes */
95       $str['objectClass'][] = "top";
96       $str['objectClass'][] = "kolab";
98       /* specific kolab attribute */
99       $str['k'][] = "kolab";
101       /* Postfix default values */
102       $str['postfix-mydomain'][] = "gonicus.de";
103       $str['postfix-mydestination'][] = "\$mydomain";
104       $str['postfix-mynetworks'][] = "127.0.0.0/8";
105       $str['postfix-enable-virus-scan'][] = "TRUE";
107       /* Cyrus Attributes */
108       $str['cyrus-autocreatequota'][] = "100000";
109       $str['cyrus-quotawarn'][] = "80";
110       $str['cyrus-admins'][] = "manager";
111       $str['cyrus-imap'][] = "TRUE";
112       $str['cyrus-pop3'][] = "FALSE";
113       $str['cyrus-imaps'][] = "FALSE";
114       $str['cyrus-pop3s'][] = "FALSE";
115       $str['cyrus-sieve'][] = "FALSE";
117       /* */
118       $str['apache-allow-unauthenticated-fb'][] = "FALSE";
119       $str['proftpd-ftp'][] = "FALSE";
120       $str['uid'][] = "freebusy";
121       $str['userPassword'][] = "ZnJlZWJ1c3k";
122       $str['apache-http'][] = "TRUE";
125       /* Set Attributes */
126       $ldap->cd($this->dn);
127       $this->attrs = $str;
129       /* Copy needed attributes */
130       foreach($this->attributes as $val) {
131         $name = preg_replace('/_/', '-', $val);
132         if (isset($this->attrs["$name"][0])) {
133           $this->$val = $this->attrs["$name"][0];
134         }
135       }
137     }
140   }
143   function execute() 
144   {
145     /* Fill templating stuff */
146     $smarty = get_smarty();
147     $display = "";
149     /* Tell the script the dn, we are using */
150     $this->dn = "k=kolab,".$this->config->current['BASE'];
152     $ldap = $this->config->get_ldap_link();
153     
154     /* Do we need to flip is_account state? */
155     if (isset($_POST['modify_state'])) {
156       $this->is_account = !$this->is_account;
157       if($this->is_account) 
158         $this->AddAccount();
159       else  
160         $this->RemoveAccount();   
161     
162     
163     }
165     /* Show tab dialog headers */
166     if ($this->is_account) {
167       /* call Add Acoount to add account */
168       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
169     } else {
170       /* call remove Account */
171       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
172       return ($display);
173     }
175     /* There a new Host submitted */
176     if (isset($_POST['NewHost'])) {
177       
178       $abort= false;
179       if(empty($_POST['NewkolabHost']))
180         {
181           //print_red(_("The given Hostname ist empty."))
182           $abort = true;
183         }
184       else
185         {
186         foreach($this->attrs['kolabHost'] as $host)
187           {
188           if(strtolower($host) ==strtolower($_POST['NewkolabHost']))
189             {
190             $abort = true;
191             //print_red(_("The given Host already exists"));
192             }
193           }
194         }
195       if(!$abort)
196         {
197         $this->attrs['kolabHost'][] = $_POST['NewkolabHost'];
198         }
199     }
201     /* We need to delete a Host */
202     if (isset($_POST['DelHost'])) {
203       foreach($this->attrs['kolabHost'] as $key => $host) {
204         if(isset($_POST['kolabHost'])){
205           if ($host == $_POST['kolabHost'])
206           unset($this->attrs['kolabHost'][$key]);
207         }
208       }
209     }
213     /* Initialize all attributes, that were submitted */
214     foreach($this->attributes as $val) {
215       /* If theres a button pressed, we need to check all attributes */
216       if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) {
217         /* Set var to value or to zero */
218         if (isset($_POST[$val])) {
220           $this->$val = $_POST[$val];
221         } else {
222           $this->$val = 0;
223         }
224       }
225       /* Tell smarty which variables we are useing */
226       $smarty->assign($val, $this->$val);
227       if (($this->$val != "FALSE") && (!empty($this->$val)))
228         $smarty->assign($val."Check", "checked");
229       else
230         $smarty->assign($val."Check", "");
232     }
234     /*  If there are some Host submitted, tell it smarty */
235     $this->kolabHost = array();
236     if (isset($this->attrs['kolabHost'])) {
237       $this->kolabHost = $this->attrs['kolabHost'];
238       unset($this->kolabHost['count']);
239     }
241     $smarty->assign("kolabHost", $this->kolabHost);
243     /* Load Template */
244     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
245   
246     return ($display);
247   }
249   function remove_from_parent() 
250   {
251   }
254   function save_object()    
255   {
256     plugin::save_object();
257   }
260   function check() 
261   {
262     $message = array();
265     if(!is_int((int)($this->cyrus_quotawarn))) {
266       $message[] = "The given Quota settings value must be a number";
267     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
268       $message[] = "Please choose a value between 1 and 100 for Quota settings";
269     }
270     
272     /* You will need a least one entry to save this settings */
273     if (count($this->kolabHost) == 0) {
274       $message[] =
275         "You will need at least one Entry in Hosts. If You want to 'Remove' Kolab extension please use the \"Remove Kolab extension\"  Button to remove Kolab  ";
276     }
277     return ($message);
278   }
281   /* Save to LDAP */
282   function save() 
283   {
284     /* Set ldap connection */
285     $ldap = $this->config->get_ldap_link();
286     $ldap->cd($this->dn);
288     /* Setup Attributes to save */
289     $newattrs = array();
291     /* Set vars with correct - _ - */
292     foreach($this->attributes as $key) {
293       $key2 = str_replace("_", "-", $key);
294       $newattrs[$key2] = $this->$key;
295     }
303     /* Set bool vars */
304     if ($newattrs['postfix-enable-virus-scan'] == 0)
305       $newattrs['postfix-enable-virus-scan'] = "FALSE";
306     else
307       $newattrs['postfix-enable-virus-scan'] = "TRUE";
308     if ($newattrs['cyrus-imap'] == 0)
309       $newattrs['cyrus-imap'] = "FALSE";
310     else
311       $newattrs['cyrus-imap'] = "TRUE";
312     if ($newattrs['cyrus-imaps'] == 0)
313       $newattrs['cyrus-imaps'] = "FALSE";
314     else
315       $newattrs['cyrus-imaps'] = "TRUE";
316     if ($newattrs['cyrus-pop3'] == 0)
317       $newattrs['cyrus-pop3'] = "FALSE";
318     else
319       $newattrs['cyrus-pop3'] = "TRUE";
320     if ($newattrs['cyrus-pop3s'] == 0)
321       $newattrs['cyrus-pop3s'] = "FALSE";
322     else
323       $newattrs['cyrus-pop3s'] = "TRUE";
324     if ($newattrs['cyrus-sieve'] == 0)
325       $newattrs['cyrus-sieve'] = "FALSE";
326     else
327       $newattrs['cyrus-sieve'] = "TRUE";
328     if ($newattrs['proftpd-ftp'] == 0)
329       $newattrs['proftpd-ftp'] = "FALSE";
330     else
331       $newattrs['proftpd-ftp'] = "TRUE";
332     if ($newattrs['apache-http'] == 0)
333       $newattrs['apache-http'] = "FALSE";
334     else
335       $newattrs['apache-http'] = "TRUE";
336     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
337       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
338     else
339       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
342     if(empty($newattrs['postfix-relayhost'])) unset( $newattrs['postfix-relayhost']);
344     /* Reorder Host array, to get constant increasing index */
345     $newattrs['kolabHost'] = array();
346     foreach($this->attrs['kolabHost'] as $key=>$val) {
347       if (is_int($key)) {
348         $newattrs['kolabHost'][] = $val;
349       }
350     }
352     /* Save as following object ! */
353     $this->dn = "k=kolab,".$this->config->current['BASE'];
355     /* If we already have an object like this one,
356        we only need to modify the entry
357      */
361     if ($ldap->dn_exists($this->dn)) {
362       gosa_log("Modifying");
363       
364       /* unset all attributes we won't change*/
365       unset($newattrs['cyrus-admins']);
366       unset($newattrs['postfix-mydomain']);
367       unset($newattrs['postfix-mydestination']);
368     
370       print ($this->dn);
371       $ldap->cd($this->dn);
372       print_a($newattrs);
373       //$ldap->modify($newattrs);
374     } else {
375       /* We must create a new Entry */
376       $newattrs['k'] = "kolab";
377       $newattrs['uid'] = "freebusy";
378       $newattrs['postfix-mydomain'] = "gonicus.de";
379       $newattrs['postfix-mydestination'] = "\$mydomain";
380       $newattrs['userPassword'] = "tester";
381       $newattrs['objectClass'] = $this->objectclasses;
383       gosa_log("Adding");
384       $ldap->cd($this->dn);
385       $ldap->add($newattrs);
386     }
387     
388     $templ = "";
389     $templ = $this->templ;
390     $this = $templ;  
391   
392     /* show any errors */
393     show_ldap_error($ldap->get_error());
394     
395     /* Optionally execute a command after we're done */
396     if ($this->initially_was_account == $this->is_account) {
397       if ($this->is_modified) {
398         $this->handle_post_events("mofify");
399       }
400     } else {
401       $this->handle_post_events("add");
402     }
404   }
408 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
409 ?>