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\"> <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_header(_("Remove nagios account"),
102 _("This account has nagios features enabled. You can disable them by clicking below."));
103 } else {
104 $display= $this->show_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 $ldap->modify($this->attrs);
145 show_ldap_error($ldap->get_error());
147 /* Optionally execute a command after we're done */
148 if ($this->initially_was_account == $this->is_account){
149 if ($this->is_modified){
150 $this->handle_post_events("modify");
151 }
152 } else {
153 $this->handle_post_events("add");
154 }
155 }
157 function check()
158 {
159 $message= array();
160 $ldap= $this->config->get_ldap_link();
161 /* must: mail */
162 if ($this->NagiosAlias == ""){
163 $message[]= _("The required field 'NagiosAlias' is not set.");
164 }
165 if ($this->NagiosMail == ""){
166 $message[]= _("The required field 'NagiosMail' is not set.");
167 }
168 if ($this->is_template){
169 if (!is_email($this->NagiosMail, TRUE)){
170 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
171 }
172 } else {
173 if (!is_email($this->NagiosMail)){
174 $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
175 }
176 }
177 return($message);
178 }
181 /* Use Save_object for every Post handling */
182 function save_object()
183 {
184 if (isset($_POST['nagiosTab'])){
185 /* Save ldap attributes */
186 plugin::save_object();
188 /* Specialhandling for checkboxes */
189 foreach($this->is_chk_box as $val){
190 if(isset($_POST[$val])){
191 $this->$val = "checked";
192 }else{
193 $this->$val = "unchecked";
194 }
195 }
196 }
197 }
199 function remove_from_parent()
200 {
201 /* Cancel if there's nothing to do here */
202 if (!$this->initially_was_account){
203 return;
204 }
206 /* include global link_info */
207 $ldap= $this->config->get_ldap_link();
209 /* Remove and write to LDAP */
210 plugin::remove_from_parent();
212 /* Adapt attributes if needed */
213 // $method= new $this->method($this->config);
214 // $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 ?>