1 <?php
3 class servkolab extends goService {
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 = "";
10 var $cyrus_admins = "";
11 var $postfix_mydestination = "";
12 var $postfix_mynetworks = "127.0.0.1/8";
13 var $postfix_enable_virus_scan = "TRUE";
14 var $postfix_relayhost = "";
15 var $postfix_mxrelayenabled = true;
16 var $postfix_allow_unauthenticated = "FALSE";
17 var $cyrus_quotawarn = "80";
18 var $kolabFreeBusyFuture = "1";
19 var $k = "kolab";
20 var $cyrus_imap = "TRUE";
21 var $cyrus_pop3 = "FALSE";
22 var $cyrus_imaps = "TRUE";
23 var $cyrus_pop3s = "TRUE";
24 var $cyrus_sieve = "TRUE";
25 var $apache_allow_unauthenticated_fb = "TRUE";
26 var $proftpd_ftp = "FALSE";
27 var $apache_http = "TRUE";
28 var $kolabHost = array();
29 var $orig_cn = "";
30 var $view_logged = FALSE;
32 var $attributes = array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
33 "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
34 "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
35 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
36 "cyrus_quotawarn");
37 var $objectclasses = array("top", "kolab");
39 /* Serverservice vars */
40 var $conflicts = array("goImapServer","goMailServer");
41 var $DisplayName = "Kolab mail service";
42 var $StatusFlag = "";
44 function servkolab(&$config, $dn = NULL, $parent= NULL)
45 {
46 /* Setting the hostname and tell this Plugin that we are the kolab extension*/
47 $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
48 $this->dn = "k=kolab,".$config->current['BASE'];
50 /* Load variables, if given*/
51 plugin::plugin($config, $this->dn);
53 /* Copy needed attributes */
54 foreach($this->attributes as $val) {
55 $name = preg_replace('/_/', '-', $val);
56 if (isset($this->attrs["$name"][0])) {
57 $this->$val = $this->attrs["$name"][0];
58 }
59 }
61 /* Toggle relayhost */
62 $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost);
63 $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
65 /* Is this Server a member of the Kolab extension or not ?*/
66 if(isset($this->attrs['kolabHost'])) {
67 $this->kolabHost= $this->attrs['kolabHost'];
68 unset($this->kolabHost['count']);
69 }
70 $this->is_account = false;
71 $this->initially_was_account = false;
72 foreach($this->kolabHost as $host){
73 if($this->hostname == $host){
74 $this->is_account = true;
75 $this->initially_was_account = true;
76 }
77 }
78 }
81 function execute()
82 {
83 /* Call parent execute */
84 plugin::execute();
86 if($this->is_account && !$this->view_logged){
87 $this->view_logged = TRUE;
88 new log("view","server/".get_class($this),$this->dn);
89 }
91 /***************
92 Variable initialisation
93 ***************/
95 $smarty = get_smarty();
96 $display = "";
97 $ldap = $this->config->get_ldap_link();
100 /* Assemble free/busy string */
101 $edit = sprintf('<input name="kolabFreeBusyFuture" value="%s" type="text" maxlength="3" size="4">',
102 $this->kolabFreeBusyFuture);
103 $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
105 /* Assemble quota string */
106 $edit = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4">',
107 $this->cyrus_quotawarn);
108 $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
110 /***************
111 Assign informations to smarty
112 ***************/
114 /* Set relayhost and if we have MX lookup enabled*/
115 if($this->postfix_mxrelayenabled) {
116 $smarty->assign("RelayMxSupportCheck"," checked ");
117 } else {
118 $smarty->assign("RelayMxSupportCheck","");
119 }
121 /* Set acls */
122 $tmp = $this->plInfo();
123 foreach($tmp['plProvidedAcls'] as $name => $translation){
124 $smarty->assign($name."ACL",$this->getacl($name));
125 }
127 /* Initialize all attributes, that were submitted */
128 foreach($this->attributes as $val)
129 {
130 /* Tell smarty which variables we are useing */
131 $smarty->assign($val, $this->$val);
132 if (($this->$val != "FALSE") && !empty($this->$val)){
133 $smarty->assign($val."Check", "checked");
134 } else {
135 $smarty->assign($val."Check", "");
136 }
137 }
139 $smarty->assign("fbfuture", $fbfuture);
140 $smarty->assign("quotastr", $quotastr);
142 /* Load Template */
143 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
144 return ($display);
145 }
147 function remove_from_parent()
148 {
150 /* Remove status flag, it is not a memeber of
151 this->attributes, so ensure that it is deleted too */
152 if(!empty($this->StatusFlag)){
153 $this->attrs[$this->StatusFlag] = array();
154 }
157 /* Only walk through following code, if this host
158 was a member of the kolab hosts, else skip this */
159 if(!$this->initially_was_account){
160 return;
161 }
163 /* !!! Don't use "cn" in this function
164 hostname -> the initial name of the host
165 cn -> is the new name of the host, in case that it was renamed.
166 */
168 $ldap = $this->config->get_ldap_link();
169 $this->dn = "k=kolab,".$this->config->current['BASE'];
171 /* We can't simply remove the whole entry, it is possible that there are
172 some other hosts assigned to this object.
173 So, first of all check if we are the last host entry within the host
174 : Remove k=kolab entry
175 if we aren't alone, only remove host name from hosts entry and save */
176 /* Are we alone? Remove complete entry... */
178 /* Check if we are definitly in kolabHosts */
179 if(!in_array_ics($this->hostname,$this->kolabHost)) {
180 return;
181 }
183 /* Integration check, not translated because they can't pop up at all, only for debug */
184 if(count($this->kolabHost) == 0){
185 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
186 return;
187 }
188 if(!isset($this->hostname) || (empty($this->hostname))){
189 print_red("The required attribute hostname seams to empty.");
190 }
192 /* Our hostname is in kolabHosts and there is a only one entry
193 = we are the last host entry, delete k=kolab entry */
194 if (count($this->kolabHost) == 1){
196 /* Remove complete entry */
197 $ldap->rmdir ($this->dn);
198 show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn));
199 } else {
201 /* Only modify kolabHost */
202 $hosts= array();
203 foreach ($this->kolabHost as $host){
204 if($host != $this->hostname){
205 $hosts[]= $host;
206 }
207 }
208 $attrs= array('kolabHost' => $hosts);
209 $ldap->cd($this->dn);
210 $this->cleanup();
211 $ldap->modify ($attrs);
212 show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn));
213 }
215 new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
217 /* Optionally execute a command after we're done */
218 $this->handle_post_events("remove");
219 }
222 function save_object()
223 {
224 if (isset($_POST['kolabtab'])){
225 plugin::save_object();
228 foreach($this->attributes as $attr){
229 if(($this->acl_is_writeable(preg_replace("/_/","",$attr))) && (isset($_POST[$attr]))){
230 $this->$attr = $_POST[$attr];
231 }
232 }
234 /* Save checkboxes */
235 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
236 "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
237 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
238 "proftpd_ftp", "apache_http") as $cb){
240 if($this->acl_is_writeable(preg_replace("/_/","",$cb))){
241 if (isset($_POST[$cb])){
242 $this->$cb= "TRUE";
243 } else {
244 $this->$cb= "FALSE";
245 }
246 }
247 }
249 /* Toggell relay check */
250 if($this->acl_is_writeable("postfixmxrelayenabled")){
251 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
252 }
253 }
255 }
258 function check()
259 {
260 /* Call common method to give check the hook */
261 $message= plugin::check();
263 if(($this->kolabFreeBusyFuture=="")) {
264 $message[] = _("Future days in Free/Busy settings must be set.");
265 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
266 $message[] = _("Future days in Free/Busy settings must be a positive value.");
267 }
269 if(!is_int((int)($this->cyrus_quotawarn))) {
270 $message[] = _("The given Quota settings value must be a number.");
271 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
272 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
273 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
274 $message[] = _("Future days must be a value.");
275 }
277 if(empty($this->postfix_mynetworks)) {
278 $message[] = _("No SMTP privileged networks set.");
279 }
281 /*if(empty($this->postfix_relayhost)) {
282 $message[] = _("No SMTP smarthost/relayhost set.");
283 }
284 */
286 return ($message);
287 }
290 /* Save to LDAP */
291 function save()
292 {
293 /* Set ldap connection */
294 $ldap = $this->config->get_ldap_link();
296 /* Open current dn*/
297 $this->dn = "k=kolab,".$this->config->current['BASE'];
299 /* Adapt relayhost */
300 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
301 if ($this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
302 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
303 }
305 /* Check if this server was renamed, in this case we have to remove old cn first*/
306 if($this->hostname != $this->cn){
307 $tmp = array();
308 if(in_array_ics($this->hostname,$this->kolabHost)){
309 foreach($this->kolabHost as $host){
310 if($host != $this->hostname){
311 $tmp[] = $host;
312 }
313 }
314 $this->kolabHost = $tmp;
315 }
316 }
318 /* Add ourselves to the list of kolabHost's if needed */
319 if (!in_array_ics($this->cn,$this->kolabHost)){
320 $this->kolabHost[]= $this->cn;
321 }
323 /* Call parents save to prepare $this->attrs */
324 plugin::save();
326 /* Save or modify? */
327 $ldap->cat($this->dn, array('dn'));
328 if (!$ldap->fetch()){
329 $mode= "add";
330 } else {
331 $mode= "modify";
332 }
334 /* Do attribute conversion */
335 foreach ($this->attrs as $key => $value){
336 if (preg_match('/_/', $key)){
337 $old_key= $key;
338 $key= preg_replace('/_/', '-', $key);
339 $this->attrs[$key]= $value;
340 unset($this->attrs[$old_key]);
341 }
342 }
343 /* Add kolab hosts */
344 $this->attrs['kolabHost']= $this->kolabHost;
346 /* Perform LDAP action */
347 $ldap->cd($this->dn);
348 $this->cleanup();;
349 $ldap->$mode($this->attrs);
351 if($mode == "add"){
352 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
353 }else{
354 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
355 }
357 show_ldap_error($ldap->get_error(), sprintf(_("Saving system server/kolab with dn '%s' failed."),$this->dn));
359 /* Optionally execute a command after we're done */
360 if ($this->initially_was_account == $this->is_account) {
361 if ($this->is_modified) {
362 $this->handle_post_events("modify");
363 }
364 } else {
365 $this->handle_post_events("add");
366 }
367 }
370 function getListEntry()
371 {
372 $fields = goService::getListEntry();
373 $fields['Message'] = _("Kolab mail service");
374 $fields['AllowEdit'] = true;
375 return($fields);
376 }
379 /* Return plugin informations for acl handling */
380 function plInfo()
381 {
382 return (array(
383 "plShortName" => _("Kolab"),
384 "plDescription" => _("Kolab mail service")." ("._("Services").")",
385 "plSelfModify" => FALSE,
386 "plDepends" => array(),
387 "plPriority" => 85,
388 "plSection" => array("administration"),
389 "plCategory" => array("server"),
391 "plProvidedAcls"=> array(
392 "postfixmydomain" => _("Postfix mydomain") ,
393 "postfixmydestination" => _("My destination") ,
394 "cyrusadmins" => _("Cyrus admins") ,
395 "proftpdftp" => _("FTP FreeBusy service") ,
396 "postfixmynetworks" => _("SMTP privileged networks") ,
397 "postfixenablevirusscan" => _("Enable virus scan") ,
398 "postfixrelayhost" => _("Relayhost") ,
399 "postfixmxrelayenabled" => _("Enable MX lookup for relayhost"),
400 "apachehttp" => _("HTTP FreeBusy service") ,
401 "apacheallowunauthenticatedfb" => _("Allow unauthenticated free busy"),
402 "postfixallowunauthenticated" => _("Accept Internet Mail") ,
403 "cyrusimap" => _("IMAP service") ,
404 "kolabFreeBusyFuture" => _("kolabFreeBusyFuture") ,
405 "cyruspop3" => _("POP3 service") ,
406 "cyrusimaps" => _("IMAP/SSL service") ,
407 "cyruspop3s" => _("POP3/SSL service") ,
408 "cyrussieve" => _("Sieve service") ,
409 "cyrusquotawarn" => _("Quota settings"))
410 ));
411 }
412 }
414 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
415 ?>