forked from Cacti/plugin_intropage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intropage_ajax.php
157 lines (131 loc) · 6.32 KB
/
intropage_ajax.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/* vim: ts=4
+-------------------------------------------------------------------------+
| Copyright (C) 2015-2021 Petr Macek |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| 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: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| https://github.com/xmacan/ |
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include_once('./include/auth.php');
if (!function_exists("array_column")) {
function array_column($array,$column_name) {
return array_map(function($element) use($column_name){return $element[$column_name];}, $array);
}
}
if (get_filter_request_var('reload_panel', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[0-9]{1,3}$/')))) {
$panel_id = get_request_var('reload_panel');
}
if (get_filter_request_var('detail_panel', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[0-9]{1,3}$/')))) {
$panel_id = get_request_var('detail_panel');
}
// gef_filter_request_var doesn't know boolean
$forced_update = filter_var(get_nfilter_request_var('force'), FILTER_VALIDATE_BOOLEAN);
// automatic reload when poller ends
if (isset_request_var('autoreload')) {
$last_poller = db_fetch_cell("SELECT unix_timestamp(cur_timestamp)
FROM plugin_intropage_trends
WHERE name='ar_poller_finish'");
$last_disp = db_fetch_cell_prepared('SELECT unix_timestamp(cur_timestamp)
FROM plugin_intropage_trends
WHERE name = ?',
array('ar_displayed_' . $_SESSION['sess_user_id']));
if (!$last_disp) {
db_execute_prepared('INSERT INTO plugin_intropage_trends (name,value)
VALUES (?, NOW())',
array('ar_displayed_' . $_SESSION['sess_user_id']));
$last_disp = $last_poller;
}
if ($last_poller > $last_disp) { // fix first double reload (login and poller finish after few seconds
db_execute_prepared("UPDATE plugin_intropage_trends
SET cur_timestamp = NOW(), value = NOW()
WHERE name = ?",
array('ar_displayed_' . $_SESSION['sess_user_id']));
print '1';
} else {
print '0';
}
}
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
if (isset_request_var('reload_panel') && isset($panel_id)) {
$panel = db_fetch_row_prepared('SELECT *
FROM plugin_intropage_panel_data
WHERE id = ?
AND user_id IN (0,?)',
array($panel_id, $_SESSION['sess_user_id']));
// Close the session to allow other tabs to operate
session_write_close();
if ($panel) {
if (isset($panel['fav_graph_id'])) { // fav_graph exception
$data = intropage_favourite_graph($panel['fav_graph_id'],$panel['fav_graph_timespan']);
} else { // normal panel
$file = db_fetch_cell_prepared('SELECT t1.file AS file FROM plugin_intropage_panel_definition AS t1
JOIN plugin_intropage_panel_data AS t2 on t1.panel_id=t2.panel_id where t2.id=?',
array($panel_id));
include_once($config['base_path'] . $file);
$data = $panel['panel_id'](true,false,$forced_update);
}
if (isset_request_var('reload_panel')) {
intropage_display_data(get_request_var('reload_panel'),$data);
// change panel color or ena/disa detail
?>
<script type='text/javascript'>
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_name').html('<?php echo $data['name'];?>');
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_header').removeClass('color_green');
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_header').removeClass('color_yellow');
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_header').removeClass('color_red');
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_header').removeClass('color_gray');
$('#panel_'+<?php print get_request_var('reload_panel');?>).find('.panel_header').addClass('color_<?php print $data['alarm'];?>');
<?php
if (db_fetch_cell("SELECT has_detail FROM plugin_intropage_panel_definition WHERE panel_id='" . $panel['panel_id'] . "'") == 'yes') {
print "$('#panel_'+" . get_request_var('reload_panel') . ").find('.maxim').show();";
} else {
print "$('#panel_'+" . get_request_var('reload_panel') . ").find('.maxim').hide();";
}
?>
</script>
<?php
// end of change panel color or ena/disa detail
}
} elseif ($panel_id == 998) { // exception for admin alert panel
print nl2br(read_config_option('intropage_admin_alert'));
} elseif ($panel_id == 997) { // exception for maint panel
if (function_exists('intropage_maint')) {
print intropage_maint();
}
} else {
print __('Panel not found');
}
}
if (isset_request_var('detail_panel') && isset($panel_id)) {
include_once($config['base_path'] . '/plugins/intropage/include/data_detail.php');
$panel = db_fetch_cell_prepared('SELECT panel_id
FROM plugin_intropage_panel_data
WHERE id = ? AND user_id in (0,?)',
array($panel_id, $_SESSION['sess_user_id']));
if ($panel) {
$pokus = $panel . '_detail';
$data = $pokus();
print '<div id="block" class="color_' . $data['alarm'] . '" ></div>';
print '<h3 style="display: inline">' . $data['name'] . '</h3>';
print '<br/>' . $data['detail'];
} else {
print __('Panel not found');
}
}