From 187ffb5f0e30e8cfe9c75a297ed3f6c4647e454c Mon Sep 17 00:00:00 2001 From: Akkadius Date: Fri, 15 Sep 2017 05:23:02 -0500 Subject: [PATCH] Statistics Page and API - MAC Address OUI Count by Vendor --- api/get_mac_oui_count_by_vendor.js | 37 +++++++++++++++++ api/get_subnet_details.js | 2 +- app.js | 1 + public/templates/dhcp_statistics_page.html | 47 ++++++++++++++++++++-- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 api/get_mac_oui_count_by_vendor.js diff --git a/api/get_mac_oui_count_by_vendor.js b/api/get_mac_oui_count_by_vendor.js new file mode 100644 index 0000000..36a20ec --- /dev/null +++ b/api/get_mac_oui_count_by_vendor.js @@ -0,0 +1,37 @@ +var express = require('express'); +var router = express.Router(); +var fs = require('fs'); + +router.get('/', function(req, res, next) { + + var stat_data = {}; + + var count = 0; + for (var key in dhcp_lease_data) { + /* Mac OUI Lookup */ + var mac_oui = dhcp_lease_data[key].mac.split(":").join("").toUpperCase().slice(0,6); + + if(typeof stat_data[mac_oui] === "undefined") + stat_data[mac_oui] = {}; + + if(typeof stat_data[mac_oui].count === "undefined") + stat_data[mac_oui].count = 0; + + stat_data[mac_oui].count++; + + if(stat_data[mac_oui].mac_prefix !== "undefined") { + stat_data[mac_oui].mac_prefix = mac_oui; + } + + if(stat_data[mac_oui].vendor !== "undefined"){ + if(typeof oui_data[mac_oui] !== "undefined") { + stat_data[mac_oui].vendor = oui_data[mac_oui]; + } + } + } + + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify(stat_data)); +}); + +module.exports = router; \ No newline at end of file diff --git a/api/get_subnet_details.js b/api/get_subnet_details.js index 38b0764..839fd36 100644 --- a/api/get_subnet_details.js +++ b/api/get_subnet_details.js @@ -15,7 +15,7 @@ router.get('/', function(req, res, next) { const execSync = require('child_process').execSync; output = execSync('./bin/dhcpd-pools -c ' + glass_config.config_file + ' -l ' + glass_config.leases_file + ' -f j -A -s e'); - console.log(JSON.parse(output)); + // console.log(JSON.parse(output)); res.send(JSON.stringify(JSON.parse(output))); }); diff --git a/app.js b/app.js index 17e8563..c89e9ed 100644 --- a/app.js +++ b/app.js @@ -49,6 +49,7 @@ app.use('/glass_settings_save', require('./routes/glass_settings_save')); app.use('/api/get_active_leases/', require('./api/get_active_leases')); app.use('/api/get_subnet_details/', require('./api/get_subnet_details')); app.use('/api/get_vendor_count/', require('./api/get_vendor_count')); +app.use('/api/get_mac_oui_count_by_vendor/', require('./api/get_mac_oui_count_by_vendor')); app.set('view engine', 'html'); diff --git a/public/templates/dhcp_statistics_page.html b/public/templates/dhcp_statistics_page.html index 5e04a7e..b510010 100644 --- a/public/templates/dhcp_statistics_page.html +++ b/public/templates/dhcp_statistics_page.html @@ -34,6 +34,24 @@ +
+
+

MAC Address OUI Count by Vendor

+
+
+ + + + + + + + + + +
MAC Address OUIVendorCount
+
+
@@ -41,7 +59,6 @@ \ No newline at end of file