Add Lamassu support microsite
This commit is contained in:
parent
4f9cc88a5e
commit
d901a36f29
5 changed files with 13347 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ const helmet = require('helmet')
|
||||||
const WebSocket = require('ws')
|
const WebSocket = require('ws')
|
||||||
const http = require('http')
|
const http = require('http')
|
||||||
const SocketIo = require('socket.io')
|
const SocketIo = require('socket.io')
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
const machineLoader = require('../machine-loader')
|
const machineLoader = require('../machine-loader')
|
||||||
const T = require('../time')
|
const T = require('../time')
|
||||||
|
|
@ -31,7 +32,7 @@ const customers = require('../customers')
|
||||||
const logs = require('../logs')
|
const logs = require('../logs')
|
||||||
const supportLogs = require('../support_logs')
|
const supportLogs = require('../support_logs')
|
||||||
const funding = require('./funding')
|
const funding = require('./funding')
|
||||||
const _ = require('lodash/fp')
|
const supportServer = require('./admin-support')
|
||||||
|
|
||||||
const NEVER = new Date(Date.now() + 100 * T.years)
|
const NEVER = new Date(Date.now() + 100 * T.years)
|
||||||
const REAUTHENTICATE_INTERVAL = T.minute
|
const REAUTHENTICATE_INTERVAL = T.minute
|
||||||
|
|
@ -72,7 +73,6 @@ app.use(helmet({noCache: true}))
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
app.use(register)
|
app.use(register)
|
||||||
app.use(authenticate)
|
app.use(authenticate)
|
||||||
|
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
app.get('/api/totem', (req, res) => {
|
app.get('/api/totem', (req, res) => {
|
||||||
|
|
@ -212,7 +212,10 @@ app.get('/api/support_logs', (req, res, next) => {
|
||||||
app.get('/api/support_logs/logs', (req, res, next) => {
|
app.get('/api/support_logs/logs', (req, res, next) => {
|
||||||
return supportLogs.get(req.query.supportLogId)
|
return supportLogs.get(req.query.supportLogId)
|
||||||
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||||
.then(log => logs.getMachineLogs(log.deviceId, log.timestamp))
|
.then(result => {
|
||||||
|
const log = result || {}
|
||||||
|
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
||||||
|
})
|
||||||
.then(r => res.send(r))
|
.then(r => res.send(r))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
})
|
})
|
||||||
|
|
@ -330,13 +333,12 @@ wss.on('connection', ws => {
|
||||||
})
|
})
|
||||||
|
|
||||||
function run () {
|
function run () {
|
||||||
if (devMode) {
|
const serverPort = devMode ? 8070 : 443
|
||||||
webServer.listen(8070, () => {
|
const supportPort = 8071
|
||||||
console.log('lamassu-admin-server listening on port 8070')
|
|
||||||
})
|
const serverLog = `lamassu-admin-server listening on port ${serverPort}`
|
||||||
} else {
|
const supportLog = `lamassu-support-server listening on port ${supportPort}`
|
||||||
webServer.listen(443, () => {
|
|
||||||
console.log('lamassu-admin-server listening on port 443')
|
webServer.listen(serverPort, () => console.log(serverLog))
|
||||||
})
|
supportServer.run(supportPort, () => console.log(supportLog))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
65
lib/admin/admin-support.js
Normal file
65
lib/admin/admin-support.js
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const bodyParser = require('body-parser')
|
||||||
|
const cookieParser = require('cookie-parser')
|
||||||
|
const helmet = require('helmet')
|
||||||
|
const morgan = require('morgan')
|
||||||
|
const express = require('express')
|
||||||
|
const app = express()
|
||||||
|
const https = require('https')
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
const serveStatic = require('serve-static')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const logs = require('../logs')
|
||||||
|
const supportLogs = require('../support_logs')
|
||||||
|
const options = require('../options')
|
||||||
|
|
||||||
|
const caOptions = {
|
||||||
|
ca: '/etc/ssl/certs/Lamassu_CA.pem'
|
||||||
|
}
|
||||||
|
|
||||||
|
app.use(morgan('dev'))
|
||||||
|
app.use(helmet({noCache: true}))
|
||||||
|
app.use(cookieParser())
|
||||||
|
app.use(bodyParser.json())
|
||||||
|
app.use(serveStatic(path.resolve(__dirname, '..', '..', 'public'), {
|
||||||
|
'index': ['support-index.html']
|
||||||
|
}))
|
||||||
|
|
||||||
|
const certOptions = {
|
||||||
|
key: fs.readFileSync(options.keyPath),
|
||||||
|
cert: fs.readFileSync(options.certPath),
|
||||||
|
ca: [fs.readFileSync(caOptions.ca)],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/api/support_logs', (req, res, next) => {
|
||||||
|
return supportLogs.batch()
|
||||||
|
.then(supportLogs => res.send({ supportLogs }))
|
||||||
|
.catch(next)
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/api/support_logs/logs', (req, res, next) => {
|
||||||
|
return supportLogs.get(req.query.supportLogId)
|
||||||
|
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||||
|
.then(result => {
|
||||||
|
const log = result || {}
|
||||||
|
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
||||||
|
})
|
||||||
|
.then(r => res.send(r))
|
||||||
|
.catch(next)
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/api/support_logs', (req, res, next) => {
|
||||||
|
return supportLogs.insert(req.query.deviceId)
|
||||||
|
.then(r => res.send(r))
|
||||||
|
.catch(next)
|
||||||
|
})
|
||||||
|
|
||||||
|
function run (port, cb) {
|
||||||
|
const webServer = https.createServer(certOptions, app)
|
||||||
|
webServer.listen(port || 443, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { run }
|
||||||
|
|
@ -69,6 +69,15 @@ function update (deviceId, logLines) {
|
||||||
* @returns {array} Array of logs for the requested machinej
|
* @returns {array} Array of logs for the requested machinej
|
||||||
*/
|
*/
|
||||||
function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||||
|
const defaults = {
|
||||||
|
logs: [],
|
||||||
|
currentMachine: {
|
||||||
|
name: '',
|
||||||
|
deviceId: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!deviceId) return defaults
|
||||||
|
|
||||||
const sql = `select id, log_level, timestamp, message from logs
|
const sql = `select id, log_level, timestamp, message from logs
|
||||||
where device_id=$1
|
where device_id=$1
|
||||||
and timestamp <= $3
|
and timestamp <= $3
|
||||||
|
|
|
||||||
13230
public/lamassu-elm.js
Normal file
13230
public/lamassu-elm.js
Normal file
File diff suppressed because it is too large
Load diff
29
public/support-index.html
Normal file
29
public/support-index.html
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<base href="/">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Nunito:400,700&subset=latin-ext" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="styles.css">
|
||||||
|
<script src="lamassu-elm.js"></script>
|
||||||
|
<style>
|
||||||
|
@keyframes fadein {
|
||||||
|
from { opacity: 0; }
|
||||||
|
to { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="number"]::-webkit-outer-spin-button,
|
||||||
|
input[type="number"]::-webkit-inner-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
input[type="number"] {
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
Elm.Main.fullscreen()
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue