Code

ACLs added to the kolab Plugin
[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");
9   var $postfix_mydomain                 = "\$domain";//<<<<<<<<<<<<<
10   var $postfix_mydestination            = "\$domain";//<<<<<<<<<<<<<
11   var $postfix_mynetworks               = "127.0.0.1/8";//ok
12   var $postfix_enable_virus_scan        = "TRUE";//ok
13   var $postfix_relayhost                = "";
14   var $postfix_mxrelayenabled           =  true;
15   var $postfix_allow_unauthenticated     = "false";
16   var $cyrus_quotawarn                  = "80";//ok
17   var $kolabFreeBusyFuture              = "1";// ok 
18   var $cyrus_admins                     = "TRUE";//<<<<<<<<<<<<<<<<
19   var $cyrus_imap                       = "TRUE";//ok
20   var $cyrus_pop3                       = "TRUE";//ok
21   var $cyrus_imaps                      = "TRUE";//ok
22   var $cyrus_pop3s                      = "TRUE";//ok
23   var $cyrus_sieve                      = "TRUE";//ok
24   var $apache_allow_unauthenticated_fb  = "TRUE";//<<<<<<<<<<<<
25   var $proftpd_ftp                      = "TRUE";//pk
26   var $apache_http                      = "TRUE";//ok
27   var $kolabHost                        = array();
28   var $added                            = false; 
29   var $remove                           = false;
30   var $attributes =  array("postfix_mydomain", "postfix_mydestination",
31         "postfix_mynetworks", "postfix_enable_virus_scan","postfix_relayhost","postfix_allow_unauthenticated",
32          "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
33         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
34         "apache_allow_unauthenticated_fb", "proftpd_ftp",
35         "apache_http", "cyrus_quotawarn", "kolabHost");
37   var $objectclasses = array("top", "kolab");
39   function servkolab($config, $dn = NULL) 
40   {
43     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
44     $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
45     $this->dn = "k=kolab,".$config->current['BASE'];
46     
47     /* Load variables, if given*/
48     plugin::plugin($config, $this->dn);
50     /* Copy needed attributes */
51     foreach($this->attributes as $val) {
52       $name = preg_replace('/_/', '-', $val);
53       if (isset($this->attrs["$name"][0])) {
54         $this->$val = $this->attrs["$name"][0];
55       }
56     }
57   
58     /* Is this Server a member of the Kolab extension or not ?*/ 
59     if(in_array($this->hostname,$this->attrs['kolabHost'])) {
60       $this->is_account=true;
61     }    else    {   
62       $this->is_account=false;    } 
63     }
66   function execute() 
67   {
69     /* Fill templating stuff */
70     $smarty = get_smarty();
71     $display = "";
73     /* Lets get all Host that are member of the Kolab extension, but don't catch count */
74     if(is_array($this->attrs['kolabHost']))
75       {
76       unset($this->attrs['kolabHost']['count']);
77       $this->kolabHost = $this->attrs['kolabHost'];
78       }
79     else
80       {
81       $this->attrs['kolabHost']=array();
82       $this->kolabHost = $this->attrs['kolabHost'];
83       }    
84     
85     /* Tell the script the dn, we are using */
86     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
88     /* The Ldap link is needed to ask ldap some questions */
89     $ldap = $this->config->get_ldap_link();
91     /* Do we need to flip is_account state? */
92     if (isset($_POST['modify_state'])) {
93       $this->is_account = !$this->is_account;
94       
96       /*if we flip to true, we'll have to create a new account, so lets do that*/
97       if($this->is_account==true)
98       {
99         /* Only add the given Hostname to the existing hosts*/
100         $this->kolabHost[]=$this->hostname;
101         $this->attrs['kolabHost'][]=$this->hostname;
102       }      
103       else
104       {
105         /* First we have to find the Host we want to delete, take the index and delete em*/
106         foreach($this->kolabHost as $key=>$host) 
107         {
108           /* Delete only if the Host is the in the array*/
109           if($host == $this->hostname)
110           {
111             unset($this->kolabHost[$key]);
112             unset($this->attrs['kolabHost'][$key]);
113           }
114         }
115       /* We deletet an Entry so we must reorder the index of the array */ 
116       $tmp = $this->kolabHost;
117       $this->kolabHost=array();
118       $this->attrs['kolabHost']=array();
119       
120       /* reorder  reorder ...*/
121       foreach($tmp as $host){
122         $this->kolabHost[]=$host;
123         $this->attrs['kolabHost'][]=$host;
124       }
125       /* Tell Save that we want to delete someone*/
126       $this->remove = true;
127       }
129     }
130     /* Check Relayhost and if we have MX lookup enabled*/
131     if($this->postfix_relayhost[0]=="[")
132       {
133       $this->postfix_mxrelayenabled=false;
134       $this->postfix_relayhost = str_replace("[","",$this->postfix_relayhost);
135       $this->postfix_relayhost = str_replace("]","",$this->postfix_relayhost);
136       }
137     if($this->postfix_mxrelayenabled)    {
138       $smarty->assign("RelayMxSupportCheck"," checked ");
139       }      else      {
140       $smarty->assign("RelayMxSupportCheck","");
141       }
142     /* Show tab dialog headers */
143     if ($this->is_account) {
144       /* call Add Acoount to add account */
145       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
146     } else {
147       /* call remove Account */
148       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
149       return ($display);
150     }
152     /* Initialize all attributes, that were submitted */
153     foreach($this->attributes as $val) 
154     {
155       $smarty->assign($val."ACL",$this->acl,str_replace("_","-",$val));
156       /* Tell smarty which variables we are useing */
157       $smarty->assign($val, $this->$val);
158       if (($this->$val != "FALSE") && (!empty($this->$val)))
159         $smarty->assign($val."Check", "checked");
160       else
161         $smarty->assign($val."Check", "");
162     }
164     /* Load Template */
165     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
166     return ($display);
167   }
169   function remove_from_parent() 
170   {
171   }
174   function save_object()    
175   {
176     plugin::save_object();
177   }
180   function check() 
181   {
182     error_reporting(E_ALL);
183     $message = array();
184     if(($this->kolabFreeBusyFuture==""))    {
185       $message[] = _("Free/Busy settings -> Future days must be set.");
186     }elseif((($this->kolabFreeBusyFuture=="")<0)){
187       $message[] = _("Free/Busy settings -> Future days must be a positiv value.");
188     }elseif(strcasecmp($this->kolabFreeBusyFuture,(int)$this->kolabFreeBusyFuture)){
189       $message[] = _("Free/Busy settings -> Future days must be a value.");
190     }
191   
192     if(!is_int((int)($this->cyrus_quotawarn))) {
193       $message[] = _("Cyrus Quota settings -> The given Quota settings value must be a number.");
194     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
195       $message[] = _("Cyrus Quota settings -> Please choose a value between 1 and 100 for Quota settings.");
196     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
197       $message[] = _("Cyrus Quota settings -> Future days must be a value.");
198     }
200    if(empty($this->postfix_mynetworks))
201     { 
202       $message[] = _("SMTP privileged networks -> No value is given.");
203     }
204     
205   if(empty($this->postfix_relayhost))
206     {
207       $message[] = _("SMTP smarthost/relayhost -> No value is given.");
208     }
211     return ($message);
212   }
215   /* Save to LDAP */
216   function save() 
217   {
218     /* Set ldap connection */
219     $ldap = $this->config->get_ldap_link();
220     
221     /* Open current dn*/
222     $ldap->cd($this->dn);
224   
225     /* Setup Attributes to save */
226     $newattrs = array();
228     /* Set vars with correct - _ - */
229     foreach($this->attributes as $key) {
230       $key2 = str_replace("_", "-", $key);
231       $newattrs[$key2] = $this->$key;
232     }
233    
236     /* Set bool vars */
237     if ($newattrs['postfix-enable-virus-scan'] == 0)
238       $newattrs['postfix-enable-virus-scan'] = "FALSE";
239     else
240       $newattrs['postfix-enable-virus-scan'] = "TRUE";
241     if ($newattrs['cyrus-imap'] == 0)
242       $newattrs['cyrus-imap'] = "FALSE";
243     else
244       $newattrs['cyrus-imap'] = "TRUE";
245     if ($newattrs['cyrus-imaps'] == 0)
246       $newattrs['cyrus-imaps'] = "FALSE";
247     else
248       $newattrs['cyrus-imaps'] = "TRUE";
249     if ($newattrs['cyrus-pop3'] == 0)
250       $newattrs['cyrus-pop3'] = "FALSE";
251     else
252       $newattrs['cyrus-pop3'] = "TRUE";
253     if ($newattrs['cyrus-pop3s'] == 0)
254       $newattrs['cyrus-pop3s'] = "FALSE";
255     else
256       $newattrs['cyrus-pop3s'] = "TRUE";
257     if ($newattrs['cyrus-sieve'] == 0)
258       $newattrs['cyrus-sieve'] = "FALSE";
259     else
260       $newattrs['cyrus-sieve'] = "TRUE";
261     if ($newattrs['proftpd-ftp'] == 0)
262       $newattrs['proftpd-ftp'] = "FALSE";
263     else
264       $newattrs['proftpd-ftp'] = "TRUE";
265     if ($newattrs['apache-http'] == 0)
266       $newattrs['apache-http'] = "FALSE";
267     else
268       $newattrs['apache-http'] = "TRUE";
269     if ($newattrs['postfix-allow-unauthenticated'] == 0)
270       $newattrs['postfix-allow-unauthenticated'] = "FALSE";
271     else
272       $newattrs['postfix-allow-unauthenticated'] = "TRUE";
273     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
274       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
275     else
276       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
279     /* Reorder Host array, to get constant increasing index */
280     $newattrs['kolabHost'] = array();
282     /* Check Relayhost and if we have MX lookup enabled*/
283     if(isset($_POST['RelayMxSupport']))
284       $this->postfix_mxrelayenabled = true ;
285     else
286       $this->postfix_mxrelayenabled = false;
287     if(!$this->postfix_mxrelayenabled)
288       {
289       $newattrs['postfix-relayhost']="[".$this->postfix_relayhost."]";
290       }
292     /* If we want to add someone or do only changes on the settings ...*/
293     if(!$this->remove)
294     {
295       /* Get all Host known, that are member of the Kolab extension */
296       $this->kolabHost = $this->attrs['kolabHost'];
297       
298       /* So, the Host is already member of the extension, so get all and do nothing */
299       if(in_array($this->hostname,$this->kolabHost))
300         {
301         $newattrs['kolabHost']=$this->kolabHost;
302         }
303       /* So this is the first entry */
304       elseif(empty($this->kolabHost))
305         {
306         /* Create an array an add the Host */  
307         $newattrs['kolabHost']=array();
308         $newattrs['kolabHost'][]=$this->hostname;
309         }
310       /* Theres already an entry, but only in a string, */
311       elseif(is_string($this->kolabHost))
312         {
313         $tmp = $this->kolabHost;
314         $newattrs['kolabHost']=array();
315         $newattrs['kolabHost'][]=$tmp;
316         $newattrs['kolabHost'][]=$this->hostname;
317         }
318       /* Here we have already some entries */
319       elseif(is_array($newattrs['kolabHost']))
320         {
321         /* Insert the new one*/
322         foreach($this->kolabHost as $key=>$val) {
323           if (is_int($key)) {
324             $newattrs['kolabHost'][] = $val;
325             }
326           }
327         $newattrs['kolabHost'][]= $this->hostname;      
328         }
329       }
330       else
331       {
332       /* Here we want to delete an entry*/
333       $newattrs['kolabHost']= $this->attrs['kolabHost'];
334       }
335     /* Save as following object ! */
336     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
338     /* If we already have an object like this one,
339        we only need to modify the entry
340      */
342     /* is this an empty extension, no host defined for it, than delet it */
343     if(count($newattrs['kolabHost'])==0)
344     {
345       /* Delete the entry*/
346       $ldap->cd ("k=kolab,".$this->config->current['BASE']);
347       $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
350     }elseif ($ldap->dn_exists($this->kolabdn)) {
351     /* Ok there is already an extension, so we only need to add the changes and the new Host, (if it was a new host)*/
352       gosa_log("Modifying");
353       
354       /* unset all attributes we won't change*/
355       unset($newattrs['cyrus-admins']);
356       unset($newattrs['postfix-mydomain']);
357       unset($newattrs['postfix-mydestination']);
358     
359       /* Update changes */
360       $ldap->cd($this->kolabdn);
361       $ldap->modify($newattrs);
362     } else {
364       /* We must create a new Entry */
365       $newattrs['k'] = "kolab";
366       $newattrs['uid'] = "freebusy";
367       $newattrs['postfix-mydomain'] = "gonicus.de";
368       $newattrs['postfix-mydestination'] = "\$mydomain";
369       $newattrs['userPassword'] = "tester";
370       $newattrs['objectClass'] = $this->objectclasses;
372       /* For better reading / Objectclass was added at last */ 
373       $newattrs = array_reverse ($newattrs);  
374       
375       /* And add the entry*/
376       $ldap->cd($this->kolabdn);
377       $ldap->add($newattrs);
378     }
379     /* show any errors */
380     show_ldap_error($ldap->get_error());
381     
382     /* Optionally execute a command after we're done */
383     if ($this->initially_was_account == $this->is_account) {
384       if ($this->is_modified) {
385         $this->handle_post_events("mofify");
386       }
387     } else {
388       $this->handle_post_events("add");
389     }
391   }
395 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
396 ?>