Code

c124abfaa44f9cf5c14cccb43242569068540f5c
[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(), _("Removing kolab host entry failed"));
175       
176     } else {
178       /* Only modify kolabHost */
179       $hosts= array();
180       foreach ($this->kolabHost as $host){
181         
182         if (isset($this->cn)&&($host != $this->cn)){
183           $hosts[]= $host;
184         }
185       }
186       $attrs= array('kolabHost' => $hosts);
187       $ldap->cd($this->dn);
188       $this->cleanup();
189       $ldap->modify ($attrs); 
191       show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
192     }
194     /* Optionally execute a command after we're done */
195     $this->handle_post_events("remove");
196   }
199   function save_object()    
200   {
201     if (isset($_POST['kolabtab'])){
202       plugin::save_object();
204       /* Save checkboxes */
205       foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
206                       "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
207                       "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
208                       "proftpd_ftp", "apache_http") as $cb){
209         if (isset($_POST[$cb])){
210           $this->$cb= "TRUE";
211         } else {
212           $this->$cb= "FALSE";
213         }
214       }
216       /* Toggle relay check */
217       $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
218     }
220   }
223   function check() 
224   {
225     /* Call common method to give check the hook */
226     $message= plugin::check();
228     if(($this->kolabFreeBusyFuture==""))    {
229       $message[] = _("Future days in Free/Busy settings must be set.");
230     }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
231       $message[] = _("Future days in Free/Busy settings must be a positive value.");
232     }
234     if(!is_int((int)($this->cyrus_quotawarn))) {
235       $message[] = _("The given Quota settings value must be a number.");
236     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
237       $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
238     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
239       $message[] = _("Future days must be a value.");
240     }
242     if(empty($this->postfix_mynetworks)) { 
243       $message[] = _("No SMTP privileged networks set.");
244     }
246     /*if(empty($this->postfix_relayhost)) {
247       $message[] = _("No SMTP smarthost/relayhost set.");
248     }
249     */
251     return ($message);
252   }
255   /* Save to LDAP */
256   function save() 
257   {
258     /* Set ldap connection */
259     $ldap = $this->config->get_ldap_link();
260     
261     /* Open current dn*/
262     $this->dn = "k=kolab,".$this->config->current['BASE'];
263   
264     /* Adapt relayhost */
265     $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
266     if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
267       $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
268     }
270     /* Add ourselves to the list of kolabHost's if needed */
271     if ((!$this->is_in_there)){
272       $this->kolabHost[]= $this->cn;
273     }
274     
275  
276   
277     $tmp = split(";",$this->postfix_mynetworks);
278     $this->postfix_mynetworks = array();
279     foreach($tmp as $tm){
280       trim($tm);
281       if(!empty($tm)){
282         $this->postfix_mynetworks[]=$tm;
283       }
284     }
285   
286     $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
288     /* Call parents save to prepare $this->attrs */
289     plugin::save();
291     /* Save or modify? */
292     $ldap->cat($this->dn, array('dn'));
293     if (!$ldap->fetch()){
294       $mode= "add"; 
295     } else {
296       $mode= "modify";
297     }
299     /* Do attribute conversion */
300     foreach ($this->attrs as $key => $value){
301       if (preg_match('/_/', $key)){
302         $old_key= $key;
303         $key= preg_replace('/_/', '-', $key);
304         $this->attrs[$key]= $value;
305         unset($this->attrs[$old_key]);
306       }
307     }
309     /* Add kolab hosts */
310     $this->attrs['kolabHost']= $this->kolabHost;
311   
312     if(($this->is_in_there)&&(!$this->exactName)){
313       unset($this->attrs['kolabHost']);
314     }
316     /* Perform LDAP action */
317     $ldap->cd($this->dn);
318     $this->cleanup();;
319     $ldap->$mode($this->attrs);
320     show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
321     
322     /* Optionally execute a command after we're done */
323     if ($this->initially_was_account == $this->is_account) {
324       if ($this->is_modified) {
325         $this->handle_post_events("mofify");
326       }
327     } else {
328       $this->handle_post_events("add");
329     }
331   }
335 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
336 ?>