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 if($this->is_account){
81 @log::log("view","server/".get_class($this),$this->dn);
82 }
83 }
86 function execute()
87 {
88 /* Call parent execute */
89 plugin::execute();
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 translatet 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 gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
201 } else {
203 /* Only modify kolabHost */
204 $hosts= array();
205 foreach ($this->kolabHost as $host){
206 if($host != $this->hostname){
207 $hosts[]= $host;
208 }
209 }
210 $attrs= array('kolabHost' => $hosts);
211 $ldap->cd($this->dn);
212 $this->cleanup();
213 $ldap->modify ($attrs);
214 show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn));
215 gosa_log("Removing ".$this->hostname." from list of kolabHosts");
216 }
218 @log::log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
220 /* Optionally execute a command after we're done */
221 $this->handle_post_events("remove");
222 }
225 function save_object()
226 {
227 if (isset($_POST['kolabtab'])){
228 plugin::save_object();
231 foreach($this->attributes as $attr){
232 if(($this->acl_is_writeable(preg_replace("/_/","",$attr))) && (isset($_POST[$attr]))){
233 $this->$attr = $_POST[$attr];
234 }
235 }
237 /* Save checkboxes */
238 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
239 "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
240 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
241 "proftpd_ftp", "apache_http") as $cb){
243 if($this->acl_is_writeable(preg_replace("/_/","",$cb))){
244 if (isset($_POST[$cb])){
245 $this->$cb= "TRUE";
246 } else {
247 $this->$cb= "FALSE";
248 }
249 }
250 }
252 /* Toggell relay check */
253 if($this->acl_is_writeable("postfixmxrelayenabled")){
254 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
255 }
256 }
258 }
261 function check()
262 {
263 /* Call common method to give check the hook */
264 $message= plugin::check();
266 if(($this->kolabFreeBusyFuture=="")) {
267 $message[] = _("Future days in Free/Busy settings must be set.");
268 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
269 $message[] = _("Future days in Free/Busy settings must be a positive value.");
270 }
272 if(!is_int((int)($this->cyrus_quotawarn))) {
273 $message[] = _("The given Quota settings value must be a number.");
274 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
275 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
276 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
277 $message[] = _("Future days must be a value.");
278 }
280 if(empty($this->postfix_mynetworks)) {
281 $message[] = _("No SMTP privileged networks set.");
282 }
284 /*if(empty($this->postfix_relayhost)) {
285 $message[] = _("No SMTP smarthost/relayhost set.");
286 }
287 */
289 return ($message);
290 }
293 /* Save to LDAP */
294 function save()
295 {
296 /* Set ldap connection */
297 $ldap = $this->config->get_ldap_link();
299 /* Open current dn*/
300 $this->dn = "k=kolab,".$this->config->current['BASE'];
302 /* Adapt relayhost */
303 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
304 if ($this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
305 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
306 }
308 /* Check if this server was renamed, in this case we have to remove old cn first*/
309 if($this->hostname != $this->cn){
310 $tmp = array();
311 if(in_array_ics($this->hostname,$this->kolabHost)){
312 foreach($this->kolabHost as $host){
313 if($host != $this->hostname){
314 $tmp[] = $host;
315 }
316 }
317 $this->kolabHost = $tmp;
318 }
319 }
321 /* Add ourselves to the list of kolabHost's if needed */
322 if (!in_array_ics($this->cn,$this->kolabHost)){
323 $this->kolabHost[]= $this->cn;
324 }
326 /* Call parents save to prepare $this->attrs */
327 plugin::save();
329 /* Save or modify? */
330 $ldap->cat($this->dn, array('dn'));
331 if (!$ldap->fetch()){
332 $mode= "add";
333 } else {
334 $mode= "modify";
335 }
337 /* Do attribute conversion */
338 foreach ($this->attrs as $key => $value){
339 if (preg_match('/_/', $key)){
340 $old_key= $key;
341 $key= preg_replace('/_/', '-', $key);
342 $this->attrs[$key]= $value;
343 unset($this->attrs[$old_key]);
344 }
345 }
346 /* Add kolab hosts */
347 $this->attrs['kolabHost']= $this->kolabHost;
349 /* Perform LDAP action */
350 $ldap->cd($this->dn);
351 $this->cleanup();;
352 $ldap->$mode($this->attrs);
354 if($mode == "add"){
355 @log::log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
356 }else{
357 @log::log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
358 }
360 show_ldap_error($ldap->get_error(), sprintf(_("Saving system server/kolab with dn '%s' failed."),$this->dn));
362 /* Optionally execute a command after we're done */
363 if ($this->initially_was_account == $this->is_account) {
364 if ($this->is_modified) {
365 $this->handle_post_events("modify");
366 }
367 } else {
368 $this->handle_post_events("add");
369 }
370 }
373 function getListEntry()
374 {
375 $fields = goService::getListEntry();
376 $fields['Message'] = _("Kolab mail service");
377 $fields['AllowEdit'] = true;
378 return($fields);
379 }
382 /* Return plugin informations for acl handling */
383 function plInfo()
384 {
385 return (array(
386 "plShortName" => _("Kolab"),
387 "plDescription" => _("Kolab mail service")." ("._("Services").")",
388 "plSelfModify" => FALSE,
389 "plDepends" => array(),
390 "plPriority" => 85,
391 "plSection" => array("administration"),
392 "plCategory" => array("server"),
394 "plProvidedAcls"=> array(
395 "postfixmydomain" => _("Postfix mydomain") ,
396 "postfixmydestination" => _("My destination") ,
397 "cyrusadmins" => _("Cyrus admins") ,
398 "proftpdftp" => _("FTP FreeBusy service") ,
399 "postfixmynetworks" => _("SMTP privileged networks") ,
400 "postfixenablevirusscan" => _("Enable virus scan") ,
401 "postfixrelayhost" => _("Relayhost") ,
402 "postfixmxrelayenabled" => _("Enable MX lookup for relayhost"),
403 "apachehttp" => _("HTTP FreeBusy service") ,
404 "apacheallowunauthenticatedfb" => _("Allow unauthenticated free busy"),
405 "postfixallowunauthenticated" => _("Accept Internet Mail") ,
406 "cyrusimap" => _("IMAP service") ,
407 "kolabFreeBusyFuture" => _("kolabFreeBusyFuture") ,
408 "cyruspop3" => _("POP3 service") ,
409 "cyrusimaps" => _("IMAP/SSL service") ,
410 "cyruspop3s" => _("POP3/SSL service") ,
411 "cyrussieve" => _("Sieve service") ,
412 "cyrusquotawarn" => _("Quota settings"))
413 ));
414 }
415 }
417 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
418 ?>