Code

Moved nagios
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Jan 2008 12:15:51 +0000 (12:15 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Jan 2008 12:15:51 +0000 (12:15 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8438 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/personal/nagios/class_nagiosAccount.inc [deleted file]
gosa-core/plugins/personal/nagios/main.inc [deleted file]
gosa-core/plugins/personal/nagios/nagios.tpl [deleted file]
gosa-plugins/nagios/personal/nagios/class_nagiosAccount.inc [new file with mode: 0644]
gosa-plugins/nagios/personal/nagios/main.inc [new file with mode: 0644]
gosa-plugins/nagios/personal/nagios/nagios.tpl [new file with mode: 0644]

diff --git a/gosa-core/plugins/personal/nagios/class_nagiosAccount.inc b/gosa-core/plugins/personal/nagios/class_nagiosAccount.inc
deleted file mode 100644 (file)
index 153f73c..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-<?php
-
-/*! \brief   mail plugin
-  \author  Guillame Delecourt <guillaume@opensides.be>
-  \author  Benoit Mortier <benoit.mortier@opensides.be>
-  \author  Vincent Seynhaeve <vincent@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 */
-  var $plHeadline= "Nagios";
-  var $plDescription= "This does something";
-
-  /* CLI vars */
-  var $cli_summary= "Manage users nagios account";
-  var $cli_description= "Manage Account and autorization\nfor Nagios";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
-  /* plugin specific values */
-  var $NagiosAlias  = "";
-  var $NagiosPager  = "";
-  var $NagiosMail   = "";
-
-  var $HostNotificationOptions      = "";
-  var $HostNotificationPeriod       = "";
-  var $ServiceNotificationPeriod    = "";
-  var $ServiceNotitificationPeriod  = "";
-  var $HostNotificationCommands     = "";
-  var $ServiceNotificationCommands  = "";
-  var $HostNotitificationOptions    = "";
-  var $ServiceNotificationOptions   = "";
-
-  var $AuthorizedAllHosts                 = "unchecked";
-  var $AuthorizedAllServices              = "unchecked";
-  var $AuthorizedSystemCommands           = "unchecked";
-  var $AuthorizedAllHostCommands          = "unchecked";
-  var $AuthorizedAllServiceCommands       = "unchecked";
-  var $AuthorizedConfigurationInformation = "unchecked";
-  var $AuthorizedSystemInformation        = "unchecked";
-
-  /* attribute list for save action */
-
-  var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
-      "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
-      "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
-      "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
-      "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
-
-  var $is_chk_box = array("AuthorizedAllHosts","AuthorizedAllServices","AuthorizedSystemCommands",
-      "AuthorizedAllHostCommands","AuthorizedAllServiceCommands",
-      "AuthorizedConfigurationInformation","AuthorizedSystemInformation");
-
-  var $objectclasses= array("nagiosContact","nagiosAuth");
-
-  var $uid = "";
-  var $view_logged = FALSE;
-
-  /* constructor, if 'dn' is set, the node loads the given
-     'dn' from LDAP */
-  function nagiosAccount (&$config, $dn= NULL)
-  {
-    /* Configuration is fine, allways */
-    $this->config= $config;
-
-    plugin::plugin ($config, $dn);
-
-    /* Setting uid to default */
-    if(isset($this->attrs['uid'][0])){
-      $this->uid = $this->attrs['uid'][0];
-    }
-
-    /* Save initial account state */  
-    $this->initially_was_account= $this->is_account;
-  }
-
-  function execute()
-  {
-    /* Call parent execute */
-    plugin::execute();
-
-    /* Log view */
-    if($this->is_account && !$this->view_logged){
-      $this->view_logged = TRUE;
-      new log("view","users/".get_class($this),$this->dn);
-    }
-
-    /* Load templating engine */
-    $smarty= get_smarty();
-    $display= "";
-
-    /* Do we need to flip is_account state? */
-    if(isset($_POST['modify_state'])){
-      if($this->is_account && $this->acl_is_removeable()){
-        $this->is_account= FALSE;
-      }elseif(!$this->is_account && $this->acl_is_createable()){
-        $this->is_account= TRUE;
-      }
-    }    
-
-    /* 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_disable_header(_("Remove nagios account"),
-            _("This account has nagios features enabled. You can disable them by clicking below."));
-      } else {
-        $display= $this->show_enable_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
-        return($display);
-      }
-    }
-
-    /* Assign acls */
-    $tmp = $this->plInfo();
-    $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
-    foreach($tmp['plProvidedAcls'] as $acl => $desc){
-      $smarty->assign($acl."ACL",$this->getacl($acl,$SkipWrite));
-    }
-
-    /* Assign attributes an ACL to smarty */
-    foreach($this->attributes as $val) { 
-      $smarty->assign("$val", $this->$val);
-      if(in_array($val,$this->is_chk_box)){
-        if($this->$val == "checked"){
-          $smarty->assign($val."CHK", " checked ");
-        }else{
-          $smarty->assign($val."CHK", "");
-        }
-      }
-    }
-    $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
-    $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
-    $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
-    $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
-    $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
-    return ($display);
-  }
-
-  /* Save to LDAP */
-  function save()
-  {
-    $ldap= $this->config->get_ldap_link();
-
-    /* Call parents save to prepare $this->attrs */
-    plugin::save();
-
-    /* Adapt attributes if needed */
-    //$method= new $this->method($this->config);
-    //$id= $method->uattrib;
-    //$method->fixAttributesOnStore($this);
-
-    /* Write back to ldap */
-    $ldap->cd($this->dn);
-    $this->cleanup();
-    $ldap->modify ($this->attrs); 
-
-    /* Log last action */
-    if($this->initially_was_account){
-      new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
-    }else{
-      new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
-    }
-
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/nagios account 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("modify",array("uid" => $this->uid));
-      }
-    } else {
-      $this->handle_post_events("add", array("uid" => $this->uid));
-    }
-  }
-
-  function check()
-  {
-    /* Call common method to give check the hook */
-    $message= plugin::check();
-
-    $ldap= $this->config->get_ldap_link();
-    /* must: mail */
-    if ($this->NagiosAlias == ""){
-      $message[]= _("The required field 'NagiosAlias' is not set.");
-    }
-    if ($this->NagiosMail == ""){
-      $message[]= _("The required field 'NagiosMail' is not set.");
-    }
-    if ($this->is_template){
-      if (!tests::is_email($this->NagiosMail, TRUE)){
-        $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
-      }
-    } else {
-      if (!tests::is_email($this->NagiosMail)){
-        $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
-      }
-    }
-    return($message);
-  }
-
-
-  /* Use Save_object for every Post handling */
-  function save_object()
-  {
-    if (isset($_POST['nagiosTab'])){
-      /* Save ldap attributes */
-      plugin::save_object();
-
-      /* Specialhandling for checkboxes */
-      foreach($this->is_chk_box as $val){
-        if($this->acl_is_writeable($val)){
-          if(isset($_POST[$val])){
-            $this->$val = "checked";
-          }else{
-            $this->$val = "unchecked";
-          }
-        }
-      }
-    }
-  }
-
-  function remove_from_parent()
-  {
-    /* Cancel if there's nothing to do here */
-    if (!$this->initially_was_account){
-      return;
-    }
-
-    /* include global link_info */
-    $ldap= $this->config->get_ldap_link();
-
-    /* Remove and write to LDAP */
-    plugin::remove_from_parent();
-
-    /* Adapt attributes if needed */
-    //     $method= new $this->method($this->config);
-    //     $method->fixAttributesOnRemove($this);
-
-    @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
-        $this->attributes, "Save");
-    $ldap->cd($this->dn);
-    $this->cleanup();
-    $ldap->modify ($this->attrs); 
-
-    new log("view","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
-
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/nagios account with dn '%s' failed."),$this->dn));
-
-    /* remove the entry from LDAP */
-    unset ($this->attrs['uid']);
-
-    /* Optionally execute a command after we're done */
-    $this->handle_post_events('remove',array("uid" => $this->uid));
-  }
-
-
-
-  static function plInfo()
-  {
-    return (array(
-          "plShortName"     => _("Nagios"),
-          "plDescription"   => _("Nagios account settings"),
-          "plSelfModify"    => TRUE,
-          "plDepends"       => array("user"),
-          "plPriority"      => 8,                                 // Position in tabs
-          "plSection"     => array("personal" => _("My account")),
-          "plCategory"    => array("users"),
-          "plOptions"       => array(),
-
-          "plProvidedAcls"  => array(
-
-            "NagiosAlias"                       =>  _("Alias"),
-            "NagiosPager"                       =>  _("Pager number"),
-            "NagiosMail"                        =>  _("Mail address"),
-
-            "HostNotificationCommands"          =>  _("Host notification commands"),
-            "HostNotificationOptions"           =>  _("Host notification options"),
-            "HostNotificationPeriod"            =>  _("Host notification period"),
-
-            "ServiceNotificationCommands"       =>  _("Service notification commands"),
-            "ServiceNotificationOptions"        =>  _("Service notification options"),
-            "ServiceNotificationPeriod"         =>  _("Service notification period"),
-
-            "AuthorizedAllHosts"                =>  _("View all hosts"),
-            "AuthorizedAllServices"             =>  _("View all services"),
-
-            "AuthorizedSystemCommands"          =>  _("Trigger system commands"),
-            "AuthorizedAllHostCommands"         =>  _("Trigger all host commands"),
-            "AuthorizedAllServiceCommands"      =>  _("Trigger all service commands"),
-
-            "AuthorizedConfigurationInformation"=>  _("View configuration information"),
-            "AuthorizedSystemInformation"       =>  _("View system informations"))
-      ));
-  }
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-
-?>
diff --git a/gosa-core/plugins/personal/nagios/main.inc b/gosa-core/plugins/personal/nagios/main.inc
deleted file mode 100644 (file)
index 8414b16..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-/*
-   This code is part of GOsa (https://gosa.gonicus.de)
-   Copyright (C) 2005  Benoit Mortier
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-$display    = "";
-$lock_msg   = "";
-
-if (!$remove_lock){
-  /* Reset requested? */
-  if (isset($_POST['edit_cancel']) || 
-      (isset($_GET['reset']) && $_GET['reset'] == 1)){
-    del_lock ($ui->dn);
-    session::un_set ('edit');
-    session::un_set ('nagiosAccount');
-  }
-
-  /* Create mail object on demand */
-  if (!session::is_set('nagiosAccount') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
-    $nagiosAccount= new nagiosAccount ($config, $ui->dn);
-    $nagiosAccount->enable_CSN_check();
-    $nagiosAccount->set_acl_base($ui->dn);
-    $nagiosAccount->set_acl_category("users");
-    session::set('nagiosAccount',$nagiosAccount);
-  }
-  $nagiosAccount = session::get('nagiosAccount');
-
-  /* save changes back to object */
-  if (session::is_set('edit')){
-    $nagiosAccount->save_object ();
-  }
-
-  /* Enter edit mode? */
-  if (isset($_POST['edit'])){
-
-    /* Check locking */
-    if (($username= get_lock($ui->dn)) != ""){
-      session::set('back_plugin',$plug);
-      session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
-      $lock_msg =  gen_locked_message ($username, $ui->dn);
-
-    }else{
-
-      /* Lock the current entry */
-      add_lock ($ui->dn, $ui->dn);
-      session::set('dn',$ui->dn);
-      session::set('edit',TRUE);
-    }
-  }
-
-  /* save changes to LDAP and disable edit mode */
-  if (isset($_POST['edit_finish'])){
-
-    /* Perform checks */
-    $message= $nagiosAccount->check ();
-
-    /* No errors, save object */
-    if (count ($message) == 0){
-      $nagiosAccount->save ();
-      del_lock ($ui->dn);
-      session::un_set ('edit');
-
-      /* Remove object */
-      session::un_set ('nagiosAccount');
-    } else {
-      /* Errors found, show message */
-      show_errors ($message);
-    }
-  }
-
-  /* Execute formular */
-  if($lock_msg){
-    $display.= $lock_msg;
-  }else{
-    $display.= $nagiosAccount->execute ();
-  }
-
-  /* Store changes  in session */
-  if (session::is_set('edit')){
-    session::set('nagiosAccount',$nagiosAccount);
-  }
-
-  $info= "";
-  /* Show page footer depending on the mode */
-  if ($nagiosAccount->is_account && empty($lock_msg)){
-    $display.= "<p class=\"plugbottom\">";
-
-    /* Are we in edit mode? */
-    if (session::is_set('edit')){
-      $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
-      $display.= "&nbsp;";
-      $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
-      $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
-             "\"> ".$ui->dn."&nbsp;";
-    } else {
-      $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
-             "\"> ".$ui->dn."&nbsp;";
-
-      if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/nagiosAccount"))){
-        $info.= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png').
-          "\"> "._("Click the 'Edit' button below to change informations in this dialog");
-        $display.= "<input type=submit name=\"edit\" value=\""._("Edit")."\">\n";
-      }
-      $display.= "<input type=\"hidden\" name=\"ignore\">\n";
-    }
-    $display.= "</p>\n";
-  }
-
-  /* Page header*/
-  $display= print_header(get_template_path('images/monitoring.png'), _("Nagios settings"), $info).$display;
-
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/plugins/personal/nagios/nagios.tpl b/gosa-core/plugins/personal/nagios/nagios.tpl
deleted file mode 100644 (file)
index e77529a..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-<table summary="" style="width:100%; vertical-align:top; text-align:left;" cellpadding="0" border="0">
- <tr>
-  <td style="width:50%; vertical-align:top;">
-   <h2>
-    <img class="center" alt="" align="middle" src="images/rightarrow.png" />&nbsp;{t}Nagios Account{/t}</h2>
-   <table summary="">
-    <tr>
-     <td><label for="NagiosAlias">{t}Alias{/t}</label>{$must}</td>
-     <td>
-{render acl=$NagiosAliasACL}
-      <input id="NagiosAlias" name="NagiosAlias" size=25 maxlength=65 value="{$NagiosAlias}">
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td><label for="NagiosMail">{t}Mail address{/t}</label>{$must}</td>
-     <td>
-{render acl=$NagiosMailACL}
-      <input id="NagiosMail" name="NagiosMail" size=25 maxlength=65 value="{$NagiosMail}">
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="HostNotificationPeriod">{t}Host notification period{/t}</label>{$must}
-     </td>
-     <td>
-{render acl=$HostNotificationPeriodACL}
-      <select name="HostNotificationPeriod" id="HostNotificationPeriod">
-       {html_options options=$HostNotificationPeriodValues values=$HostNotificationPeriodValues selected=$HostNotificationPeriod }
-      </select>
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="ServiceNotificationPeriod">{t}Service notification period{/t}</label>{$must}
-     </td>
-     <td>
-{render acl=$ServiceNotificationPeriodACL}
-      <select name="ServiceNotificationPeriod" id="ServiceNotificationPeriod">
-       {html_options options=$ServiceNotificationPeriodValues values=$ServiceNotificationPeriodValues selected=$ServiceNotificationPeriod}
-      </select>
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="ServiceNotificationOptions">{t}Service notification options{/t}</label>{$must}
-     </td>
-     <td>
-{render acl=$ServiceNotificationOptionsACL}
-      <select name="ServiceNotificationOptions" id="ServiceNotificationOptions">
-       {html_options options=$ServiceNotificationOptionsValues values=$ServiceNotificationOptionsValues selected=$ServiceNotificationOptions}
-      </select>
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="HostNotificationOptions">{t}Host notification options{/t}</label>{$must}
-     </td>
-     <td>
-{render acl=$HostNotificationOptionsACL}
-      <select name="HostNotificationOptions" id="HostNotificationOptions">
-       {html_options options=$HostNotificationOptionsValues values=$HostNotificationOptionsValues selected=$HostNotificationOptions }
-      </select>
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="NagiosPager">{t}Pager{/t}</label>
-     </td>
-     <td>
-{render acl=$NagiosPagerACL}
-      <input id="NagiosPager" name="NagiosPager" size=25 maxlength=65 value="{$NagiosPager}">
-{/render}
-     </td>
-    </tr>
-
-    <tr>
-     <td>
-      <label for="ServiceNotificationCommands">{t}Service notification commands{/t}</label>
-     </td>
-     <td>
-{render acl=$ServiceNotificationCommandsACL}
-      <input id="ServiceNotificationCommands" disabled name="ServiceNotificationCommands" size=25 maxlength=65  value="{$ServiceNotificationCommands}">
-{/render}
-     </td>
-    </tr>
-    <tr>
-     <td>
-      <label for="HostNotificationCommands">{t}Host notification commands{/t}</label>
-     </td>
-     <td>
-{render acl=$HostNotificationCommandsACL}
-      <input id="HostNotificationCommands" disabled name="HostNotificationCommands" size=25 maxlength=65  value="{$HostNotificationCommands}">
-{/render}
-     </td>
-    </tr>
-   </table>
-  </td>
-  <td style="border-left:1px solid #A0A0A0">
-   &nbsp;
-  </td>
-  <td style="width:100%; vertical-align:top;">
-   <h2> 
-    <img class="center" alt="" align="middle" src="images/rightarrow.png" />&nbsp;{t}Nagios authentification{/t}
-   </h2>
-   <table summary="">
-    <tr>
-     <td>
-{render acl=$AuthorizedSystemInformationACL}
-      <input type="checkbox" name="AuthorizedSystemInformation" value="1" {$AuthorizedSystemInformationCHK}>{t}view system informations{/t}
-{/render}
-     </td>
-    </tr>
-    <tr>
-     <td>
-{render acl=$AuthorizedConfigurationInformationACL}
-      <input type="checkbox" name="AuthorizedConfigurationInformation" value="1" 
-       {$AuthorizedConfigurationInformationCHK}>{t}view configuration information{/t}
-{/render}
-     </td>
-    </tr>
-       
-    <tr>
-     <td>
-{render acl=$AuthorizedSystemCommandsACL}
-      <input type="checkbox" name="AuthorizedSystemCommands" value="1" 
-       {$AuthorizedSystemCommandsCHK}>{t}trigger system commands{/t}
-{/render}
-     </td>
-    </tr>
-       
-    <tr>
-     <td>
-{render acl=$AuthorizedAllServicesACL}
-      <input type="checkbox" name="AuthorizedAllServices" value="1" 
-       {$AuthorizedAllServicesCHK}>{t}view all services{/t}
-{/render}
-     </td>
-    </tr>
-       
-    <tr>
-     <td>
-{render acl=$AuthorizedAllHostsACL}
-      <input type="checkbox" name="AuthorizedAllHosts" value="1" 
-       {$AuthorizedAllHostsCHK}>{t}view all hosts{/t}
-{/render}
-     </td> 
-    </tr>
-       
-    <tr>
-     <td>
-{render acl=$AuthorizedAllServiceCommandsACL}
-      <input type="checkbox" name="AuthorizedAllServiceCommands" value="1" 
-       {$AuthorizedAllServiceCommandsCHK}>{t}trigger all service commands{/t}
-{/render}
-     </td>
-    </tr>
-       
-    <tr>
-     <td>
-{render acl=$AuthorizedAllHostCommandsACL}
-      <input type="checkbox" name="AuthorizedAllHostCommands" value="1" 
-       {$AuthorizedAllHostCommandsCHK}>{t}trigger all host commands{/t}
-{/render}
-     </td>
-    </tr>
-   </table>
-  </td>
- </tr>
-</table>
-
-<input type="hidden" name="nagiosTab" value="nagiosTab">
-
-<!-- Place cursor -->
-<script language="JavaScript" type="text/javascript">
-  <!-- // First input field on page
-       focus_field('NagiosAlias');
-  -->
-</script>
-
diff --git a/gosa-plugins/nagios/personal/nagios/class_nagiosAccount.inc b/gosa-plugins/nagios/personal/nagios/class_nagiosAccount.inc
new file mode 100644 (file)
index 0000000..153f73c
--- /dev/null
@@ -0,0 +1,313 @@
+<?php
+
+/*! \brief   mail plugin
+  \author  Guillame Delecourt <guillaume@opensides.be>
+  \author  Benoit Mortier <benoit.mortier@opensides.be>
+  \author  Vincent Seynhaeve <vincent@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 */
+  var $plHeadline= "Nagios";
+  var $plDescription= "This does something";
+
+  /* CLI vars */
+  var $cli_summary= "Manage users nagios account";
+  var $cli_description= "Manage Account and autorization\nfor Nagios";
+  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+  /* plugin specific values */
+  var $NagiosAlias  = "";
+  var $NagiosPager  = "";
+  var $NagiosMail   = "";
+
+  var $HostNotificationOptions      = "";
+  var $HostNotificationPeriod       = "";
+  var $ServiceNotificationPeriod    = "";
+  var $ServiceNotitificationPeriod  = "";
+  var $HostNotificationCommands     = "";
+  var $ServiceNotificationCommands  = "";
+  var $HostNotitificationOptions    = "";
+  var $ServiceNotificationOptions   = "";
+
+  var $AuthorizedAllHosts                 = "unchecked";
+  var $AuthorizedAllServices              = "unchecked";
+  var $AuthorizedSystemCommands           = "unchecked";
+  var $AuthorizedAllHostCommands          = "unchecked";
+  var $AuthorizedAllServiceCommands       = "unchecked";
+  var $AuthorizedConfigurationInformation = "unchecked";
+  var $AuthorizedSystemInformation        = "unchecked";
+
+  /* attribute list for save action */
+
+  var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
+      "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
+      "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
+      "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
+      "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
+
+  var $is_chk_box = array("AuthorizedAllHosts","AuthorizedAllServices","AuthorizedSystemCommands",
+      "AuthorizedAllHostCommands","AuthorizedAllServiceCommands",
+      "AuthorizedConfigurationInformation","AuthorizedSystemInformation");
+
+  var $objectclasses= array("nagiosContact","nagiosAuth");
+
+  var $uid = "";
+  var $view_logged = FALSE;
+
+  /* constructor, if 'dn' is set, the node loads the given
+     'dn' from LDAP */
+  function nagiosAccount (&$config, $dn= NULL)
+  {
+    /* Configuration is fine, allways */
+    $this->config= $config;
+
+    plugin::plugin ($config, $dn);
+
+    /* Setting uid to default */
+    if(isset($this->attrs['uid'][0])){
+      $this->uid = $this->attrs['uid'][0];
+    }
+
+    /* Save initial account state */  
+    $this->initially_was_account= $this->is_account;
+  }
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+    /* Log view */
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","users/".get_class($this),$this->dn);
+    }
+
+    /* Load templating engine */
+    $smarty= get_smarty();
+    $display= "";
+
+    /* Do we need to flip is_account state? */
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
+    }    
+
+    /* 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_disable_header(_("Remove nagios account"),
+            _("This account has nagios features enabled. You can disable them by clicking below."));
+      } else {
+        $display= $this->show_enable_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
+        return($display);
+      }
+    }
+
+    /* Assign acls */
+    $tmp = $this->plInfo();
+    $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
+    foreach($tmp['plProvidedAcls'] as $acl => $desc){
+      $smarty->assign($acl."ACL",$this->getacl($acl,$SkipWrite));
+    }
+
+    /* Assign attributes an ACL to smarty */
+    foreach($this->attributes as $val) { 
+      $smarty->assign("$val", $this->$val);
+      if(in_array($val,$this->is_chk_box)){
+        if($this->$val == "checked"){
+          $smarty->assign($val."CHK", " checked ");
+        }else{
+          $smarty->assign($val."CHK", "");
+        }
+      }
+    }
+    $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
+    $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
+    $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
+    $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
+    $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
+    return ($display);
+  }
+
+  /* Save to LDAP */
+  function save()
+  {
+    $ldap= $this->config->get_ldap_link();
+
+    /* Call parents save to prepare $this->attrs */
+    plugin::save();
+
+    /* Adapt attributes if needed */
+    //$method= new $this->method($this->config);
+    //$id= $method->uattrib;
+    //$method->fixAttributesOnStore($this);
+
+    /* Write back to ldap */
+    $ldap->cd($this->dn);
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    /* Log last action */
+    if($this->initially_was_account){
+      new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }else{
+      new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }
+
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/nagios account 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("modify",array("uid" => $this->uid));
+      }
+    } else {
+      $this->handle_post_events("add", array("uid" => $this->uid));
+    }
+  }
+
+  function check()
+  {
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
+    $ldap= $this->config->get_ldap_link();
+    /* must: mail */
+    if ($this->NagiosAlias == ""){
+      $message[]= _("The required field 'NagiosAlias' is not set.");
+    }
+    if ($this->NagiosMail == ""){
+      $message[]= _("The required field 'NagiosMail' is not set.");
+    }
+    if ($this->is_template){
+      if (!tests::is_email($this->NagiosMail, TRUE)){
+        $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
+      }
+    } else {
+      if (!tests::is_email($this->NagiosMail)){
+        $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
+      }
+    }
+    return($message);
+  }
+
+
+  /* Use Save_object for every Post handling */
+  function save_object()
+  {
+    if (isset($_POST['nagiosTab'])){
+      /* Save ldap attributes */
+      plugin::save_object();
+
+      /* Specialhandling for checkboxes */
+      foreach($this->is_chk_box as $val){
+        if($this->acl_is_writeable($val)){
+          if(isset($_POST[$val])){
+            $this->$val = "checked";
+          }else{
+            $this->$val = "unchecked";
+          }
+        }
+      }
+    }
+  }
+
+  function remove_from_parent()
+  {
+    /* Cancel if there's nothing to do here */
+    if (!$this->initially_was_account){
+      return;
+    }
+
+    /* include global link_info */
+    $ldap= $this->config->get_ldap_link();
+
+    /* Remove and write to LDAP */
+    plugin::remove_from_parent();
+
+    /* Adapt attributes if needed */
+    //     $method= new $this->method($this->config);
+    //     $method->fixAttributesOnRemove($this);
+
+    @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
+        $this->attributes, "Save");
+    $ldap->cd($this->dn);
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    new log("view","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+
+    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/nagios account with dn '%s' failed."),$this->dn));
+
+    /* remove the entry from LDAP */
+    unset ($this->attrs['uid']);
+
+    /* Optionally execute a command after we're done */
+    $this->handle_post_events('remove',array("uid" => $this->uid));
+  }
+
+
+
+  static function plInfo()
+  {
+    return (array(
+          "plShortName"     => _("Nagios"),
+          "plDescription"   => _("Nagios account settings"),
+          "plSelfModify"    => TRUE,
+          "plDepends"       => array("user"),
+          "plPriority"      => 8,                                 // Position in tabs
+          "plSection"     => array("personal" => _("My account")),
+          "plCategory"    => array("users"),
+          "plOptions"       => array(),
+
+          "plProvidedAcls"  => array(
+
+            "NagiosAlias"                       =>  _("Alias"),
+            "NagiosPager"                       =>  _("Pager number"),
+            "NagiosMail"                        =>  _("Mail address"),
+
+            "HostNotificationCommands"          =>  _("Host notification commands"),
+            "HostNotificationOptions"           =>  _("Host notification options"),
+            "HostNotificationPeriod"            =>  _("Host notification period"),
+
+            "ServiceNotificationCommands"       =>  _("Service notification commands"),
+            "ServiceNotificationOptions"        =>  _("Service notification options"),
+            "ServiceNotificationPeriod"         =>  _("Service notification period"),
+
+            "AuthorizedAllHosts"                =>  _("View all hosts"),
+            "AuthorizedAllServices"             =>  _("View all services"),
+
+            "AuthorizedSystemCommands"          =>  _("Trigger system commands"),
+            "AuthorizedAllHostCommands"         =>  _("Trigger all host commands"),
+            "AuthorizedAllServiceCommands"      =>  _("Trigger all service commands"),
+
+            "AuthorizedConfigurationInformation"=>  _("View configuration information"),
+            "AuthorizedSystemInformation"       =>  _("View system informations"))
+      ));
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+
+?>
diff --git a/gosa-plugins/nagios/personal/nagios/main.inc b/gosa-plugins/nagios/personal/nagios/main.inc
new file mode 100644 (file)
index 0000000..8414b16
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+/*
+   This code is part of GOsa (https://gosa.gonicus.de)
+   Copyright (C) 2005  Benoit Mortier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+$display    = "";
+$lock_msg   = "";
+
+if (!$remove_lock){
+  /* Reset requested? */
+  if (isset($_POST['edit_cancel']) || 
+      (isset($_GET['reset']) && $_GET['reset'] == 1)){
+    del_lock ($ui->dn);
+    session::un_set ('edit');
+    session::un_set ('nagiosAccount');
+  }
+
+  /* Create mail object on demand */
+  if (!session::is_set('nagiosAccount') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
+    $nagiosAccount= new nagiosAccount ($config, $ui->dn);
+    $nagiosAccount->enable_CSN_check();
+    $nagiosAccount->set_acl_base($ui->dn);
+    $nagiosAccount->set_acl_category("users");
+    session::set('nagiosAccount',$nagiosAccount);
+  }
+  $nagiosAccount = session::get('nagiosAccount');
+
+  /* save changes back to object */
+  if (session::is_set('edit')){
+    $nagiosAccount->save_object ();
+  }
+
+  /* Enter edit mode? */
+  if (isset($_POST['edit'])){
+
+    /* Check locking */
+    if (($username= get_lock($ui->dn)) != ""){
+      session::set('back_plugin',$plug);
+      session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
+      $lock_msg =  gen_locked_message ($username, $ui->dn);
+
+    }else{
+
+      /* Lock the current entry */
+      add_lock ($ui->dn, $ui->dn);
+      session::set('dn',$ui->dn);
+      session::set('edit',TRUE);
+    }
+  }
+
+  /* save changes to LDAP and disable edit mode */
+  if (isset($_POST['edit_finish'])){
+
+    /* Perform checks */
+    $message= $nagiosAccount->check ();
+
+    /* No errors, save object */
+    if (count ($message) == 0){
+      $nagiosAccount->save ();
+      del_lock ($ui->dn);
+      session::un_set ('edit');
+
+      /* Remove object */
+      session::un_set ('nagiosAccount');
+    } else {
+      /* Errors found, show message */
+      show_errors ($message);
+    }
+  }
+
+  /* Execute formular */
+  if($lock_msg){
+    $display.= $lock_msg;
+  }else{
+    $display.= $nagiosAccount->execute ();
+  }
+
+  /* Store changes  in session */
+  if (session::is_set('edit')){
+    session::set('nagiosAccount',$nagiosAccount);
+  }
+
+  $info= "";
+  /* Show page footer depending on the mode */
+  if ($nagiosAccount->is_account && empty($lock_msg)){
+    $display.= "<p class=\"plugbottom\">";
+
+    /* Are we in edit mode? */
+    if (session::is_set('edit')){
+      $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
+      $display.= "&nbsp;";
+      $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
+      $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
+             "\"> ".$ui->dn."&nbsp;";
+    } else {
+      $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
+             "\"> ".$ui->dn."&nbsp;";
+
+      if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/nagiosAccount"))){
+        $info.= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png').
+          "\"> "._("Click the 'Edit' button below to change informations in this dialog");
+        $display.= "<input type=submit name=\"edit\" value=\""._("Edit")."\">\n";
+      }
+      $display.= "<input type=\"hidden\" name=\"ignore\">\n";
+    }
+    $display.= "</p>\n";
+  }
+
+  /* Page header*/
+  $display= print_header(get_template_path('images/monitoring.png'), _("Nagios settings"), $info).$display;
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/nagios/personal/nagios/nagios.tpl b/gosa-plugins/nagios/personal/nagios/nagios.tpl
new file mode 100644 (file)
index 0000000..e77529a
--- /dev/null
@@ -0,0 +1,192 @@
+<table summary="" style="width:100%; vertical-align:top; text-align:left;" cellpadding="0" border="0">
+ <tr>
+  <td style="width:50%; vertical-align:top;">
+   <h2>
+    <img class="center" alt="" align="middle" src="images/rightarrow.png" />&nbsp;{t}Nagios Account{/t}</h2>
+   <table summary="">
+    <tr>
+     <td><label for="NagiosAlias">{t}Alias{/t}</label>{$must}</td>
+     <td>
+{render acl=$NagiosAliasACL}
+      <input id="NagiosAlias" name="NagiosAlias" size=25 maxlength=65 value="{$NagiosAlias}">
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td><label for="NagiosMail">{t}Mail address{/t}</label>{$must}</td>
+     <td>
+{render acl=$NagiosMailACL}
+      <input id="NagiosMail" name="NagiosMail" size=25 maxlength=65 value="{$NagiosMail}">
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="HostNotificationPeriod">{t}Host notification period{/t}</label>{$must}
+     </td>
+     <td>
+{render acl=$HostNotificationPeriodACL}
+      <select name="HostNotificationPeriod" id="HostNotificationPeriod">
+       {html_options options=$HostNotificationPeriodValues values=$HostNotificationPeriodValues selected=$HostNotificationPeriod }
+      </select>
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="ServiceNotificationPeriod">{t}Service notification period{/t}</label>{$must}
+     </td>
+     <td>
+{render acl=$ServiceNotificationPeriodACL}
+      <select name="ServiceNotificationPeriod" id="ServiceNotificationPeriod">
+       {html_options options=$ServiceNotificationPeriodValues values=$ServiceNotificationPeriodValues selected=$ServiceNotificationPeriod}
+      </select>
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="ServiceNotificationOptions">{t}Service notification options{/t}</label>{$must}
+     </td>
+     <td>
+{render acl=$ServiceNotificationOptionsACL}
+      <select name="ServiceNotificationOptions" id="ServiceNotificationOptions">
+       {html_options options=$ServiceNotificationOptionsValues values=$ServiceNotificationOptionsValues selected=$ServiceNotificationOptions}
+      </select>
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="HostNotificationOptions">{t}Host notification options{/t}</label>{$must}
+     </td>
+     <td>
+{render acl=$HostNotificationOptionsACL}
+      <select name="HostNotificationOptions" id="HostNotificationOptions">
+       {html_options options=$HostNotificationOptionsValues values=$HostNotificationOptionsValues selected=$HostNotificationOptions }
+      </select>
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="NagiosPager">{t}Pager{/t}</label>
+     </td>
+     <td>
+{render acl=$NagiosPagerACL}
+      <input id="NagiosPager" name="NagiosPager" size=25 maxlength=65 value="{$NagiosPager}">
+{/render}
+     </td>
+    </tr>
+
+    <tr>
+     <td>
+      <label for="ServiceNotificationCommands">{t}Service notification commands{/t}</label>
+     </td>
+     <td>
+{render acl=$ServiceNotificationCommandsACL}
+      <input id="ServiceNotificationCommands" disabled name="ServiceNotificationCommands" size=25 maxlength=65  value="{$ServiceNotificationCommands}">
+{/render}
+     </td>
+    </tr>
+    <tr>
+     <td>
+      <label for="HostNotificationCommands">{t}Host notification commands{/t}</label>
+     </td>
+     <td>
+{render acl=$HostNotificationCommandsACL}
+      <input id="HostNotificationCommands" disabled name="HostNotificationCommands" size=25 maxlength=65  value="{$HostNotificationCommands}">
+{/render}
+     </td>
+    </tr>
+   </table>
+  </td>
+  <td style="border-left:1px solid #A0A0A0">
+   &nbsp;
+  </td>
+  <td style="width:100%; vertical-align:top;">
+   <h2> 
+    <img class="center" alt="" align="middle" src="images/rightarrow.png" />&nbsp;{t}Nagios authentification{/t}
+   </h2>
+   <table summary="">
+    <tr>
+     <td>
+{render acl=$AuthorizedSystemInformationACL}
+      <input type="checkbox" name="AuthorizedSystemInformation" value="1" {$AuthorizedSystemInformationCHK}>{t}view system informations{/t}
+{/render}
+     </td>
+    </tr>
+    <tr>
+     <td>
+{render acl=$AuthorizedConfigurationInformationACL}
+      <input type="checkbox" name="AuthorizedConfigurationInformation" value="1" 
+       {$AuthorizedConfigurationInformationCHK}>{t}view configuration information{/t}
+{/render}
+     </td>
+    </tr>
+       
+    <tr>
+     <td>
+{render acl=$AuthorizedSystemCommandsACL}
+      <input type="checkbox" name="AuthorizedSystemCommands" value="1" 
+       {$AuthorizedSystemCommandsCHK}>{t}trigger system commands{/t}
+{/render}
+     </td>
+    </tr>
+       
+    <tr>
+     <td>
+{render acl=$AuthorizedAllServicesACL}
+      <input type="checkbox" name="AuthorizedAllServices" value="1" 
+       {$AuthorizedAllServicesCHK}>{t}view all services{/t}
+{/render}
+     </td>
+    </tr>
+       
+    <tr>
+     <td>
+{render acl=$AuthorizedAllHostsACL}
+      <input type="checkbox" name="AuthorizedAllHosts" value="1" 
+       {$AuthorizedAllHostsCHK}>{t}view all hosts{/t}
+{/render}
+     </td> 
+    </tr>
+       
+    <tr>
+     <td>
+{render acl=$AuthorizedAllServiceCommandsACL}
+      <input type="checkbox" name="AuthorizedAllServiceCommands" value="1" 
+       {$AuthorizedAllServiceCommandsCHK}>{t}trigger all service commands{/t}
+{/render}
+     </td>
+    </tr>
+       
+    <tr>
+     <td>
+{render acl=$AuthorizedAllHostCommandsACL}
+      <input type="checkbox" name="AuthorizedAllHostCommands" value="1" 
+       {$AuthorizedAllHostCommandsCHK}>{t}trigger all host commands{/t}
+{/render}
+     </td>
+    </tr>
+   </table>
+  </td>
+ </tr>
+</table>
+
+<input type="hidden" name="nagiosTab" value="nagiosTab">
+
+<!-- Place cursor -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+       focus_field('NagiosAlias');
+  -->
+</script>
+