From 64a08e2e680d5fbfa5e169aa497821bd08f1ce26 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Thu, 21 Sep 2017 17:32:52 -0500 Subject: [PATCH] Implement MAC OUI translation while streaming the logs --- api/get_mac_oui_list.js | 13 + app.js | 2 + public/assets/js/glass-pages/dhcp-logs.js | 13 +- public/assets/js/glass-websockets.js | 26 +- public/templates/api_examples.html | 43 +++ public/templates/email_template.html | 338 ++++++++++++++++++++++ 6 files changed, 431 insertions(+), 4 deletions(-) create mode 100644 api/get_mac_oui_list.js diff --git a/api/get_mac_oui_list.js b/api/get_mac_oui_list.js new file mode 100644 index 0000000..107997c --- /dev/null +++ b/api/get_mac_oui_list.js @@ -0,0 +1,13 @@ +/** + * Created by cmiles on 9/21/2017. + */ + +var express = require('express'); +var router = express.Router(); + +router.get('/', function(req, res, next) { + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify(oui_data)); +}); + +module.exports = router; \ No newline at end of file diff --git a/app.js b/app.js index bd10c8f..1848940 100644 --- a/app.js +++ b/app.js @@ -53,6 +53,7 @@ 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.use('/api/get_dhcp_requests/', require('./api/get_dhcp_requests')); app.use('/api/get_server_info/', require('./api/get_server_info')); +app.use('/api/get_mac_oui_list/', require('./api/get_mac_oui_list')); app.set('view engine', 'html'); @@ -97,6 +98,7 @@ debug_watch_lease_parse_stream = 0; host_name = execSync("cat /etc/hostname").toString().replace("\n", ""); + /** * Ingest OUI Database */ diff --git a/public/assets/js/glass-pages/dhcp-logs.js b/public/assets/js/glass-pages/dhcp-logs.js index 39f09de..1fa5a0e 100644 --- a/public/assets/js/glass-pages/dhcp-logs.js +++ b/public/assets/js/glass-pages/dhcp-logs.js @@ -42,4 +42,15 @@ $('#dhcp_log').height($(window).height() * 0.6); var editor = ace.edit("dhcp_log"); editor.setTheme("ace/theme/terminal"); -editor.$blockScrolling = Infinity; \ No newline at end of file +editor.$blockScrolling = Infinity; + +get_mac_oui_data(); + +function get_mac_oui_data() { + if(typeof mac_oui_data === "undefined") { + mac_oui_data = {}; + $.getJSON("/api/get_mac_oui_list", function (data) { + mac_oui_data = data; + }); + } +} \ No newline at end of file diff --git a/public/assets/js/glass-websockets.js b/public/assets/js/glass-websockets.js index a13bf79..c000a2c 100644 --- a/public/assets/js/glass-websockets.js +++ b/public/assets/js/glass-websockets.js @@ -26,12 +26,32 @@ function connect_websocket() { return false; } + + console_data = event.data; + + if(typeof mac_oui_data !== "undefined") { + if (console_data.split(":").length - 1 >= 8) { + var line_data = console_data.split(" "); + for (i = 0; i < line_data.length; i++) { + if ((line_data[i].split(":").length - 1) == 5) { + var mac_oui = line_data[i].split(":").join("").toUpperCase().slice(0, 6); + console_data = console_data.replace(line_data[i], line_data[i] + " (" + mac_oui_data[mac_oui] + ")"); + } + } + } + } + + /* + Note: the only thing I stream currently is dhcp log - so later incoming messages will need to be + keyed by their "type" via json + */ + var grep_value = document.getElementById("grep_fitler").value; if(grep_value){ var matcher = new RegExp(grep_value, "i"); - var found = matcher.test(event.data); - if(!found && !event.data.includes(grep_value)){ + var found = matcher.test(console_data); + if(!found && !console_data.includes(grep_value)){ return false; } } @@ -40,7 +60,7 @@ function connect_websocket() { session.insert({ row: session.getLength(), column: 0 - }, "\n" + event.data); + }, "\n" + console_data); if(session.getLength() >= 50000){ /* If we get over 500,000 lines lets clear the editor */ diff --git a/public/templates/api_examples.html b/public/templates/api_examples.html index dba812c..5a51460 100644 --- a/public/templates/api_examples.html +++ b/public/templates/api_examples.html @@ -1,3 +1,8 @@ +
+

DHCP Data Calls

+
+ +
@@ -72,6 +77,43 @@
+ +
+
+
+
+

+ GET: Mac Vendor OUI List (Full) +

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+ +
+
+
+
+

Statistics Data

@@ -194,6 +236,7 @@

GET: Excessive DHCP Requests + Over a 10 minute audit interval

diff --git a/public/templates/email_template.html b/public/templates/email_template.html index e69de29..43c6909 100644 --- a/public/templates/email_template.html +++ b/public/templates/email_template.html @@ -0,0 +1,338 @@ + + + + + + Glass Alert + + + + + + + + + + + +
+
+ + + + + + + +
+ Warning: You're approaching your limit. Please upgrade. +
+ + + + + + + + + + + + + +
+ You have 1 free report remaining. +
+ Add your credit card now to upgrade your account to a premium plan to ensure you don't miss out on any reports. +
+ Upgrade my account +
+ Thanks for choosing Company Inc. +
+
+
+
+ + + \ No newline at end of file