2017-08-09 22:18:28 +02:00
|
|
|
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.get('/', function(req, res, next) {
|
|
|
|
dhcp_leases = template_render.get_template("dhcp_leases");
|
|
|
|
|
|
|
|
table_data = '';
|
|
|
|
|
2017-09-15 09:45:27 +02:00
|
|
|
var count = 0;
|
2017-08-09 22:18:28 +02:00
|
|
|
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>';
|
2017-09-15 10:08:29 +02:00
|
|
|
table_row = table_row + '<td>' + dhcp_lease_data[key].mac_oui_vendor + '</td>';
|
2017-08-09 22:18:28 +02:00
|
|
|
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>';
|
2017-09-15 09:45:27 +02:00
|
|
|
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>';
|
2017-08-09 22:18:28 +02:00
|
|
|
|
|
|
|
table_data = table_data + '<tr>' + table_row + '</tr>';
|
2017-09-15 09:45:27 +02:00
|
|
|
|
|
|
|
count++;
|
2017-09-15 10:19:05 +02:00
|
|
|
|
|
|
|
if(count >= 1000){
|
|
|
|
break;
|
|
|
|
}
|
2017-09-15 11:40:28 +02:00
|
|
|
|
2017-08-09 22:18:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
table_data = template_render.set_template_variable(dhcp_leases, "table_data", table_data);
|
|
|
|
|
|
|
|
res.send(template_render.get_index_template(table_data, req.url));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|