2020-09-28 10:50:23 +01:00
|
|
|
const http = require('http')
|
|
|
|
const globalVars = require('../libs/globalVars')
|
|
|
|
const led = require('../libs/led')
|
|
|
|
const common = require('../libs/common')
|
|
|
|
const lcd = require('../libs/lcd')
|
2020-10-10 13:56:55 +01:00
|
|
|
const logger = require('perfect-logger');
|
|
|
|
|
2020-09-28 10:50:23 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
getStatus: () => {
|
|
|
|
var rest_options = {
|
|
|
|
host: '192.168.4.5',
|
|
|
|
port: 80,
|
|
|
|
path: '/admin/api.php',
|
|
|
|
method: 'GET'
|
|
|
|
};
|
2020-10-10 13:56:55 +01:00
|
|
|
logger.info('piHole request')
|
2020-09-28 10:50:23 +01:00
|
|
|
var request = http.request(rest_options, function (response) {
|
|
|
|
var content = "";
|
|
|
|
|
|
|
|
// Handle data chunks
|
|
|
|
response.on('data', function (chunk) {
|
|
|
|
content += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Once we're done streaming the response, parse it as json.
|
|
|
|
response.on('end', async function () {
|
|
|
|
var data = JSON.parse(content);
|
2020-10-10 13:56:55 +01:00
|
|
|
let piHoleData = {
|
|
|
|
"domainsBeingBlocked": data.domains_being_blocked,
|
|
|
|
"queriesToday": data.dns_queries_today,
|
|
|
|
"queriesBlockedToday": data.ads_blocked_today,
|
|
|
|
"percentageBlocked": data.ads_percentage_today
|
|
|
|
}
|
2020-09-28 10:50:23 +01:00
|
|
|
|
2020-10-10 13:56:55 +01:00
|
|
|
lcd.piHolePage(piHoleData.domainsBeingBlocked, piHoleData.queriesToday, piHoleData.queriesBlockedToday, piHoleData.percentageBlocked)
|
2020-09-28 10:50:23 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
})
|
|
|
|
// Report errors
|
|
|
|
request.on('error', function (error) {
|
|
|
|
led.set('green')
|
|
|
|
lcd.heatingStatus('Error No Data')
|
|
|
|
globalVars.heatingOn = 'error'
|
|
|
|
});
|
|
|
|
request.end();
|
|
|
|
}
|
|
|
|
}
|