X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_servKolab.inc;h=a2c9ffef71e4fad997bed7878304d7396d16268a;hb=88d7a7686efaf3d5585206cb5808ed83081a5f5b;hp=910ab152ec2ea47dd69d1d4944d4aa68b9156ff7;hpb=c37e7c5ca5d20191f1db61cf6a9f1e4c2a7d72ec;p=gosa.git diff --git a/plugins/admin/systems/class_servKolab.inc b/plugins/admin/systems/class_servKolab.inc index 910ab152e..a2c9ffef7 100644 --- a/plugins/admin/systems/class_servKolab.inc +++ b/plugins/admin/systems/class_servKolab.inc @@ -26,20 +26,26 @@ class servkolab extends plugin { var $proftpd_ftp = "TRUE"; var $apache_http = "TRUE"; var $kolabHost = array(); - + var $orig_cn = ""; + var $attributes = array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k", - "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http", - "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture", - "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb", - "cyrus_quotawarn"); + "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http", + "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture", + "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb", + "cyrus_quotawarn"); var $objectclasses = array("top", "kolab"); + /* Serverservice vars */ + var $conflicts = array("goImapServer","goMailServer"); + var $DisplayName = "Kolab mail service"; + var $StatusFlag = ""; + function servkolab($config, $dn = NULL) { /* Setting the hostname and tell this Plugin that we are the kolab extension*/ - $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn); - $this->dn = "k=kolab,".$config->current['BASE']; - + $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn); + $this->dn = "k=kolab,".$config->current['BASE']; + /* Load variables, if given*/ plugin::plugin($config, $this->dn); @@ -50,47 +56,57 @@ class servkolab extends plugin { $this->$val = $this->attrs["$name"][0]; } } - + /* Toggle relayhost */ - $this->postfix_mxrelayenabled= preg_match('/^\[/', $this->postfix_relayhost); - $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost); + $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost); + $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost); /* Is this Server a member of the Kolab extension or not ?*/ if(isset($this->attrs['kolabHost'])) { $this->kolabHost= $this->attrs['kolabHost']; unset($this->kolabHost['count']); } - if(in_array($this->hostname, $this->kolabHost)) { - $this->is_account=true; - } else { - $this->is_account=false; + $this->is_account = false; + $this->initially_was_account = false; + foreach($this->kolabHost as $host){ + if($this->hostname == $host){ + $this->is_account = true; + $this->initially_was_account = true; + } } + } function execute() { - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; + /* Call parent execute */ + plugin::execute(); - /* The Ldap link is needed to ask ldap some questions */ - $ldap = $this->config->get_ldap_link(); + /*************** + Variable initialisation + ***************/ + + $smarty = get_smarty(); + $display = ""; + $ldap = $this->config->get_ldap_link(); - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])) { - $this->is_account = !$this->is_account; - } - /* Show tab dialog headers */ - if ($this->is_account) { - /* call Add Acoount to add account */ - $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below.")); - } else { - /* call remove Account */ - $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below.")); - return ($display); - } + /* Assemble free/busy string */ + $edit = sprintf('', + $this->kolabFreeBusyFuture, + chkacl($this->acl, 'kolabFreeBusyFuture')); + $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit); + + /* Assemble quota string */ + $edit = sprintf('', + $this->cyrus_quotawarn, + chkacl($this->acl, 'cyrus_quotawarn')); + $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit); + + /*************** + Assign informations to smarty + ***************/ /* Set relayhost and if we have MX lookup enabled*/ if($this->postfix_mxrelayenabled) { @@ -98,7 +114,7 @@ class servkolab extends plugin { } else { $smarty->assign("RelayMxSupportCheck",""); } - + /* Initialize all attributes, that were submitted */ foreach($this->attributes as $val) { @@ -113,16 +129,7 @@ class servkolab extends plugin { } } - /* Assemble free/busy string */ - $edit= sprintf('', - $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture')); - $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit); $smarty->assign("fbfuture", $fbfuture); - - /* Assemble quota string */ - $edit= sprintf('', - $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn')); - $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit); $smarty->assign("quotastr", $quotastr); /* Load Template */ @@ -132,33 +139,73 @@ class servkolab extends plugin { function remove_from_parent() { - $ldap= $this->config->get_ldap_link(); - $this->dn = "k=kolab,".$this->config->current['BASE']; - if (count($this->kolabHost) == 0){ + /* Remove status flag, it is not a memeber of + this->attributes, so ensure that it is deleted too */ + if(!empty($this->StatusFlag)){ + $this->attrs[$this->StatusFlag] = array(); + } + + + /* Only walk through following code, if this host + was a member of the kolab hosts, else skip this */ + if(!$this->initially_was_account){ return; } + /* !!! Don't use "cn" in this function + hostname -> the initial name of the host + cn -> is the new name of the host, in case that it was renamed. + */ + + $ldap = $this->config->get_ldap_link(); + $this->dn = "k=kolab,".$this->config->current['BASE']; + + /* We can't simply remove the whole entry, it is possible that there are + some other hosts assigned to this object. + So, first of all check if we are the last host entry within the host + : Remove k=kolab entry + if we aren't alone, only remove host name from hosts entry and save */ /* Are we alone? Remove complete entry... */ + + /* Check if we are definitly in kolabHosts */ + if(!in_array_ics($this->hostname,$this->kolabHost)) { + return; + } + + /* Integration check, not translatet because they can't pop up at all, only for debug */ + if(count($this->kolabHost) == 0){ + print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists."); + return; + } + if(!isset($this->hostname) || (empty($this->hostname))){ + print_red("The required attribute hostname seams to empty."); + } + + /* Our hostname is in kolabHosts and there is a only one entry + = we are the last host entry, delete k=kolab entry */ if (count($this->kolabHost) == 1){ /* Remove complete entry */ $ldap->rmdir ($this->dn); - show_ldap_error($ldap->get_error()); - + show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn)); + gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry."); + } else { /* Only modify kolabHost */ $hosts= array(); foreach ($this->kolabHost as $host){ - if ($host != $this->cn){ + if($host != $this->hostname){ $hosts[]= $host; } } $attrs= array('kolabHost' => $hosts); $ldap->cd($this->dn); - $ldap->modify($attrs); - show_ldap_error($ldap->get_error()); + $this->cleanup(); + $ldap->modify ($attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Removing host entry from system server/kolab with dn '%s' failed."),$this->dn)); + gosa_log("Removing ".$this->hostname." from list of kolabHosts"); } /* Optionally execute a command after we're done */ @@ -173,9 +220,9 @@ class servkolab extends plugin { /* Save checkboxes */ foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated", - "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps", - "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb", - "proftpd_ftp", "apache_http") as $cb){ + "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps", + "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb", + "proftpd_ftp", "apache_http") as $cb){ if (isset($_POST[$cb])){ $this->$cb= "TRUE"; } else { @@ -192,7 +239,9 @@ class servkolab extends plugin { function check() { - $message = array(); + /* Call common method to give check the hook */ + $message= plugin::check(); + if(($this->kolabFreeBusyFuture=="")) { $message[] = _("Future days in Free/Busy settings must be set."); }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){ @@ -211,9 +260,10 @@ class servkolab extends plugin { $message[] = _("No SMTP privileged networks set."); } - if(empty($this->postfix_relayhost)) { + /*if(empty($this->postfix_relayhost)) { $message[] = _("No SMTP smarthost/relayhost set."); - } + } + */ return ($message); } @@ -223,19 +273,32 @@ class servkolab extends plugin { function save() { /* Set ldap connection */ - $ldap = $this->config->get_ldap_link(); - + $ldap = $this->config->get_ldap_link(); + /* Open current dn*/ - $this->dn = "k=kolab,".$this->config->current['BASE']; - + $this->dn = "k=kolab,".$this->config->current['BASE']; + /* Adapt relayhost */ $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost); if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){ $this->postfix_relayhost= "[".$this->postfix_relayhost."]"; } + /* Check if this server was renamed, in this case we have to remove old cn first*/ + if($this->hostname != $this->cn){ + $tmp = array(); + if(in_array_ics($this->hostname,$this->kolabHost)){ + foreach($this->kolabHost as $host){ + if($host != $this->hostname){ + $tmp[] = $host; + } + } + $this->kolabHost = $tmp; + } + } + /* Add ourselves to the list of kolabHost's if needed */ - if (!in_array($this->cn, $this->kolabHost)){ + if (!in_array_ics($this->cn,$this->kolabHost)){ $this->kolabHost[]= $this->cn; } @@ -243,7 +306,7 @@ class servkolab extends plugin { plugin::save(); /* Save or modify? */ - $ldap->cat($this->dn); + $ldap->cat($this->dn, array('dn')); if (!$ldap->fetch()){ $mode= "add"; } else { @@ -259,26 +322,120 @@ class servkolab extends plugin { unset($this->attrs[$old_key]); } } - /* Add kolab hosts */ $this->attrs['kolabHost']= $this->kolabHost; /* Perform LDAP action */ $ldap->cd($this->dn); + $this->cleanup();; $ldap->$mode($this->attrs); - show_ldap_error($ldap->get_error()); - + show_ldap_error($ldap->get_error(), sprintf(_("Saving system server/kolab with dn '%s' failed."),$this->dn)); + /* Optionally execute a command after we're done */ if ($this->initially_was_account == $this->is_account) { if ($this->is_modified) { - $this->handle_post_events("mofify"); + $this->handle_post_events("modify"); } } else { $this->handle_post_events("add"); } + } + + + function getListEntry() + { + $this->updateStatusState(); + $flag = $this->StatusFlag; + if(empty($flag)){ + $fields['Status'] = ""; + }else{ + $fields['Status'] = $this->$flag; + } + $fields['Message'] = _("Kolab mail service"); + $fields['AllowStart'] = true; + $fields['AllowStop'] = true; + $fields['AllowRestart'] = true; + $fields['AllowRemove'] = true; + $fields['AllowEdit'] = true; + return($fields); + } + + /* Directly save new status flag */ + function setStatus($value) + { + return; + + if($value == "none") return; + if(!$this->initially_was_account) return; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->cat($this->dn,array("objectClass")); + if($ldap->count()){ + + $tmp = $ldap->fetch(); + for($i = 0; $i < $tmp['objectClass']['count']; $i ++){ + $attrs['objectClass'][] = $tmp['objectClass'][$i]; + } + $flag = $this->StatusFlag; + $attrs[$flag] = $value; + $this->$flag = $value; + $ldap->modify($attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for system server/kolab with dn '%s' failed."),$this->dn)); + $this->action_hook(); + } + } + + /* Get updates for status flag */ + function updateStatusState() + { + if(empty($this->StatusFlag)) return; + + $attrs = array(); + $flag = $this->StatusFlag; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->cn); + $ldap->cat($this->dn,array($flag)); + if($ldap->count()){ + $attrs = $ldap->fetch(); + } + if(isset($attrs[$flag][0])){ + $this->$flag = $attrs[$flag][0]; + } } + + + /* Return plugin informations for acl handling */ + function plInfo() + { + return (array( + "plShortName" => _("Kolab"), + "plDescription" => _("Kolab service"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("server"), + + "plProvidedAcls"=> array( + "postfix_mydomain" => _("Postfix mydomain") , + "postfix_mydestination" => _("My destination") , + "proftpd_ftp" => _("FTP FreeBusy service") , + "postfix_mynetworks" => _("SMTP privileged networks") , + "postfix_enable_virus_scan" => _("Enable virus scan") , + "postfix_relayhost" => _("Relayhost") , + "apache_http" => _("HTTP FreeBusy service") , + "postfix_allow_unauthenticated" => _("Accept Internet Mail") , + "cyrus_imap" => _("IMAP service") , + "kolabFreeBusyFuture" => _("kolabFreeBusyFuture") , + "cyrus_pop3" => _("POP3 service") , + "cyrus_imaps" => _("IMAP/SSL service") , + "cyrus_pop3s" => _("POP3/SSL service") , + "cyrus_sieve" => _("Sieve service") , + "cyrus_quotawarn" => _("Quota settings")) + )); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: