Update 'node.js'
This commit is contained in:
@@ -5,6 +5,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
const ping = require('ping');
|
||||||
|
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const exec = util.promisify(require('child_process').exec);
|
||||||
const readFileAsync = util.promisify(fs.readFile);
|
const readFileAsync = util.promisify(fs.readFile);
|
||||||
@@ -27,7 +28,9 @@ app.get('/dvbStatus', async (req, res) => {
|
|||||||
res.set({
|
res.set({
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*'
|
||||||
});
|
});
|
||||||
const { stdout, stderr } = await exec('DTV');
|
let tuner = 0;
|
||||||
|
tuner = req.query.t;
|
||||||
|
const { stdout, stderr } = await exec(`DTV2 -t ${tuner}`);
|
||||||
const i = parseInt(stdout) * 1e-6; // i is in Hz; divide by 1M to have MHz
|
const i = parseInt(stdout) * 1e-6; // i is in Hz; divide by 1M to have MHz
|
||||||
res.send({
|
res.send({
|
||||||
"id": "dvb-t-status",
|
"id": "dvb-t-status",
|
||||||
@@ -41,7 +44,9 @@ app.get('/dvbChannel', async (req, res) => {
|
|||||||
res.set({
|
res.set({
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*'
|
||||||
});
|
});
|
||||||
const { stdout, stderr } = await exec('DTV');
|
let tuner = 0;
|
||||||
|
tuner = req.query.t;
|
||||||
|
const { stdout, stderr } = await exec(`DTV2 -t ${tuner}`);
|
||||||
const i = parseInt(stdout) * 1e-6; // i is in Hz; divide by 1M to have MHz
|
const i = parseInt(stdout) * 1e-6; // i is in Hz; divide by 1M to have MHz
|
||||||
readFileAsync(path.join(__dirname,"frequencies.json"))
|
readFileAsync(path.join(__dirname,"frequencies.json"))
|
||||||
.then(res2 => {
|
.then(res2 => {
|
||||||
@@ -75,6 +80,29 @@ app.get('/internetCheck', async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
app.get('/vpnCheck', async (req, res) => {
|
||||||
|
res.set({
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
});
|
||||||
|
let ifaces = os.networkInterfaces()
|
||||||
|
if(ifaces.hasOwnProperty('tun0')){
|
||||||
|
res.send(
|
||||||
|
{
|
||||||
|
"id": "vpn-check",
|
||||||
|
"data": ifaces["tun0"][0]["cidr"],
|
||||||
|
"stderr": ""
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
res.send(
|
||||||
|
{
|
||||||
|
"id": "vpn-check",
|
||||||
|
"data": "Not connected",
|
||||||
|
"stderr": ""
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/sysStatus', (req, res) => {
|
app.get('/sysStatus', (req, res) => {
|
||||||
@@ -84,33 +112,58 @@ app.get('/sysStatus', (req, res) => {
|
|||||||
readFileAsync('/sys/class/thermal/thermal_zone0/temp')
|
readFileAsync('/sys/class/thermal/thermal_zone0/temp')
|
||||||
.then(res2=>
|
.then(res2=>
|
||||||
{
|
{
|
||||||
res.send(
|
res.send({
|
||||||
{
|
|
||||||
"id": "sys-stats",
|
"id": "sys-stats",
|
||||||
"data": `Temp: ${(parseFloat(res2)*1e-3).toFixed(2)} °C Load Avg: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
|
"data": `${(parseFloat(res2)*1e-3).toFixed(2)} °C Load: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
|
||||||
"stderr": ""
|
"stderr": ""
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.catch(err=> {
|
.catch(err=> {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
res.send(
|
res.send({
|
||||||
{
|
|
||||||
"id": "sys-stats",
|
"id": "sys-stats",
|
||||||
"data": `Load Avg: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
|
"data": `Load Avg: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
|
||||||
"stderr": err
|
"stderr": err
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/lancianoCheck', async (req, res) => {
|
||||||
|
res.set({
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
});
|
||||||
|
let hostRes='';
|
||||||
|
let hosts = ["10.8.0.2","10.8.0.3"];
|
||||||
|
let promArr=[];
|
||||||
|
for(let host of hosts) {
|
||||||
|
promArr.push(ping.promise.probe(host));
|
||||||
|
}
|
||||||
|
Promise.all(promArr)
|
||||||
|
.then(function (res) {
|
||||||
|
for (let item of res) {
|
||||||
|
if(item.alive) {
|
||||||
|
hostRes+=item.host+' is alive ';
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
hostRes+=item.host+' is dead ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(()=>{
|
||||||
|
res.send({
|
||||||
|
"id": "lanciano-check",
|
||||||
|
"data": hostRes.toString(),
|
||||||
|
"stderr": ""
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
app.use(express.static('/var/www/default')); // serve static build site
|
app.use(express.static('/var/www/forbidden-fruit-dashboard')); // serve static build site
|
||||||
|
|
||||||
// app.get('*', (req, res) => {
|
// app.get('*', (req, res) => {
|
||||||
// res.sendFile(__dirname + '/public/index.html');
|
// res.sendFile(__dirname + '/public/index.html');
|
||||||
// });
|
// });
|
||||||
|
|
||||||
//app.listen(8000,"192.168.10.14", () => console.log('listen on 8000'));
|
//app.listen(8000,"192.168.10.14", () => console.log('listen on 8000'));
|
||||||
app.listen(process.env.NODE_PORT,'127.0.0.80', () => console.log('listen on 3000'));
|
app.listen(process.env.NODE_PORT,process.env.NODE_IP, () => console.log(`Bind on ${process.env.NODE_IP}:${process.env.NODE_PORT}`));
|
||||||
Reference in New Issue
Block a user