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 /* Call parent execute */
71 plugin::execute();
73 /* Load templating engine */
74 $smarty= get_smarty();
75 $display= "";
77 /* Do we need to flip is_account state? */
78 if (isset($_POST['modify_state'])){
79 $this->is_account= !$this->is_account;
80 }
82 /* Do we represent a valid account? */
83 if (!$this->is_account && $this->parent == NULL){
84 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
85 _("This account has no nagios extensions.")."</b>";
87 $display.= back_to_main();
88 return ($display);
89 }
91 /* Show tab dialog headers */
92 if ($this->parent != NULL){
93 if ($this->is_account){
94 $display= $this->show_header(_("Remove nagios account"),
95 _("This account has nagios features enabled. You can disable them by clicking below."));
96 } else {
97 $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
98 return($display);
99 }
100 }
102 foreach(array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
103 "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
104 "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
105 "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
106 "AuthorizedConfigurationInformation", "AuthorizedSystemInformation") as $val) {
108 $smarty->assign("$val", $this->$val);
109 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
110 }
111 $smarty->assign('ServiceNotificationOptionsValues',array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
112 $smarty->assign('HostNotificationOptionsValues',array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
115 $smarty->assign('ServiceNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
116 $smarty->assign('HostNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
118 $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
119 return ($display);
121 }
123 /* Save to LDAP */
124 function save()
125 {
126 $ldap= $this->config->get_ldap_link();
128 /* Call parents save to prepare $this->attrs */
129 plugin::save();
131 /* Adapt attributes if needed */
132 //$method= new $this->method($this->config);
133 //$id= $method->uattrib;
134 //$method->fixAttributesOnStore($this);
136 $check="unchecked";
137 if(isset($_POST['AuthorizedSystemInformation'])){$check="checked";}$this->attrs['AuthorizedSystemInformation']=$check;
138 $check="unchecked";
139 if(isset($_POST['AuthorizedConfigurationInformation'])){$check="checked";}$this->attrs['AuthorizedConfigurationInformation']=$check;
140 $check="unchecked";
141 if(isset($_POST['AuthorizedSystemCommands'])){$check="checked";}$this->attrs['AuthorizedSystemCommands']=$check;
142 $check="unchecked";
143 if(isset($_POST['AuthorizedAllServices'])){$check="checked";}$this->attrs['AuthorizedAllServices']=$check;
144 $check="unchecked";
145 if(isset($_POST['AuthorizedAllHosts'])){$check="checked";}$this->attrs['AuthorizedAllHosts']=$check;
146 $check="unchecked";
147 if(isset($_POST['AuthorizedAllServiceCommands'])){$check="checked";}$this->attrs['AuthorizedAllServiceCommands']=$check;
148 $check="unchecked";
149 if(isset($_POST['AuthorizedAllHostCommands'])){$check="checked";}$this->attrs['AuthorizedAllHostCommands']=$check;
150 /* Write back to ldap */
151 $ldap->cd($this->dn);
152 $ldap->modify($this->attrs);
153 show_ldap_error($ldap->get_error());
155 /* Optionally execute a command after we're done */
156 if ($this->initially_was_account == $this->is_account){
157 if ($this->is_modified){
158 $this->handle_post_events("modify");
159 }
160 } else {
161 $this->handle_post_events("add");
162 }
164 }
166 function check()
167 {
168 $message= array();
169 $ldap= $this->config->get_ldap_link();
170 /* must: mail */
171 if ($this->NagiosAlias == ""){
172 $message[]= _("The required field 'NagiosAlias' is not set.");
173 }
174 if ($this->NagiosMail == ""){
175 $message[]= _("The required field 'NagiosMail' is not set.");
176 }
177 if ($this->is_template){
178 if (!is_email($this->NagiosMail, TRUE)){
179 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
180 }
181 } else {
182 if (!is_email($this->NagiosMail)){
183 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
184 }
185 }
186 return($message);
187 }
189 function save_object()
190 {
192 if (isset($_POST['nagiosTab'])){
193 /* Save ldap attributes */
194 plugin::save_object();
195 }
196 }
198 function remove_from_parent()
199 {
200 /* Cancel if there's nothing to do here */
201 if (!$this->initially_was_account){
202 return;
203 }
205 /* include global link_info */
206 $ldap= $this->config->get_ldap_link();
208 /* Remove and write to LDAP */
209 plugin::remove_from_parent();
211 /* Adapt attributes if needed */
212 // $method= new $this->method($this->config);
213 // $method->fixAttributesOnRemove($this);
216 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
217 $this->attributes, "Save");
218 $ldap->cd($this->dn);
219 $ldap->modify($this->attrs);
220 show_ldap_error($ldap->get_error());
222 /* remove the entry from LDAP */
223 unset ($this->attrs['uid']);
225 /* Optionally execute a command after we're done */
226 $this->handle_post_events('remove');
227 }
229 }
231 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
233 ?>