Code

Fixed headpage
[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                 = "";
10   var $postfix_mydestination            = "";
11   var $postfix_mynetworks               = "127.0.0.1/8";
12   var $postfix_enable_virus_scan        = "TRUE";
13   var $postfix_relayhost                = "";
14   var $postfix_mxrelayenabled           =  true;
15   var $postfix_allow_unauthenticated     = "FALSE";
16   var $cyrus_quotawarn                  = "80";
17   var $kolabFreeBusyFuture              = "1";
18   var $k                                = "kolab";
19   var $cyrus_admins                     = "TRUE";
20   var $cyrus_imap                       = "TRUE";
21   var $cyrus_pop3                       = "TRUE";
22   var $cyrus_imaps                      = "TRUE";
23   var $cyrus_pop3s                      = "TRUE";
24   var $cyrus_sieve                      = "TRUE";
25   var $apache_allow_unauthenticated_fb  = "TRUE";
26   var $proftpd_ftp                      = "TRUE";
27   var $apache_http                      = "TRUE";
28   var $kolabHost                        = array();
29   var $is_in_there                      = false;
30   var $exactName                        = false;
31   var $attributes =  array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
32         "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
33         "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
34         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
35         "cyrus_quotawarn");
36   var $objectclasses = array("top", "kolab");
38   function servkolab($config, $dn = NULL) 
39   {
40     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
41     $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
42     $this->dn = "k=kolab,".$config->current['BASE'];
43     
44     /* Load variables, if given*/
45     plugin::plugin($config, $this->dn);
47     /* Copy needed attributes */
48     foreach($this->attributes as $val) {
49       $name = preg_replace('/_/', '-', $val);
50       if (isset($this->attrs["$name"][0])) {
51         $this->$val = $this->attrs["$name"][0];
52       }
53     }
54   
55     /* Toggle relayhost */
56     $this->postfix_mxrelayenabled= preg_match('/^\[/', $this->postfix_relayhost);
57     $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
59     /* Is this Server a member of the Kolab extension or not ?*/ 
60     if(isset($this->attrs['kolabHost'])) {
61       $this->kolabHost= $this->attrs['kolabHost'];
62       unset($this->kolabHost['count']);
63     }
64   
66     $this->is_in_there=false;
67     $this->is_account=false;
68     foreach($this->kolabHost as $host){
69       if(preg_match("/".$this->hostname.".*/i",$host)){
70         $this->is_account=true;
71         $this->is_in_there=true;
72       }
73     } 
74   
75     if(in_array($this->hostname, $this->kolabHost)) {
76       $this->exactName=true;
77     } else {   
78       $this->exactName=false;    
79     } 
80     if(isset($this->attrs['postfix-mynetworks'])){
81       if(is_array($this->attrs['postfix-mynetworks'])){  
82         unset($this->attrs['postfix-mynetworks']['count']);
83         $tmp="";
84         foreach($this->attrs['postfix-mynetworks'] as $tm){
85           $tmp.=$tm.";";
86         }
87         $this->postfix_mynetworks = $tmp;
88       }
89     }else{
90       $this->postfix_mynetworks="";
91     }
92   }
95   function execute() 
96   {
97         /* Call parent execute */
98         plugin::execute();
100     /* Fill templating stuff */
101     $smarty = get_smarty();
102     $display = "";
104     /* The Ldap link is needed to ask ldap some questions */
105     $ldap = $this->config->get_ldap_link();
107     /* Do we need to flip is_account state? */
108     if (isset($_POST['modify_state'])) {
109       $this->is_account = !$this->is_account;
110     }
112     /* Show tab dialog headers */
113     if ($this->is_account) {
114       /* call Add Acoount to add account */
115       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
116     } else {
117       /* call remove Account */
118       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
119       return ($display);
120     }
122     /* Set relayhost and if we have MX lookup enabled*/
123     if($this->postfix_mxrelayenabled) {
124       $smarty->assign("RelayMxSupportCheck"," checked ");
125     } else {
126       $smarty->assign("RelayMxSupportCheck","");
127     }
128     
129     /* Initialize all attributes, that were submitted */
130     foreach($this->attributes as $val) 
131     {
132       $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
134       /* Tell smarty which variables we are useing */
135       $smarty->assign($val, $this->$val);
136       if (($this->$val != "FALSE") && !empty($this->$val)){
137         $smarty->assign($val."Check", "checked");
138       } else {
139         $smarty->assign($val."Check", "");
140       }
141     }
143     /* Assemble free/busy string */
144     $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
145             $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
146     $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
147     $smarty->assign("fbfuture", $fbfuture);
149     /* Assemble quota string */
150     $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
151           $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
152     $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
153     $smarty->assign("quotastr", $quotastr);
155     /* Load Template */
156     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
157     return ($display);
158   }
160   function remove_from_parent() 
161   {
162     $ldap= $this->config->get_ldap_link();
163     $this->dn = "k=kolab,".$this->config->current['BASE'];
165     if (count($this->kolabHost) == 0){
166       return;
167     }
169     /* Are we alone? Remove complete entry... */
170     if (count($this->kolabHost) == 1){
172       /* Remove complete entry */
173       $ldap->rmdir ($this->dn);
174       show_ldap_error($ldap->get_error());
175       
176     } else {
178       /* Only modify kolabHost */
179       $hosts= array();
180       foreach ($this->kolabHost as $host){
181         if ($host != $this->cn){
182           $hosts[]= $host;
183         }
184       }
185       $attrs= array('kolabHost' => $hosts);
186       $ldap->cd($this->dn);
187       $ldap->modify($attrs);
188       show_ldap_error($ldap->get_error());
189     }
191     /* Optionally execute a command after we're done */
192     $this->handle_post_events("remove");
193   }
196   function save_object()    
197   {
198     if (isset($_POST['kolabtab'])){
199       plugin::save_object();
201       /* Save checkboxes */
202       foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
203                       "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
204                       "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
205                       "proftpd_ftp", "apache_http") as $cb){
206         if (isset($_POST[$cb])){
207           $this->$cb= "TRUE";
208         } else {
209           $this->$cb= "FALSE";
210         }
211       }
213       /* Toggle relay check */
214       $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
215     }
217   }
220   function check() 
221   {
222     $message = array();
223     if(($this->kolabFreeBusyFuture==""))    {
224       $message[] = _("Future days in Free/Busy settings must be set.");
225     }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
226       $message[] = _("Future days in Free/Busy settings must be a positive value.");
227     }
229     if(!is_int((int)($this->cyrus_quotawarn))) {
230       $message[] = _("The given Quota settings value must be a number.");
231     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
232       $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
233     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
234       $message[] = _("Future days must be a value.");
235     }
237     if(empty($this->postfix_mynetworks)) { 
238       $message[] = _("No SMTP privileged networks set.");
239     }
241     if(empty($this->postfix_relayhost)) {
242       $message[] = _("No SMTP smarthost/relayhost set.");
243     }
245     return ($message);
246   }
249   /* Save to LDAP */
250   function save() 
251   {
252     /* Set ldap connection */
253     $ldap = $this->config->get_ldap_link();
254     
255     /* Open current dn*/
256     $this->dn = "k=kolab,".$this->config->current['BASE'];
257   
258     /* Adapt relayhost */
259     $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
260     if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
261       $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
262     }
264     /* Add ourselves to the list of kolabHost's if needed */
265     if ((!$this->is_in_there)){
266       $this->kolabHost[]= $this->cn;
267     }
268     
269  
270   
271     $tmp = split(";",$this->postfix_mynetworks);
272     $this->postfix_mynetworks = array();
273     foreach($tmp as $tm){
274       trim($tm);
275       if(!empty($tm)){
276         $this->postfix_mynetworks[]=$tm;
277       }
278     }
279   
280     $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
282     /* Call parents save to prepare $this->attrs */
283     plugin::save();
285     /* Save or modify? */
286     $ldap->cat($this->dn);
287     if (!$ldap->fetch()){
288       $mode= "add"; 
289     } else {
290       $mode= "modify";
291     }
293     /* Do attribute conversion */
294     foreach ($this->attrs as $key => $value){
295       if (preg_match('/_/', $key)){
296         $old_key= $key;
297         $key= preg_replace('/_/', '-', $key);
298         $this->attrs[$key]= $value;
299         unset($this->attrs[$old_key]);
300       }
301     }
303     /* Add kolab hosts */
304     $this->attrs['kolabHost']= $this->kolabHost;
305   
306     if(($this->is_in_there)&&(!$this->exactName)){
307       unset($this->attrs['kolabHost']);
308     }
310     /* Perform LDAP action */
311     $ldap->cd($this->dn);
312     $ldap->$mode($this->attrs);
313     show_ldap_error($ldap->get_error());
314     
315     /* Optionally execute a command after we're done */
316     if ($this->initially_was_account == $this->is_account) {
317       if ($this->is_modified) {
318         $this->handle_post_events("mofify");
319       }
320     } else {
321       $this->handle_post_events("add");
322     }
324   }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>