Code

3365211b96bee4bb46b8a62fadb5869848e14f9c
[gosa.git] / plugins / admin / systems / class_servKolab.inc
1 <?php
3 require_once("class_goService.inc");
5 class servkolab extends goService {
6   /* CLI vars */
7   var $cli_summary = "Manage server basic objects";
8   var $cli_description = "Some longer text\nfor help";
9   var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
11   var $postfix_mydomain                 = "";
12   var $postfix_mydestination            = "";
13   var $postfix_mynetworks               = "127.0.0.1/8";
14   var $postfix_enable_virus_scan        = "TRUE";
15   var $postfix_relayhost                = "";
16   var $postfix_mxrelayenabled           =  true;
17   var $postfix_allow_unauthenticated     = "FALSE";
18   var $cyrus_quotawarn                  = "80";
19   var $kolabFreeBusyFuture              = "1";
20   var $k                                = "kolab";
21   var $cyrus_admins                     = "TRUE";
22   var $cyrus_imap                       = "TRUE";
23   var $cyrus_pop3                       = "TRUE";
24   var $cyrus_imaps                      = "TRUE";
25   var $cyrus_pop3s                      = "TRUE";
26   var $cyrus_sieve                      = "TRUE";
27   var $apache_allow_unauthenticated_fb  = "TRUE";
28   var $proftpd_ftp                      = "TRUE";
29   var $apache_http                      = "TRUE";
30   var $kolabHost                        = array();
31   var $orig_cn                          = "";
33   var $attributes =  array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
34       "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
35       "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
36       "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
37       "cyrus_quotawarn");
38   var $objectclasses = array("top", "kolab");
40   /* Serverservice vars */
41   var $conflicts    = array("goImapServer","goMailServer");
42   var $DisplayName  = "Kolab mail service";
43   var $StatusFlag   = "";
45   function servkolab($config, $dn = NULL, $parent= NULL) 
46   {
47     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
48     $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
49     $this->dn       = "k=kolab,".$config->current['BASE'];
51     /* Load variables, if given*/
52     plugin::plugin($config, $this->dn, $parent);
54     /* Copy needed attributes */
55     foreach($this->attributes as $val) {
56       $name = preg_replace('/_/', '-', $val);
57       if (isset($this->attrs["$name"][0])) {
58         $this->$val = $this->attrs["$name"][0];
59       }
60     }
62     /* Toggle relayhost */
63     $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost);
64     $this->postfix_relayhost      = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
66     /* Is this Server a member of the Kolab extension or not ?*/ 
67     if(isset($this->attrs['kolabHost'])) {
68       $this->kolabHost= $this->attrs['kolabHost'];
69       unset($this->kolabHost['count']);
70     }
71     $this->is_account            = false;
72     $this->initially_was_account = false;
73     foreach($this->kolabHost as $host){
74       if($this->hostname == $host){
75         $this->is_account            = true;
76         $this->initially_was_account = true;
77       }
78     } 
80   }
83   function execute() 
84   {
85     /* Call parent execute */
86     plugin::execute();
88     /***************  
89       Variable initialisation
90      ***************/  
91     
92     $smarty     = get_smarty();
93     $display    = "";
94     $ldap       = $this->config->get_ldap_link();
97     /* Assemble free/busy string */
98     $edit       = sprintf('<input name="kolabFreeBusyFuture" value="%s" type="text" maxlength="3" size="4">',
99                     $this->kolabFreeBusyFuture);
100     $fbfuture   = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
102     /* Assemble quota string */
103     $edit       = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4">',
104                     $this->cyrus_quotawarn);
105     $quotastr   = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
107     /***************
108       Assign informations to smarty 
109      ***************/
111     /* Set relayhost and if we have MX lookup enabled*/ 
112     if($this->acl_is_writeable("postfixmxrelayenabled")){
113       if($this->postfix_mxrelayenabled) {
114         $smarty->assign("RelayMxSupportCheck"," checked ");
115       } else {
116         $smarty->assign("RelayMxSupportCheck","");
117       }
118     }
120     /* Set acls */
121     $tmp = $this->plInfo();
122     foreach($tmp['plProvidedAcls'] as $name => $translation){
123       $smarty->assign($name."ACL",$this->getacl($name));
124     }
126     /* Initialize all attributes, that were submitted */
127     foreach($this->attributes as $val) 
128     {
129       /* Tell smarty which variables we are useing */
130       $smarty->assign($val, $this->$val);
131       if (($this->$val != "FALSE") && !empty($this->$val)){
132         $smarty->assign($val."Check", "checked");
133       } else {
134         $smarty->assign($val."Check", "");
135       }
136     }
138     $smarty->assign("fbfuture", $fbfuture);
139     $smarty->assign("quotastr", $quotastr);
141     /* Load Template */
142     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
143     return ($display);
144   }
146   function remove_from_parent() 
147   {
149      /* Remove status flag, it is not a memeber of
150         this->attributes, so ensure that it is deleted too */
151     if(!empty($this->StatusFlag)){
152       $this->attrs[$this->StatusFlag] = array();
153     }
156     /* Only walk through following code, if this host 
157        was a member of the kolab hosts, else skip this */
158     if(!$this->initially_was_account){
159       return;
160     }
162     /* !!! Don't use "cn" in this function 
163        hostname -> the initial name of the host
164        cn       -> is the new name of the host, in case that it was renamed.
165      */
167     $ldap     = $this->config->get_ldap_link();
168     $this->dn = "k=kolab,".$this->config->current['BASE'];
170     /* We can't simply remove the whole entry, it is possible that there are 
171        some other hosts assigned to this object. 
172        So, first of all check if we are the last host entry within the host 
173        : Remove k=kolab entry 
174        if we aren't alone, only remove host name from hosts entry and save */
175     /* Are we alone? Remove complete entry... */
177     /* Check if we are definitly in kolabHosts */
178     if(!in_array_ics($this->hostname,$this->kolabHost)) {
179       return;
180     }
182     /* Integration check, not translatet because they can't pop up at all, only for debug */ 
183     if(count($this->kolabHost) == 0){
184       print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
185       return;
186     }
187     if(!isset($this->hostname) || (empty($this->hostname))){
188       print_red("The required attribute hostname seams to empty.");
189     }
191     /* Our hostname is in kolabHosts and there is a only one entry 
192        = we are the last host entry, delete k=kolab entry  */
193     if (count($this->kolabHost) == 1){
195       /* Remove complete entry */
196       $ldap->rmdir ($this->dn);
197       show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn));
198       gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
200     } else {
202       /* Only modify kolabHost */
203       $hosts= array();
204       foreach ($this->kolabHost as $host){
205         if($host != $this->hostname){
206           $hosts[]= $host;
207         }
208       }
209       $attrs= array('kolabHost' => $hosts);
210       $ldap->cd($this->dn);
211       $this->cleanup();
212       $ldap->modify ($attrs); 
213       show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn));
214       gosa_log("Removing ".$this->hostname." from list of kolabHosts");
215     }
217     /* Optionally execute a command after we're done */
218     $this->handle_post_events("remove");
219   }
222   function save_object()    
223   {
224     if (isset($_POST['kolabtab'])){
225       plugin::save_object();
228       foreach($this->attributes as $attr){
229         if(($this->acl_is_writeable(preg_replace("/_/","",$attr))) && (isset($_POST[$attr]))){
230           $this->$attr = $_POST[$attr];
231         }
232       }
234       /* Save checkboxes */
235       foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
236             "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
237             "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
238             "proftpd_ftp", "apache_http") as $cb){
240         if($this->acl_is_writeable(preg_replace("/_/","",$cb))){
241           if (isset($_POST[$cb])){
242             $this->$cb= "TRUE";
243           } else {
244             $this->$cb= "FALSE";
245           }
246         }
247       }
249       /* Toggle relay check */
250       $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
251     }
253   }
256   function check() 
257   {
258     /* Call common method to give check the hook */
259     $message= plugin::check();
261     if(($this->kolabFreeBusyFuture==""))    {
262       $message[] = _("Future days in Free/Busy settings must be set.");
263     }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
264       $message[] = _("Future days in Free/Busy settings must be a positive value.");
265     }
267     if(!is_int((int)($this->cyrus_quotawarn))) {
268       $message[] = _("The given Quota settings value must be a number.");
269     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
270       $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
271     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
272       $message[] = _("Future days must be a value.");
273     }
275     if(empty($this->postfix_mynetworks)) { 
276       $message[] = _("No SMTP privileged networks set.");
277     }
279     /*if(empty($this->postfix_relayhost)) {
280       $message[] = _("No SMTP smarthost/relayhost set.");
281       }
282      */
284     return ($message);
285   }
288   /* Save to LDAP */
289   function save() 
290   {
291     /* Set ldap connection */
292     $ldap       = $this->config->get_ldap_link();
294     /* Open current dn*/
295     $this->dn   = "k=kolab,".$this->config->current['BASE'];
297     /* Adapt relayhost */
298     $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
299     if ($this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
300       $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
301     }
303     /* Check if this server was renamed, in this case we have to remove old cn first*/
304     if($this->hostname != $this->cn){
305       $tmp = array();
306       if(in_array_ics($this->hostname,$this->kolabHost)){
307         foreach($this->kolabHost as $host){
308           if($host != $this->hostname){
309             $tmp[] = $host;
310           }
311         }
312         $this->kolabHost = $tmp;
313       }
314     }
316     /* Add ourselves to the list of kolabHost's if needed */
317     if (!in_array_ics($this->cn,$this->kolabHost)){
318       $this->kolabHost[]= $this->cn;
319     }
321     /* Call parents save to prepare $this->attrs */
322     plugin::save();
324     /* Save or modify? */
325     $ldap->cat($this->dn, array('dn'));
326     if (!$ldap->fetch()){
327       $mode= "add"; 
328     } else {
329       $mode= "modify";
330     }
332     /* Do attribute conversion */
333     foreach ($this->attrs as $key => $value){
334       if (preg_match('/_/', $key)){
335         $old_key= $key;
336         $key= preg_replace('/_/', '-', $key);
337         $this->attrs[$key]= $value;
338         unset($this->attrs[$old_key]);
339       }
340     }
341     /* Add kolab hosts */
342     $this->attrs['kolabHost']= $this->kolabHost;
344     /* Perform LDAP action */
345     $ldap->cd($this->dn);
346     $this->cleanup();;
347     $ldap->$mode($this->attrs);
348     show_ldap_error($ldap->get_error(), sprintf(_("Saving system server/kolab with dn '%s' failed."),$this->dn));
350     /* Optionally execute a command after we're done */
351     if ($this->initially_was_account == $this->is_account) {
352       if ($this->is_modified) {
353         $this->handle_post_events("modify");
354       }
355     } else {
356       $this->handle_post_events("add");
357     }
358   }
361   function getListEntry()
362   {
363     $fields                 = goService::getListEntry();
364     $fields['Message']      = _("Kolab mail service");
365     $fields['AllowEdit']    = true;
366     return($fields);
367   }
370   /* Return plugin informations for acl handling */
371   function plInfo()
372   {
373     return (array(
374           "plShortName"   => _("Kolab"),
375           "plDescription" => _("Kolab service"),
376           "plSelfModify"  => FALSE,
377           "plDepends"     => array(),
378           "plPriority"    => 0,
379           "plSection"     => array("administration"),
380           "plCategory"    => array("server"),
382           "plProvidedAcls"=> array(
383             "postfixmydomain"                => _("Postfix mydomain") ,
384             "postfixmydestination"           => _("My destination") ,
385             "proftpdftp"                     => _("FTP FreeBusy service") ,
386             "postfixmynetworks"              => _("SMTP privileged networks") ,
387             "postfixenablevirusscan"         => _("Enable virus scan") ,
388             "postfixrelayhost"               => _("Relayhost") ,
389             "postfixmxrelayenabled"          => _("Enable MX lookup for relayhost"),
390             "apachehttp"                     => _("HTTP FreeBusy service") ,
391             "apacheallowunauthenticatedfb"   => _("Allow unauthenticated free busy"),
392             "postfixallowunauthenticated"    => _("Accept Internet Mail") ,
393             "cyrusimap"                      => _("IMAP service") ,
394             "kolabFreeBusyFuture"            => _("kolabFreeBusyFuture") ,
395             "cyruspop3"                      => _("POP3 service") ,
396             "cyrusimaps"                     => _("IMAP/SSL service") ,
397             "cyruspop3s"                     => _("POP3/SSL service") ,
398             "cyrussieve"                     => _("Sieve service") ,
399             "cyrusquotawarn"                 => _("Quota settings")) 
400             ));
401   }
404 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
405 ?>