mirror of
https://github.com/Akkadius/glass-isc-dhcp.git
synced 2025-07-27 23:54:32 +02:00
Syntax formatting
This commit is contained in:
parent
949740fc6b
commit
07e00ce72e
@ -5,20 +5,20 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
var lease_parser = require('../lib/lease_parser.js');
|
||||
lease_parser.clean();
|
||||
|
||||
var dhcp_lease_data_return_buffer = {};
|
||||
|
||||
var search_string = req.query.search;
|
||||
if (typeof search_string !== "undefined"){
|
||||
if (typeof search_string !== "undefined") {
|
||||
|
||||
for (var key in dhcp_lease_data) {
|
||||
|
||||
var matcher = new RegExp(search_string, "i");
|
||||
|
||||
if(
|
||||
if (
|
||||
!matcher.test(dhcp_lease_data[key].mac_oui_vendor)
|
||||
&& !matcher.test(dhcp_lease_data[key].host)
|
||||
&& !matcher.test(key)
|
||||
@ -27,7 +27,7 @@ router.get('/', function(req, res, next) {
|
||||
continue;
|
||||
|
||||
|
||||
if(typeof dhcp_lease_data_return_buffer[key] !== "undefined")
|
||||
if (typeof dhcp_lease_data_return_buffer[key] !== "undefined")
|
||||
dhcp_lease_data_return_buffer[key] = {};
|
||||
|
||||
dhcp_lease_data_return_buffer[key] = dhcp_lease_data[key];
|
||||
|
@ -1,13 +1,12 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var fs = require('fs');
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
|
||||
var stat_data = dhcp_requests;
|
||||
|
||||
for (var key in stat_data) {
|
||||
if(stat_data[key].request_count <= 10)
|
||||
if (stat_data[key].request_count <= 10)
|
||||
delete stat_data[key];
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var fs = require('fs');
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
|
||||
var stat_data = {};
|
||||
|
||||
@ -11,27 +10,27 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
/* Mac OUI Lookup */
|
||||
var mac_oui = "";
|
||||
if(typeof dhcp_lease_data[key].mac.split(":").join("") !== "undefined") {
|
||||
if (typeof dhcp_lease_data[key].mac.split(":").join("") !== "undefined") {
|
||||
mac_oui = dhcp_lease_data[key].mac.split(":").join("").toUpperCase().slice(0, 6);
|
||||
}
|
||||
|
||||
if(mac_oui == "")
|
||||
if (mac_oui === "")
|
||||
continue;
|
||||
|
||||
if(typeof stat_data[mac_oui] === "undefined")
|
||||
if (typeof stat_data[mac_oui] === "undefined")
|
||||
stat_data[mac_oui] = {};
|
||||
|
||||
if(typeof stat_data[mac_oui].count === "undefined")
|
||||
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") {
|
||||
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") {
|
||||
if (stat_data[mac_oui].vendor !== "undefined") {
|
||||
if (typeof oui_data[mac_oui] !== "undefined") {
|
||||
stat_data[mac_oui].vendor = oui_data[mac_oui];
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(oui_data));
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
|
@ -5,18 +5,16 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
|
||||
var json_file = require('jsonfile');
|
||||
glass_config = json_file.readFileSync('config/glass_config.json');
|
||||
let glass_config = json_file.readFileSync('config/glass_config.json');
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
||||
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));
|
||||
|
||||
res.send(JSON.stringify(JSON.parse(output)));
|
||||
});
|
||||
|
||||
|
@ -27,9 +27,12 @@ function websockets_unsubscribe_all_events(){
|
||||
}
|
||||
|
||||
function connect_websocket() {
|
||||
$.getJSON("/api/get_websocket_config", function (data) {
|
||||
|
||||
var websocket_port = data.ws_port;
|
||||
|
||||
delete socket;
|
||||
socket = new WebSocket("ws://" + window.location.hostname + ":8080");
|
||||
socket = new WebSocket("ws://" + window.location.hostname + ":" + websocket_port);
|
||||
|
||||
socket.onopen = function (event) {
|
||||
console.log("[Websocket] socket is opened - readystate is " + socket.readyState);
|
||||
@ -47,13 +50,14 @@ function connect_websocket() {
|
||||
return false;
|
||||
|
||||
/* Event Hooks */
|
||||
if (event_data['event'] == 'dhcp_log_subscription')
|
||||
parse_log_stream (event_data.data);
|
||||
if (event_data['event'] === 'dhcp_log_subscription')
|
||||
parse_log_stream(event_data.data);
|
||||
|
||||
if (event_data['event'] == 'dhcp_statistics')
|
||||
parse_statistics_stream (event_data.data);
|
||||
if (event_data['event'] === 'dhcp_statistics')
|
||||
parse_statistics_stream(event_data.data);
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
connect_websocket();
|
||||
|
@ -1,33 +1,30 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var fs = require('fs');
|
||||
var template_render = require('../lib/render_template.js');
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
|
||||
var json_file = require('jsonfile');
|
||||
var glass_config = json_file.readFileSync('config/glass_config.json');
|
||||
|
||||
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');
|
||||
let output = execSync('./bin/dhcpd-pools -c ' + glass_config.config_file + ' -l ' + glass_config.leases_file + ' -f j -A -s e');
|
||||
|
||||
var dhcp_data = JSON.parse(output);
|
||||
|
||||
for ( var i = 0; i < dhcp_data['shared-networks'].length; i++) {
|
||||
for (var i = 0; i < dhcp_data['shared-networks'].length; i++) {
|
||||
utilization = round(parseFloat(dhcp_data['shared-networks'][i].used / dhcp_data['shared-networks'][i].defined) * 100, 2);
|
||||
if(isNaN(utilization))
|
||||
if (isNaN(utilization))
|
||||
utilization = 0;
|
||||
|
||||
dhcp_data['shared-networks'][i].utilization = utilization;
|
||||
}
|
||||
dhcp_data['shared-networks'].sort(function(a, b) {
|
||||
dhcp_data['shared-networks'].sort(function (a, b) {
|
||||
return parseFloat(b.utilization) - parseFloat(a.utilization);
|
||||
});
|
||||
|
||||
shared_networks = '';
|
||||
let shared_networks = '';
|
||||
|
||||
for ( var i = 0; i < dhcp_data['shared-networks'].length; i++) {
|
||||
for (var i = 0; i < dhcp_data['shared-networks'].length; i++) {
|
||||
|
||||
utilization = dhcp_data['shared-networks'][i].utilization;
|
||||
|
||||
@ -39,9 +36,9 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
utilization_color = 'green';
|
||||
|
||||
if(utilization >= 80)
|
||||
if (utilization >= 80)
|
||||
utilization_color = 'orange';
|
||||
if(utilization >= 90)
|
||||
if (utilization >= 90)
|
||||
utilization_color = 'red';
|
||||
|
||||
table_row = table_row + '<td><div class="progress">' +
|
||||
@ -52,21 +49,21 @@ router.get('/', function(req, res, next) {
|
||||
}
|
||||
|
||||
/* Display All Subnets */
|
||||
for ( var i = 0; i < dhcp_data.subnets.length; i++) {
|
||||
for (var i = 0; i < dhcp_data.subnets.length; i++) {
|
||||
utilization = round(parseFloat(dhcp_data.subnets[i].used / dhcp_data.subnets[i].defined) * 100, 2);
|
||||
if(isNaN(utilization))
|
||||
if (isNaN(utilization))
|
||||
utilization = 0;
|
||||
|
||||
dhcp_data.subnets[i].utilization = utilization;
|
||||
}
|
||||
|
||||
dhcp_data.subnets.sort(function(a, b) {
|
||||
dhcp_data.subnets.sort(function (a, b) {
|
||||
return parseFloat(b.utilization) - parseFloat(a.utilization);
|
||||
});
|
||||
|
||||
display_subnets = '';
|
||||
|
||||
for ( var i = 0; i < dhcp_data.subnets.length; i++) {
|
||||
for (var i = 0; i < dhcp_data.subnets.length; i++) {
|
||||
utilization = dhcp_data.subnets[i].utilization;
|
||||
|
||||
table_row = '';
|
||||
@ -78,9 +75,9 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
utilization_color = 'green';
|
||||
|
||||
if(utilization >= 80)
|
||||
if (utilization >= 80)
|
||||
utilization_color = 'orange';
|
||||
if(utilization >= 90)
|
||||
if (utilization >= 90)
|
||||
utilization_color = 'red';
|
||||
|
||||
table_row = table_row + '<td><div class="progress">' +
|
||||
@ -92,7 +89,7 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
total_leases = dhcp_data.summary.used.toLocaleString('en');
|
||||
|
||||
return_data = {
|
||||
let return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_used": total_leases,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
|
Loading…
x
Reference in New Issue
Block a user