Implement active lease search

This commit is contained in:
Akkadius 2017-09-15 06:28:23 -05:00
parent 7029c5e2e7
commit 32b4808048
7 changed files with 136 additions and 53 deletions

1
app.js
View File

@ -33,6 +33,7 @@ app.use('/users', require('./routes/users'));
app.use('/get_stats', require('./routes/get_stats'));
app.use('/dhcp_statistics', require('./routes/dhcp_statistics_page'));
app.use('/dhcp_leases', require('./routes/dhcp_leases'));
app.use('/dhcp_lease_search', require('./routes/dhcp_lease_search'));
app.use('/dhcp_log', require('./routes/dhcp_log'));
app.use('/dhcp_config', require('./routes/dhcp_config'));
app.use('/dhcp_config_snapshots', require('./routes/dhcp_config_snapshots'));

View File

@ -2,6 +2,17 @@
* Created by cmiles on 8/9/2017.
*/
var loader_html = '<div class="preloader"> \
<div class="spinner-layer pl-light-blue"> \
<div class="circle-clipper left"> \
<div class="circle"></div> \
</div> \
<div class="circle-clipper right"> \
<div class="circle"></div> \
</div> \
</div> \
</div>';
$( document ).ajaxComplete(function( event, request, settings ) {
/*
* Form input focus event
@ -142,4 +153,23 @@ $(document).on("click",".option_data",function() {
$("#" + lease).show();
$(this).text('Hide');
}
});
$(document).on("keypress","#lease_search_criteria", function(e) {
if (e.which == 13) {
$('#search_result').html(loader_html);
$.post("/dhcp_lease_search", { search: $("#lease_search_criteria").val() }, function(result) {
$("#search_result").html(result);
if(typeof display_leases !== "undefined")
display_leases.destroy();
display_leases = $('#display-leases').DataTable({
dom: 'tip',
responsive: true,
"pageLength": 100,
"aaSorting": []
});
});
}
});

View File

@ -0,0 +1,17 @@
<table id="display-leases" class="table table-bordered table-striped table-hover js-basic-example dataTable dashboard-task-infos">
<thead>
<tr>
<th>IP</th>
<th>MAC</th>
<th>Vendor</th>
<th>Hostname</th>
<th>Start</th>
<th>End</th>
<th>Option Data</th>
</tr>
</thead>
<tbody>
[table_data]
</tbody>
</table>

View File

@ -3,36 +3,28 @@
<h2>Active Leases</h2>
</div>
<div class="body">
<div class="table-responsive">
<table id="display-leases" class="table table-bordered table-striped table-hover js-basic-example dataTable dashboard-task-infos">
<thead>
<tr>
<th>IP</th>
<th>MAC</th>
<th>Vendor</th>
<th>Hostname</th>
<th>Start</th>
<th>End</th>
<th>Option Data</th>
</tr>
</thead>
<tbody>
[table_data]
</tbody>
</table>
<div id="glass-alerts-form"><label>Search Active Leases</label>
<div class="form-group">
<div class="form-line">
<input type="input" class="form-control" id="lease_search_criteria" placeholder="Enter Search Criteria...">
</div>
</div>
</div>
<div class="table-responsive">
<div id="search_result"></div>
</div>
</div>
</div>
<script type="text/javascript">
/*
$('#display-leases').DataTable({
dom: 'tip',
responsive: true,
"pageLength": 100,
"aaSorting": []
});
</script>
*/
</script>

View File

@ -1,6 +1,6 @@
<div class="row clearfix">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="card">
<div class="card hide_me">
<div class="header">
<h2>Vendor List Count</h2>
<ul class="header-dropdown m-r--5">
@ -34,7 +34,7 @@
</div>
</div>
</div>
<div class="card">
<div class="card hide_me">
<div class="header">
<h2>MAC Address OUI Count by Vendor</h2>
</div>
@ -57,6 +57,8 @@
</div>
<script type="text/javascript">
$('.hide_me').hide();
var chart_data = [];
$.getJSON( "/api/get_vendor_count", function( data ) {
$.each(data, function(k, v) {
@ -105,6 +107,9 @@
"aaSorting": [],
"order": [[ 2, "desc" ]]
});
// $('table').fadeIn(100);
$('.hide_me').show();
});

View File

@ -0,0 +1,67 @@
var express = require('express');
var router = express.Router();
var fs = require('fs');
var template_render = require('../lib/render_template.js');
function human_time (time){
var time = new Date(time);
var year = time.getFullYear();
var month = time.getMonth()+1;
var date1 = time.getDate();
var hour = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
return year + "-" + month+"-"+date1+" "+hour+":"+minutes+":"+seconds;
}
router.post('/', function(req, res, next) {
var request = req.body;
var search = request.search;
dhcp_leases = template_render.get_template("dhcp_lease_search");
table_data = '';
var count = 0;
for (var key in dhcp_lease_data) {
var matcher = new RegExp(search, "i");
if(
!matcher.test(dhcp_lease_data[key].mac_oui_vendor)
&& !matcher.test(dhcp_lease_data[key].host)
&& !matcher.test(key)
&& !matcher.test(dhcp_lease_data[key].mac)
&& !matcher.test(JSON.stringify(dhcp_lease_data[key].options, null, 2))
)
continue;
table_row = '';
table_row = table_row + '<td>' + key + '</td>';
table_row = table_row + '<td>' + dhcp_lease_data[key].mac + '</td>';
table_row = table_row + '<td>' + dhcp_lease_data[key].mac_oui_vendor + '</td>';
table_row = table_row + '<td>' + (dhcp_lease_data[key].host ? dhcp_lease_data[key].host : '') + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].start * 1000) + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].end * 1000) + '</td>';
table_row = table_row + '<td>' +
'<button class="btn btn-default waves-effect option_data" lease="' + dhcp_lease_data[key].mac.split(":").join("") + '">Show</button>' +
'<pre style="display:none;margin-top:10px" id="' + dhcp_lease_data[key].mac.split(":").join("") + '">' + JSON.stringify(dhcp_lease_data[key].options, null, 2) + '</pre>' +
'</td>';
table_data = table_data + '<tr>' + table_row + '</tr>';
count++;
if(count >= 10000){
break;
}
}
table_data = template_render.set_template_variable(dhcp_leases, "table_data", table_data);
res.send(table_data);
});
module.exports = router;

View File

@ -18,36 +18,7 @@ function human_time (time){
router.get('/', function(req, res, next) {
dhcp_leases = template_render.get_template("dhcp_leases");
table_data = '';
var count = 0;
for (var key in dhcp_lease_data) {
table_row = '';
table_row = table_row + '<td>' + key + '</td>';
table_row = table_row + '<td>' + dhcp_lease_data[key].mac + '</td>';
table_row = table_row + '<td>' + dhcp_lease_data[key].mac_oui_vendor + '</td>';
table_row = table_row + '<td>' + (dhcp_lease_data[key].host ? dhcp_lease_data[key].host : '') + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].start * 1000) + '</td>';
table_row = table_row + '<td>' + human_time(dhcp_lease_data[key].end * 1000) + '</td>';
table_row = table_row + '<td>' +
'<button class="btn btn-default waves-effect option_data" lease="' + dhcp_lease_data[key].mac.split(":").join("") + '">Show</button>' +
'<pre style="display:none;margin-top:10px" id="' + dhcp_lease_data[key].mac.split(":").join("") + '">' + JSON.stringify(dhcp_lease_data[key].options, null, 2) + '</pre>' +
'</td>';
table_data = table_data + '<tr>' + table_row + '</tr>';
count++;
if(count >= 1000){
break;
}
}
table_data = template_render.set_template_variable(dhcp_leases, "table_data", table_data);
res.send(template_render.get_index_template(table_data, req.url));
res.send(template_render.get_index_template(dhcp_leases, req.url));
});
module.exports = router;