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= "";
36 var $AuthorizedAllHosts= "";
37 var $AuthorizedAllServices= "";
38 var $AuthorizedSystemCommands= "";
39 var $AuthorizedAllHostCommands= "";
40 var $AuthorizedAllServiceCommands= "";
41 var $AuthorizedConfigurationInformation= "";
42 var $AuthorizedSystemInformation= "";
44 /* attribute list for save action */
46 var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
47 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
48 "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
49 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
50 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
52 var $objectclasses= array("nagiosContact");
54 /* constructor, if 'dn' is set, the node loads the given
55 'dn' from LDAP */
56 function nagiosAccount ($config, $dn= NULL)
57 {
58 /* Configuration is fine, allways */
59 $this->config= $config;
61 plugin::plugin ($config, $dn);
63 /* Save initial account state */
64 $this->initially_was_account= $this->is_account;
65 }
67 function execute()
68 {
69 /* Load templating engine */
70 $smarty= get_smarty();
71 $display= "";
73 /* Do we need to flip is_account state? */
74 if (isset($_POST['modify_state'])){
75 $this->is_account= !$this->is_account;
76 }
78 /* Do we represent a valid account? */
79 if (!$this->is_account && $this->parent == NULL){
80 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
81 _("This account has no nagios extensions.")."</b>";
83 $display.= back_to_main();
84 return ($display);
85 }
87 /* Show tab dialog headers */
88 if ($this->parent != NULL){
89 if ($this->is_account){
90 $display= $this->show_header(_("Remove nagios account"),
91 _("This account has nagios features enabled. You can disable them by clicking below."));
92 } else {
93 $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
94 return($display);
95 }
96 }
98 foreach(array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
99 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
100 "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
101 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
102 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation") as $val) {
104 $smarty->assign("$val", $this->$val);
105 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
106 }
108 $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
109 return ($display);
111 }
113 /* Save to LDAP */
114 function save()
115 {
116 $ldap= $this->config->get_ldap_link();
118 /* Call parents save to prepare $this->attrs */
119 plugin::save();
121 /* Adapt attributes if needed */
122 //$method= new $this->method($this->config);
123 //$id= $method->uattrib;
124 //$method->fixAttributesOnStore($this);
127 /* Write back to ldap */
128 $ldap->cd($this->dn);
129 $ldap->modify($this->attrs);
130 show_ldap_error($ldap->get_error());
132 /* Optionally execute a command after we're done */
133 if ($this->initially_was_account == $this->is_account){
134 if ($this->is_modified){
135 $this->handle_post_events("modify");
136 }
137 } else {
138 $this->handle_post_events("add");
139 }
141 }
143 function check()
144 {
145 }
147 function save_object()
148 {
150 if (isset($_POST['nagiosTab'])){
151 /* Save ldap attributes */
152 plugin::save_object();
153 }
154 }
156 function remove_from_parent()
157 {
158 /* Cancel if there's nothing to do here */
159 if (!$this->initially_was_account){
160 return;
161 }
163 /* include global link_info */
164 $ldap= $this->config->get_ldap_link();
166 /* Remove and write to LDAP */
167 plugin::remove_from_parent();
169 /* Adapt attributes if needed */
170 $method= new $this->method($this->config);
171 $method->fixAttributesOnRemove($this);
174 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
175 $this->attributes, "Save");
176 $ldap->cd($this->dn);
177 $ldap->modify($this->attrs);
178 show_ldap_error($ldap->get_error());
180 /* remove the entry from LDAP */
181 unset ($this->attrs['uid']);
183 /* Optionally execute a command after we're done */
184 $this->handle_post_events('remove');
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>