2ab91d46735c98891b20235c172806ba298347ef
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 $postfix_relayhost = "";
14 var $postfix_mxrelayenabled = true;
15 var $postfix_allow_unauthenticated = "false";
16 var $cyrus_quotawarn = "80";//ok
17 var $kolabFreeBusyFuture = "1";// ok
18 var $cyrus_admins = "TRUE";//<<<<<<<<<<<<<<<<
19 var $cyrus_imap = "TRUE";//ok
20 var $cyrus_pop3 = "TRUE";//ok
21 var $cyrus_imaps = "TRUE";//ok
22 var $cyrus_pop3s = "TRUE";//ok
23 var $cyrus_sieve = "TRUE";//ok
24 var $apache_allow_unauthenticated_fb = "TRUE";//<<<<<<<<<<<<
25 var $proftpd_ftp = "TRUE";//pk
26 var $apache_http = "TRUE";//ok
27 var $kolabHost = array();
28 var $added = false;
29 var $remove = false;
30 var $attributes = array("postfix_mydomain", "postfix_mydestination",
31 "postfix_mynetworks", "postfix_enable_virus_scan","postfix_relayhost","postfix_allow_unauthenticated",
32 "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
33 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
34 "apache_allow_unauthenticated_fb", "proftpd_ftp",
35 "apache_http", "cyrus_quotawarn", "kolabHost");
37 var $objectclasses = array("top", "kolab");
39 function servkolab($config, $dn = NULL)
40 {
43 /* Setting the hostname and tell this Plugin that we are the kolab extension*/
44 $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
45 $this->dn = "k=kolab,".$config->current['BASE'];
47 /* Load variables, if given*/
48 plugin::plugin($config, $this->dn);
50 /* Copy needed attributes */
51 foreach($this->attributes as $val) {
52 $name = preg_replace('/_/', '-', $val);
53 if (isset($this->attrs["$name"][0])) {
54 $this->$val = $this->attrs["$name"][0];
55 }
56 }
58 /* Is this Server a member of the Kolab extension or not ?*/
59 if(in_array($this->hostname,$this->attrs['kolabHost'])) {
60 $this->is_account=true;
61 } else {
62 $this->is_account=false; }
63 }
66 function execute()
67 {
69 /* Fill templating stuff */
70 $smarty = get_smarty();
71 $display = "";
73 /* Lets get all Host that are member of the Kolab extension, but don't catch count */
74 if(is_array($this->attrs['kolabHost']))
75 {
76 unset($this->attrs['kolabHost']['count']);
77 $this->kolabHost = $this->attrs['kolabHost'];
78 }
79 else
80 {
81 $this->attrs['kolabHost']=array();
82 $this->kolabHost = $this->attrs['kolabHost'];
83 }
85 /* Tell the script the dn, we are using */
86 $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
88 /* The Ldap link is needed to ask ldap some questions */
89 $ldap = $this->config->get_ldap_link();
91 /* Do we need to flip is_account state? */
92 if (isset($_POST['modify_state'])) {
93 $this->is_account = !$this->is_account;
96 /*if we flip to true, we'll have to create a new account, so lets do that*/
97 if($this->is_account==true)
98 {
99 /* Only add the given Hostname to the existing hosts*/
100 $this->kolabHost[]=$this->hostname;
101 $this->attrs['kolabHost'][]=$this->hostname;
102 }
103 else
104 {
105 /* First we have to find the Host we want to delete, take the index and delete em*/
106 foreach($this->kolabHost as $key=>$host)
107 {
108 /* Delete only if the Host is the in the array*/
109 if($host == $this->hostname)
110 {
111 unset($this->kolabHost[$key]);
112 unset($this->attrs['kolabHost'][$key]);
113 }
114 }
115 /* We deletet an Entry so we must reorder the index of the array */
116 $tmp = $this->kolabHost;
117 $this->kolabHost=array();
118 $this->attrs['kolabHost']=array();
120 /* reorder reorder ...*/
121 foreach($tmp as $host){
122 $this->kolabHost[]=$host;
123 $this->attrs['kolabHost'][]=$host;
124 }
125 /* Tell Save that we want to delete someone*/
126 $this->remove = true;
127 }
129 }
130 /* Check Relayhost and if we have MX lookup enabled*/
131 if(isset($this->postfix_relayhost[0]) && $this->postfix_relayhost[0]=="[")
132 {
133 $this->postfix_mxrelayenabled=false;
134 $this->postfix_relayhost = str_replace("[","",$this->postfix_relayhost);
135 $this->postfix_relayhost = str_replace("]","",$this->postfix_relayhost);
136 }
137 if($this->postfix_mxrelayenabled) {
138 $smarty->assign("RelayMxSupportCheck"," checked ");
139 } else {
140 $smarty->assign("RelayMxSupportCheck","");
141 }
142 /* Show tab dialog headers */
143 if ($this->is_account) {
144 /* call Add Acoount to add account */
145 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
146 } else {
147 /* call remove Account */
148 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
149 return ($display);
150 }
152 /* Initialize all attributes, that were submitted */
153 foreach($this->attributes as $val)
154 {
155 $smarty->assign($val."ACL",$this->acl,str_replace("_","-",$val));
156 /* Tell smarty which variables we are useing */
157 $smarty->assign($val, $this->$val);
158 if (($this->$val != "FALSE") && (!empty($this->$val)))
159 $smarty->assign($val."Check", "checked");
160 else
161 $smarty->assign($val."Check", "");
162 }
164 /* Assemble free/busy string */
165 $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
166 $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
167 $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
168 $smarty->assign("fbfuture", $fbfuture);
170 /* Assemble quota string */
171 $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
172 $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
173 $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
174 $smarty->assign("quotastr", $quotastr);
176 /* Load Template */
177 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
178 return ($display);
179 }
181 function remove_from_parent()
182 {
183 }
186 function save_object()
187 {
188 plugin::save_object();
189 }
192 function check()
193 {
194 error_reporting(E_ALL);
195 $message = array();
196 if(($this->kolabFreeBusyFuture=="")) {
197 $message[] = _("Free/Busy settings -> Future days must be set.");
198 }elseif((($this->kolabFreeBusyFuture=="")<0)){
199 $message[] = _("Free/Busy settings -> Future days must be a positive value.");
200 }elseif(strcasecmp($this->kolabFreeBusyFuture,(int)$this->kolabFreeBusyFuture)){
201 $message[] = _("Free/Busy settings -> Future days must be a value.");
202 }
204 if(!is_int((int)($this->cyrus_quotawarn))) {
205 $message[] = _("Cyrus Quota settings -> The given Quota settings value must be a number.");
206 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
207 $message[] = _("Cyrus Quota settings -> Please choose a value between 1 and 100 for Quota settings.");
208 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
209 $message[] = _("Cyrus Quota settings -> Future days must be a value.");
210 }
212 if(empty($this->postfix_mynetworks))
213 {
214 $message[] = _("SMTP privileged networks -> No value is given.");
215 }
217 if(empty($this->postfix_relayhost))
218 {
219 $message[] = _("SMTP smarthost/relayhost -> No value is given.");
220 }
223 return ($message);
224 }
227 /* Save to LDAP */
228 function save()
229 {
230 /* Set ldap connection */
231 $ldap = $this->config->get_ldap_link();
233 /* Open current dn*/
234 $ldap->cd($this->dn);
237 /* Setup Attributes to save */
238 $newattrs = array();
240 /* Set vars with correct - _ - */
241 foreach($this->attributes as $key) {
242 $key2 = str_replace("_", "-", $key);
243 $newattrs[$key2] = $this->$key;
244 }
248 /* Set bool vars */
249 if ($newattrs['postfix-enable-virus-scan'] == 0)
250 $newattrs['postfix-enable-virus-scan'] = "FALSE";
251 else
252 $newattrs['postfix-enable-virus-scan'] = "TRUE";
253 if ($newattrs['cyrus-imap'] == 0)
254 $newattrs['cyrus-imap'] = "FALSE";
255 else
256 $newattrs['cyrus-imap'] = "TRUE";
257 if ($newattrs['cyrus-imaps'] == 0)
258 $newattrs['cyrus-imaps'] = "FALSE";
259 else
260 $newattrs['cyrus-imaps'] = "TRUE";
261 if ($newattrs['cyrus-pop3'] == 0)
262 $newattrs['cyrus-pop3'] = "FALSE";
263 else
264 $newattrs['cyrus-pop3'] = "TRUE";
265 if ($newattrs['cyrus-pop3s'] == 0)
266 $newattrs['cyrus-pop3s'] = "FALSE";
267 else
268 $newattrs['cyrus-pop3s'] = "TRUE";
269 if ($newattrs['cyrus-sieve'] == 0)
270 $newattrs['cyrus-sieve'] = "FALSE";
271 else
272 $newattrs['cyrus-sieve'] = "TRUE";
273 if ($newattrs['proftpd-ftp'] == 0)
274 $newattrs['proftpd-ftp'] = "FALSE";
275 else
276 $newattrs['proftpd-ftp'] = "TRUE";
277 if ($newattrs['apache-http'] == 0)
278 $newattrs['apache-http'] = "FALSE";
279 else
280 $newattrs['apache-http'] = "TRUE";
281 if ($newattrs['postfix-allow-unauthenticated'] == 0)
282 $newattrs['postfix-allow-unauthenticated'] = "FALSE";
283 else
284 $newattrs['postfix-allow-unauthenticated'] = "TRUE";
285 if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
286 $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
287 else
288 $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
291 /* Reorder Host array, to get constant increasing index */
292 $newattrs['kolabHost'] = array();
294 /* Check Relayhost and if we have MX lookup enabled*/
295 if(isset($_POST['RelayMxSupport']))
296 $this->postfix_mxrelayenabled = true ;
297 else
298 $this->postfix_mxrelayenabled = false;
299 if(!$this->postfix_mxrelayenabled)
300 {
301 $newattrs['postfix-relayhost']="[".$this->postfix_relayhost."]";
302 }
304 /* If we want to add someone or do only changes on the settings ...*/
305 if(!$this->remove)
306 {
307 /* Get all Host known, that are member of the Kolab extension */
308 $this->kolabHost = $this->attrs['kolabHost'];
310 /* So, the Host is already member of the extension, so get all and do nothing */
311 if(in_array($this->hostname,$this->kolabHost))
312 {
313 $newattrs['kolabHost']=$this->kolabHost;
314 }
315 /* So this is the first entry */
316 elseif(empty($this->kolabHost))
317 {
318 /* Create an array an add the Host */
319 $newattrs['kolabHost']=array();
320 $newattrs['kolabHost'][]=$this->hostname;
321 }
322 /* Theres already an entry, but only in a string, */
323 elseif(is_string($this->kolabHost))
324 {
325 $tmp = $this->kolabHost;
326 $newattrs['kolabHost']=array();
327 $newattrs['kolabHost'][]=$tmp;
328 $newattrs['kolabHost'][]=$this->hostname;
329 }
330 /* Here we have already some entries */
331 elseif(is_array($newattrs['kolabHost']))
332 {
333 /* Insert the new one*/
334 foreach($this->kolabHost as $key=>$val) {
335 if (is_int($key)) {
336 $newattrs['kolabHost'][] = $val;
337 }
338 }
339 $newattrs['kolabHost'][]= $this->hostname;
340 }
341 }
342 else
343 {
344 /* Here we want to delete an entry*/
345 $newattrs['kolabHost']= $this->attrs['kolabHost'];
346 }
347 /* Save as following object ! */
348 $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
350 /* If we already have an object like this one,
351 we only need to modify the entry
352 */
354 /* is this an empty extension, no host defined for it, than delet it */
355 if(count($newattrs['kolabHost'])==0)
356 {
357 /* Delete the entry*/
358 $ldap->cd ("k=kolab,".$this->config->current['BASE']);
359 $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
362 }elseif ($ldap->dn_exists($this->kolabdn)) {
363 /* Ok there is already an extension, so we only need to add the changes and the new Host, (if it was a new host)*/
364 gosa_log("Modifying");
366 /* unset all attributes we won't change*/
367 unset($newattrs['cyrus-admins']);
368 unset($newattrs['postfix-mydomain']);
369 unset($newattrs['postfix-mydestination']);
371 /* Update changes */
372 $ldap->cd($this->kolabdn);
373 $ldap->modify($newattrs);
374 } else {
376 /* We must create a new Entry */
377 $newattrs['k'] = "kolab";
378 $newattrs['uid'] = "freebusy";
379 $newattrs['postfix-mydomain'] = "gonicus.de";
380 $newattrs['postfix-mydestination'] = "\$mydomain";
381 $newattrs['userPassword'] = "tester";
382 $newattrs['objectClass'] = $this->objectclasses;
384 /* For better reading / Objectclass was added at last */
385 $newattrs = array_reverse ($newattrs);
387 /* And add the entry*/
388 $ldap->cd($this->kolabdn);
389 $ldap->add($newattrs);
390 }
391 /* show any errors */
392 show_ldap_error($ldap->get_error());
394 /* Optionally execute a command after we're done */
395 if ($this->initially_was_account == $this->is_account) {
396 if ($this->is_modified) {
397 $this->handle_post_events("mofify");
398 }
399 } else {
400 $this->handle_post_events("add");
401 }
403 }
405 }
407 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
408 ?>