From 0c8ebc8226783092279583c7a067cd38f8e1e3a8 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Thu, 21 Sep 2017 22:18:27 -0500 Subject: [PATCH] Fix indents --- lib/lease_parser.js | 188 +++++++++++----------- public/assets/js/glass-pages/dhcp-logs.js | 58 +++---- public/assets/js/glass-websockets.js | 8 +- 3 files changed, 127 insertions(+), 127 deletions(-) diff --git a/lib/lease_parser.js b/lib/lease_parser.js index 1364cdb..6004747 100644 --- a/lib/lease_parser.js +++ b/lib/lease_parser.js @@ -3,132 +3,132 @@ */ module.exports = { - parse: function(input) { - var lease_data = input.split("lease"); - for (i = 0; i < lease_data.length; i++) { - ip_address = ""; + parse: function (input) { + var lease_data = input.split("lease"); + for (i = 0; i < lease_data.length; i++) { + ip_address = ""; - lines = lease_data[i].split("\n"); - for (l = 0; l < lines.length; l++) { + lines = lease_data[i].split("\n"); + for (l = 0; l < lines.length; l++) { /* 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 - 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])){ - ip_address = line_data_arg[0].trim(); - if(typeof dhcp_lease_data[ip_address] === "undefined") { - dhcp_lease_data[ip_address] = {}; - } - option_data = {}; - } - if(ip_address != "") { - if (/start/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(); + if (typeof dhcp_lease_data[ip_address] === "undefined") { + dhcp_lease_data[ip_address] = {}; + } + option_data = {}; + } + if (ip_address != "") { + if (/start/i.test(lines[l])) { /* - 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 + 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)); - end_unix_time = parseInt((new Date(lease_end).getTime() / 1000).toFixed(0).toLocaleString()); + 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'; + + 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('end ' + end_unix_time); + console.log('now ' + now_unix_time); + console.log('end ' + end_unix_time); - console.log('now ' + new Date()); - console.log('end_raw ' + lease_end); - console.log('end ' + new Date(lease_end)); - */ + console.log('now ' + new Date()); + console.log('end_raw ' + lease_end); + console.log('end ' + new Date(lease_end)); + */ - if (end_unix_time <= now_unix_time) { - delete dhcp_lease_data[ip_address]; - break; - } - dhcp_lease_data[ip_address].end = end_unix_time; - } - if (/ethernet/i.test(lines[l])) { - if(typeof line_data_arg[2] !== "undefined") { + if (end_unix_time <= now_unix_time) { + delete dhcp_lease_data[ip_address]; + break; + } + 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(); - /* Mac OUI Lookup */ - var mac_oui = dhcp_lease_data[ip_address].mac.split(":").join("").toUpperCase().slice(0,6); + /* 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") { + 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") - dhcp_lease_data[ip_address].host = line_data_arg[1].replace(/;/gi, '').replace(/"/gi, '').trim(); - } - if (/set/i.test(lines[l])) { - set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/set/gi, '').trim(); - set_data_split = set_data.split(" "); + } + if (/hostname/i.test(lines[l])) { + if (typeof line_data_arg[1] !== "undefined") + dhcp_lease_data[ip_address].host = line_data_arg[1].replace(/;/gi, '').replace(/"/gi, '').trim(); + } + if (/set/i.test(lines[l])) { + set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/set/gi, '').trim(); + set_data_split = set_data.split(" "); - option_key = set_data_split[0].trim(); - option_value = set_data.replace(RegExp(option_key, "g"), '').trim(); + option_key = set_data_split[0].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") - dhcp_lease_data[ip_address]['options'] = []; - } - if (/option/i.test(lines[l])) { - set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/option/gi, '').trim(); - set_data_split = set_data.split(" "); + if (typeof dhcp_lease_data[ip_address]['options'] === "undefined") + dhcp_lease_data[ip_address]['options'] = []; + } + if (/option/i.test(lines[l])) { + set_data = lines[l].replace(/;/gi, '').replace(/"/gi, '').replace(/ = /gi, ' ').replace(/option/gi, '').trim(); + set_data_split = set_data.split(" "); - option_key = set_data_split[0].trim(); - option_value = set_data.replace(RegExp(option_key, "g"), '').trim(); + option_key = set_data_split[0].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") - dhcp_lease_data[ip_address]['options'] = []; - } - if (lines[l].charAt(0) == "}" && typeof dhcp_lease_data[ip_address]['options'] !== "undefined"){ - if (typeof option_data !== 'undefined') { + if (typeof dhcp_lease_data[ip_address]['options'] === "undefined") + dhcp_lease_data[ip_address]['options'] = []; + } + if (lines[l].charAt(0) == "}" && typeof dhcp_lease_data[ip_address]['options'] !== "undefined") { + if (typeof option_data !== 'undefined') { dhcp_lease_data[ip_address]['options'] = option_data; } - option_data = []; - } + option_data = []; + } /* End of Lease */ - if (lines[l].charAt(0) == "}"){ - if(debug_watch_lease_parse_stream) { + 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)); } - } - } - } - } - return; - }, - clean: function() { - for (var key in dhcp_lease_data) { - now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0)); - end_unix_time = dhcp_lease_data[key].end; + } + } + } + } + return; + }, + clean: function () { + for (var key in dhcp_lease_data) { + now_unix_time = parseInt((new Date().getTime() / 1000).toFixed(0)); + end_unix_time = dhcp_lease_data[key].end; - if((now_unix_time >= end_unix_time)) { - console.log("[DHCP Lease Data] Lease " + key + " has expired - clearing"); - delete dhcp_lease_data[key]; - } - } - }, + if ((now_unix_time >= end_unix_time)) { + console.log("[DHCP Lease Data] Lease " + key + " has expired - clearing"); + delete dhcp_lease_data[key]; + } + } + }, }; diff --git a/public/assets/js/glass-pages/dhcp-logs.js b/public/assets/js/glass-pages/dhcp-logs.js index 1fa5a0e..c21aaad 100644 --- a/public/assets/js/glass-pages/dhcp-logs.js +++ b/public/assets/js/glass-pages/dhcp-logs.js @@ -1,34 +1,34 @@ -function log_action (action){ - switch(action) { - case "stop": - socket.send(JSON.stringify({"event_unsubscribe": "dhcp_log_subscription"})); - break; - case "start": - killed_connection = 0; - console.log('start readystate is ' + socket.readyState); - socket.send(JSON.stringify({"event_subscription": "dhcp_log_subscription"})); - break; - case "clear": - editor.setValue(""); - break; - case "download_logs": - if(editor.getValue() == ''){ - notification('There is nothing to save!'); - return; - } +function log_action (action) { + switch (action) { + case "stop": + socket.send(JSON.stringify({"event_unsubscribe": "dhcp_log_subscription"})); + break; + case "start": + killed_connection = 0; + console.log('start readystate is ' + socket.readyState); + socket.send(JSON.stringify({"event_subscription": "dhcp_log_subscription"})); + break; + case "clear": + editor.setValue(""); + break; + case "download_logs": + if (editor.getValue() == '') { + notification('There is nothing to save!'); + return; + } - var d = new Date(); - var am_pm = format_am_pm(d); - var df = d.getMonth() + '-' + d.getDate() + '-' + d.getFullYear() + '_' + (d.getHours()) + '-' + d.getMinutes() + ' ' + am_pm; - var filename = "dhcp_logs_" + df; - var text = editor.getValue(); - var blob = new Blob([text], {type: "text/plain;charset=utf-8"}); - saveAs(blob, filename + ".txt"); + var d = new Date(); + var am_pm = format_am_pm(d); + var df = d.getMonth() + '-' + d.getDate() + '-' + d.getFullYear() + '_' + (d.getHours()) + '-' + d.getMinutes() + ' ' + am_pm; + var filename = "dhcp_logs_" + df; + var text = editor.getValue(); + var blob = new Blob([text], {type: "text/plain;charset=utf-8"}); + saveAs(blob, filename + ".txt"); - break; - default: - break; - } + break; + default: + break; + } } function format_am_pm(date) { diff --git a/public/assets/js/glass-websockets.js b/public/assets/js/glass-websockets.js index fc72b38..c13da35 100644 --- a/public/assets/js/glass-websockets.js +++ b/public/assets/js/glass-websockets.js @@ -1,8 +1,8 @@ function check_websocket_connection () { - if(socket.readyState == 3) { - connect_websocket(); - console.log("[Websocket] Connection lost... reconnecting..."); - } + if (socket.readyState == 3) { + connect_websocket(); + console.log("[Websocket] Connection lost... reconnecting..."); + } } function connect_websocket() {