Code

changes in fucntions inc --> there was & in a link but it must be & to be conform
[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(isset($this->postfix_relayhost[0]) && $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     /* Assemble free/busy string */
165     $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
166             $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
167     $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
168     $smarty->assign("fbfuture", $fbfuture);
170     /* Assemble quota string */
171     $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
172           $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
173     $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
174     $smarty->assign("quotastr", $quotastr);
176     /* Load Template */
177     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
178     return ($display);
179   }
181   function remove_from_parent() 
182   {
183   }
186   function save_object()    
187   {
188     plugin::save_object();
189   }
192   function check() 
193   {
194     error_reporting(E_ALL);
195     $message = array();
196     if(($this->kolabFreeBusyFuture==""))    {
197       $message[] = _("Future days in Free/Busy settings must be set.");
198     }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
199       $message[] = _("Future days in Free/Busy settings must be a positive value.");
200     }
202     if(!is_int((int)($this->cyrus_quotawarn))) {
203       $message[] = _("The given Quota settings value must be a number.");
204     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
205       $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
206     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
207       $message[] = _("Future days must be a value.");
208     }
210     if(empty($this->postfix_mynetworks))
211     { 
212       $message[] = _("No SMTP privileged networks set.");
213     }
215     if(empty($this->postfix_relayhost))
216     {
217       $message[] = _("No SMTP smarthost/relayhost set.");
218     }
221     return ($message);
222   }
225   /* Save to LDAP */
226   function save() 
227   {
228     /* Set ldap connection */
229     $ldap = $this->config->get_ldap_link();
230     
231     /* Open current dn*/
232     $ldap->cd($this->dn);
234   
235     /* Setup Attributes to save */
236     $newattrs = array();
238     /* Set vars with correct - _ - */
239     foreach($this->attributes as $key) {
240       $key2 = str_replace("_", "-", $key);
241       $newattrs[$key2] = $this->$key;
242     }
243    
246     /* Set bool vars */
247     if ($newattrs['postfix-enable-virus-scan'] == 0)
248       $newattrs['postfix-enable-virus-scan'] = "FALSE";
249     else
250       $newattrs['postfix-enable-virus-scan'] = "TRUE";
251     if ($newattrs['cyrus-imap'] == 0)
252       $newattrs['cyrus-imap'] = "FALSE";
253     else
254       $newattrs['cyrus-imap'] = "TRUE";
255     if ($newattrs['cyrus-imaps'] == 0)
256       $newattrs['cyrus-imaps'] = "FALSE";
257     else
258       $newattrs['cyrus-imaps'] = "TRUE";
259     if ($newattrs['cyrus-pop3'] == 0)
260       $newattrs['cyrus-pop3'] = "FALSE";
261     else
262       $newattrs['cyrus-pop3'] = "TRUE";
263     if ($newattrs['cyrus-pop3s'] == 0)
264       $newattrs['cyrus-pop3s'] = "FALSE";
265     else
266       $newattrs['cyrus-pop3s'] = "TRUE";
267     if ($newattrs['cyrus-sieve'] == 0)
268       $newattrs['cyrus-sieve'] = "FALSE";
269     else
270       $newattrs['cyrus-sieve'] = "TRUE";
271     if ($newattrs['proftpd-ftp'] == 0)
272       $newattrs['proftpd-ftp'] = "FALSE";
273     else
274       $newattrs['proftpd-ftp'] = "TRUE";
275     if ($newattrs['apache-http'] == 0)
276       $newattrs['apache-http'] = "FALSE";
277     else
278       $newattrs['apache-http'] = "TRUE";
279     if ($newattrs['postfix-allow-unauthenticated'] == 0)
280       $newattrs['postfix-allow-unauthenticated'] = "FALSE";
281     else
282       $newattrs['postfix-allow-unauthenticated'] = "TRUE";
283     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
284       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
285     else
286       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
289     /* Reorder Host array, to get constant increasing index */
290     $newattrs['kolabHost'] = array();
292     /* Check Relayhost and if we have MX lookup enabled*/
293     if(isset($_POST['RelayMxSupport']))
294       $this->postfix_mxrelayenabled = true ;
295     else
296       $this->postfix_mxrelayenabled = false;
297     if(!$this->postfix_mxrelayenabled)
298       {
299       $newattrs['postfix-relayhost']="[".$this->postfix_relayhost."]";
300       }
302     /* If we want to add someone or do only changes on the settings ...*/
303     if(!$this->remove)
304     {
305       /* Get all Host known, that are member of the Kolab extension */
306       $this->kolabHost = $this->attrs['kolabHost'];
307       
308       /* So, the Host is already member of the extension, so get all and do nothing */
309       if(in_array($this->hostname,$this->kolabHost))
310         {
311         $newattrs['kolabHost']=$this->kolabHost;
312         }
313       /* So this is the first entry */
314       elseif(empty($this->kolabHost))
315         {
316         /* Create an array an add the Host */  
317         $newattrs['kolabHost']=array();
318         $newattrs['kolabHost'][]=$this->hostname;
319         }
320       /* Theres already an entry, but only in a string, */
321       elseif(is_string($this->kolabHost))
322         {
323         $tmp = $this->kolabHost;
324         $newattrs['kolabHost']=array();
325         $newattrs['kolabHost'][]=$tmp;
326         $newattrs['kolabHost'][]=$this->hostname;
327         }
328       /* Here we have already some entries */
329       elseif(is_array($newattrs['kolabHost']))
330         {
331         /* Insert the new one*/
332         foreach($this->kolabHost as $key=>$val) {
333           if (is_int($key)) {
334             $newattrs['kolabHost'][] = $val;
335             }
336           }
337         $newattrs['kolabHost'][]= $this->hostname;      
338         }
339       }
340       else
341       {
342       /* Here we want to delete an entry*/
343       $newattrs['kolabHost']= $this->attrs['kolabHost'];
344       }
345     /* Save as following object ! */
346     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
348     /* If we already have an object like this one,
349        we only need to modify the entry
350      */
352     /* is this an empty extension, no host defined for it, than delet it */
353     if(count($newattrs['kolabHost'])==0)
354     {
355       /* Delete the entry*/
356       $ldap->cd ("k=kolab,".$this->config->current['BASE']);
357       $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
360     }elseif ($ldap->dn_exists($this->kolabdn)) {
361     /* Ok there is already an extension, so we only need to add the changes and the new Host, (if it was a new host)*/
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     
369       /* Update changes */
370       $ldap->cd($this->kolabdn);
371       $ldap->modify($newattrs);
372     } else {
374       /* We must create a new Entry */
375       $newattrs['k'] = "kolab";
376       $newattrs['uid'] = "freebusy";
377       $newattrs['postfix-mydomain'] = "gonicus.de";
378       $newattrs['postfix-mydestination'] = "\$mydomain";
379       $newattrs['userPassword'] = "tester";
380       $newattrs['objectClass'] = $this->objectclasses;
382       /* For better reading / Objectclass was added at last */ 
383       $newattrs = array_reverse ($newattrs);  
384       
385       /* And add the entry*/
386       $ldap->cd($this->kolabdn);
387       $ldap->add($newattrs);
388     }
389     /* show any errors */
390     show_ldap_error($ldap->get_error());
391     
392     /* Optionally execute a command after we're done */
393     if ($this->initially_was_account == $this->is_account) {
394       if ($this->is_modified) {
395         $this->handle_post_events("mofify");
396       }
397     } else {
398       $this->handle_post_events("add");
399     }
401   }
405 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
406 ?>