reports: Fix id of custom date selector
[ninja.git] / application / controllers / config.php
blob22208cb51a7127fd8c7b1d76e0964d13e3246263
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Config controller
4 * Requires authentication
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
12 * PARTICULAR PURPOSE.
14 class Config_Controller extends Authenticated_Controller {
15 public $current = false;
16 public $type = 'hosts';
17 const SERVICE_NOTIFICATION_COMMANDS = 'service_notification_commands';
18 const HOST_NOTIFICATION_COMMANDS = 'host_notification_commands';
20 /**
21 * Default controller method
22 * Redirects to show_process_info() which
23 * is the equivalent of calling extinfo.cgi?type=0
25 public function index()
27 if (!Auth::instance()->authorized_for('system_information')) {
28 return url::redirect('extinfo/unauthorized/0');
31 $this->type = isset($_GET['type']) ? $_GET['type'] : $this->type;
32 $items_per_page = $this->input->get('items_per_page', config::get('pagination.default.items_per_page', '*'));
33 $pagination = new CountlessPagination(array('items_per_page' => $items_per_page));
35 $filter = $this->input->get('filterbox', null);
36 if($filter && $filter == _('Enter text to filter')) {
37 $filter = null;
39 $poolname = ucfirst(substr($this->type,0,-1)).'Pool_Model';
40 if (class_exists($poolname)) {
41 $set = $poolname::all();
42 $set->reduce_by("name", $filter, "~~");
43 $data = $set->it(false, array(), $pagination->items_per_page, ($pagination->current_page-1)*$pagination->items_per_page);
44 $i = 0;
45 $result=array();
46 switch ($this->type) {
47 case 'hosts': // *****************************************************************************
48 $header = array(
49 _('Host Name'),
50 _('Alias/Description'),
51 _('Display Name'),
52 _('Address'),
53 _('Parent Hosts'),
54 _('Max. Check Attempts'),
55 _('Check Interval'),
56 _('Retry Interval'),
57 _('Host Check Command'),
58 _('Check Period'),
59 _('Obsess Over'),
60 _('Enable Active Checks'),
61 _('Enable Passive Checks'),
62 _('Check Freshness'),
63 //_('Freshness Threshold'),
64 _('Default Contact Groups'),
65 _('Notification Interval'),
66 _('First Notification Delay'),
67 //_('Notification Options'),
68 _('Notification Period'),
69 _('Event Handler'),
70 _('Enable Event Handler'),
71 //_('Stalking Options'),
72 _('Enable Flap Detection'),
73 _('Low Flap Threshold'),
74 _('High Flap Threshold'),
75 _('Process Performance Data'),
76 //_('Enable Failure Prediction'),
77 //_('Failure Prediction Options'),
78 _('Notes'),
79 _('Notes URL'),
80 _('Action URL'),
81 _('Icon image'),
82 _('Icon image alt'),
83 //_('Retention Options')
86 foreach($data as $row) {
87 $row = (object) $row;
88 $result[$i][]= '<a name="'.$row->get_name().'"></a>'.$row->get_name();
89 $result[$i][]= $row->get_alias();
90 $result[$i][]= $row->get_display_name();
91 $result[$i][]= $row->get_address();
92 $tmp = array();
93 foreach ($row->get_parents() as $parent) {
94 $tmp[] = html::anchor(Router::$controller.'/?type=hosts#'.$parent, $parent);
96 $result[$i][] = implode(', ',$tmp);
97 $result[$i][]= $row->get_max_check_attempts();
98 $result[$i][]= time::to_string($row->get_check_interval()*60);
99 $result[$i][]= time::to_string($row->get_retry_interval()*60);
100 $result[$i][]= html::anchor(Router::$controller.'/?type=commands#'.$row->get_check_command(), $row->get_check_command());
101 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.$row->get_check_period(), $row->get_check_period());
102 $result[$i][]= $row->get_obsess() == 1 ? _('Yes') : _('No');
103 $result[$i][]= $row->get_active_checks_enabled() == 1 ? _('Yes') : _('No');
104 $result[$i][]= $row->get_accept_passive_checks() == 1 ? _('Yes') : _('No');
105 $result[$i][]= $row->get_check_freshness() == 1 ? _('Yes') : _('No');
106 //$result[$i][]= $row->get_freshness_threshold() == 0 ? _('Auto-determined value') : $row->get_freshness_threshold().' '._('seconds');
107 $c_link = array();
108 foreach($row->get_contact_groups() as $cg){
109 $c_link[] = html::anchor(Router::$controller.'/?type=contactgroups#'.$cg, $cg);
111 foreach($row->get_contacts() as $c){
112 $c_link[] = html::anchor(Router::$controller.'/?type=contacts#'.$c, $c);
114 $result[$i][] = implode(', ', $c_link);
116 $result[$i][]= $row->get_notification_interval() == 0 ? _('No Re-notification') : $row->get_notification_interval();
117 $result[$i][]= time::to_string($row->get_first_notification_delay());
118 //$note_options = explode(',',$row->get_notification_options());
119 //$tmp = false;
120 //foreach($note_options as $option) {
121 //$tmp[] = $options['host']['notification'][$option];
123 //$result[$i][]= implode(', ',$tmp);
124 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.$row->get_notification_period(), $row->get_notification_period());
125 $result[$i][]= $row->get_event_handler() == 0 ? '&nbsp;' : $row->get_event_handler();
126 $result[$i][]= $row->get_event_handler_enabled() == 1 ? _('Yes') : _('No');
127 //$result[$i][]= $row->get_stalking_options() == 'n' ? _('None') : _('??');
128 $result[$i][]= $row->get_flap_detection_enabled() == 1 ? _('Yes') : _('No');
129 $result[$i][]= $row->get_low_flap_threshold() == 0.0 ? _('Program-wide value') : $row->get_low_flap_threshold();
130 $result[$i][]= $row->get_high_flap_threshold() == 0.0 ? _('Program-wide value') : $row->get_high_flap_threshold();
131 $result[$i][]= $row->get_process_performance_data() == 1 ? _('Yes') : _('No');
132 //$result[$i][]= $row->get_failure_prediction_enabled() == 1 ? _('Yes') : _('No');
133 //$result[$i][]= !isset($row->get_failure_prediction_options()) ? '&nbsp;' : $row->get_failure_prediction_options(); // ?
134 $result[$i][]= $row->get_notes();
135 $result[$i][]= $row->get_notes_url();
136 $result[$i][]= $row->get_action_url();
137 $result[$i][]= $row->get_icon_image();
138 $result[$i][]= $row->get_icon_image_alt();
139 // retention options
140 //$ret = false;
141 //if ($row->get_retain_status_information() == true) {
142 //$ret[] = _('Status Information');
144 //if ($row->get_retain_nonstatus_information() == true) {
145 //$ret[] = _('Non-status Information');
147 //$result[$i][] = is_array($ret) ? implode(', ',$ret) : 'None';
148 $i++;
150 break;
152 case 'services': // **************************************************************************
153 $header = array(
154 _('Host'),
155 _('Service Description'),
156 _('Max. Check Attempts'),
157 _('Normal Check Interval'),
158 _('Retry Check Interval'),
159 _('Check Command'),
160 _('Check Period'),
161 //_('Parallelize'),
162 //_('Volatile'),
163 _('Obsess Over'),
164 _('Enable Active Checks'),
165 _('Enable Passive Checks'),
166 _('Check Freshness'),
167 //_('Freshness Threshold'),
168 _('Default Contact Groups'),
169 _('Enable Notifications'),
170 _('Notification Interval'),
171 _('First Notification Delay'),
172 //_('Notification Options'),
173 _('Notification Period'),
174 _('Event Handler'),
175 _('Enable Event Handler'),
176 //_('Stalking Options'),
177 _('Enable Flap Detection'),
178 _('Low Flap Threshold'),
179 _('High Flap Threshold'),
180 _('Process Performance Data'),
181 //_('Enable Failure Prediction'),
182 //_('Failure Prediction Options'),
183 _('Notes'),
184 _('Notes URL'),
185 _('Action URL'),
186 _('Icon image'),
187 _('Icon image alt'),
188 //_('Retention Options'),
191 foreach($data as $row) {
192 $row = (object) $row;
193 //$note_options = explode(',',$row->get_notification_options());
195 $result[$i][]= '<a name="'.$row->get_host()->get_name().'"></a>'.$row->get_host()->get_name();
196 $result[$i][]= '<a name="'.$row->get_description().'"></a>'.$row->get_description();
197 $result[$i][]= $row->get_max_check_attempts();
198 $result[$i][]= time::to_string($row->get_check_interval()*60);
199 $result[$i][]= time::to_string($row->get_retry_interval()*60);
200 $result[$i][]= $row->get_check_command();
201 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.$row->get_check_period(), $row->get_check_period());
202 //$result[$i][]= $row->get_parallelize_check() == 1 ? _('Yes') : _('No');
203 //$result[$i][]= $row->get_is_volatile() == 1 ? _('Yes') : _('No');
204 $result[$i][]= $row->get_obsess() == 1 ? _('Yes') : _('No');
205 $result[$i][]= $row->get_active_checks_enabled() == 1 ? _('Yes') : _('No');
206 $result[$i][]= $row->get_accept_passive_checks() == 1 ? _('Yes') : _('No');
207 $result[$i][]= $row->get_check_freshness() == 1 ? _('Yes') : _('No');
208 //$result[$i][]= $row->get_freshness_threshold() == 0 ? _('Auto-determined value') : $row->get_freshness_threshold().' '._('seconds');
210 $c_link = array();
211 foreach($row->get_contact_groups() as $cg){
212 $c_link[] = html::anchor(Router::$controller.'/?type=contactgroups#'.$cg, $cg);
214 foreach($row->get_contacts() as $c){
215 $c_link[] = html::anchor(Router::$controller.'/?type=contacts#'.$c, $c);
217 $result[$i][] = implode(', ', $c_link);
219 $result[$i][]= $row->get_notifications_enabled() == 1 ? _('Yes') : _('No');
220 $result[$i][]= $row->get_notification_interval() == 0 ? _('No Re-notification') : $row->get_notification_interval();
221 $result[$i][]= time::to_string($row->get_first_notification_delay());
222 //$notification_options = explode(',',$row->get_notification_options());
223 //$tmp = array();
224 //foreach($notification_options as $option) {
225 //$tmp[] = $options['service']['notification'][$option];
227 //$result[$i][]= is_array($tmp) ? implode(', ',$tmp) : '';
228 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.$row->get_notification_period(), $row->get_notification_period());
229 $result[$i][]= $row->get_event_handler() == 0 ? '&nbsp;' : $row->get_event_handler();
230 $result[$i][]= $row->get_event_handler_enabled() == 1 ? _('Yes') : _('No');
231 //$result[$i][]= $row->get_stalking_options() == 'n' ? _('None') : _('??');
232 $result[$i][]= $row->get_flap_detection_enabled() == 1 ? _('Yes') : _('No');
233 $result[$i][]= $row->get_low_flap_threshold() == 0.0 ? _('Program-wide value') : $row->get_low_flap_threshold();
234 $result[$i][]= $row->get_high_flap_threshold() == 0.0 ? _('Program-wide value') : $row->get_high_flap_threshold();
235 $result[$i][]= $row->get_process_performance_data() == 1 ? _('Yes') : _('No');
236 //$result[$i][]= $row->get_failure_prediction_enabled() == 1 ? _('Yes') : _('No');
237 //$result[$i][]= !isset($row->get_failure_prediction_options()) ? '&nbsp;' : $row->get_failure_prediction_options(); // ?
238 $result[$i][]= $row->get_notes();
239 $result[$i][]= $row->get_notes_url();
240 $result[$i][]= $row->get_action_url();
241 $result[$i][]= $row->get_icon_image();
242 $result[$i][]= $row->get_icon_image_alt();
243 //retention options
244 //$ret = false;
245 //if ($row->get_retain_status_information() == true) {
246 //$ret[] = _('Status Information');
248 //if ($row->get_retain_nonstatus_information() == true) {
249 //$ret[] = _('Non-status Information');
251 //$result[$i][] = is_array($ret) ? implode(', ',$ret) : 'None';
252 $i++;
254 break;
256 case 'contacts': // **************************************************************************
257 $header = array(
258 _('Contact Name'),
259 _('Alias'),
260 _('Email Address'),
261 _('Pager Address/Number'),
262 //_('Service Notification Options'),
263 //_('Host Notification Options'),
264 _('Service Notification Period'),
265 _('Host Notification Period'),
266 //_('Service Notification Commands'),
267 //_('Host Notification Commands'),
268 //_('Retention Options'),
271 foreach($data as $row) {
272 $row = (object) $row;
273 $result[$i][]= '<a name="'.$row->get_name().'"></a>'.$row->get_name();
274 $result[$i][]= $row->get_alias();
275 $result[$i][]= '<a href="mailto:'.$row->get_email().'">'.$row->get_email().'</a>';
276 $result[$i][]= $row->get_pager();
278 //$s_notification_options = explode(',',$row->get_service_notification_options());
279 //$s_tmp = false;
280 //foreach($s_notification_options as $s_option) {
281 //$s_tmp[] = $options['service']['notification'][$s_option];
283 //$result[$i][]= implode(', ',$s_tmp);
285 //$h_notification_options = explode(',',$row->get_host_notification_options());
286 //$h_tmp = false;
287 //foreach($h_notification_options as $h_option) {
288 //$h_tmp[] = $options['host']['notification'][$h_option];
290 //$result[$i][]= implode(', ',$h_tmp);
292 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.($row->get_host_notification_period() == 0 ? _('None') : $row->get_host_notification_period()), $row->get_service_notification_period() == 0 ? _('None') : $row->get_service_notification_period());
293 $result[$i][]= html::anchor(Router::$controller.'/?type=timeperiods#'.($row->get_host_notification_period() == 0 ? _('None') : $row->get_host_notification_period()), $row->get_host_notification_period() == 0 ? _('None') : $row->get_host_notification_period());
294 //$result[$i][]= html::anchor(Router::$controller.'/?type=commands#'.$row->{self::SERVICE_NOTIFICATION_COMMANDS}, $row->{self::SERVICE_NOTIFICATION_COMMANDS});
295 //$result[$i][]= html::anchor(Router::$controller.'/?type=commands#'.$row->{self::HOST_NOTIFICATION_COMMANDS}, $row->{self::HOST_NOTIFICATION_COMMANDS});
296 // retention options
297 //$ret = false;
298 //if ($row->get_retain_status_information() == true) {
299 //$ret[] = _('Status Information');
301 //if ($row->get_retain_nonstatus_information() == true) {
302 //$ret[] = _('Non-status Information');
304 //$result[$i][] = is_array($ret) ? implode(', ',$ret) : 'None';
305 $i++;
307 break;
309 case 'contactgroups': // ********************************************************************
310 $header = array(
311 _('Group Name'),
312 _('Description'),
313 _('Contact Members'),
316 foreach($data as $row) {
317 $row = (object) $row;
319 $result[$i][]= '<a name="'.$row->get_name().'"></a>'.$row->get_name();
320 $result[$i][]= $row->get_alias();
322 $temp = array();
323 foreach ($row->get_members() as $trip) {
324 $temp[] = html::anchor(Router::$controller.'/?type=contacts#'.$trip, $trip);
326 if($temp) {
327 $result[$i][]= implode(', ',$temp);
328 } else {
329 $result[$i][]= '';
331 $i++;
333 break;
335 case 'timeperiods': // ***********************************************************************
336 $header = array(
337 _('Name'),
338 _('Alias/Description'),
339 _('In effect?'),
342 foreach($data as $row) {
343 $result[$i][] = $row->get_name();
344 $result[$i][] = $row->get_alias();
345 $result[$i][] = $row->get_in() ? _('Yes') : _('No');
346 $i++;
348 break;
350 case 'commands': // **************************************************************************
351 $header = array(
352 _('Command Name'),
353 _('Command Line')
356 foreach($data as $row) {
357 $result[$i][] = $row->get_name();
358 $result[$i][] = $row->get_line();
359 $i++;
361 break;
363 case 'hostgroups': // ***********************************************************************
364 $header = array(
365 _('Group Name'),
366 _('Description'),
367 _('Host Members'),
368 _('Notes'),
369 _('Notes URL'),
370 _('Action URL'),
373 foreach($data as $row) {
374 $row = (object) $row;
375 $result[$i][]= '<a name="'.$row->get_name().'"></a>'.$row->get_name();
376 $result[$i][]= $row->get_alias();
378 $temp = array();
379 foreach ($row->get_members() as $trip) {
380 $temp[] = html::anchor(Router::$controller.'/?type=hosts#'.$trip, $trip);
382 $result[$i][]= implode(', ',$temp);
384 $result[$i][]= $row->get_notes();
385 $result[$i][]= $row->get_notes_url();
386 $result[$i][]= $row->get_action_url();
387 $i++;
388 unset($travel);
390 break;
392 case 'servicegroups': // ********************************************************************
393 $header = array(
394 _('Group Name'),
395 _('Description'),
396 _('Service Members'),
397 _('Notes'),
398 _('Notes URL'),
399 _('Action URL'),
402 foreach($data as $row) {
403 $row = (object) $row;
404 $result[$i][]= '<a name="'.$row->get_name().'"></a>'.$row->get_name();
405 $result[$i][]= $row->get_alias();
407 $temp = array();
408 foreach ($row->get_members() as $host_service) {
409 $temp[] = html::anchor(Router::$controller.'/?type=hosts#'.$host_service[0], $host_service[0]).' / '.html::anchor(Router::$controller.'/?type=services#'.$host_service[1], $host_service[1]);
411 if($temp) {
412 $result[$i][]= implode(', ',$temp);
413 } else {
414 $result[$i][]= '';
417 $result[$i][]= $row->get_notes();
418 $result[$i][]= $row->get_notes_url();
419 $result[$i][]= $row->get_action_url();
420 $i++;
421 unset($travel);
423 break;
425 } else {
426 $result = false;
427 $header = false;
429 $this->template->title = _('Configuration').' ยป '._('View config');
430 $this->template->content = $this->add_view('config/index');
432 $this->xtra_js[] = 'application/media/js/jquery.tablesorter.min.js';
433 $this->template->js_header = $this->add_view('js_header');
434 $this->js_strings .= "var _filter_label = '"._('Enter text to filter')."';";
435 $this->template->js_strings = $this->js_strings;
436 $this->template->js_header->js = $this->xtra_js;
437 $this->template->content->header = $header;
438 $this->template->content->data = $result;
439 if(!$result || count($result) < $pagination->items_per_page) {
440 $pagination->hide_next = true;
442 $this->template->content->pagination = $pagination;
443 $this->template->content->filter_string = $this->input->get('filterbox', _('Enter text to filter'));
444 $this->template->content->type = $this->type;
447 public function unauthorized()
449 $this->template->content = $this->add_view('extinfo/unauthorized');
450 $this->template->disable_refresh = true;
452 $this->template->content->error_description = _('If you believe this is an error, check the HTTP server authentication requirements for accessing this page and check the authorization options in your CGI configuration file.');