Code

4c562fffba4035cec9e44cbc0e25d39c0d6fed40
[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";
12   var $postfix_enable_virus_scan        = "TRUE";
13   var $cyrus_quotawarn                  = "999";//ok
14   var $cyrus_admins                     = "TRUE";
15   var $cyrus_imap                       = "TRUE";//ok
16   var $cyrus_pop3                       = "TRUE";//ok
17   var $cyrus_imaps                      = "TRUE";//ok
18   var $cyrus_pop3s                      = "TRUE";//ok
19   var $cyrus_sieve                      = "TRUE";//ok
20   var $apache_allow_unauthenticated_fb  = "TRUE";//doing now
21   var $proftpd_ftp                      = "TRUE";
22   var $apache_http                      = "TRUE";
23   var $kolabHost                        = array();
24   var $postfix_relayhost                = "";
25   var $added                            = false; 
26   var $remove                           = false;
27   var $attributes =  array("postfix_mydomain", "postfix_mydestination",
28         "postfix_mynetworks", "postfix_enable_virus_scan","postfix_relayhost",
29          "cyrus_admins", "cyrus_imap",
30         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
31         "apache_allow_unauthenticated_fb", "proftpd_ftp",
32         "apache_http", "cyrus_quotawarn", "kolabHost");
34   var $objectclasses = array("top", "kolab");
36   function servkolab($config, $dn = NULL) 
37   {
38     $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
39     $this->dn = "k=kolab,".$config->current['BASE'];
40     
41     plugin::plugin($config, $this->dn);
43     /* Copy needed attributes */
44     foreach($this->attributes as $val) {
45       $name = preg_replace('/_/', '-', $val);
46       if (isset($this->attrs["$name"][0])) {
47         $this->$val = $this->attrs["$name"][0];
48       }
49     }
50     
51     if(in_array($this->hostname,$this->attrs['kolabHost']))
52     {
53       $this->is_account=true;
54     }
55     else
56     {   
57       $this->is_account=false;
58     } 
59   }
62   function execute() 
63   {
64     /* Fill templating stuff */
65     $smarty = get_smarty();
66     $display = "";
69     unset($this->attrs['kolabHost']['count']);
70     $this->kolabHost = $this->attrs['kolabHost'];
73     /* Tell the script the dn, we are using */
74     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
76     $ldap = $this->config->get_ldap_link();
77     
78     /* Do we need to flip is_account state? */
79     if (isset($_POST['modify_state'])) {
80       $this->is_account = !$this->is_account;
81       
82       if($this->is_account==true)
83       {
84         $this->kolabHost[]=$this->hostname;
85         $this->attrs['kolabHost'][]=$this->hostname;
86       }      
87       else
88       {
89         foreach($this->kolabHost as $key=>$host) 
90         {
91           if($host == $this->hostname)
92           {
93             unset($this->kolabHost[$key]);
94             unset($this->attrs['kolabHost'][$key]);
95           }
96         }
97       $tmp = $this->kolabHost;
98       $this->kolabHost=array();
99       $this->attrs['kolabHost']=array();
100       foreach($tmp as $host){
101         $this->kolabHost[]=$host;
102         $this->attrs['kolabHost'][]=$host;
103       }
104       $this->remove = true;
105       }
107     }
110     print_a($this);
111     
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     /* Initialize all attributes, that were submitted */
123     foreach($this->attributes as $val) 
124     {
125       /* If theres a button pressed, we need to check all attributes */
126       if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) 
127       {
128         /* Set var to value or to zero */
129         if (isset($_POST[$val])) 
130         {
132           $this->$val = $_POST[$val];
133         } else {
134           $this->$val = 0;
135         }
136       }
137       /* Tell smarty which variables we are useing */
138       $smarty->assign($val, $this->$val);
139       if (($this->$val != "FALSE") && (!empty($this->$val)))
140         $smarty->assign($val."Check", "checked");
141       else
142         $smarty->assign($val."Check", "");
143     }
145     /* Load Template */
146     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
147     return ($display);
148   }
150   function remove_from_parent() 
151   {
152   }
155   function save_object()    
156   {
157     plugin::save_object();
158   }
161   function check() 
162   {
163     $message = array();
166     if(!is_int((int)($this->cyrus_quotawarn))) {
167       $message[] = "The given Quota settings value must be a number";
168     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
169       $message[] = "Please choose a value between 1 and 100 for Quota settings";
170     }
171     
173     return ($message);
174   }
177   /* Save to LDAP */
178   function save() 
179   {
180     /* Set ldap connection */
181     $ldap = $this->config->get_ldap_link();
182     $ldap->cd($this->dn);
184   
185   /* Setup Attributes to save */
186     $newattrs = array();
188     /* Set vars with correct - _ - */
189     foreach($this->attributes as $key) {
190       $key2 = str_replace("_", "-", $key);
191       $newattrs[$key2] = $this->$key;
192     }
193    
196     /* Set bool vars */
197     if ($newattrs['postfix-enable-virus-scan'] == 0)
198       $newattrs['postfix-enable-virus-scan'] = "FALSE";
199     else
200       $newattrs['postfix-enable-virus-scan'] = "TRUE";
201     if ($newattrs['cyrus-imap'] == 0)
202       $newattrs['cyrus-imap'] = "FALSE";
203     else
204       $newattrs['cyrus-imap'] = "TRUE";
205     if ($newattrs['cyrus-imaps'] == 0)
206       $newattrs['cyrus-imaps'] = "FALSE";
207     else
208       $newattrs['cyrus-imaps'] = "TRUE";
209     if ($newattrs['cyrus-pop3'] == 0)
210       $newattrs['cyrus-pop3'] = "FALSE";
211     else
212       $newattrs['cyrus-pop3'] = "TRUE";
213     if ($newattrs['cyrus-pop3s'] == 0)
214       $newattrs['cyrus-pop3s'] = "FALSE";
215     else
216       $newattrs['cyrus-pop3s'] = "TRUE";
217     if ($newattrs['cyrus-sieve'] == 0)
218       $newattrs['cyrus-sieve'] = "FALSE";
219     else
220       $newattrs['cyrus-sieve'] = "TRUE";
221     if ($newattrs['proftpd-ftp'] == 0)
222       $newattrs['proftpd-ftp'] = "FALSE";
223     else
224       $newattrs['proftpd-ftp'] = "TRUE";
225     if ($newattrs['apache-http'] == 0)
226       $newattrs['apache-http'] = "FALSE";
227     else
228       $newattrs['apache-http'] = "TRUE";
229     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
230       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
231     else
232       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
235     if(empty($newattrs['postfix-relayhost'])) unset( $newattrs['postfix-relayhost']);
237     /* Reorder Host array, to get constant increasing index */
238     $newattrs['kolabHost'] = array();
240     if(!$this->remove)
241     {
242       $this->kolabHost = $this->attrs['kolabHost'];
243       
244       if(in_array($this->hostname,$this->kolabHost))
245         {
246         $newattrs['kolabHost']=$this->kolabHost;
247         }
248       elseif(empty($this->kolabHost))
249         {
250         print "empty";
251         $newattrs['kolabHost']=array();
252         $newattrs['kolabHost'][]=$this->hostname;
253         }
254       elseif(is_string($this->kolabHost))
255         {
256         print "string";
257         $tmp = $this->kolabHost;
258         $newattrs['kolabHost']=array();
259         $newattrs['kolabHost'][]=$tmp;
260         $newattrs['kolabHost'][]=$this->hostname;
261         }
262       elseif(is_array($newattrs['kolabHost']))
263         {
264         print "array";
265         foreach($this->kolabHost as $key=>$val) {
266           if (is_int($key)) {
267             $newattrs['kolabHost'][] = $val;
268             }
269           }
270         $newattrs['kolabHost'][]= $this->hostname;      
271         }
272       }
273       else
274       {
275       $newattrs['kolabHost']= $this->attrs['kolabHost'];
276       }
277     /* Save as following object ! */
278     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
280     /* If we already have an object like this one,
281        we only need to modify the entry
282      */
284     if(count($newattrs['kolabHost'])==0)
285     {
286     $ldap->cd ("k=kolab,".$this->config->current['BASE']);
287     print "Deleting";
288     $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
290     }elseif ($ldap->dn_exists($this->kolabdn)) {
291       gosa_log("Modifying");
292       
293       /* unset all attributes we won't change*/
294       unset($newattrs['cyrus-admins']);
295       unset($newattrs['postfix-mydomain']);
296       unset($newattrs['postfix-mydestination']);
297     
299       $ldap->cd($this->kolabdn);
300       $ldap->modify($newattrs);
301     } else {
303       /* We must create a new Entry */
304       $newattrs['k'] = "kolab";
305       $newattrs['uid'] = "freebusy";
306       $newattrs['postfix-mydomain'] = "gonicus.de";
307       $newattrs['postfix-mydestination'] = "\$mydomain";
308       $newattrs['userPassword'] = "tester";
309       $newattrs['objectClass'] = $this->objectclasses;
311       gosa_log("Adding");
312       
313       $newattrs = array_reverse ($newattrs);  
314     
315       $ldap->cd($this->kolabdn);
316       $ldap->add($newattrs);
317     }
318     
319     print_a($newattrs);
320     /* show any errors */
321     show_ldap_error($ldap->get_error());
322     
323     /* Optionally execute a command after we're done */
324     if ($this->initially_was_account == $this->is_account) {
325       if ($this->is_modified) {
326         $this->handle_post_events("mofify");
327       }
328     } else {
329       $this->handle_post_events("add");
330     }
332   }
336 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
337 ?>