Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_goMailServer.inc
index 851ad5b5846ec90995fdf6a05590cc2d259f31dc..d8e1985691c04af3e6390bb986f1d70200c6988a 100644 (file)
@@ -10,12 +10,10 @@ class goMailServer extends plugin{
   var $objectclasses    = array("goMailServer");
 
   /* This class can't be assigned twice so it conflicts with itsself */
-  var $conflicts        = array("goMailServer");
-
   var $DisplayName      = "";
   var $dn               = NULL;
   var $StatusFlag       = "goMailServerStatus";
-  var $attributes       = array("goMailServerStatus","description","postfixHeaderSizeLimit",
+  var $attributes       = array("description","postfixHeaderSizeLimit",
       "postfixMailboxSizeLimit","postfixMessageSizeLimit",
       "postfixMyDestinations","postfixMyDomain","postfixMyhostname",
       "postfixMyNetworks","postfixRelayhost","postfixTransportTable",
@@ -37,7 +35,8 @@ class goMailServer extends plugin{
   var $RestrictionFilters               = array();
   var $TransportProtocols               = array(); 
   var $Actions                          = array();
-
+  var $cn                               = "";
+  var $conflicts                        = array("goMailServer","kolab");
 
   function goMailServer($config,$dn)
   {
@@ -79,6 +78,7 @@ class goMailServer extends plugin{
 
     /* Get postfix my networks */
     $this->postfixMyNetworks = array();
+    $tmp = array();
     if(isset($this->attrs['postfixMyNetworks'][0])){
       $tmp = split(",",$this->attrs['postfixMyNetworks'][0]);
       foreach($tmp as $str){
@@ -106,6 +106,7 @@ class goMailServer extends plugin{
 
 
     /* Get transport tables */
+    $tmp = array();
     $this->postfixTransportTable = array();
     if(isset($this->attrs['postfixTransportTable'])){
       $tmp = array();
@@ -131,6 +132,7 @@ class goMailServer extends plugin{
    
 
     /* Get sender restrictions */
+    $tmp = array();
     $this->postfixSenderRestrictions = array();
     if(isset($this->attrs['postfixSenderRestrictions'])){
       unset($this->attrs['postfixSenderRestrictions']['count']);
@@ -154,6 +156,7 @@ class goMailServer extends plugin{
 
  
     /* Get sender restrictions */
+    $tmp = array();
     $this->postfixRecipientRestrictions = array();
     if(isset($this->attrs['postfixRecipientRestrictions'])){
       unset($this->attrs['postfixRecipientRestrictions']['count']);
@@ -473,6 +476,7 @@ class goMailServer extends plugin{
   /* Return list entry */
   function getListEntry()
   {
+    $this->updateStatusState();
     $flag = $this->StatusFlag;
     $fields['Status']     = $this->$flag;
     $fields['Message']    = _("Postfix")." ["._("configured for")." ".$this->postfixMyhostname."] ";
@@ -499,6 +503,7 @@ class goMailServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    $this->handle_post_events("remove");
   }
 
 
@@ -549,7 +554,7 @@ class goMailServer extends plugin{
       foreach($this->postfixMyNetworks as $entry){
         $this->attrs['postfixMyNetworks'] .=$entry.",";
       }
-      $this->postfixMyNetworks = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
+      $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
     }else{
       $this->attrs['postfixMyNetworks']  = array();
     }
@@ -566,6 +571,12 @@ class goMailServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    if($this->initially_was_account){
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+    }
+
   }
 
 
@@ -588,6 +599,7 @@ class goMailServer extends plugin{
       $this->$flag = $value;
       $ldap->modify($attrs);
       show_ldap_error($ldap->get_error());
+      $this->action_hook();
     }
   }
 
@@ -679,6 +691,66 @@ class goMailServer extends plugin{
     return($ret);
   }
 
+  
+  function action_hook($add_attrs= array())
+  {
+    /* Find postcreate entries for this class */
+    $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
+    if ($command == "" && isset($this->config->data['TABS'])){
+      $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
+    }
+    if ($command != ""){
+      /* Walk through attribute list */
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $command= preg_replace("/%$attr/", $this->$attr, $command);
+        }
+      }
+      $command= preg_replace("/%dn/", $this->dn, $command);
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
+      /* If there are still some %.. in our command, try to fill these with some other class vars */
+      if(preg_match("/%/",$command)){
+        $attrs = get_object_vars($this);
+        foreach($attrs as $name => $value){
+          if(!is_string($value)) continue;
+          $command= preg_replace("/%$name/", $value, $command);
+        }
+      }
+
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+
+        exec($command);
+      } else {
+        $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
+        print_red ($message);
+      }
+    }
+  }
+
+
+  /* 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];
+    }
+  }
 
   function save_object()
   {