forked from casdr/weathermap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-pick.php
executable file
·503 lines (417 loc) · 15.1 KB
/
data-pick.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<?php
// ******************************************
// sensible defaults
$mapdir='configs';
$observium_base = '../../';
$observium_url = '/';
$ignore_observium=FALSE;
$config['base_url'] = $observium_url;
$whats_installed = '';
// check if the goalposts have moved
if( is_dir($observium_base) && file_exists($observium_base."/config.php") )
{
// include the observium-config, so we know about the database
include_once($observium_base."/config.php");
include_once($observium_base."/includes/defaults.inc.php");
// $config['base_url'] = $observium_url;
$config['base_url'] = (isset($config['url_path'])? $config['url_path'] : $observium_url);
$observium_found = TRUE;
// print "global";
if($config['project_name'] == 'LibreNMS') {
$whats_installed = 'LibreNMS';
} else {
$whats_installed = 'Observium';
}
}
else
{
$observium_found = FALSE;
}
$link = mysqli_connect($config['db_host'],$config['db_user'],$config['db_pass'])
or die('Could not connect: ' . mysqli_connect_error());
mysqli_select_db($link, $config['db_name']) or die('Could not select database: '.mysqli_connect_error());
// ******************************************
function js_escape($str)
{
$str = str_replace('\\', '\\\\', $str);
$str = str_replace("'", "\\\'", $str);
$str = "'".$str."'";
return($str);
}
if(isset($_REQUEST['command']) && $_REQUEST["command"]=='link_step2')
{
$dataid = intval($_REQUEST['dataid']);
//$SQL_graphid = sprintf("SELECT graph_templates_item.local_graph_id, title_cache FROM graph_templates_item,graph_templates_graph,data_template_rrd where graph_templates_graph.local_graph_id = graph_templates_item.local_graph_id and task_item_id=data_template_rrd.id and local_data_id=%d LIMIT 1;",$dataid);
//mysql_selectdb($config['db_name'],$link) or die('Could not select database: '.mysql_error());
//$result = mysql_query($SQL_graphid) or die('Query failed: ' . mysql_error());
//$line = mysql_fetch_array($result, MYSQL_ASSOC);
//$graphid = $line['local_graph_id'];
?>
<html>
<head>
<script type="text/javascript">
function update_source_step2(graphid)
{
var graph_url, hover_url;
var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>';
if (typeof window.opener == "object") {
graph_url = base_url + 'graph.php?height=100&width=512&device=' + graphid + '&type=device_bits&legend=no';
info_url = base_url + 'device/device=' + graphid +'/';
opener.document.forms["frmMain"].node_new_name.value ='test';
opener.document.forms["frmMain"].node_label.value ='testing';
opener.document.forms["frmMain"].link_infourl.value = info_url;
opener.document.forms["frmMain"].link_hover.value = graph_url;
}
self.close();
}
window.onload = update_source_step2(<?php echo $graphid ?>);
</script>
</head>
<body>
This window should disappear in a moment.
</body>
</html>
<?php
// end of link step 2
}
if(isset($_REQUEST['command']) && $_REQUEST["command"]=='link_step1')
{
?>
<html>
<head>
<script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
<script type="text/javascript">
function filterlist(previous)
{
var filterstring = $('input#filterstring').val();
if(filterstring=='')
{
$('ul#dslist > li').show();
if($('#ignore_desc').is(':checked')) {
$("ul#dslist > li:contains('Desc::')").hide();
}
return;
} else if(filterstring!=previous)
{
$('ul#dslist > li').hide();
$("ul#dslist > li:contains('" + filterstring + "')").show();
if($('#ignore_desc').is(':checked')) {
$("ul#dslist > li:contains('Desc::')").hide();
}
} else if(filterstring==previous)
{
if($('#ignore_desc').is(':checked')) {
$("ul#dslist > li:contains('Desc::')").hide();
} else {
$('ul#dslist > li').hide();
$("ul#dslist > li:contains('" + filterstring + "')").show();
}
}
}
function filterignore()
{
if($('#ignore_desc').is(':checked')) {
$("ul#dslist > li:contains('Desc::')").hide();
} else {
//$('ul#dslist > li').hide();
$("ul#dslist > li:contains('" + previous + "')").show();
}
}
$(document).ready( function() {
$('span.filter').keyup(function() {
var previous = $('input#filterstring').val();
setTimeout(function () {filterlist(previous)}, 500);
}).show();
$('span.ignore').click(function() {
var previous = $('input#filterstring').val();
setTimeout(function () {filterlist(previous)}, 500);
});
});
function update_source_step2(graphid,name,portid,ifAlias,ifDesc,ifIndex)
{
var graph_url, hover_url;
var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>';
if (typeof window.opener == "object") {
graph_url = base_url + 'graph.php?height=100&width=512&id=' + portid + '&type=port_bits&legend=no';
info_url = base_url + 'graphs/type=port_bits/id=' + portid +'/';
opener.document.forms["frmMain"].node_new_name.value ='test';
opener.document.forms["frmMain"].node_label.value ='testing';
opener.document.forms["frmMain"].link_infourl.value = info_url;
opener.document.forms["frmMain"].link_hover.value = graph_url;
}
self.close();
}
function update_source_step1(dataid,name,portid,ifAlias,ifDesc,ifIndex)
{
// This must be the section that looks after link properties
var newlocation;
var fullpath;
var rra_path = <?php echo js_escape($observium_base.'rrd/'); ?>+name+'/port-';
if (typeof window.opener == "object") {
fullpath = rra_path+ifIndex+'.rrd:INOCTETS:OUTOCTETS';
if(document.forms['mini'].aggregate.checked)
{
opener.document.forms["frmMain"].link_target.value = opener.document.forms["frmMain"].link_target.value + " " + fullpath;
}
else
{
opener.document.forms["frmMain"].link_target.value = fullpath;
}
}
if(document.forms['mini'].overlib.checked)
{
window.onload = update_source_step2(dataid,name,portid,ifAlias,ifDesc,ifIndex);
}
else
{
self.close();
}
}
function applyDSFilterChange(objForm) {
strURL = '?host_id=' + objForm.host_id.value;
strURL = strURL + '&command=link_step1';
if( objForm.overlib.checked)
{
strURL = strURL + "&overlib=1";
}
else
{
strURL = strURL + "&overlib=0";
}
// document.frmMain.link_bandwidth_out_cb.checked
if( objForm.aggregate.checked)
{
strURL = strURL + "&aggregate=1";
}
else
{
strURL = strURL + "&aggregate=0";
}
document.location = strURL;
}
</script>
<style type="text/css">
body { font-family: sans-serif; font-size: 10pt; }
ul { list-style: none; margin: 0; padding: 0; }
ul { border: 1px solid black; }
ul li.row0 { background: #ddd;}
ul li.row1 { background: #ccc;}
ul li { border-bottom: 1px solid #aaa; border-top: 1px solid #eee; padding: 2px;}
ul li a { text-decoration: none; color: black; }
</style>
<title>Pick a data source</title>
</head>
<body>
<?php
//$SQL_picklist = "select data_local.host_id, data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_template_data.data_source_path from data_local,data_template_data,data_input,data_template where data_local.id=data_template_data.local_data_id and data_input.id=data_template_data.data_input_id and data_local.data_template_id=data_template.id ";
$host_id = -1;
$overlib = true;
$aggregate = false;
if(isset($_REQUEST['aggregate'])) $aggregate = ( $_REQUEST['aggregate']==0 ? false : true);
if(isset($_REQUEST['overlib'])) $overlib= ( $_REQUEST['overlib']==0 ? false : true);
if(isset($_REQUEST['host_id']))
{
$host_id = intval($_REQUEST['host_id']);
//if($host_id>=0) $SQL_picklist .= " and data_local.host_id=$host_id ";
}
//$SQL_picklist .= " order by name_cache;";
// Link query
$result = mysqli_query($link,"SELECT device_id,hostname FROM devices ORDER BY hostname");
//$hosts = mysqli_fetch_assoc($result);
//$result = mysql_query($SQL_picklist);
$hosts = 1;
?>
<h3>Pick a data source:</h3>
<form name="mini">
<?php
if(sizeof($hosts) > 0) {
print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
print '<option '.($host_id==-1 ? 'SELECTED' : '' ).' value="-1">Any</option>';
print '<option '.($host_id==0 ? 'SELECTED' : '' ).' value="0">None</option>';
while ($host = mysqli_fetch_assoc($result))
{
print '<option ';
if($host_id==$host['device_id']) print " SELECTED ";
print 'value="'.$host['device_id'].'">'.$host['hostname'].'</option>';
}
print '</select><br />';
}
print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
print '<input id="overlib" name="overlib" type="checkbox" value="yes" '.($overlib ? 'CHECKED' : '' ).'> <label for="overlib">Also set OVERLIBGRAPH and INFOURL.</label><br />';
print '<input id="aggregate" name="aggregate" type="checkbox" value="yes" '.($aggregate ? 'CHECKED' : '' ).'> <label for="aggregate">Append TARGET to existing one (Aggregate)</label><br />';
print '<span class="ignore"><input id="ignore_desc" name="ignore_desc" type="checkbox" value="yes"> <label for="ignore_desc">Ignore blank interface descriptions</label></span>';
print '</form><div class="listcontainer"><ul id="dslist">';
$query = "SELECT devices.device_id,hostname,ports.port_id,ports.ifAlias,ports.ifIndex,ports.ifDescr FROM devices LEFT JOIN ports ON devices.device_id=ports.device_id WHERE ports.disabled=0";
if($host_id > 0) {
$query .= " AND devices.device_id='$host_id'";
}
$query .= " ORDER BY hostname,ports.ifAlias";
$result = mysqli_query($link,$query);
// print $SQL_picklist;
$i=0;
if( mysqli_num_rows($result) > 0 )
{
while ($queryrows = mysqli_fetch_assoc($result)) {
echo "<li class=\"row".($i%2)."\">";
$key = $queryrows['device_id']."','".$queryrows['hostname']."','".$queryrows['port_id']."','".$queryrows['ifAlias']."','".addslashes($queryrows['ifDescr'])."','".$queryrows['ifIndex'];
echo "<a href=\"#\" onclick=\"update_source_step1('$key')\">". $queryrows['hostname'] . "/" . $queryrows['ifDescr'] . " Desc:" . $queryrows['ifAlias'] . ":</a>";
echo "</li>\n";
$i++;
}
}
else
{
print "<li>No results...</li>";
}
// Free resultset
//mysql_free_result($result);
// Closing connection
//mysql_close($link);
?>
</ul>
</div>
</body>
</html>
<?php
} // end of link step 1
if(isset($_REQUEST['command']) && $_REQUEST["command"]=='node_step1')
{
$host_id = -1;
$SQL_picklist = "SELECT `device_id` AS `id`,`hostname` AS `name` FROM devices ORDER BY hostname";
//$SQL_picklist = "SELECT 1,2,'Test','Y','/dsad'";
$overlib = true;
$aggregate = false;
if(isset($_REQUEST['aggregate'])) $aggregate = ( $_REQUEST['aggregate']==0 ? false : true);
if(isset($_REQUEST['overlib'])) $overlib= ( $_REQUEST['overlib']==0 ? false : true);
if(isset($_REQUEST['host_id']))
{
$host_id = intval($_REQUEST['host_id']);
//if($host_id>=0) $SQL_picklist .= " and graph_local.host_id=$host_id ";
}
//$SQL_picklist .= " order by title_cache";
$query = mysqli_query("SELECT id,hostname AS name FROM `devices` ORDER BY hostname");
$hosts = mysqli_fetch_assoc($query);
?>
<html>
<head>
<script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
<script type="text/javascript">
function filterlist(previous)
{
var filterstring = $('input#filterstring').val();
if(filterstring=='')
{
$('ul#dslist > li').show();
return;
}
if(filterstring!=previous)
{
$('ul#dslist > li').hide();
$("ul#dslist > li:contains('" + filterstring + "')").show();
//$('ul#dslist > li').contains(filterstring).show();
}
}
$(document).ready( function() {
$('span.filter').keyup(function() {
var previous = $('input#filterstring').val();
setTimeout(function () {filterlist(previous)}, 500);
}).show();
});
function applyDSFilterChange(objForm) {
strURL = '?host_id=' + objForm.host_id.value;
strURL = strURL + '&command=node_step1';
if( objForm.overlib.checked)
{
strURL = strURL + "&overlib=1";
}
else
{
strURL = strURL + "&overlib=0";
}
//if( objForm.aggregate.checked)
//{
// strURL = strURL + "&aggregate=1";
//}
//else
//{
// strURL = strURL + "&aggregate=0";
//}
document.location = strURL;
}
</script>
<script type="text/javascript">
function update_source_step1(graphid,name)
{
// This is the section that sets the Node Properties
var graph_url, hover_url;
var base_url = '<?php echo isset($config['base_url'])?$config['base_url']:''; ?>';
if (typeof window.opener == "object") {
graph_url = base_url + 'graph.php?height=100&width=512&device=' + graphid + '&type=device_bits&legend=no';
info_url = base_url + 'device/device=' + graphid +'/';
// only set the overlib URL unless the box is checked
if( document.forms['mini'].overlib.checked)
{
opener.document.forms["frmMain"].node_infourl.value = info_url;
}
opener.document.forms["frmMain"].node_hover.value = graph_url;
opener.document.forms["frmMain"].node_new_name.value = graphid;
opener.document.forms["frmMain"].node_label.value = name;
}
self.close();
}
</script>
<style type="text/css">
body { font-family: sans-serif; font-size: 10pt; }
ul { list-style: none; margin: 0; padding: 0; }
ul { border: 1px solid black; }
ul li.row0 { background: #ddd;}
ul li.row1 { background: #ccc;}
ul li { border-bottom: 1px solid #aaa; border-top: 1px solid #eee; padding: 2px;}
ul li a { text-decoration: none; color: black; }
</style>
<title>Pick a graph</title>
</head>
<body>
<h3>Pick a graph:</h3>
<form name="mini">
<?php
if(sizeof($hosts) > 0) {
print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
print '<option '.($host_id==-1 ? 'SELECTED' : '' ).' value="-1">Any</option>';
print '<option '.($host_id==0 ? 'SELECTED' : '' ).' value="0">None</option>';
foreach ($hosts as $host)
{
print '<option ';
if($host_id==$host['id']) print " SELECTED ";
print 'value="'.$host['id'].'">'.$host['name'].'</option>';
}
print '</select><br />';
}
print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
print '<input id="overlib" name="overlib" type="checkbox" value="yes" '.($overlib ? 'CHECKED' : '' ).'> <label for="overlib">Set both OVERLIBGRAPH and INFOURL.</label><br />';
print '</form><div class="listcontainer"><ul id="dslist">';
$result = mysqli_query($SQL_picklist);
if( mysqli_num_rows($result) > 0)
{
$i=0;
while($queryrows = mysqli_fetch_assoc($result)) {
echo "<li class=\"row".($i%2)."\">";
$key = $queryrows['id'];
$name = $queryrows['name'];
echo "<a href=\"#\" onclick=\"update_source_step1('$key','$name')\">". $queryrows['name'] . "</a>";
echo "</li>\n";
$i++;
}
}
else
{
print "No results...";
}
?>
</ul>
</body>
</html>
<?php
} // end of node step 1
// vim:ts=4:sw=4:
?>