Code

Updated rSyslog plugin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 29 Dec 2009 11:07:09 +0000 (11:07 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 29 Dec 2009 11:07:09 +0000 (11:07 +0000)
-Database connection are now optional

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14974 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/rsyslog/admin/systems/services/rsyslog/class_rSyslogServer.inc
gosa-plugins/rsyslog/admin/systems/services/rsyslog/rSyslogServer.tpl

index 9204611423f96fd2ee136c8eaa17d6db169b4712..74fcdaab0dd18196a92176957e2db0d6e4976e4c 100644 (file)
@@ -3,27 +3,39 @@
 class rSyslogServer extends goService{
        
   /* This plugin only writes its objectClass */
-  var $objectclasses    = array("goLogDBServer");
-  var $attributes       = array("gosaLogDB","goLogAdmin","goLogPassword");
+  var $objectclasses    = array("goSyslogServer");
+  var $attributes       = array();
+  var $db_attributes    = array("gosaLogDB","goLogAdmin","goLogPassword");
   var $StatusFlag       = "";
 
   /* This class can't be assigned twice so it conflicts with itsself */
-  var $conflicts        = array("goLogDBServer");
+  var $conflicts        = array("goSyslogServer");
 
   var $DisplayName      = "";
   var $dn               = NULL;
   var $acl;
   var $cn                 = "";
-  var $gosaLogDB    = "Syslog";
-  var $goLogAdmin        = "rsyslog";
-  var $goLogPassword    = "";  
-  var $view_logged  =FALSE;
+  var $use_database = FALSE;
+  var $initial_use_database = FALSE;
+  var $gosaLogDB     = "Syslog";
+  var $goLogAdmin    = "rsyslog";
+  var $goLogPassword = "";  
+  var $view_logged   = FALSE;
 
 
   function rSyslogServer(&$config,$dn)
   {
     goService::goService($config,$dn);
     $this->DisplayName = _("rSyslog");
+    $this->initial_use_database = $this->use_database = isset($this->attrs['objectClass']) &&in_array("goLogDBServer", $this->attrs['objectClass']);
+
+    if($this->use_database){
+      foreach($this->db_attributes as $attr){
+        if(isset($this->attrs[$attr][0])){
+          $this->$attr = $this->attrs[$attr][0];
+        }
+      }
+    }
   }
 
 
@@ -41,9 +53,10 @@ class rSyslogServer extends goService{
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
-    foreach($this->attributes as $attr){
+    foreach($this->db_attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
+    $smarty->assign("use_database" , $this->use_database);
     return($smarty->fetch(get_template_path("rSyslogServer.tpl",TRUE,dirname(__FILE__))));
   }
 
@@ -51,7 +64,7 @@ class rSyslogServer extends goService{
   function getListEntry()
   {
     $fields = goService::getListEntry();
-    $fields['Message']      = _("rSyslog logging service");
+    $fields['Message']      = _("Logging service");
     #$fields['AllowEdit']    = true;
     #$fields['AllowStart']   = FALSE;
     #$fields['AllowStop']    = FALSE;
@@ -63,14 +76,16 @@ class rSyslogServer extends goService{
   function check()
   { 
     $message = plugin::check();
-    if (empty($this->goLogAdmin)){
-      $message[]= msgPool::required(_("User"));
-    }
-    if (empty($this->goLogPassword)){
-      $message[]= msgPool::required(_("Password"));
-    }
-    if (empty($this->gosaLogDB)){
-      $message[]= msgPool::required(_("Database"));
+    if($this->use_database){
+      if (empty($this->goLogAdmin)){
+        $message[]= msgPool::required(_("User"));
+      }
+      if (empty($this->gosaLogDB)){
+        $message[]= msgPool::required(_("Database"));
+      }
+      if (empty($this->goLogPassword)){
+        $message[]= msgPool::required(_("Password"));
+      }
     }
     return($message);
   }
@@ -80,8 +95,77 @@ class rSyslogServer extends goService{
   {
     if(isset($_POST['rSyslogServerPosted'])){
       plugin::save_object();
+
+      foreach($this->db_attributes as $attr){
+        if(isset($_POST[$attr])){
+          $this->$attr = get_post($attr);
+        }
+      }
+      $this->use_database = isset($_POST['use_database']);
+    }
+  }  
+
+
+  function save()
+  {
+    // Store rSyslog database connection info if enabled.
+    if($this->use_database){
+      $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
+      $this->objectclasses = array('goSyslogServer','goLogDBServer');
+    }else{
+      $this->attributes = array();
+      $this->objectclasses = array('goSyslogServer');
+
+    }
+
+    plugin::save();
+
+    if(!$this->use_database && $this->initial_use_database){
+      $this->attrs['objectClass'] = array_remove_entries(array('goLogDBServer'),$this->attrs['objectClass']);
+      $this->attrs['objectClass'] = array_values($this->attrs['objectClass']);
+      foreach($this->db_attributes as $attr){
+        $this->attrs[$attr] = array();
+      }
     }
-  } 
+
+    /* Check if this is a new entry ... add/modify */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cat($this->dn,array("objectClass"));
+    if($ldap->count()){
+      $ldap->cd($this->dn);
+      $ldap->modify($this->attrs);
+    }else{
+      $ldap->cd($this->dn);
+      $ldap->add($this->attrs);
+    }
+    if($this->initially_was_account){
+      new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+      new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
+  }
+
+
+  /* Remove service */
+  function remove_from_parent()
+  {
+    // Store rSyslog database connection info if enabled.
+    if($this->initial_use_database){
+      $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
+      $this->objectclasses = array('goSyslogServer','goLogDBServer');
+    }else{
+      $this->attributes = array();
+      $this->objectclasses = array('goSyslogServer');
+    }
+
+    goService::remove_from_parent();
+  }
+
 
   /* Return plugin informations for acl handling */
   static function plInfo()
index aaa903d8041bc9745f7030698cd5e75fc0894f1a..61f1ab0d197d15946c648c311a1e0e7c9b0c47f1 100644 (file)
@@ -1,10 +1,17 @@
-<h2><img class="center" alt="" align="middle" src="images/rightarrow.png" /> {t}rSyslog logging database{/t}</h2>
+<h2><img class="center" alt="" align="middle" src="images/rightarrow.png" /> {t}Syslog logging{/t}</h2>
+
+<br>
+<input type="checkbox" name="use_database" value="1" {if $use_database} checked {/if}
+  onChange="changeState('gosaLogDB'); changeState('goLogAdmin');changeState('goLogPassword');"
+  class="center">
+<b>{t}This server provides a rSyslog mysql database{/t}</b>
 <table summary="">
     <tr>
      <td>{t}Database{/t}{$must}</td>
      <td>
 {render acl=$gosaLogDBACL}
-       <input name="gosaLogDB" id="gosaLogDB" size=30 maxlength=60 value="{$gosaLogDB}">
+       <input name="gosaLogDB" id="gosaLogDB" size=30 maxlength=60 value="{$gosaLogDB}"
+    {if !$use_database} disabled {/if}>
 {/render}
      </td>
     </tr>
@@ -12,7 +19,8 @@
      <td>{t}Database user{/t}{$must}</td>
      <td>
 {render acl=$goLogAdminACL}
-       <input name="goLogAdmin" id="goLogAdmin" size=30 maxlength=60 value="{$goLogAdmin}">
+       <input name="goLogAdmin" id="goLogAdmin" size=30 maxlength=60 value="{$goLogAdmin}"
+    {if !$use_database} disabled {/if}>
 {/render}
      </td>
     </tr>
@@ -20,7 +28,8 @@
      <td>{t}Password{/t}{$must}</td>
      <td>
 {render acl=$goLogPasswordACL}
-       <input type="password" name="goLogPassword" id="goLogPassword" size=30 maxlength=60 value="{$goLogPassword}">
+       <input type="password" name="goLogPassword" id="goLogPassword" size=30 maxlength=60 value="{$goLogPassword}"
+    {if !$use_database} disabled {/if}>
 {/render}
      </td>
     </tr>