Code

new version of nagios plugin
authoropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 25 Sep 2005 16:30:38 +0000 (16:30 +0000)
committeropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 25 Sep 2005 16:30:38 +0000 (16:30 +0000)
removal of ugly code ;-(

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

plugins/personal/nagios/class_nagiosAccount.inc
plugins/personal/nagios/nagios.tpl

index 0d668cab088d9c9a470c08c64fbb953f7364968a..a6ebedf56c82880f3bece26eaab50a37107b2787 100644 (file)
@@ -1,8 +1,16 @@
 <?php
 
-/* Create a class (name must be unique inside GOsa) which extends plugin. The plugin base
-    class contains all methods that are used by GOsa and it provides the mechanism to load data
-    from LDAP to local variables and prepare the save to ldap routine for you. */
+/*! \brief   mail plugin
+  \author  Guillame Delecourt <guillaume@opensides.be>
+  \author  Benoit Mortier <benoit.mortier@opensides.be>
+  \version 1.00
+  \date    25.09.2005
+
+  This class provides the functionality to read and write all attributes
+  relevant for nagiosAccount from/to the LDAP. It does syntax checking
+  and displays the formulars required.
+ */
+
 class nagiosAccount extends plugin
 {
        /* Definitions */
@@ -11,125 +19,112 @@ class nagiosAccount extends plugin
        
        /* CLI vars */
        var $cli_summary= "Manage users nagios account";
-       var $cli_description= "Some longer text\nfor help";
+       var $cli_description= "Manage Account and autorization\nfor Nagios";
        var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-       
-       /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't
-       care... */
-       var $attributes= array("NagiosAlias","NagiosPager","NagiosMail","HostNotificationPeriod","ServiceNotificationPeriod","HostNotificationCommands","ServiceNotificationCommands",
-       "HostNotificationOptions",
-       "ServiceNotificationOptions",
-       "HostNotificationPeriod",
-       "ServiceNotificationPeriod",
-       "AuthorizedAllHosts",
-       "AuthorizedAllServices",
-       "AuthorizedSystemCommands",
-       "AuthorizedAllHostCommands",
-       "AuthorizedAllServiceCommands",
-       "AuthorizedConfigurationInformation",
-       "AuthorizedSystemInformation");
+
+  /* plugin specific values */
+  var $NagiosAlias= "";
+  var $NagiosPager= "";
+  var $NagiosMail= "";
+  var $HostNotificationPeriod= "";
+  var $ServiceNotitificationPeriod= "";
+  var $HostNotificationCommands= "";
+  var $ServiceNotificationCommands= "";
+  var $HostNotitificationOptions= "";
+  var $ServiceNotificationOptions= "";
+  var $HostNotificationPeriod= "";
+  var $ServiceNotificationPeriod= "";
+
+  var $AuthorizedAllHosts= "";
+  var $AuthorizedAllServices= "";
+  var $AuthorizedSystemCommands= "";
+  var $AuthorizedAllHostCommands= "";
+  var $AuthorizedAllServiceCommands= "";
+  var $AuthorizedConfigurationInformation= "";
+  var $AuthorizedSystemInformation= "";
+
+  /* attribute list for save action */
+  
+       var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
+      "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
+      "HostNotificationOptions", "ServiceNotificationOptions", "HostNotificationPeriod",
+      "ServiceNotificationPeriod", "AuthorizedAllHosts", "AuthorizedAllServices",
+      "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
+      "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
+
   var $objectclasses= array("nagiosContact");
 
-  /* The constructor just saves a copy of the config. You may add what ever you need. */
+  /* constructor, if 'dn' is set, the node loads the given
+       'dn' from LDAP */
   function nagiosAccount ($config, $dn= NULL)
   {
-        /* Include config object */
-        $this->config= $config;
+    /* Configuration is fine, allways */
+    $this->config= $config;
+    
        plugin::plugin ($config, $dn);
-       $this->initially_was_account= $this->is_account;
-}
 
-  /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
+    /* Save initial account state */  
+         $this->initially_was_account= $this->is_account;
+  }
+
   function execute()
   {
-        $display= "";
-       /* Use the smarty templating engine here... */
-        $smarty= get_smarty();
-
-       //echo "<pre>";print_r($_POST);echo "</pre>";
-       /* Do we need to flip is_account state? */
-       if (isset($_POST['modify_state'])){
-       $this->is_account= !$this->is_account;
-       }
-       /* Do we represent a valid account? */
-       if (!$this->is_account && $this->parent == NULL){
-       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-               _("This account has no nagios extensions.")."</b>";
-       $display.= back_to_main();
-       return ($display);
-       }
-       /* Load attributes */
-       foreach($this->attributes as $val){
-       $smarty->assign("$val", $this->$val);
-       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
-       }
-       
-       if ($this->is_account){
-               $smarty->assign("nagiosAuth","checked");
-               $smarty->assign("nagiosContact","checked");
-       }
-       
-       /* Show tab dialog headers */
-       if ($this->parent != NULL){
-       if ($this->is_account){
-               $display= $this->show_header(_("Remove nagios account"),
-               _("This account has nagios features enabled. You can disable them by clicking below."));
-       } else {
-               $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
-               return($display);
-       }
-       }
+    /* Load templating engine */
+    $smarty= get_smarty();
+    $display= "";
+            
+         /* Do we need to flip is_account state? */
+         if (isset($_POST['modify_state'])){
+           $this->is_account= !$this->is_account;
+         }
+  
+         /* Do we represent a valid account? */
+           if (!$this->is_account && $this->parent == NULL){
+             $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
+                     _("This account has no nagios extensions.")."</b>";
+    
+        $display.= back_to_main();
+         return ($display);
+           }
+  
+         /* Show tab dialog headers */
+         if ($this->parent != NULL){
+      if ($this->is_account){
+        $display= $this->show_header(_("Remove nagios account"),
+            _("This account has nagios features enabled. You can disable them by clicking below."));
+      } else {
+        $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
+        return($display);
+           }
+         }
        $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
-       //echo "<pre>";print_r($_POST);echo "</pre>";
-       return ($display);
+           return ($display);
   }
- /* Save to LDAP */
-function save()
-{
-       /* Load uid and gid of this 'dn' */
-       $ldap= $this->config->get_ldap_link();
-       $ldap->cat($this->dn);
-       $tmp= $ldap->fetch();
-       
-       plugin::save();
-
-       //nagiosContact
-       //ugly code but i will correct this after :)
-
-       if(isset($_POST['NagiosAlias']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias'];
-       if(isset($_POST['NagiosPager']))$this->attrs['NagiosAlias']=$_POST['NagiosAlias'];
-       if(isset($_POST['NagiosMail']))$this->attrs['NagiosMail']=$_POST['NagiosMail'];
-       if(isset($_POST['ServiceNotificationPeriod']))$this->attrs['ServiceNotificationPeriod']=$_POST['ServiceNotificationPeriod'];
-       if(isset($_POST['HostNotificationPeriod']))$this->attrs['HostNotificationPeriod']=$_POST['HostNotificationPeriod'];
-       if(isset($_POST['ServiceNotificationOptions']))$this->attrs['ServiceNotificationOptions']=$_POST['ServiceNotificationOptions'];
-       if(isset($_POST['HostNotificationOptions']))$this->attrs['HostNotificationOptions']=$_POST['HostNotificationOptions'];
-       if(isset($_POST['ServiceNotificationCommands']))$this->attrs['ServiceNotificationCommands']=$_POST['ServiceNotificationCommands'];
-       if(isset($_POST['HostNotificationCommands']))$this->attrs['HostNotificationCommands']=$_POST['HostNotificationCommands'];
-
-       //nagiosAuth
-       if(isset($_POST['AuthorizedSystemInformation']))$this->attrs['AuthorizedSystemInformation']="checked";else $this->attrs['AuthorizedSystemInformation']="unchecked";
-       if(isset($_POST['AuthorizedConfigurationInformation']))$this->attrs['AuthorizedConfigurationInformation']="checked";else $this->attrs['AuthorizedConfigurationInformation']="unchecked";
-       if(isset($_POST['AuthorizedSystemCommands']))$this->attrs['AuthorizedSystemCommands']="checked";else $this->attrs['AuthorizedSystemCommands']="unchecked";
-       if(isset($_POST['AuthorizedAllServices']))$this->attrs['AuthorizedAllServices']="checked";else $this->attrs['AuthorizedAllServices']="unchecked";
-       if(isset($_POST['AuthorizedAllHosts']))$this->attrs['AuthorizedAllHosts']="checked";else $this->attrs['AuthorizedAllHosts']="unchecked";
-       if(isset($_POST['AuthorizedAllServiceCommands']))$this->attrs['AuthorizedAllServiceCommands']="checked";else $this->attrs['AuthorizedAllServiceCommands']="unchecked";
-       if(isset($_POST['AuthorizedAllHostCommands']))$this->attrs['AuthorizedAllHostCommands']="checked";else $this->attrs['AuthorizedAllHostCommands']="unchecked";
-
-       /* Write back to ldap */
-       $ldap->cd($this->dn);
-       $ldap->modify($this->attrs);
-       show_ldap_error($ldap->get_error());
+
+  /* Save to LDAP */
+  function save()
+  {
+    $ldap= $this->config->get_ldap_link();
+
+    /* Call parents save to prepare $this->attrs */
+         plugin::save();
+
+
+         /* Write back to ldap */
+         $ldap->cd($this->dn);
+         $ldap->modify($this->attrs);
+         show_ldap_error($ldap->get_error());
        
-       /* Optionally execute a command after we're done */
-       if ($this->initially_was_account == $this->is_account){
-       if ($this->is_modified){
-               $this->handle_post_events("modify");
-       }
-       } else {
-       $this->handle_post_events("add");
-       }
+         /* Optionally execute a command after we're done */
+         if ($this->initially_was_account == $this->is_account){
+           if ($this->is_modified){
+                   $this->handle_post_events("modify");
+           }
+         } else {
+           $this->handle_post_events("add");
+    }
        
-}
+  }
 
 function save_object()
 {
@@ -162,5 +157,9 @@ function remove_from_parent()
        /* Optionally execute a command after we're done */
        $this->handle_post_events('remove');
 }
+
 }
-?>
\ No newline at end of file
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+
+?>
index 1ffb10ecf8e4ca9f0476186ba8c1ecb5056cbc50..2b51f15f52e0cecc8473d47b250f918d549e6b0e 100644 (file)
 
 <input type="checkbox" name="AuthorizedAllHostCommands" {$AuthorizedAllHostCommandsACL} value="{$AuthorizedAllHostCommands}" {$AuthorizedAllHostCommands}>authorized_for_all_host_commands<br />
 
+<input type="hidden" name="nagiosTab" value="nagiosTab">
+
+<!-- Place cursor -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+  document.mainform.mail.focus();
+  -->
+</script>
+