46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
|
const http = require('http')
|
||
|
const globalVars = require('../libs/globalVars')
|
||
|
const led = require('../libs/led')
|
||
|
const common = require('../libs/common')
|
||
|
const lcd = require('../libs/lcd')
|
||
|
|
||
|
module.exports = {
|
||
|
|
||
|
getStatus: () => {
|
||
|
var rest_options = {
|
||
|
host: '192.168.4.5',
|
||
|
port: 80,
|
||
|
path: '/admin/api.php',
|
||
|
method: 'GET'
|
||
|
};
|
||
|
let t = new Date().toUTCString()
|
||
|
console.log(t + ' piHole request')
|
||
|
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);
|
||
|
let domainsBeingBlocked = data.domains_being_blocked
|
||
|
let queriesToday = data.dns_queries_today
|
||
|
let queriesBlockedToday = data.ads_blocked_today
|
||
|
let percentageBlocked = data.ads_percentage_today
|
||
|
|
||
|
lcd.piHolePage(domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked)
|
||
|
|
||
|
});
|
||
|
})
|
||
|
// Report errors
|
||
|
request.on('error', function (error) {
|
||
|
led.set('green')
|
||
|
lcd.heatingStatus('Error No Data')
|
||
|
globalVars.heatingOn = 'error'
|
||
|
});
|
||
|
request.end();
|
||
|
}
|
||
|
}
|