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