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