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= "";
30 var $HostNotificationPeriod= "";
31 var $ServiceNotitificationPeriod= "";
32 var $HostNotificationCommands= "";
33 var $ServiceNotificationCommands= "";
34 var $HostNotitificationOptions= "";
35 var $ServiceNotificationOptions= "";
37 var $AuthorizedAllHosts= "";
38 var $AuthorizedAllServices= "";
39 var $AuthorizedSystemCommands= "";
40 var $AuthorizedAllHostCommands= "";
41 var $AuthorizedAllServiceCommands= "";
42 var $AuthorizedConfigurationInformation= "";
43 var $AuthorizedSystemInformation= "";
45 /* attribute list for save action */
47 var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
48 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
49 "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
50 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
51 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
53 var $objectclasses= array("nagiosContact","nagiosAuth");
55 /* constructor, if 'dn' is set, the node loads the given
56 'dn' from LDAP */
57 function nagiosAccount ($config, $dn= NULL)
58 {
59 /* Configuration is fine, allways */
60 $this->config= $config;
62 plugin::plugin ($config, $dn);
64 /* Save initial account state */
65 $this->initially_was_account= $this->is_account;
66 }
68 function execute()
69 {
70 /* Load templating engine */
71 $smarty= get_smarty();
72 $display= "";
74 /* Do we need to flip is_account state? */
75 if (isset($_POST['modify_state'])){
76 $this->is_account= !$this->is_account;
77 }
79 /* Do we represent a valid account? */
80 if (!$this->is_account && $this->parent == NULL){
81 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
82 _("This account has no nagios extensions.")."</b>";
84 $display.= back_to_main();
85 return ($display);
86 }
88 /* Show tab dialog headers */
89 if ($this->parent != NULL){
90 if ($this->is_account){
91 $display= $this->show_header(_("Remove nagios account"),
92 _("This account has nagios features enabled. You can disable them by clicking below."));
93 } else {
94 $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
95 return($display);
96 }
97 }
99 foreach(array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
100 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
101 "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
102 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
103 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation") as $val) {
105 $smarty->assign("$val", $this->$val);
106 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
107 }
108 $smarty->assign('ServiceNotificationOptionsValues',array("d,u,r,v" ,"d,u,r" ,"d,u"));
109 $smarty->assign('HostNotificationOptionsValues',array("w,u,c,r" ,"w,u,c" ,"c,w"));
112 $smarty->assign('ServiceNotificationPeriodValues',array("24x7" ,"24x5" ,"8x5"));
113 $smarty->assign('HostNotificationPeriodValues',array("24x7" ,"24x5" ,"8x5"));
115 $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
116 return ($display);
118 }
120 /* Save to LDAP */
121 function save()
122 {
123 $ldap= $this->config->get_ldap_link();
125 /* Call parents save to prepare $this->attrs */
126 plugin::save();
128 /* Adapt attributes if needed */
129 //$method= new $this->method($this->config);
130 //$id= $method->uattrib;
131 //$method->fixAttributesOnStore($this);
133 $check="unchecked";
134 if(isset($_POST['AuthorizedSystemInformation'])){$check="checked";}$this->attrs['AuthorizedSystemInformation']=$check;
135 $check="unchecked";
136 if(isset($_POST['AuthorizedConfigurationInformation'])){$check="checked";}$this->attrs['AuthorizedConfigurationInformation']=$check;
137 $check="unchecked";
138 if(isset($_POST['AuthorizedSystemCommands'])){$check="checked";}$this->attrs['AuthorizedSystemCommands']=$check;
139 $check="unchecked";
140 if(isset($_POST['AuthorizedAllServices'])){$check="checked";}$this->attrs['AuthorizedAllServices']=$check;
141 $check="unchecked";
142 if(isset($_POST['AuthorizedAllHosts'])){$check="checked";}$this->attrs['AuthorizedAllHosts']=$check;
143 $check="unchecked";
144 if(isset($_POST['AuthorizedAllServiceCommands'])){$check="checked";}$this->attrs['AuthorizedAllServiceCommands']=$check;
145 $check="unchecked";
146 if(isset($_POST['AuthorizedAllHostCommands'])){$check="checked";}$this->attrs['AuthorizedAllHostCommands']=$check;
147 /* Write back to ldap */
148 $ldap->cd($this->dn);
149 $ldap->modify($this->attrs);
150 show_ldap_error($ldap->get_error());
152 /* Optionally execute a command after we're done */
153 if ($this->initially_was_account == $this->is_account){
154 if ($this->is_modified){
155 $this->handle_post_events("modify");
156 }
157 } else {
158 $this->handle_post_events("add");
159 }
161 }
163 function check()
164 {
165 $message= array();
166 $ldap= $this->config->get_ldap_link();
167 /* must: mail */
168 if ($this->NagiosAlias == ""){
169 $message[]= _("The required field 'NagiosAlias' is not set.");
170 }
171 if ($this->NagiosMail == ""){
172 $message[]= _("The required field 'NagiosMail' is not set.");
173 }
174 if ($this->is_template){
175 if (!is_email($this->NagiosMail, TRUE)){
176 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
177 }
178 } else {
179 if (!is_email($this->NagiosMail)){
180 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
181 }
182 }
183 return($message);
184 }
186 function save_object()
187 {
189 if (isset($_POST['nagiosTab'])){
190 /* Save ldap attributes */
191 plugin::save_object();
192 }
193 }
195 function remove_from_parent()
196 {
197 /* Cancel if there's nothing to do here */
198 if (!$this->initially_was_account){
199 return;
200 }
202 /* include global link_info */
203 $ldap= $this->config->get_ldap_link();
205 /* Remove and write to LDAP */
206 plugin::remove_from_parent();
208 /* Adapt attributes if needed */
209 // $method= new $this->method($this->config);
210 // $method->fixAttributesOnRemove($this);
213 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
214 $this->attributes, "Save");
215 $ldap->cd($this->dn);
216 $ldap->modify($this->attrs);
217 show_ldap_error($ldap->get_error());
219 /* remove the entry from LDAP */
220 unset ($this->attrs['uid']);
222 /* Optionally execute a command after we're done */
223 $this->handle_post_events('remove');
224 }
226 }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>