Load OUI Database into core memory - push vendor data onto lease stack

This commit is contained in:
Akkadius 2017-09-15 03:08:29 -05:00
parent d6c4682697
commit 4e2aa2359a
6 changed files with 52 additions and 8 deletions

30
app.js
View File

@ -87,8 +87,38 @@ listening_to_log_file = 0;
options = {};
options.interval = 1000;
debug_watch_lease_parse_stream = 0;
host_name = execSync("cat /etc/hostname").toString();
/**
* Ingest OUI Database
*/
fs = require('fs');
var oui_database_file = "bin/oui_table.txt";
/* Global oui_data bucket */
oui_data = {};
if (fs.existsSync(oui_database_file)) {
fs.readFile(oui_database_file, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
else {
/* Iterate through file */
lines = data.split("\n");
for (l = 0; l < lines.length; l++) {
/* Trim whitespaces at each ends of the line */
lines[l] = lines[l].trim();
var oui_line_data = lines[l].split(":::");
if(typeof oui_line_data[1] !== "undefined")
oui_data[oui_line_data[0].trim()] = oui_line_data[1].trim();
}
console.log("[Glass Server] OUI Database Loaded");
}
});
}
/**
* Ingest Current Lease File
*/

View File

@ -61,8 +61,17 @@ module.exports = {
dhcp_lease_data[ip_address].end = end_unix_time;
}
if (/ethernet/i.test(lines[l])) {
if(typeof line_data_arg[2] !== "undefined")
dhcp_lease_data[ip_address].mac = line_data_arg[2].replace(/;/gi, '').trim();
if(typeof line_data_arg[2] !== "undefined") {
dhcp_lease_data[ip_address].mac = line_data_arg[2].replace(/;/gi, '').trim();
/* Mac OUI Lookup */
var mac_oui = dhcp_lease_data[ip_address].mac.split(":").join("").toUpperCase().slice(0,6);
dhcp_lease_data[ip_address].mac_oui_vendor = '';
if(typeof oui_data[mac_oui] !== "undefined") {
dhcp_lease_data[ip_address].mac_oui_vendor = oui_data[mac_oui];
}
}
}
if (/hostname/i.test(lines[l])) {
if(typeof line_data_arg[1] !== "undefined")
@ -99,6 +108,13 @@ module.exports = {
option_data = [];
}
/* End of Lease */
if (lines[l].charAt(0) == "}"){
if(debug_watch_lease_parse_stream) {
console.log("[Glass Server] Lease Parse");
console.log(JSON.stringify(dhcp_lease_data[ip_address], null, 2));
}
}
}
}
}

View File

@ -11,7 +11,7 @@ module.exports = {
}
else {
core = fs.readFileSync('./public/templates/index.html', 'utf8');
core = core.replace(/\[application_name\]/, 'Glass | ISC DHCP server utility');
core = core.replace(/\[application_name\]/, 'Glass | ISC DHCP Server Interface');
core = core.replace(/\[body_content\]/, body_content);
// core = core.replace(/\[(.*?)\]/, "");
return core;

View File

@ -11,6 +11,7 @@
<tr>
<th>IP</th>
<th>MAC</th>
<th>Vendor</th>
<th>Hostname</th>
<th>Start</th>
<th>End</th>

View File

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>Glass | ISC DHCP Server Utility</title>
<title>Glass | ISC DHCP Server Interface</title>
<!-- Favicon-->
<link rel="icon" href="../../favicon.ico" type="image/x-icon">

View File

@ -26,6 +26,7 @@ router.get('/', function(req, res, next) {
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>';
@ -37,10 +38,6 @@ router.get('/', function(req, res, next) {
table_data = table_data + '<tr>' + table_row + '</tr>';
count++;
if(count > 30){
break;
}
}
table_data = template_render.set_template_variable(dhcp_leases, "table_data", table_data);