glass-isc-dhcp/api/get_active_leases.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-08-09 22:18:28 +02:00
/**
* Created by cmiles on 8/9/2017.
*/
var express = require('express');
2018-08-14 07:03:36 +02:00
var router = express.Router();
2017-08-09 22:18:28 +02:00
2018-08-14 07:03:36 +02:00
router.get('/', function (req, res, next) {
2017-08-09 22:18:28 +02:00
var lease_parser = require('../lib/lease_parser.js');
lease_parser.clean();
var dhcp_lease_data_return_buffer = {};
var search_string = req.query.search;
2018-08-14 07:03:36 +02:00
if (typeof search_string !== "undefined") {
2018-08-14 07:03:36 +02:00
for (var key in dhcp_lease_data) {
2018-08-14 07:03:36 +02:00
var matcher = new RegExp(search_string, "i");
2018-08-14 07:03:36 +02:00
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;
2018-08-14 07:03:36 +02:00
if (typeof dhcp_lease_data_return_buffer[key] !== "undefined")
dhcp_lease_data_return_buffer[key] = {};
2018-08-14 07:03:36 +02:00
dhcp_lease_data_return_buffer[key] = dhcp_lease_data[key];
2018-08-14 07:03:36 +02:00
}
2018-08-14 07:03:36 +02:00
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(dhcp_lease_data_return_buffer));
2018-08-14 07:03:36 +02:00
return true;
}
2017-08-09 22:18:28 +02:00
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(dhcp_lease_data));
});
module.exports = router;