1 <?php
3 /*! \brief mail plugin
4 \author Guillame Delecourt <guillaume@opensides.be>
5 \author Benoit Mortier <benoit.mortier@opensides.be>
6 \version 1.00
7 \date 25.09.2005
9 This class provides the functionality to read and write all attributes
10 relevant for nagiosAccount from/to the LDAP. It does syntax checking
11 and displays the formulars required.
12 */
14 class nagiosAccount extends plugin
15 {
16 /* Definitions */
17 var $plHeadline= "Nagios";
18 var $plDescription= "This does something";
20 /* CLI vars */
21 var $cli_summary= "Manage users nagios account";
22 var $cli_description= "Manage Account and autorization\nfor Nagios";
23 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
25 /* plugin specific values */
26 var $NagiosAlias= "";
27 var $NagiosPager= "";
28 var $NagiosMail= "";
29 var $HostNotificationPeriod= "";
30 var $ServiceNotitificationPeriod= "";
31 var $HostNotificationCommands= "";
32 var $ServiceNotificationCommands= "";
33 var $HostNotitificationOptions= "";
34 var $ServiceNotificationOptions= "";
35 var $HostNotificationPeriod= "";
36 var $ServiceNotificationPeriod= "";
38 var $AuthorizedAllHosts= "";
39 var $AuthorizedAllServices= "";
40 var $AuthorizedSystemCommands= "";
41 var $AuthorizedAllHostCommands= "";
42 var $AuthorizedAllServiceCommands= "";
43 var $AuthorizedConfigurationInformation= "";
44 var $AuthorizedSystemInformation= "";
46 /* attribute list for save action */
48 var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
49 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
50 "HostNotificationOptions", "ServiceNotificationOptions", "HostNotificationPeriod",
51 "ServiceNotificationPeriod", "AuthorizedAllHosts", "AuthorizedAllServices",
52 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
53 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
55 var $objectclasses= array("nagiosContact");
57 /* constructor, if 'dn' is set, the node loads the given
58 'dn' from LDAP */
59 function nagiosAccount ($config, $dn= NULL)
60 {
61 /* Configuration is fine, allways */
62 $this->config= $config;
64 plugin::plugin ($config, $dn);
66 /* Save initial account state */
67 $this->initially_was_account= $this->is_account;
68 }
70 function execute()
71 {
72 /* Load templating engine */
73 $smarty= get_smarty();
74 $display= "";
76 /* Do we need to flip is_account state? */
77 if (isset($_POST['modify_state'])){
78 $this->is_account= !$this->is_account;
79 }
81 /* Do we represent a valid account? */
82 if (!$this->is_account && $this->parent == NULL){
83 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
84 _("This account has no nagios extensions.")."</b>";
86 $display.= back_to_main();
87 return ($display);
88 }
90 /* Show tab dialog headers */
91 if ($this->parent != NULL){
92 if ($this->is_account){
93 $display= $this->show_header(_("Remove nagios account"),
94 _("This account has nagios features enabled. You can disable them by clicking below."));
95 } else {
96 $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
97 return($display);
98 }
99 }
100 $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
101 return ($display);
102 }
104 /* Save to LDAP */
105 function save()
106 {
107 $ldap= $this->config->get_ldap_link();
109 /* Call parents save to prepare $this->attrs */
110 plugin::save();
113 /* Write back to ldap */
114 $ldap->cd($this->dn);
115 $ldap->modify($this->attrs);
116 show_ldap_error($ldap->get_error());
118 /* Optionally execute a command after we're done */
119 if ($this->initially_was_account == $this->is_account){
120 if ($this->is_modified){
121 $this->handle_post_events("modify");
122 }
123 } else {
124 $this->handle_post_events("add");
125 }
127 }
129 function save_object()
130 {
132 if (!$this->is_account && ($_POST['nagiosAuth'] == "B" || $_POST['nagiosContact'] == "B")) {
133 $this->is_account= TRUE;
134 }
135 else {
136 $this->is_account= FALSE;
137 }
138 plugin::save_object();
139 }
141 function remove_from_parent()
142 {
143 /* Cancel if there's nothing to do here */
144 if (!$this->initially_was_account){
145 return;
146 }
148 plugin::remove_from_parent();
149 $ldap= $this->config->get_ldap_link();
151 $ldap->cd($this->dn);
152 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
153 $this->attributes, "Save");
154 $ldap->modify($this->attrs);
155 show_ldap_error($ldap->get_error());
157 /* Optionally execute a command after we're done */
158 $this->handle_post_events('remove');
159 }
161 }
163 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
165 ?>