mirror of
https://github.com/Akkadius/glass-isc-dhcp.git
synced 2025-07-27 15:44:32 +02:00
Syntax formatting
This commit is contained in:
parent
949740fc6b
commit
07e00ce72e
@ -3,41 +3,41 @@
|
||||
*/
|
||||
|
||||
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');
|
||||
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) {
|
||||
for (var key in dhcp_lease_data) {
|
||||
|
||||
var matcher = new RegExp(search_string, "i");
|
||||
var matcher = new RegExp(search_string, "i");
|
||||
|
||||
if(
|
||||
!matcher.test(dhcp_lease_data[key].mac_oui_vendor)
|
||||
&& !matcher.test(dhcp_lease_data[key].host)
|
||||
&& !matcher.test(key)
|
||||
&& !matcher.test(dhcp_lease_data[key].mac)
|
||||
)
|
||||
continue;
|
||||
if (
|
||||
!matcher.test(dhcp_lease_data[key].mac_oui_vendor)
|
||||
&& !matcher.test(dhcp_lease_data[key].host)
|
||||
&& !matcher.test(key)
|
||||
&& !matcher.test(dhcp_lease_data[key].mac)
|
||||
)
|
||||
continue;
|
||||
|
||||
|
||||
if(typeof dhcp_lease_data_return_buffer[key] !== "undefined")
|
||||
dhcp_lease_data_return_buffer[key] = {};
|
||||
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];
|
||||
dhcp_lease_data_return_buffer[key] = dhcp_lease_data[key];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(dhcp_lease_data_return_buffer));
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(dhcp_lease_data_return_buffer));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
@ -1,18 +1,17 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var fs = require('fs');
|
||||
var router = express.Router();
|
||||
|
||||
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) {
|
||||
if(stat_data[key].request_count <= 10)
|
||||
delete stat_data[key];
|
||||
}
|
||||
for (var key in stat_data) {
|
||||
if (stat_data[key].request_count <= 10)
|
||||
delete stat_data[key];
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(stat_data));
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(stat_data));
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -1,44 +1,43 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var fs = require('fs');
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
router.get('/', function (req, res, next) {
|
||||
|
||||
var stat_data = {};
|
||||
var stat_data = {};
|
||||
|
||||
var count = 0;
|
||||
for (var key in dhcp_lease_data) {
|
||||
var count = 0;
|
||||
for (var key in dhcp_lease_data) {
|
||||
|
||||
/* Mac OUI Lookup */
|
||||
var mac_oui = "";
|
||||
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 Lookup */
|
||||
var mac_oui = "";
|
||||
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 == "")
|
||||
continue;
|
||||
if (mac_oui === "")
|
||||
continue;
|
||||
|
||||
if(typeof stat_data[mac_oui] === "undefined")
|
||||
stat_data[mac_oui] = {};
|
||||
if (typeof stat_data[mac_oui] === "undefined")
|
||||
stat_data[mac_oui] = {};
|
||||
|
||||
if(typeof stat_data[mac_oui].count === "undefined")
|
||||
stat_data[mac_oui].count = 0;
|
||||
if (typeof stat_data[mac_oui].count === "undefined")
|
||||
stat_data[mac_oui].count = 0;
|
||||
|
||||
stat_data[mac_oui].count++;
|
||||
stat_data[mac_oui].count++;
|
||||
|
||||
if(stat_data[mac_oui].mac_prefix !== "undefined") {
|
||||
stat_data[mac_oui].mac_prefix = mac_oui;
|
||||
}
|
||||
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") {
|
||||
stat_data[mac_oui].vendor = oui_data[mac_oui];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stat_data[mac_oui].vendor !== "undefined") {
|
||||
if (typeof oui_data[mac_oui] !== "undefined") {
|
||||
stat_data[mac_oui].vendor = oui_data[mac_oui];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(stat_data));
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(stat_data));
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -3,11 +3,11 @@
|
||||
*/
|
||||
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(oui_data));
|
||||
router.get('/', function (req, res, next) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(oui_data));
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -3,18 +3,18 @@
|
||||
*/
|
||||
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var router = express.Router();
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
"leases_per_minute": leases_per_minute,
|
||||
"host_name": host_name
|
||||
};
|
||||
router.get('/', function (req, res, next) {
|
||||
return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
"leases_per_minute": leases_per_minute,
|
||||
"host_name": host_name
|
||||
};
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(return_data));
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(return_data));
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -3,19 +3,17 @@
|
||||
*/
|
||||
|
||||
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');
|
||||
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));
|
||||
output = execSync('./bin/dhcpd-pools -c ' + glass_config.config_file + ' -l ' + glass_config.leases_file + ' -f j -A -s e');
|
||||
|
||||
res.send(JSON.stringify(JSON.parse(output)));
|
||||
});
|
||||
|
@ -27,33 +27,37 @@ function websockets_unsubscribe_all_events(){
|
||||
}
|
||||
|
||||
function connect_websocket() {
|
||||
$.getJSON("/api/get_websocket_config", function (data) {
|
||||
|
||||
delete socket;
|
||||
socket = new WebSocket("ws://" + window.location.hostname + ":8080");
|
||||
var websocket_port = data.ws_port;
|
||||
|
||||
socket.onopen = function (event) {
|
||||
console.log("[Websocket] socket is opened - readystate is " + socket.readyState);
|
||||
};
|
||||
delete socket;
|
||||
socket = new WebSocket("ws://" + window.location.hostname + ":" + websocket_port);
|
||||
|
||||
socket.onmessage = function (data) {
|
||||
socket.onopen = function (event) {
|
||||
console.log("[Websocket] socket is opened - readystate is " + socket.readyState);
|
||||
};
|
||||
|
||||
var event_data = JSON.parse(data.data);
|
||||
socket.onmessage = function (data) {
|
||||
|
||||
/*
|
||||
{event: "dhcp_log_subscription", data: "Oct 3 16:02:59 DHCP-Server dhcpd[5303]: reuse_l…% threshold, reply with unaltered, existing lease"}
|
||||
*/
|
||||
var event_data = JSON.parse(data.data);
|
||||
|
||||
if (!subscribed_events[event_data['event']])
|
||||
return false;
|
||||
/*
|
||||
{event: "dhcp_log_subscription", data: "Oct 3 16:02:59 DHCP-Server dhcpd[5303]: reuse_l…% threshold, reply with unaltered, existing lease"}
|
||||
*/
|
||||
|
||||
/* Event Hooks */
|
||||
if (event_data['event'] == 'dhcp_log_subscription')
|
||||
parse_log_stream (event_data.data);
|
||||
if (!subscribed_events[event_data['event']])
|
||||
return false;
|
||||
|
||||
if (event_data['event'] == 'dhcp_statistics')
|
||||
parse_statistics_stream (event_data.data);
|
||||
/* Event Hooks */
|
||||
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);
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
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');
|
||||
var router = express.Router();
|
||||
|
||||
/* 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');
|
||||
|
||||
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,13 +89,13 @@ router.get('/', function(req, res, next) {
|
||||
|
||||
total_leases = dhcp_data.summary.used.toLocaleString('en');
|
||||
|
||||
return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_used": total_leases,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
"leases_per_minute": leases_per_minute,
|
||||
"shared_network_table": shared_networks,
|
||||
"host_name": host_name,
|
||||
let return_data = {
|
||||
"cpu_utilization": cpu_utilization,
|
||||
"leases_used": total_leases,
|
||||
"leases_per_second": current_leases_per_second,
|
||||
"leases_per_minute": leases_per_minute,
|
||||
"shared_network_table": shared_networks,
|
||||
"host_name": host_name,
|
||||
"display_subnets_table": display_subnets
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user