Fix indents

This commit is contained in:
Akkadius 2017-09-21 22:18:27 -05:00
parent 7765e23d53
commit 0c8ebc8226
3 changed files with 127 additions and 127 deletions

View File

@ -3,132 +3,132 @@
*/ */
module.exports = { module.exports = {
parse: function(input) { parse: function (input) {
var lease_data = input.split("lease"); var lease_data = input.split("lease");
for (i = 0; i < lease_data.length; i++) { for (i = 0; i < lease_data.length; i++) {
ip_address = ""; ip_address = "";
lines = lease_data[i].split("\n"); lines = lease_data[i].split("\n");
for (l = 0; l < lines.length; l++) { for (l = 0; l < lines.length; l++) {
/* Trim whitespaces at each ends of the line */ /* Trim whitespaces at each ends of the line */
lines[l] = lines[l].trim(); lines[l] = lines[l].trim();
/* Break each newline into an array split into spaces /* Break each newline into an array split into spaces
Ex: [ 'starts', '3', '2017/08/09', '04:50:53;' ] Ex: [ 'starts', '3', '2017/08/09', '04:50:53;' ]
*/ */
line_data_arg = lines[l].split(" "); line_data_arg = lines[l].split(" ");
if (/{/i.test(lines[l]) && /\./i.test(lines[l]) && !/uid/i.test(lines[l])){ if (/{/i.test(lines[l]) && /\./i.test(lines[l]) && !/uid/i.test(lines[l])) {
ip_address = line_data_arg[0].trim(); ip_address = line_data_arg[0].trim();
if(typeof dhcp_lease_data[ip_address] === "undefined") { if (typeof dhcp_lease_data[ip_address] === "undefined") {
dhcp_lease_data[ip_address] = {}; dhcp_lease_data[ip_address] = {};
} }
option_data = {}; option_data = {};
} }
if(ip_address != "") { if (ip_address != "") {
if (/start/i.test(lines[l])) { if (/start/i.test(lines[l])) {
/* /*
Make sure we force format as UTC because that is what the leases are formatted in Make sure we force format as UTC because that is what the leases are formatted in
*/
date = (line_data_arg[2] + ' ' + line_data_arg[3]).trim().replace(/\//gi, '-').replace(/;/i, '') + ' UTC';
start_unix_time = (Date.parse(date) / 1000);
dhcp_lease_data[ip_address].start = start_unix_time;
}
if (/ends/i.test(lines[l])) {
/*
Make sure we force format as UTC because that is what the leases are formatted in
*/ */
lease_end = (line_data_arg[2] + ' ' + line_data_arg[3]).trim().replace(/\//gi, '-').replace(/;/i, '') + ' UTC'; date = (line_data_arg[2] + ' ' + line_data_arg[3]).trim().replace(/\//gi, '-').replace(/;/i, '') + ' UTC';
now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0)); start_unix_time = (Date.parse(date) / 1000);
end_unix_time = parseInt((new Date(lease_end).getTime() / 1000).toFixed(0).toLocaleString()); dhcp_lease_data[ip_address].start = start_unix_time;
}
if (/ends/i.test(lines[l])) {
/*
Make sure we force format as UTC because that is what the leases are formatted in
*/
lease_end = (line_data_arg[2] + ' ' + line_data_arg[3]).trim().replace(/\//gi, '-').replace(/;/i, '') + ' UTC';
now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0));
end_unix_time = parseInt((new Date(lease_end).getTime() / 1000).toFixed(0).toLocaleString());
/* /*
console.log('now ' + now_unix_time); console.log('now ' + now_unix_time);
console.log('end ' + end_unix_time); console.log('end ' + end_unix_time);
console.log('now ' + new Date()); console.log('now ' + new Date());
console.log('end_raw ' + lease_end); console.log('end_raw ' + lease_end);
console.log('end ' + new Date(lease_end)); console.log('end ' + new Date(lease_end));
*/ */
if (end_unix_time <= now_unix_time) { if (end_unix_time <= now_unix_time) {
delete dhcp_lease_data[ip_address]; delete dhcp_lease_data[ip_address];
break; break;
} }
dhcp_lease_data[ip_address].end = end_unix_time; dhcp_lease_data[ip_address].end = end_unix_time;
} }
if (/ethernet/i.test(lines[l])) { if (/ethernet/i.test(lines[l])) {
if(typeof line_data_arg[2] !== "undefined") { if (typeof line_data_arg[2] !== "undefined") {
dhcp_lease_data[ip_address].mac = line_data_arg[2].replace(/;/gi, '').trim(); dhcp_lease_data[ip_address].mac = line_data_arg[2].replace(/;/gi, '').trim();
/* Mac OUI Lookup */ /* Mac OUI Lookup */
var mac_oui = dhcp_lease_data[ip_address].mac.split(":").join("").toUpperCase().slice(0,6); var mac_oui = dhcp_lease_data[ip_address].mac.split(":").join("").toUpperCase().slice(0, 6);
dhcp_lease_data[ip_address].mac_oui_vendor = ''; dhcp_lease_data[ip_address].mac_oui_vendor = '';
if(typeof oui_data[mac_oui] !== "undefined") { if (typeof oui_data[mac_oui] !== "undefined") {
dhcp_lease_data[ip_address].mac_oui_vendor = oui_data[mac_oui]; dhcp_lease_data[ip_address].mac_oui_vendor = oui_data[mac_oui];
} }
} }
} }
if (/hostname/i.test(lines[l])) { if (/hostname/i.test(lines[l])) {
if(typeof line_data_arg[1] !== "undefined") if (typeof line_data_arg[1] !== "undefined")
dhcp_lease_data[ip_address].host = line_data_arg[1].replace(/;/gi, '').replace(/"/gi, '').trim(); dhcp_lease_data[ip_address].host = line_data_arg[1].replace(/;/gi, '').replace(/"/gi, '').trim();
} }
if (/set/i.test(lines[l])) { if (/set/i.test(lines[l])) {
set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/set/gi, '').trim(); set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/set/gi, '').trim();
set_data_split = set_data.split(" "); set_data_split = set_data.split(" ");
option_key = set_data_split[0].trim(); option_key = set_data_split[0].trim();
option_value = set_data.replace(RegExp(option_key, "g"), '').trim(); option_value = set_data.replace(RegExp(option_key, "g"), '').trim();
option_data[option_key] = option_value; option_data[option_key] = option_value;
if (typeof dhcp_lease_data[ip_address]['options'] === "undefined") if (typeof dhcp_lease_data[ip_address]['options'] === "undefined")
dhcp_lease_data[ip_address]['options'] = []; dhcp_lease_data[ip_address]['options'] = [];
} }
if (/option/i.test(lines[l])) { if (/option/i.test(lines[l])) {
set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/option/gi, '').trim(); set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/option/gi, '').trim();
set_data_split = set_data.split(" "); set_data_split = set_data.split(" ");
option_key = set_data_split[0].trim(); option_key = set_data_split[0].trim();
option_value = set_data.replace(RegExp(option_key, "g"), '').trim(); option_value = set_data.replace(RegExp(option_key, "g"), '').trim();
option_data[option_key] = option_value; option_data[option_key] = option_value;
if (typeof dhcp_lease_data[ip_address]['options'] === "undefined") if (typeof dhcp_lease_data[ip_address]['options'] === "undefined")
dhcp_lease_data[ip_address]['options'] = []; dhcp_lease_data[ip_address]['options'] = [];
} }
if (lines[l].charAt(0) == "}" && typeof dhcp_lease_data[ip_address]['options'] !== "undefined"){ if (lines[l].charAt(0) == "}" && typeof dhcp_lease_data[ip_address]['options'] !== "undefined") {
if (typeof option_data !== 'undefined') { if (typeof option_data !== 'undefined') {
dhcp_lease_data[ip_address]['options'] = option_data; dhcp_lease_data[ip_address]['options'] = option_data;
} }
option_data = []; option_data = [];
} }
/* End of Lease */ /* End of Lease */
if (lines[l].charAt(0) == "}"){ if (lines[l].charAt(0) == "}") {
if(debug_watch_lease_parse_stream) { if (debug_watch_lease_parse_stream) {
console.log("[Glass Server] Lease Parse"); console.log("[Glass Server] Lease Parse");
console.log(JSON.stringify(dhcp_lease_data[ip_address], null, 2)); console.log(JSON.stringify(dhcp_lease_data[ip_address], null, 2));
} }
} }
} }
} }
} }
return; return;
}, },
clean: function() { clean: function () {
for (var key in dhcp_lease_data) { for (var key in dhcp_lease_data) {
now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0)); now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0));
end_unix_time = dhcp_lease_data[key].end; end_unix_time = dhcp_lease_data[key].end;
if((now_unix_time >= end_unix_time)) { if ((now_unix_time >= end_unix_time)) {
console.log("[DHCP Lease Data] Lease " + key + " has expired - clearing"); console.log("[DHCP Lease Data] Lease " + key + " has expired - clearing");
delete dhcp_lease_data[key]; delete dhcp_lease_data[key];
} }
} }
}, },
}; };

View File

@ -1,34 +1,34 @@
function log_action (action){ function log_action (action) {
switch(action) { switch (action) {
case "stop": case "stop":
socket.send(JSON.stringify({"event_unsubscribe": "dhcp_log_subscription"})); socket.send(JSON.stringify({"event_unsubscribe": "dhcp_log_subscription"}));
break; break;
case "start": case "start":
killed_connection = 0; killed_connection = 0;
console.log('start readystate is ' + socket.readyState); console.log('start readystate is ' + socket.readyState);
socket.send(JSON.stringify({"event_subscription": "dhcp_log_subscription"})); socket.send(JSON.stringify({"event_subscription": "dhcp_log_subscription"}));
break; break;
case "clear": case "clear":
editor.setValue(""); editor.setValue("");
break; break;
case "download_logs": case "download_logs":
if(editor.getValue() == ''){ if (editor.getValue() == '') {
notification('There is nothing to save!'); notification('There is nothing to save!');
return; return;
} }
var d = new Date(); var d = new Date();
var am_pm = format_am_pm(d); var am_pm = format_am_pm(d);
var df = d.getMonth() + '-' + d.getDate() + '-' + d.getFullYear() + '_' + (d.getHours()) + '-' + d.getMinutes() + ' ' + am_pm; var df = d.getMonth() + '-' + d.getDate() + '-' + d.getFullYear() + '_' + (d.getHours()) + '-' + d.getMinutes() + ' ' + am_pm;
var filename = "dhcp_logs_" + df; var filename = "dhcp_logs_" + df;
var text = editor.getValue(); var text = editor.getValue();
var blob = new Blob([text], {type: "text/plain;charset=utf-8"}); var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
saveAs(blob, filename + ".txt"); saveAs(blob, filename + ".txt");
break; break;
default: default:
break; break;
} }
} }
function format_am_pm(date) { function format_am_pm(date) {

View File

@ -1,8 +1,8 @@
function check_websocket_connection () { function check_websocket_connection () {
if(socket.readyState == 3) { if (socket.readyState == 3) {
connect_websocket(); connect_websocket();
console.log("[Websocket] Connection lost... reconnecting..."); console.log("[Websocket] Connection lost... reconnecting...");
} }
} }
function connect_websocket() { function connect_websocket() {