-
Notifications
You must be signed in to change notification settings - Fork 3
/
npc.php
94 lines (75 loc) · 2.91 KB
/
npc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2007 Billy Gunn aka divagater ([email protected]) |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License (GPLv3) |
| version 3 as published by the Free Software Foundation. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti and Nagios are the copyright of their respective owners. |
+-------------------------------------------------------------------------+
*/
chdir('../../');
require_once('include/auth.php');
include(dirname(__FILE__) . '/config.php');
// Setup a timer
$starttime = microtime(true);
$params['config'] = $config;
$module = 'layout';
$action = 'drawFrame';
$format = 'json';
// Set the default module and action
if (isset_request_var('module')) {
$module = get_request_var_request('module');
}
if (isset_request_var('action')) {
$action = get_request_var_request('action');
}
if (isset_request_var('format')) {
$format = get_request_var_request('format');
}
if ($action == 'csrf') {
print csrf_get_tokens();
exit;
}
// Include the requested controller
require_once('plugins/npc/controllers/' . $module . '.php');
$class = 'Npc' . ucfirst($module) . 'Controller';
$obj = new $class;
if (is_object($conn)) {
$obj->conn = $conn;
} else {
cacti_log('ERROR: Unable to make NPC Connection', false, 'NPC');
raise_message('npc_error', __('FATAL: Unable to make NPC Connection', 'npc'), MESSAGE_LEVEL_ERROR);
exit;
}
if (is_array($_REQUEST)) {
foreach($_REQUEST as $key => $value) {
if (preg_match('/^p_/', $key) || $key == 'start' || $key == 'limit') {
$parm = preg_replace('/^p_/', '', $key);
$obj->$parm = $value;
$params[$parm] = get_request_var_request($key);
} else {
$params[$key] = get_request_var_request($key);
}
}
}
// Set the current page for pagination
if (get_request_var_request('start')) {
$obj->currentPage = (($obj->start / $obj->limit) + 1);
}
if ($out = $obj->$action($params)) {
print $out;
}
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = sprintf('%01.2f', ($endtime - $starttime));
$obj->logger('debug', get_class($obj), get_request_var_request('action'), "Script execution time: $totaltime seconds");