Code

Kolab functions would runn now
[gosa.git] / plugins / admin / systems / class_servKolab.inc
1 <?php class servkolab extends plugin {
2   /* CLI vars */
3   var $cli_summary = "Manage server basic objects";
4   var $cli_description = "Some longer text\nfor help";
5   var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
8   var $postfix_mydomain                 = "";
9   var $postfix_mydestination            = "";
10   var $postfix_mynetworks               = "";
11   var $postfix_enable_virus_scan        = "";
12   var $cyrus_autocreatequota            = "";
13   var $cyrus_quotawarn                  = "";
14   var $cyrus_admins                     = "";
15   var $cyrus_imap                       = "";
16   var $cyrus_pop3                       = "";
17   var $cyrus_imaps                      = "";
18   var $cyrus_pop3s                      = "";
19   var $cyrus_sieve                      = "";
20   var $apache_allow_unauthenticated_fb  = "";
21   var $proftpd_ftp                      = "";
22   var $apache_http                      = "";
23   var $kolabHost                        = array("");
25   var $attributes =  array("postfix_mydomain", "postfix_mydestination",
26         "postfix_mynetworks", "postfix_enable_virus_scan",
27         "cyrus_autocreatequota", "cyrus_admins", "cyrus_imap",
28         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
29         "apache_allow_unauthenticated_fb", "proftpd_ftp",
30         "apache_http", "cyrus_quotawarn", "kolabHost");
32   var $objectclasses = array("top", "kolab");
34   function servkolab($config, $dn = NULL) 
35   {
36     echo "DN korrigieren<br>";
37     $this->dn = "k=kolab,".$config->current['BASE'];
38     
39     plugin::plugin($config, $this->dn);
40     $this->dn = $dn;
42     /* Copy needed attributes */
43     foreach($this->attributes as $val) {
44       $name = preg_replace('/_/', '-', $val);
45       if (isset($this->attrs["$name"][0])) {
46         $this->$val = $this->attrs["$name"][0];
47       }
48     }
49   }
54   /* If the Button remove Kolab extension is clicked, this will be called */
55   function RemoveAccount() 
56   {
57   
58   gosa_log("Remove function");
59     
60     $ldap = $this->config->get_ldap_link();
61     $ldap->cd($this->dn);
63     if ($ldap->dn_exists($this->dn)) {
64       $ldap->rmdir($this->dn);
65       show_ldap_error($ldap->get_error());
66     }
67   }
73   /* this fucntion generates all needed attributes to start a new kolab extension */
74   function AddAccount() 
75   {
77     /* get the Ldap link, to test if there is an obeject with the same dn */
78     $ldap = $this->config->get_ldap_link();
79     
80     gosa_log("Add function");
82     /* test */
83     if (!$ldap->dn_exists($this->dn)) {
84       /* Object Classes */
85       $str['objectClass'][] = "top";
86       $str['objectClass'][] = "kolab";
88       /* specific kolab attribute */
89       $str['k'][] = "kolab";
91       /* Postfix default values */
92       $str['postfix-mydomain'][] = "gonicus.de";
93       $str['postfix-mydestination'][] = "\$mydomain";
94       $str['postfix-mynetworks'][] = "127.0.0.0/8";
95       $str['postfix-enable-virus-scan'][] = "TRUE";
97       /* Cyrus Attributes */
98       $str['cyrus-autocreatequota'][] = "100000";
99       $str['cyrus-quotawarn'][] = "80";
100       $str['cyrus-admins'][] = "manager";
101       $str['cyrus-imap'][] = "TRUE";
102       $str['cyrus-pop3'][] = "FALSE";
103       $str['cyrus-imaps'][] = "FALSE";
104       $str['cyrus-pop3s'][] = "FALSE";
105       $str['cyrus-sieve'][] = "FALSE";
107       /* */
108       $str['apache-allow-unauthenticated-fb'][] = "FALSE";
109       $str['proftpd-ftp'][] = "FALSE";
110       $str['uid'][] = "freebusy";
111       $str['userPassword'][] = "ZnJlZWJ1c3k";
112       $str['apache-http'][] = "TRUE";
115       /* Set Attributes */
116       $ldap->cd($this->dn);
117       $this->attrs = $str;
119       /* Copy needed attributes */
120       foreach($this->attributes as $val) {
121         $name = preg_replace('/_/', '-', $val);
122         if (isset($this->attrs["$name"][0])) {
123           $this->$val = $this->attrs["$name"][0];
124         }
125       }
127     }
130   }
133   function execute() 
134   {
135     /* Fill templating stuff */
136     $smarty = get_smarty();
137     $display = "";
139     /* Tell the script the dn, we are using */
140     $this->dn = "k=kolab,".$this->config->current['BASE'];
142     $ldap = $this->config->get_ldap_link();
143     
144     /* Do we need to flip is_account state? */
145     if (isset($_POST['modify_state'])) {
146       $this->is_account = !$this->is_account;
147       if($this->is_account) 
148         $this->AddAccount();
149       else  
150         $this->RemoveAccount();   
151     
152     
153     }
155     /* Show tab dialog headers */
156     if ($this->is_account) {
157       /* call Add Acoount to add account */
158       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
159     } else {
160       /* call remove Account */
161       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
162       return ($display);
163     }
165     /* There a new Host submitted */
166     if (isset($_POST['NewHost'])) {
167       $this->attrs['kolabHost'][] = $_POST['NewkolabHost'];
168       gosa_log("Adding Host");
169     }
171     /* We need to delete a Host */
172     if (isset($_POST['DelHost'])) {
173       foreach($this->attrs['kolabHost'] as $key => $host) {
174         if ($host == $_POST['kolabHost'])
175           unset($this->attrs['kolabHost'][$key]);
176       }
177       gosa_log("Removing Host".$this->attrs['kolabHost'][$key]);
178     }
182     /* Initialize all attributes, that were submitted */
183     foreach($this->attributes as $val) {
184       /* If theres a button pressed, we need to check all attributes */
185       if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) {
186         /* Set var to value or to zero */
187         if (isset($_POST[$val])) {
189           $this->$val = $_POST[$val];
190         } else {
191           $this->$val = 0;
192         }
193       }
194       /* Tell smarty which variables we are useing */
195       $smarty->assign($val, $this->$val);
196       if (($this->$val != "FALSE") && (!empty($this->$val)))
197         $smarty->assign($val."Check", "checked");
199     }
201     /*  If there are some Host submitted, tell it smarty */
202     $this->kolabHost = array();
203     if (isset($this->attrs['kolabHost'])) {
204       $this->kolabHost = $this->attrs['kolabHost'];
205       unset($this->kolabHost['count']);
206     }
208     $smarty->assign("kolabHost", $this->kolabHost);
210     /* Load Template */
211     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
212   
213     print_a($this);
214   
215     return ($display);
216   }
218   function remove_from_parent() 
219   {
220   }
223   function save_object()    
224   {
225     plugin::save_object();
226   }
229   function check() 
230   {
231     $message = array();
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>=1))){
237       $message[] = "Please choose a value between 1 and 100 for Quota settings";
238     }
239     
241     /* You will need a least one entry to save this settings */
242     if (count($this->kolabHost) == 0) {
243       $message[] =
244         "You will need at least one Entry in Hosts. If You want to 'Remove' Kolab extension please use the \"Remove Kolab extension\"  Button to remove Kolab  ";
245     }
246     return ($message);
247   }
250   /* Save to LDAP */
251   function save() 
252   {
253     /* Set ldap connection */
254     $ldap = $this->config->get_ldap_link();
255     $ldap->cd($this->dn);
257     /* Setup Attributes to save */
258     $newattrs = array();
260     /* Set vars with correct - _ - */
261     foreach($this->attributes as $key) {
262       $key2 = str_replace("_", "-", $key);
263       $newattrs[$key2] = $this->$key;
264     }
266     /* Set bool vars */
267     if ($newattrs['postfix-enable-virus-scan'] == 0)
268       $newattrs['postfix-enable-virus-scan'] = "FALSE";
269     else
270       $newattrs['postfix-enable-virus-scan'] = "TRUE";
271     if ($newattrs['cyrus-imap'] == 0)
272       $newattrs['cyrus-imap'] = "FALSE";
273     else
274       $newattrs['cyrus-imap'] = "TRUE";
275     if ($newattrs['cyrus-imaps'] == 0)
276       $newattrs['cyrus-imaps'] = "FALSE";
277     else
278       $newattrs['cyrus-imaps'] = "TRUE";
279     if ($newattrs['cyrus-pop3'] == 0)
280       $newattrs['cyrus-pop3'] = "FALSE";
281     else
282       $newattrs['cyrus-pop3'] = "TRUE";
283     if ($newattrs['cyrus-pop3s'] == 0)
284       $newattrs['cyrus-pop3s'] = "FALSE";
285     else
286       $newattrs['cyrus-pop3s'] = "TRUE";
287     if ($newattrs['cyrus-sieve'] == 0)
288       $newattrs['cyrus-sieve'] = "FALSE";
289     else
290       $newattrs['cyrus-sieve'] = "TRUE";
291     if ($newattrs['proftpd-ftp'] == 0)
292       $newattrs['proftpd-ftp'] = "FALSE";
293     else
294       $newattrs['proftpd-ftp'] = "TRUE";
295     if ($newattrs['apache-http'] == 0)
296       $newattrs['apache-http'] = "FALSE";
297     else
298       $newattrs['apache-http'] = "TRUE";
299     if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
300       $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
301     else
302       $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
305     /* Reorder Host array, to get constant increasing index */
306     $newattrs['kolabHost'] = array();
307     foreach($this->attrs['kolabHost'] as $key=>$val) {
308       if (is_int($key)) {
309         $newattrs['kolabHost'][] = $val;
310       }
311     }
313     /* Save as following object ! */
314     $this->dn = "k=kolab,".$this->config->current['BASE'];
316     /* If we already have an object like this one,
317        we only need to modify the entry
318      */
319     if ($ldap->dn_exists($this->dn)) {
320       gosa_log("Modifying");
321       $ldap->cd($this->dn);
322       $ldap->modify($newattrs);
323     } else {
324       /* We must create a new Entry */
325       gosa_log("Adding");
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;
332       $ldap->cd($this->dn);
333       $ldap->add($newattrs);
334     }
336     /* show any errors */
337     show_ldap_error($ldap->get_error());
339     /* Optionally execute a command after we're done */
340     if ($this->initially_was_account == $this->is_account) {
341       if ($this->is_modified) {
342         $this->handle_post_events("mofify");
343       }
344     } else {
345       $this->handle_post_events("add");
346     }
348   }
352 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
353 ?>