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