Add Lamassu support microsite
This commit is contained in:
parent
4f9cc88a5e
commit
d901a36f29
5 changed files with 13347 additions and 12 deletions
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 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue