Code

Replaced 'show_header' with 'show_disable_header' && 'show_enable_header'
[gosa.git] / plugins / personal / nagios / class_nagiosAccount.inc
1 <?php
3 /*! \brief   mail plugin
4   \author  Guillame Delecourt <guillaume@opensides.be>
5   \author  Benoit Mortier <benoit.mortier@opensides.be>
6   \author  Vincent Seynhaeve <vincent@opensides.be>  
7   \version 1.00
8   \date    25.09.2005
10   This class provides the functionality to read and write all attributes
11   relevant for nagiosAccount from/to the LDAP. It does syntax checking
12   and displays the formulars required.
13  */
15 class nagiosAccount extends plugin
16 {
17   /* Definitions */
18   var $plHeadline= "Nagios";
19   var $plDescription= "This does something";
21   /* CLI vars */
22   var $cli_summary= "Manage users nagios account";
23   var $cli_description= "Manage Account and autorization\nfor Nagios";
24   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
26   /* plugin specific values */
27   var $NagiosAlias  = "";
28   var $NagiosPager  = "";
29   var $NagiosMail   = "";
31   var $HostNotificationOptions      = "";
32   var $HostNotificationPeriod       = "";
33   var $ServiceNotificationPeriod    = "";
34   var $ServiceNotitificationPeriod  = "";
35   var $HostNotificationCommands     = "";
36   var $ServiceNotificationCommands  = "";
37   var $HostNotitificationOptions    = "";
38   var $ServiceNotificationOptions   = "";
40   var $AuthorizedAllHosts                 = "unchecked";
41   var $AuthorizedAllServices              = "unchecked";
42   var $AuthorizedSystemCommands           = "unchecked";
43   var $AuthorizedAllHostCommands          = "unchecked";
44   var $AuthorizedAllServiceCommands       = "unchecked";
45   var $AuthorizedConfigurationInformation = "unchecked";
46   var $AuthorizedSystemInformation        = "unchecked";
48   /* attribute list for save action */
50   var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
51       "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
52       "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
53       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
54       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
56   var $is_chk_box = array("AuthorizedAllHosts","AuthorizedAllServices","AuthorizedSystemCommands",
57       "AuthorizedAllHostCommands","AuthorizedAllServiceCommands",
58       "AuthorizedConfigurationInformation","AuthorizedSystemInformation");
60   var $objectclasses= array("nagiosContact","nagiosAuth");
62   /* constructor, if 'dn' is set, the node loads the given
63      'dn' from LDAP */
64   function nagiosAccount ($config, $dn= NULL)
65   {
66     /* Configuration is fine, allways */
67     $this->config= $config;
69     plugin::plugin ($config, $dn);
71     /* Save initial account state */  
72     $this->initially_was_account= $this->is_account;
73   }
75   function execute()
76   {
77     /* Call parent execute */
78     plugin::execute();
80     /* Load templating engine */
81     $smarty= get_smarty();
82     $display= "";
84     /* Do we need to flip is_account state? */
85     if (isset($_POST['modify_state'])){
86       $this->is_account= !$this->is_account;
87     }
89     /* Do we represent a valid account? */
90     if (!$this->is_account && $this->parent == NULL){
91       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
92         _("This account has no nagios extensions.")."</b>";
94       $display.= back_to_main();
95       return ($display);
96     }
98     /* Show tab dialog headers */
99     if ($this->parent != NULL){
100       if ($this->is_account){
101         $display= $this->show_disable_header(_("Remove nagios account"),
102             _("This account has nagios features enabled. You can disable them by clicking below."));
103       } else {
104         $display= $this->show_enable_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
105         return($display);
106       }
107     }
109     /* Assign attributes an ACL to smarty */
110     foreach($this->attributes as $val) { 
111       $smarty->assign("$val", $this->$val);
112       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
113       if(in_array($val,$this->is_chk_box)){
114         if($this->$val == "checked"){
115           $smarty->assign($val."CHK", " checked ");
116         }else{
117           $smarty->assign($val."CHK", "");
118         }
119       }
120     }
121     $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
122     $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
123     $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
124     $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
125     $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
126     return ($display);
127   }
129   /* Save to LDAP */
130   function save()
131   {
132     $ldap= $this->config->get_ldap_link();
134     /* Call parents save to prepare $this->attrs */
135     plugin::save();
137     /* Adapt attributes if needed */
138     //$method= new $this->method($this->config);
139     //$id= $method->uattrib;
140     //$method->fixAttributesOnStore($this);
142     /* Write back to ldap */
143     $ldap->cd($this->dn);
144     $this->cleanup();
145     $ldap->modify ($this->attrs); 
147     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/nagios account with dn '%s' failed."),$this->dn));
149     /* Optionally execute a command after we're done */
150     if ($this->initially_was_account == $this->is_account){
151       if ($this->is_modified){
152         $this->handle_post_events("modify");
153       }
154     } else {
155       $this->handle_post_events("add");
156     }
157   }
159   function check()
160   {
161     /* Call common method to give check the hook */
162     $message= plugin::check();
164     $ldap= $this->config->get_ldap_link();
165     /* must: mail */
166     if ($this->NagiosAlias == ""){
167       $message[]= _("The required field 'NagiosAlias' is not set.");
168     }
169     if ($this->NagiosMail == ""){
170       $message[]= _("The required field 'NagiosMail' is not set.");
171     }
172     if ($this->is_template){
173       if (!is_email($this->NagiosMail, TRUE)){
174         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
175       }
176     } else {
177       if (!is_email($this->NagiosMail)){
178         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
179       }
180     }
181     return($message);
182   }
185   /* Use Save_object for every Post handling */
186   function save_object()
187   {
188     if (isset($_POST['nagiosTab'])){
189       /* Save ldap attributes */
190       plugin::save_object();
192       /* Specialhandling for checkboxes */
193       foreach($this->is_chk_box as $val){
194         if(isset($_POST[$val])){
195           $this->$val = "checked";
196         }else{
197           $this->$val = "unchecked";
198         }
199       }
200     }
201   }
203   function remove_from_parent()
204   {
205     /* Cancel if there's nothing to do here */
206     if (!$this->initially_was_account){
207       return;
208     }
210     /* include global link_info */
211     $ldap= $this->config->get_ldap_link();
213     /* Remove and write to LDAP */
214     plugin::remove_from_parent();
216     /* Adapt attributes if needed */
217     //     $method= new $this->method($this->config);
218     //     $method->fixAttributesOnRemove($this);
220     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
221         $this->attributes, "Save");
222     $ldap->cd($this->dn);
223     $this->cleanup();
224     $ldap->modify ($this->attrs); 
226     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/nagios account with dn '%s' failed."),$this->dn));
228     /* remove the entry from LDAP */
229     unset ($this->attrs['uid']);
231     /* Optionally execute a command after we're done */
232     $this->handle_post_events('remove');
233   }
237   function plInfo()
238   {
239     return (array(
240           "plShortName"     => _("Nagios"),
241           "plDescription"   => _("Nagios account settings"),
242           "plSelfModify"    => TRUE,
243           "plDepends"       => array("user"),
244           "plPriority"      => 8,                                 // Position in tabs
245           "plSection"       => "personal",                        // This belongs to personal
246           "plCategory"      => array("users"),                   
247           "plOptions"       => array(),
249           "plProvidedAcls"  => array(
251             "NagiosAlias"                       =>  _("Alias"),
252             "NagiosPager"                       =>  _("Pager number"),
253             "NagiosMail"                        =>  _("Mail address"),
255             "HostNotificationCommands"          =>  _("Host notification commands"),
256             "HostNotificationOptions"           =>  _("Host notification options"),
257             "HostNotificationPeriod"            =>  _("Host notification period"),
259             "ServiceNotificationCommands"       =>  _("Service notification commands"),
260             "ServiceNotificationOptions"        =>  _("Service notification options"),
261             "ServiceNotificationPeriod"         =>  _("Service notification period"),
263             "AuthorizedAllHosts"                =>  _("View all hosts"),
264             "AuthorizedAllServices"             =>  _("View all services"),
266             "AuthorizedSystemCommands"          =>  _("Trigger system commands"),
267             "AuthorizedAllHostCommands"         =>  _("Trigger all host commands"),
268             "AuthorizedAllServiceCommands"      =>  _("Trigger all service commands"),
270             "AuthorizedConfigurationInformation"=>  _("View configuration information"),
271             "AuthorizedSystemInformation"       =>  _("View system informations"))
272       ));
273   }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
278 ?>