Code

Some Atributes are missing, but it will runn
[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 $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";//<<<<<<<<<<<<
21   var $proftpd_ftp                      = "TRUE";//pk
22   var $apache_http                      = "TRUE";//ok
23   var $kolabHost                        = array();
24   var $added                            = false; 
25   var $remove                           = false;
26   var $attributes =  array("postfix_mydomain", "postfix_mydestination",
27         "postfix_mynetworks", "postfix_enable_virus_scan",
28          "cyrus_admins", "cyrus_imap",
29         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
30         "apache_allow_unauthenticated_fb", "proftpd_ftp",
31         "apache_http", "cyrus_quotawarn", "kolabHost");
33   var $objectclasses = array("top", "kolab");
35   function servkolab($config, $dn = NULL) 
36   {
39     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
40     $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
41     $this->dn = "k=kolab,".$config->current['BASE'];
42     
43     /* Load variables, if given*/
44     plugin::plugin($config, $this->dn);
46     /* Copy needed attributes */
47     foreach($this->attributes as $val) {
48       $name = preg_replace('/_/', '-', $val);
49       if (isset($this->attrs["$name"][0])) {
50         $this->$val = $this->attrs["$name"][0];
51       }
52     }
53   
54     /* Is this Server a member of the Kolab extension or not ?*/ 
55     if(in_array($this->hostname,$this->attrs['kolabHost'])) {
56       $this->is_account=true;
57     }    else    {   
58       $this->is_account=false;    } 
59     }
62   function execute() 
63   {
64     /* Fill templating stuff */
65     $smarty = get_smarty();
66     $display = "";
68     /* Lets get all Host that are member of the Kolab extension, but don't catch count */
69     if(is_array($this->attrs['kolabHost']))
70       {
71       unset($this->attrs['kolabHost']['count']);
72       $this->kolabHost = $this->attrs['kolabHost'];
73       }
74     else
75       {
76       $this->attrs['kolabHost']=array();
77       $this->kolabHost = $this->attrs['kolabHost'];
78       }    
79     
80     /* Tell the script the dn, we are using */
81     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
83     /* The Ldap link is needed to ask ldap some questions */
84     $ldap = $this->config->get_ldap_link();
86     /* Do we need to flip is_account state? */
87     if (isset($_POST['modify_state'])) {
88       $this->is_account = !$this->is_account;
89       
91       /*if we flip to true, we'll have to create a new account, so lets do that*/
92       if($this->is_account==true)
93       {
94         /* Only add the given Hostname to the existing hosts*/
95         $this->kolabHost[]=$this->hostname;
96         $this->attrs['kolabHost'][]=$this->hostname;
97       }      
98       else
99       {
100         /* First we have to find the Host we want to delete, take the index and delete em*/
101         foreach($this->kolabHost as $key=>$host) 
102         {
103           /* Delete only if the Host is the in the array*/
104           if($host == $this->hostname)
105           {
106             unset($this->kolabHost[$key]);
107             unset($this->attrs['kolabHost'][$key]);
108           }
109         }
110       /* We deletet an Entry so we must reorder the index of the array */ 
111       $tmp = $this->kolabHost;
112       $this->kolabHost=array();
113       $this->attrs['kolabHost']=array();
114       
115       /* reorder  reorder ...*/
116       foreach($tmp as $host){
117         $this->kolabHost[]=$host;
118         $this->attrs['kolabHost'][]=$host;
119       }
120       /* Tell Save that we want to delete someone*/
121       $this->remove = true;
122       }
124     }
126     /* Show tab dialog headers */
127     if ($this->is_account) {
128       /* call Add Acoount to add account */
129       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
130     } else {
131       /* call remove Account */
132       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
133       return ($display);
134     }
136     /* Initialize all attributes, that were submitted */
137     foreach($this->attributes as $val) 
138     {
139       /* If theres a button pressed, we need to check all attributes */
140       if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) 
141       {
142         /* Set var to value or to zero */
143         if (isset($_POST[$val])) 
144         {
146           $this->$val = $_POST[$val];
147         } else {
148           $this->$val = 0;
149         }
150       }
151       /* Tell smarty which variables we are useing */
152       $smarty->assign($val, $this->$val);
153       if (($this->$val != "FALSE") && (!empty($this->$val)))
154         $smarty->assign($val."Check", "checked");
155       else
156         $smarty->assign($val."Check", "");
157     }
159     /* Load Template */
160     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
161     return ($display);
162   }
164   function remove_from_parent() 
165   {
166   }
169   function save_object()    
170   {
171     plugin::save_object();
172   }
175   function check() 
176   {
177     $message = array();
180     if(!is_int((int)($this->cyrus_quotawarn))) {
181       $message[] = "The given Quota settings value must be a number";
182     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
183       $message[] = "Please choose a value between 1 and 100 for Quota settings";
184     }
185     
187     return ($message);
188   }
191   /* Save to LDAP */
192   function save() 
193   {
194     /* Set ldap connection */
195     $ldap = $this->config->get_ldap_link();
196     
197     /* Open current dn*/
198     $ldap->cd($this->dn);
200   
201     /* Setup Attributes to save */
202     $newattrs = array();
204     /* Set vars with correct - _ - */
205     foreach($this->attributes as $key) {
206       $key2 = str_replace("_", "-", $key);
207       $newattrs[$key2] = $this->$key;
208     }
209    
212     /* Set bool vars */
213     if ($newattrs['postfix-enable-virus-scan'] == 0)
214       $newattrs['postfix-enable-virus-scan'] = "FALSE";
215     else
216       $newattrs['postfix-enable-virus-scan'] = "TRUE";
217     if ($newattrs['cyrus-imap'] == 0)
218       $newattrs['cyrus-imap'] = "FALSE";
219     else
220       $newattrs['cyrus-imap'] = "TRUE";
221     if ($newattrs['cyrus-imaps'] == 0)
222       $newattrs['cyrus-imaps'] = "FALSE";
223     else
224       $newattrs['cyrus-imaps'] = "TRUE";
225     if ($newattrs['cyrus-pop3'] == 0)
226       $newattrs['cyrus-pop3'] = "FALSE";
227     else
228       $newattrs['cyrus-pop3'] = "TRUE";
229     if ($newattrs['cyrus-pop3s'] == 0)
230       $newattrs['cyrus-pop3s'] = "FALSE";
231     else
232       $newattrs['cyrus-pop3s'] = "TRUE";
233     if ($newattrs['cyrus-sieve'] == 0)
234       $newattrs['cyrus-sieve'] = "FALSE";
235     else
236       $newattrs['cyrus-sieve'] = "TRUE";
237     if ($newattrs['proftpd-ftp'] == 0)
238       $newattrs['proftpd-ftp'] = "FALSE";
239     else
240       $newattrs['proftpd-ftp'] = "TRUE";
241     if ($newattrs['apache-http'] == 0)
242       $newattrs['apache-http'] = "FALSE";
243     else
244       $newattrs['apache-http'] = "TRUE";
245     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
246       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
247     else
248       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
251     /* Reorder Host array, to get constant increasing index */
252     $newattrs['kolabHost'] = array();
254     /* If we want to add someone or do only changes on the settings ...*/
255     if(!$this->remove)
256     {
257       /* Get all Host known, that are member of the Kolab extension */
258       $this->kolabHost = $this->attrs['kolabHost'];
259       
260       /* So, the Host is already member of the extension, so get all and do nothing */
261       if(in_array($this->hostname,$this->kolabHost))
262         {
263         $newattrs['kolabHost']=$this->kolabHost;
264         }
265       /* So this is the first entry */
266       elseif(empty($this->kolabHost))
267         {
268         /* Create an array an add the Host */  
269         $newattrs['kolabHost']=array();
270         $newattrs['kolabHost'][]=$this->hostname;
271         }
272       /* Theres already an entry, but only in a string, */
273       elseif(is_string($this->kolabHost))
274         {
275         $tmp = $this->kolabHost;
276         $newattrs['kolabHost']=array();
277         $newattrs['kolabHost'][]=$tmp;
278         $newattrs['kolabHost'][]=$this->hostname;
279         }
280       /* Here we have already some entries */
281       elseif(is_array($newattrs['kolabHost']))
282         {
283         /* Insert the new one*/
284         foreach($this->kolabHost as $key=>$val) {
285           if (is_int($key)) {
286             $newattrs['kolabHost'][] = $val;
287             }
288           }
289         $newattrs['kolabHost'][]= $this->hostname;      
290         }
291       }
292       else
293       {
294       /* Here we want to delete an entry*/
295       $newattrs['kolabHost']= $this->attrs['kolabHost'];
296       }
297     /* Save as following object ! */
298     $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
300     /* If we already have an object like this one,
301        we only need to modify the entry
302      */
304     /* is this an empty extension, no host defined for it, than delet it */
305     if(count($newattrs['kolabHost'])==0)
306     {
307       /* Delete the entry*/
308       $ldap->cd ("k=kolab,".$this->config->current['BASE']);
309       $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
311     }elseif ($ldap->dn_exists($this->kolabdn)) {
312     /* Ok there is already an extension, so we only need to add the changes and the new Host, (if it was a new host)*/
313       gosa_log("Modifying");
314       
315       /* unset all attributes we won't change*/
316       unset($newattrs['cyrus-admins']);
317       unset($newattrs['postfix-mydomain']);
318       unset($newattrs['postfix-mydestination']);
319     
320       /* Update changes */
321       $ldap->cd($this->kolabdn);
322       $ldap->modify($newattrs);
323     } else {
325       /* We must create a new Entry */
326       $newattrs['k'] = "kolab";
327       $newattrs['uid'] = "freebusy";
328       $newattrs['postfix-mydomain'] = "gonicus.de";
329       $newattrs['postfix-mydestination'] = "\$mydomain";
330       $newattrs['userPassword'] = "tester";
331       $newattrs['objectClass'] = $this->objectclasses;
333       /* For better reading / Objectclass was added at last */ 
334       $newattrs = array_reverse ($newattrs);  
335       
336       /* And add the entry*/
337       $ldap->cd($this->kolabdn);
338       $ldap->add($newattrs);
339     }
340     /* show any errors */
341     show_ldap_error($ldap->get_error());
342     
343     /* Optionally execute a command after we're done */
344     if ($this->initially_was_account == $this->is_account) {
345       if ($this->is_modified) {
346         $this->handle_post_events("mofify");
347       }
348     } else {
349       $this->handle_post_events("add");
350     }
352   }
356 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
357 ?>