-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcycle.php
404 lines (343 loc) · 12.9 KB
/
cycle.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| 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. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
$guest_account = true;
chdir('../../');
include_once('./include/auth.php');
include_once('./lib/time.php');
include_once('./lib/html_tree.php');
include_once('./lib/api_graph.php');
include_once('./lib/api_tree.php');
include_once('./lib/utility.php');
include_once('./lib/api_data_source.php');
include_once('./plugins/cycle/functions.php');
set_default_action();
cycle_set_defaults();
validate_request_vars();
switch(get_request_var('action')) {
case 'save':
save_settings();
break;
case 'graphs':
cycle_graphs();
break;
default:
cycle();
break;
}
function cycle_graphs() {
global $graphs_ppage, $graph_cols, $graphs;
global $page_refresh_interval, $graph_timespans;
global $cycle_width, $cycle_height;
global $id, $graph_id, $next_graph_id, $prev_graph_id;
$tree_list = get_allowed_trees();
$legend = get_request_var('legend');
$tree_id = get_request_var('tree_id');
$leaf_id = get_request_var('leaf_id');
$graphpp = get_request_var('graphs');
$cols = get_request_var('cols');
$rfilter = get_request_var('rfilter');
$id = get_request_var('id');
$width = get_request_var('width');
$height = get_request_var('height');
if (empty($tree_id)) $tree_id = db_fetch_cell('SELECT id FROM graph_tree ORDER BY name LIMIT 1');
if (empty($id)) $id = -1;
/* get the start and end times for the graph */
$timespan = array();
$first_weekdayid = read_user_setting('first_weekdayid');
get_timespan($timespan, time(), get_request_var('timespan'), $first_weekdayid);
$graph_tree = $tree_id;
$html = '';
$out = '';
get_next_graphid($graphpp, $rfilter, $graph_tree, $leaf_id);
/* create the graph structure and output */
$out = '<table style="margin-left:auto;margin-right:auto;">';
$max_cols = $cols;
$col_count = 1;
if ($graphs !== null && $graphs !== false && sizeof($graphs)) {
foreach($graphs as $graph) {
if ($col_count == 1)
$out .= '<tr>';
$out .= '<td align="center" class="graphholder">'
. "<a href='../../graph.php?local_graph_id=" . $graph['graph_id'] . "&rra_id=all'>"
. "<img class='cycle_image' "
. "src='../../graph_image.php?image_format=svg&disable_cache=true&local_graph_id="
. $graph['graph_id'] . "&rra_id=0&graph_start=" . $timespan['begin_now']
. "&graph_end=" . time() . "&graph_width=" . $width . "&graph_height=" . $height
. ($legend == '' || $legend=='false' ? "&graph_nolegend=true" : "") . "'>"
. "</a></td>";
ob_start();
$out .= ob_get_clean();
if ($col_count == $max_cols) {
$out .= '</tr>';
$col_count=1;
} else {
$col_count++;
}
}
} else {
$out = '<h1>' . __('No Graphs Found Matching Criteria', 'cycle') . '</h1>';
}
if ($col_count <= $max_cols) {
$col_count--;
$addcols = $max_cols - $col_count;
for($x=1; $x <= $addcols; $x++) {
$out .= '<td class="graphholder"> </td>';
}
$out .= '</tr>';
}
$out .= '</table>';
$output = array('graphid' => $graph_id, 'nextgraphid' => $next_graph_id, 'prevgraphid' => $prev_graph_id, 'image' => base64_encode($out));
print json_encode($output);
}
function cycle() {
global $graphs_ppage, $graph_cols;
global $page_refresh_interval, $graph_timespans;
global $cycle_width, $cycle_height;
general_header();
global $config;
if (function_exists('get_md5_include_js')) {
print get_md5_include_js('plugins/cycle/cycle.js');
} else {
print "<script type='text/javascript' src='" . $config['url_path'] . "plugins/cycle/cycle.js'></script>";
}
$tree_list = get_allowed_trees();
$legend = get_request_var('legend');
$tree_id = get_request_var('tree_id');
$leaf_id = get_request_var('leaf_id');
$graphpp = get_request_var('graphs');
$cols = get_request_var('cols');
$rfilter = get_request_var('rfilter');
$id = get_request_var('id');
$width = get_request_var('width');
$height = get_request_var('height');
if (empty($tree_id)) {
$tree_id = db_fetch_cell('SELECT id
FROM graph_tree
ORDER BY name
LIMIT 1');
}
if (empty($id)) {
$id = -1;
}
/* get the start and end times for the graph */
$timespan = array();
$first_weekdayid = read_user_setting('first_weekdayid');
get_timespan($timespan, time(), get_request_var('timespan') , $first_weekdayid);
$graph_tree = $tree_id;
$html = '';
$out = '';
html_start_box(__('Cycle Graph Filter', 'cycle') . ' [ ' . __('Next Update In', 'cycle') . " <i id='countdown'></i> ]", '100%', '', 3, 'center', '');
?>
<tr class='odd'><td>
<form id='form_cycle'>
<table class='filterTable'>
<tr>
<td>
<script type='text/javascript'>
var rtime=<?php print get_request_var('delay')*1000;?>;
</script>
<select id='timespan' title='<?php print __esc('Graph Display Timespan', 'cycle');?>'>
<?php
if (cacti_sizeof($graph_timespans)) {
foreach($graph_timespans as $key => $value) {
print "<option value='$key'"; if (get_request_var('timespan') == $key) { print ' selected'; } print '>' . html_escape($value) . '</option>';
}
}
?>
</select>
</td>
<td>
<select id='delay' title='<?php print __esc('Cycle Rotation Refresh Frequency', 'cycle');?>'>
<?php
if (cacti_sizeof($page_refresh_interval)) {
foreach($page_refresh_interval as $key => $value) {
print "<option value='$key'"; if (get_request_var('delay') == $key) { print ' selected'; } print '>' . html_escape($value) . '</option>';
}
}
?>
</select>
</td>
<td>
<select id='graphs' title='<?php print __esc('Number of Graphs per Page', 'cycle');?>'>
<?php
foreach($graphs_ppage as $key => $value) {
print "<option value='$key'"; if (get_request_var('graphs') == $key) { print ' selected'; } print '>' . $value . '</option>';
}
?>
</select>
</td>
<td>
<span class='nowrap'>
<input type='button' id='prev' value='<?php print __esc('Prev', 'cycle');?>' title='<?php print __esc('Cycle to Previous Graphs', 'cycle');?>'>
<input type='button' id='cstop' value='<?php print __esc('Stop', 'cycle');?>' title='<?php print __esc('Stop Cycling', 'cycle');?>'>
<input type='button' id='cstart' value='<?php print __esc('Start', 'cycle');?>' style='display:none;' title='<?php print __esc('Resume Cycling', 'cycle');?>'>
<input type='button' id='next' value='<?php print __esc('Next', 'cycle');?>' title='<?php print __esc('Cycle to Next Graphs', 'cycle');?>'>
<input type='submit' id='refresh' value='<?php print __esc('Refresh', 'cycle');?>' title='<?php print __esc('Refresh Graphs Now', 'cycle');?>'>
<input type='button' id='clear' value='<?php print __esc('Clear', 'cycle');?>' title='<?php print __esc('Clear Filter', 'cycle');?>'>
<input type='button' id='save' value='<?php print __esc('Save', 'cycle');?>' title='<?php print __esc('Save Filter Settings', 'cycle');?>'>
<i id='text'></i>
</span>
</td>
</table>
<table class='filterTable'>
<td>
<select id='cols' title='<?php print __esc('Number of Graph Columns', 'cycle');?>'>
<?php
foreach($graph_cols as $key=>$value) {
print "<option value='$key'"; if (get_request_var('cols') == $key) { print ' selected'; } print '>' . $value . '</option>';
}
?>
</select>
</td>
<td>
<select id='height' title='<?php print __esc('Graph Height', 'cycle');?>'>
<?php
foreach($cycle_height as $key=>$value) {
print "<option value='$key'"; if (get_request_var('height') == $key) { print ' selected'; } print '>' . $key . '</option>';
}
?>
</select>
</td>
<td>
<span style='vertical-align:center;'>X</span>
</td>
<td>
<select id='width' title='<?php print __esc('Graph Width', 'cycle');?>'>
<?php
foreach($cycle_width as $key=>$value) {
print "<option value='$key'"; if (get_request_var('width') == $key) { print ' selected'; } print '>' . $key . '</option>';
}
?>
</select>
</td>
<td>
<input type='checkbox' id='legend' <?php (get_request_var('legend') == 'true' || get_request_var('legend') == 'on' ? print " checked='checked'" : '' );?> title='<?php print __esc('Display Graph Legend', 'cycle');?>'>
</td>
<td>
<label for='legend' style='vertical-align:25%' title='<?php print __esc('Display Graph Legend', 'cycle');?>'><?php print __esc('Legend', 'cycle');?> </label>
</td>
</tr>
</table>
<table class='filterTable'>
<tr>
<?php
switch(read_config_option('cycle_custom_graphs_type')) {
case '0':
case '1':
/* will only use the rfilter for full rotation */
break;
case '2':
if (cacti_sizeof($tree_list)) {
$html ="<td><select id='tree_id' title='" . __esc('Select Tree to View', 'cycle') . "'>";
foreach ($tree_list as $tree) {
$html .= "<option value='" . $tree['id'] . "'" . ($graph_tree == $tree['id'] ? ' selected' : '') . '>' . html_escape($tree['name']) . '</option>';
}
$html .= '</select>';
$leaves = db_fetch_assoc_prepared('SELECT *
FROM graph_tree_items
WHERE title != ""
AND graph_tree_id = ?
ORDER BY parent, position',
array($graph_tree));
if (cacti_sizeof($leaves)) {
$html .= "<select id='leaf_id' title='" . __esc('Select Tree Leaf to Display', 'cycle') . "'>";
$html .= "<option value='-1'" . ($leaf_id == -1 ? ' selected' : '') . ">" . __('All Levels', 'cycle') . '</option>';
$html .= "<option value='-2'" . ($leaf_id == -2 ? ' selected' : '') . ">" . __('Top Level', 'cycle') . '</option>';
foreach ($leaves as $leaf) {
$html .= "<option value='" . $leaf['id'] . "'" . ($leaf_id == $leaf['id'] ? ' selected':'') . '>' . $leaf['title'] . '</option>';
}
$html .= '</select>';
} else {
$html .= '</td>';
}
}
}
/* process the rfilter section */
$html .= "<td><input id='rfilter' type='textbox' title='" . __esc('Enter Regular Expression Match (only alpha, numeric, and special characters \"(^_|?)\" permitted)', 'cycle') . "' size='45' value='" . $rfilter . "'></td>";
print $html;
?>
</tr>
</table>
<table class='filterTable'>
<tr id='izone'>
<td>
</td>
</tr>
</table>
</form>
</td></tr>
<?php html_end_box();?>
<?php html_start_box(__('Cycle Graphs', 'cycle'), '100%', '', '3', 'center', '');?>
<tr>
<td>
<span style='text-align:center;' id='image'></span>
</td>
</tr>
<tr>
<td>
<script type='text/javascript'>
$(function() {
$('#timespan').change(function(){
newTimespan()
});
$('#prev').click(function(){
getPrev()
});
$('#next').click(function(){
getNext()
});
$('#cstop').click(function(){
stopTime()
});
$('#cstart').click(function(){
startTime()
});
$('#clear').click(function(){
clearFilter()
});
$('#save').click(function(){
saveFilter()
});
$('#tree_id, #leaf_id, #height, #width, #cols, #graphs, #delay').change(function() {
applyFilter();
});
$('#refresh, #legend').click(function() {
applyFilter();
});
$('#form_cycle').submit(function(event) {
event.preventDefault();
applyFilter();
});
$('input, label, button').tooltip();
stopTime();
startTime();
newGraph();
});
</script>
</td>
</tr>
<?php
html_end_box();
bottom_footer();
}