switch to static

This commit is contained in:
sco
2020-11-07 02:53:26 +01:00
parent 597500232b
commit 0dda7f4840
6 changed files with 37 additions and 224 deletions
+1 -9
View File
@@ -10,18 +10,10 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.13.0", "@fortawesome/fontawesome-free": "^5.13.0",
"bulma": "^0.8.2", "bulma": "^0.8.2",
"compression": "^1.7.4",
"core-js": "^3.6.4", "core-js": "^3.6.4",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"js-yaml": "^3.14.0", "js-yaml": "^3.14.0",
"lodash.merge": "^4.6.2", "lodash.merge": "^4.6.2",
"passport": "^0.4.1", "register-service-worker": "^1.7.1"
"passport-local": "^1.0.0",
"ping": "^0.3.0",
"register-service-worker": "^1.7.1",
"rpio": "^2.2.0",
"vue": "^2.6.11"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "~4.4.1", "@vue/cli-plugin-babel": "~4.4.1",
-3
View File
@@ -1,3 +0,0 @@
NODE_PORT=3000
NODE_ENV=production
NODE_IP=127.0.0.80
+13 -8
View File
@@ -112,6 +112,11 @@ services:
subtitle: "192.168.10.6" subtitle: "192.168.10.6"
url: "http://192.168.10.6" url: "http://192.168.10.6"
target: "_blank" target: "_blank"
- name: " Turn on PC"
icon: "fas fa-ethernet"
subtitle: "192.168.10.15"
url: "/api/powerOnPc"
target: "_blank"
external: external:
- name: "System" - name: "System"
icon: "fas fa-heartbeat" icon: "fas fa-heartbeat"
@@ -119,35 +124,35 @@ external:
- name: "System Status" - name: "System Status"
icon: "fas fa-joint" icon: "fas fa-joint"
subtitle: "" subtitle: ""
url: "/sysStatus" url: "/api/sysStatus"
- name: "Icanhazip" - name: "Icanhazip"
icon: "fas fa-joint" icon: "fas fa-joint"
subtitle: "" subtitle: ""
url: "/internetCheck" url: "/api/internetCheck"
- name: "VPN" - name: "VPN"
icon: "fas fa-joint" icon: "fas fa-joint"
subtitle: "" subtitle: ""
url: "/vpnCheck" url: "/api/vpnCheck"
- name: "VPN" - name: "VPN"
icon: "fas fa-joint" icon: "fas fa-joint"
subtitle: "" subtitle: ""
url: "/lancianoCheck" url: "/api/lancianoCheck"
- name: "TV Status" - name: "TV Status"
icon: "fas fa-heartbeat" icon: "fas fa-heartbeat"
items: items:
- name: "Tv Hat Frequency" - name: "Tv Hat Frequency"
icon: "fas fa-broadcast-tower" icon: "fas fa-broadcast-tower"
subtitle: "" subtitle: ""
url: "/dvbStatus?t=1" url: "/api/dvbStatus?t=1"
- name: "Tv Hat Channel" - name: "Tv Hat Channel"
icon: "fas fa-tv" icon: "fas fa-tv"
subtitle: "" subtitle: ""
url: "/dvbChannel?t=1" url: "/api/dvbChannel?t=1"
- name: "USB tuner Frequency" - name: "USB tuner Frequency"
icon: "fas fa-broadcast-tower" icon: "fas fa-broadcast-tower"
subtitle: "" subtitle: ""
url: "/dvbStatus?t=0" url: "/api/dvbStatus?t=0"
- name: "USB Tv Channel" - name: "USB Tv Channel"
icon: "fas fa-tv" icon: "fas fa-tv"
subtitle: "" subtitle: ""
url: "/dvbChannel?t=0" url: "/api/dvbChannel?t=0"
-169
View File
@@ -1,169 +0,0 @@
const express = require('express');
const compression = require('compression');
const util = require('util');
const fs = require('fs');
const path = require('path');
const os = require('os');
const http = require("http");
const ping = require('ping');
const exec = util.promisify(require('child_process').exec);
const readFileAsync = util.promisify(fs.readFile);
const app = express(); // app is an instance of express
app.use(compression()); // enables gzip compression
app.options('*', (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': 600
})
res.status(200).end();
})
app.get('/dvbStatus', async (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*'
});
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
res.send({
"id": "dvb-t-status",
"data": `Frontend Frequency: ${i} Mhz`,
"stderr": stderr
});
});
app.get('/dvbChannel', async (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*'
});
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
readFileAsync(path.join(__dirname,"frequencies.json"))
.then(res2 => {
const db = JSON.parse(res2);
res.send({
"id": `dvb-t-channel`,
"name": db[i]["name"].toString(),
"data": db[i]["channels"].toString(),
"stderr": stderr
});
})
.catch(err => console.error(err))
});
app.get('/internetCheck', async (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*'
});
http.get('http://icanhazip.com', (httpRes) => {
httpRes.setEncoding('utf8');
httpRes.on('data', (body) => {
res.send(
{
"id": "internet-check",
"data": body,
"stderr": ""
}
)
});
});
});
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": "VPN not connected"
})
}
});
app.get('/sysStatus', (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*'
});
readFileAsync('/sys/class/thermal/thermal_zone0/temp')
.then(res2=>
{
res.send({
"id": "sys-stats",
"data": `${(parseFloat(res2)*1e-3).toFixed(2)} °C Load: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
"stderr": ""
})
})
.catch(err=> {
console.error(err)
res.send({
"id": "sys-stats",
"data": `Load Avg: ${os.loadavg().map(x=>x.toFixed(2)).toString()}`,
"stderr": err
})
})
});
app.get('/lancianoCheck', async (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*'
});
let hostRes='';
let hosts = ["10.8.0.45","10.8.0.46"];
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+' alive ';
}
else{
hostRes+=item.host+' dead ';
}
}
})
.finally(()=>{
res.send({
"id": "lanciano-check",
"data": hostRes.toString(),
"stderr": ""
})
})
})
app.use(express.static('/var/www/forbidden-fruit-dashboard')); // serve static build site
// app.get('*', (req, res) => {
// res.sendFile(__dirname + '/public/index.html');
// });
//app.listen(8000,"192.168.10.14", () => console.log('listen on 8000'));
app.listen(process.env.NODE_PORT,process.env.NODE_IP, () => console.log(`Bind on ${process.env.NODE_IP}:${process.env.NODE_PORT}`));
-15
View File
@@ -1,15 +0,0 @@
{
"name": "forbidden-fruit-dashboard",
"version": "3.0.0",
"license": "Apache-2.0",
"dependencies": {
"compression": "^1.7.4",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"ping": "^0.3.0",
"rpio": "^2.2.0",
"passport": "^0.4.1",
"passport-local": "^1.0.0"
}
}
+23 -20
View File
@@ -3,18 +3,19 @@
<div class="card"> <div class="card">
<a href="#" :target="item.target" rel="noreferrer"> <a href="#" :target="item.target" rel="noreferrer">
<div class="card-content"> <div class="card-content">
<div class="media"> <div class="media">
<!-- <div class="card-content "> --> <!-- <div class="card-content "> -->
<div v-if="item.icon" class="media-left"> <div v-if="item.icon" class="media-left">
<figure class="image is-48x48"> <figure class="image is-48x48">
<i style="font-size: 35px;" :class="item.icon"></i> <i style="font-size: 35px;" :class="item.icon"></i>
</figure> </figure>
</div> </div>
<div class="media-content"> <div class="media-content">
<p class="title is-5">{{ item.name }}</p> <p class="title is-5">{{ item.name }}</p>
<p class="subtitle is-6">{{ response.data }}</p> <p class="subtitle is-6">{{ response.data }}</p>
</div>
</div> </div>
</div></div> </div>
</a> </a>
</div> </div>
</div> </div>
@@ -28,21 +29,23 @@ export default {
}, },
data: function () { data: function () {
return { return {
response: null response: null,
}; };
}, },
mounted: async function () { mounted: async function () {
let response = await fetch(this.item.url,{headers: { let response = await fetch(this.item.url, {
'Content-Type': 'application/json' headers: {
}}); "Content-Type": "application/json",
if (!response.ok) { },
throw Error(response.statusText); });
} if (!response.ok) {
this.response = await response.json(); throw Error(response.statusText);
if(this.response.stderr !== "") { }
console.error(this.response.stderr); this.response = await response.json();
} if (this.response.stderr !== "") {
} console.error(this.response.stderr);
}
},
}; };
</script> </script>