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");
10 var $postfix_mydomain = "";
11 var $postfix_mydestination = "";
12 var $postfix_mynetworks = "";
13 var $postfix_enable_virus_scan = "";
14 var $cyrus_autocreatequota = "";
15 var $cyrus_quotawarn = "";//ok
16 var $cyrus_admins = "";
17 var $cyrus_imap = "";//ok
18 var $cyrus_pop3 = "";//ok
19 var $cyrus_imaps = "";//ok
20 var $cyrus_pop3s = "";//ok
21 var $cyrus_sieve = "";//ok
22 var $apache_allow_unauthenticated_fb = "";//doing now
23 var $proftpd_ftp = "";
24 var $apache_http = "";
25 var $kolabHost = array("");
26 var $postfix_relayhost = "";
27 var $attributes = array("postfix_mydomain", "postfix_mydestination",
28 "postfix_mynetworks", "postfix_enable_virus_scan","postfix_relayhost",
29 "cyrus_autocreatequota", "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 echo "DN korrigieren<br>";
39 $this->dn = "k=kolab,".$config->current['BASE'];
41 plugin::plugin($config, $this->dn);
42 $this->dn = $dn;
44 /* Copy needed attributes */
45 foreach($this->attributes as $val) {
46 $name = preg_replace('/_/', '-', $val);
47 if (isset($this->attrs["$name"][0])) {
48 $this->$val = $this->attrs["$name"][0];
49 }
50 }
51 }
56 /* If the Button remove Kolab extension is clicked, this will be called */
57 function RemoveAccount()
58 {
60 gosa_log("Remove function");
62 $ldap = $this->config->get_ldap_link();
63 $ldap->cd($this->dn);
65 if ($ldap->dn_exists($this->dn)) {
66 $ldap->rmdir($this->dn);
67 show_ldap_error($ldap->get_error());
68 }
69 }
75 /* this fucntion generates all needed attributes to start a new kolab extension */
76 function AddAccount()
77 {
79 /* get the Ldap link, to test if there is an obeject with the same dn */
80 $ldap = $this->config->get_ldap_link();
82 gosa_log("Add function");
84 /* test */
85 if (!$ldap->dn_exists($this->dn)) {
86 /* Object Classes */
87 $str['objectClass'][] = "top";
88 $str['objectClass'][] = "kolab";
90 /* specific kolab attribute */
91 $str['k'][] = "kolab";
93 /* Postfix default values */
94 $str['postfix-mydomain'][] = "gonicus.de";
95 $str['postfix-mydestination'][] = "\$mydomain";
96 $str['postfix-mynetworks'][] = "127.0.0.0/8";
97 $str['postfix-enable-virus-scan'][] = "TRUE";
99 /* Cyrus Attributes */
100 $str['cyrus-autocreatequota'][] = "100000";
101 $str['cyrus-quotawarn'][] = "80";
102 $str['cyrus-admins'][] = "manager";
103 $str['cyrus-imap'][] = "TRUE";
104 $str['cyrus-pop3'][] = "FALSE";
105 $str['cyrus-imaps'][] = "FALSE";
106 $str['cyrus-pop3s'][] = "FALSE";
107 $str['cyrus-sieve'][] = "FALSE";
109 /* */
110 $str['apache-allow-unauthenticated-fb'][] = "FALSE";
111 $str['proftpd-ftp'][] = "FALSE";
112 $str['uid'][] = "freebusy";
113 $str['userPassword'][] = "ZnJlZWJ1c3k";
114 $str['apache-http'][] = "TRUE";
117 /* Set Attributes */
118 $ldap->cd($this->dn);
119 $this->attrs = $str;
121 /* Copy needed attributes */
122 foreach($this->attributes as $val) {
123 $name = preg_replace('/_/', '-', $val);
124 if (isset($this->attrs["$name"][0])) {
125 $this->$val = $this->attrs["$name"][0];
126 }
127 }
129 }
132 }
135 function execute()
136 {
137 /* Fill templating stuff */
138 $smarty = get_smarty();
139 $display = "";
141 /* Tell the script the dn, we are using */
142 $this->dn = "k=kolab,".$this->config->current['BASE'];
144 $ldap = $this->config->get_ldap_link();
146 /* Do we need to flip is_account state? */
147 if (isset($_POST['modify_state'])) {
148 $this->is_account = !$this->is_account;
149 if($this->is_account)
150 $this->AddAccount();
151 else
152 $this->RemoveAccount();
155 }
157 /* Show tab dialog headers */
158 if ($this->is_account) {
159 /* call Add Acoount to add account */
160 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
161 } else {
162 /* call remove Account */
163 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
164 return ($display);
165 }
167 /* There a new Host submitted */
168 if (isset($_POST['NewHost'])) {
170 $abort= false;
171 if(empty($_POST['NewkolabHost']))
172 {
173 //print_red(_("The given Hostname ist empty."))
174 $abort = true;
175 }
176 else
177 {
178 foreach($this->attrs['kolabHost'] as $host)
179 {
180 if(strtolower($host) ==strtolower($_POST['NewkolabHost']))
181 {
182 $abort = true;
183 //print_red(_("The given Host already exists"));
184 }
185 }
186 }
187 if(!$abort)
188 {
189 $this->attrs['kolabHost'][] = $_POST['NewkolabHost'];
190 }
191 }
193 /* We need to delete a Host */
194 if (isset($_POST['DelHost'])) {
195 foreach($this->attrs['kolabHost'] as $key => $host) {
196 if(isset($_POST['kolabHost'])){
197 if ($host == $_POST['kolabHost'])
198 unset($this->attrs['kolabHost'][$key]);
199 }
200 }
201 }
205 /* Initialize all attributes, that were submitted */
206 foreach($this->attributes as $val) {
207 /* If theres a button pressed, we need to check all attributes */
208 if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) {
209 /* Set var to value or to zero */
210 if (isset($_POST[$val])) {
212 $this->$val = $_POST[$val];
213 } else {
214 $this->$val = 0;
215 }
216 }
217 /* Tell smarty which variables we are useing */
218 $smarty->assign($val, $this->$val);
219 if (($this->$val != "FALSE") && (!empty($this->$val)))
220 $smarty->assign($val."Check", "checked");
221 else
222 $smarty->assign($val."Check", "");
224 }
226 /* If there are some Host submitted, tell it smarty */
227 $this->kolabHost = array();
228 if (isset($this->attrs['kolabHost'])) {
229 $this->kolabHost = $this->attrs['kolabHost'];
230 unset($this->kolabHost['count']);
231 }
233 $smarty->assign("kolabHost", $this->kolabHost);
235 /* Load Template */
236 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
238 return ($display);
239 }
241 function remove_from_parent()
242 {
243 }
246 function save_object()
247 {
248 plugin::save_object();
249 }
252 function check()
253 {
254 $message = array();
257 if(!is_int((int)($this->cyrus_quotawarn))) {
258 $message[] = "The given Quota settings value must be a number";
259 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
260 $message[] = "Please choose a value between 1 and 100 for Quota settings";
261 }
264 /* You will need a least one entry to save this settings */
265 if (count($this->kolabHost) == 0) {
266 $message[] =
267 "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 ";
268 }
269 return ($message);
270 }
273 /* Save to LDAP */
274 function save()
275 {
276 /* Set ldap connection */
277 $ldap = $this->config->get_ldap_link();
278 $ldap->cd($this->dn);
280 /* Setup Attributes to save */
281 $newattrs = array();
283 /* Set vars with correct - _ - */
284 foreach($this->attributes as $key) {
285 $key2 = str_replace("_", "-", $key);
286 $newattrs[$key2] = $this->$key;
287 }
295 /* Set bool vars */
296 if ($newattrs['postfix-enable-virus-scan'] == 0)
297 $newattrs['postfix-enable-virus-scan'] = "FALSE";
298 else
299 $newattrs['postfix-enable-virus-scan'] = "TRUE";
300 if ($newattrs['cyrus-imap'] == 0)
301 $newattrs['cyrus-imap'] = "FALSE";
302 else
303 $newattrs['cyrus-imap'] = "TRUE";
304 if ($newattrs['cyrus-imaps'] == 0)
305 $newattrs['cyrus-imaps'] = "FALSE";
306 else
307 $newattrs['cyrus-imaps'] = "TRUE";
308 if ($newattrs['cyrus-pop3'] == 0)
309 $newattrs['cyrus-pop3'] = "FALSE";
310 else
311 $newattrs['cyrus-pop3'] = "TRUE";
312 if ($newattrs['cyrus-pop3s'] == 0)
313 $newattrs['cyrus-pop3s'] = "FALSE";
314 else
315 $newattrs['cyrus-pop3s'] = "TRUE";
316 if ($newattrs['cyrus-sieve'] == 0)
317 $newattrs['cyrus-sieve'] = "FALSE";
318 else
319 $newattrs['cyrus-sieve'] = "TRUE";
320 if ($newattrs['proftpd-ftp'] == 0)
321 $newattrs['proftpd-ftp'] = "FALSE";
322 else
323 $newattrs['proftpd-ftp'] = "TRUE";
324 if ($newattrs['apache-http'] == 0)
325 $newattrs['apache-http'] = "FALSE";
326 else
327 $newattrs['apache-http'] = "TRUE";
328 if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
329 $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
330 else
331 $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
334 if(empty($newattrs['postfix-relayhost'])) unset( $newattrs['postfix-relayhost']);
336 /* Reorder Host array, to get constant increasing index */
337 $newattrs['kolabHost'] = array();
338 foreach($this->attrs['kolabHost'] as $key=>$val) {
339 if (is_int($key)) {
340 $newattrs['kolabHost'][] = $val;
341 }
342 }
344 /* Save as following object ! */
345 $this->dn = "k=kolab,".$this->config->current['BASE'];
347 /* If we already have an object like this one,
348 we only need to modify the entry
349 */
353 if ($ldap->dn_exists($this->dn)) {
354 gosa_log("Modifying");
356 /* unset all attributes we won't change*/
357 unset($newattrs['cyrus-admins']);
358 unset($newattrs['postfix-mydomain']);
359 unset($newattrs['postfix-mydestination']);
360 //print_a($newattrs);
364 $ldap->cd($this->dn);
365 $ldap->modify($newattrs);
366 } else {
367 /* We must create a new Entry */
368 $newattrs['k'] = "kolab";
369 $newattrs['uid'] = "freebusy";
370 $newattrs['postfix-mydomain'] = "gonicus.de";
371 $newattrs['postfix-mydestination'] = "\$mydomain";
372 $newattrs['userPassword'] = "tester";
373 $newattrs['objectClass'] = $this->objectclasses;
375 gosa_log("Adding");
376 $ldap->cd($this->dn);
377 $ldap->add($newattrs);
378 }
380 /* show any errors */
381 show_ldap_error($ldap->get_error());
383 /* Optionally execute a command after we're done */
384 if ($this->initially_was_account == $this->is_account) {
385 if ($this->is_modified) {
386 $this->handle_post_events("mofify");
387 }
388 } else {
389 $this->handle_post_events("add");
390 }
392 }
394 }
396 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
397 ?>