Code

Removed duplicated post call
[gosa.git] / plugins / admin / systems / class_servKolab.inc
index 4145f5525dd6e45a2e3ff96cc222b105d795b362..3b666fd43bbae9848f4ebb8cfcc630909d4d4c81 100644 (file)
@@ -1,12 +1,15 @@
 <?php
 
-class servkolab extends plugin {
+require_once("class_goService.inc");
+
+class servkolab extends goService {
   /* CLI vars */
   var $cli_summary = "Manage server basic objects";
   var $cli_description = "Some longer text\nfor help";
   var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
 
   var $postfix_mydomain                 = "";
+  var $cyrus_admins                     = "";
   var $postfix_mydestination            = "";
   var $postfix_mynetworks               = "127.0.0.1/8";
   var $postfix_enable_virus_scan        = "TRUE";
@@ -16,7 +19,6 @@ class servkolab extends plugin {
   var $cyrus_quotawarn                  = "80";
   var $kolabFreeBusyFuture              = "1";
   var $k                                = "kolab";
-  var $cyrus_admins                     = "TRUE";
   var $cyrus_imap                       = "TRUE";
   var $cyrus_pop3                       = "TRUE";
   var $cyrus_imaps                      = "TRUE";
@@ -26,9 +28,6 @@ class servkolab extends plugin {
   var $proftpd_ftp                      = "TRUE";
   var $apache_http                      = "TRUE";
   var $kolabHost                        = array();
-  var $is_in_there                      = false;
-  var $exactName                        = false;
-
   var $orig_cn                          = "";
 
   var $attributes =  array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
@@ -38,7 +37,12 @@ class servkolab extends plugin {
       "cyrus_quotawarn");
   var $objectclasses = array("top", "kolab");
 
-  function servkolab($config, $dn = NULL) 
+  /* Serverservice vars */
+  var $conflicts    = array("goImapServer","goMailServer");
+  var $DisplayName  = "Kolab mail service";
+  var $StatusFlag   = "";
+
+  function servkolab($config, $dn = NULL, $parent= NULL) 
   {
     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
     $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
@@ -64,37 +68,17 @@ class servkolab extends plugin {
       $this->kolabHost= $this->attrs['kolabHost'];
       unset($this->kolabHost['count']);
     }
-    $this->is_in_there           = false;
     $this->is_account            = false;
     $this->initially_was_account = false;
     foreach($this->kolabHost as $host){
-      if(preg_match("/".$this->hostname.".*/i",$host)){
+      if($this->hostname == $host){
         $this->is_account            = true;
-        $this->is_in_there           = true;
         $this->initially_was_account = true;
       }
     } 
 
-
-    /* Mhh */ 
-    if(in_array($this->hostname, $this->kolabHost)) {
-      $this->exactName=true;
-    } else {   
-      $this->exactName=false;    
-    } 
-
-    /* Parse mynetworks */
-    if(isset($this->attrs['postfix-mynetworks'])){
-      if(is_array($this->attrs['postfix-mynetworks'])){  
-        unset($this->attrs['postfix-mynetworks']['count']);
-        $tmp="";
-        foreach($this->attrs['postfix-mynetworks'] as $tm){
-          $tmp.=$tm.";";
-        }
-        $this->postfix_mynetworks = $tmp;
-      }
-    }else{
-      $this->postfix_mynetworks="";
+    if($this->is_account){
+      @log::log("view","server/".get_class($this),$this->dn);
     }
   }
 
@@ -114,54 +98,35 @@ class servkolab extends plugin {
 
 
     /* Assemble free/busy string */
-    $edit       = sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
-                    $this->kolabFreeBusyFuture, 
-                    chkacl($this->acl, 'kolabFreeBusyFuture'));
+    $edit       = sprintf('<input name="kolabFreeBusyFuture" value="%s" type="text" maxlength="3" size="4">',
+                    $this->kolabFreeBusyFuture);
     $fbfuture   = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
 
     /* Assemble quota string */
-    $edit       = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
-                    $this->cyrus_quotawarn, 
-                    chkacl($this->acl, 'cyrus_quotawarn'));
+    $edit       = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4">',
+                    $this->cyrus_quotawarn);
     $quotastr   = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
 
-
-    /***************  
-      Handle Account is_account state
-     ***************/  
-  
-    /* 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);
-    }
-
-
     /***************
       Assign informations to smarty 
      ***************/
 
-    /* Set relayhost and if we have MX lookup enabled*/
+    /* Set relayhost and if we have MX lookup enabled*/ 
     if($this->postfix_mxrelayenabled) {
       $smarty->assign("RelayMxSupportCheck"," checked ");
     } else {
       $smarty->assign("RelayMxSupportCheck","");
     }
 
+    /* Set acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+
     /* Initialize all attributes, that were submitted */
     foreach($this->attributes as $val) 
     {
-      $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
-
       /* Tell smarty which variables we are useing */
       $smarty->assign($val, $this->$val);
       if (($this->$val != "FALSE") && !empty($this->$val)){
@@ -181,6 +146,14 @@ class servkolab extends plugin {
 
   function remove_from_parent() 
   {
+
+     /* 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){
@@ -222,7 +195,7 @@ class servkolab extends plugin {
 
       /* Remove complete entry */
       $ldap->rmdir ($this->dn);
-      show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
+      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 {
@@ -238,10 +211,12 @@ class servkolab extends plugin {
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($attrs); 
-      show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
+      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");
     }
 
+    @log::log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove");
   }
@@ -252,20 +227,32 @@ class servkolab extends plugin {
     if (isset($_POST['kolabtab'])){
       plugin::save_object();
 
+
+      foreach($this->attributes as $attr){
+        if(($this->acl_is_writeable(preg_replace("/_/","",$attr))) && (isset($_POST[$attr]))){
+          $this->$attr = $_POST[$attr];
+        }
+      }
+
       /* Save checkboxes */
       foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
-            "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
+            "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 {
-          $this->$cb= "FALSE";
+
+        if($this->acl_is_writeable(preg_replace("/_/","",$cb))){
+          if (isset($_POST[$cb])){
+            $this->$cb= "TRUE";
+          } else {
+            $this->$cb= "FALSE";
+          }
         }
       }
 
-      /* Toggle relay check */
-      $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
+      /* Toggell relay check */
+      if($this->acl_is_writeable("postfixmxrelayenabled")){
+        $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
+      }
     }
 
   }
@@ -314,7 +301,7 @@ class servkolab extends plugin {
 
     /* Adapt relayhost */
     $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
-    if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
+    if ($this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
       $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
     }
 
@@ -327,26 +314,15 @@ class servkolab extends plugin {
             $tmp[] = $host;
           }
         }
+        $this->kolabHost = $tmp;
       }
-      $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;
     }
 
-    /* Create mynetworks array by splitting the string with ; */
-    $tmp = split(";",$this->postfix_mynetworks);
-    $this->postfix_mynetworks = array();
-    foreach($tmp as $tm){
-      trim($tm);
-      if(!empty($tm)){
-        $this->postfix_mynetworks[]=$tm;
-      }
-    }
-    $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
-
     /* Call parents save to prepare $this->attrs */
     plugin::save();
 
@@ -370,25 +346,72 @@ class servkolab extends plugin {
     /* Add kolab hosts */
     $this->attrs['kolabHost']= $this->kolabHost;
 
-    if(($this->is_in_there)&&(!$this->exactName)){
-      unset($this->attrs['kolabHost']);
-    }
-
     /* Perform LDAP action */
     $ldap->cd($this->dn);
     $this->cleanup();;
     $ldap->$mode($this->attrs);
-    show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
+
+    if($mode == "add"){
+      @log::log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }else{
+      @log::log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$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()
+  {
+    $fields                 = goService::getListEntry();
+    $fields['Message']      = _("Kolab mail service");
+    $fields['AllowEdit']    = true;
+    return($fields);
+  }
+
+
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Kolab"),
+          "plDescription" => _("Kolab mail service")." ("._("Services").")",
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 85,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("server"),
+
+          "plProvidedAcls"=> array(
+            "postfixmydomain"                => _("Postfix mydomain") ,
+            "postfixmydestination"           => _("My destination") ,
+            "cyrusadmins"                    => _("Cyrus admins") ,
+            "proftpdftp"                     => _("FTP FreeBusy service") ,
+            "postfixmynetworks"              => _("SMTP privileged networks") ,
+            "postfixenablevirusscan"         => _("Enable virus scan") ,
+            "postfixrelayhost"               => _("Relayhost") ,
+            "postfixmxrelayenabled"          => _("Enable MX lookup for relayhost"),
+            "apachehttp"                     => _("HTTP FreeBusy service") ,
+            "apacheallowunauthenticatedfb"   => _("Allow unauthenticated free busy"),
+            "postfixallowunauthenticated"    => _("Accept Internet Mail") ,
+            "cyrusimap"                      => _("IMAP service") ,
+            "kolabFreeBusyFuture"            => _("kolabFreeBusyFuture") ,
+            "cyruspop3"                      => _("POP3 service") ,
+            "cyrusimaps"                     => _("IMAP/SSL service") ,
+            "cyruspop3s"                     => _("POP3/SSL service") ,
+            "cyrussieve"                     => _("Sieve service") ,
+            "cyrusquotawarn"                 => _("Quota settings")) 
+            ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: