add CA download page

This commit is contained in:
guox191
2019-03-26 14:11:22 +08:00
parent 15d7ed48bf
commit 7f02664079
7 changed files with 116 additions and 61 deletions

View File

@@ -12,7 +12,8 @@ const express = require('express'),
wsServer = require('./wsServer'),
juicer = require('juicer'),
ip = require('ip'),
compress = require('compression');
compress = require('compression'),
pug = require('pug');
const DEFAULT_WEB_PORT = 8002; // port for web interface
@@ -202,6 +203,11 @@ class webInterface extends events.EventEmitter {
}
});
app.get('/downloadCrt', (req, res) => {
const pageFn = pug.compileFile(path.join(__dirname, '../resource/cert_download.pug'));
res.end(pageFn({ ua: req.get('user-agent') }));
});
app.get('/fetchCrtFile', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
const _crtFilePath = certMgr.getRootCAFilePath();
@@ -219,9 +225,8 @@ class webInterface extends events.EventEmitter {
app.get('/api/getQrCode', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
const fileType = certFileTypes.indexOf(req.query.type) !== -1 ? req.query.type : 'crt';
const qr = qrCode.qrcode(4, 'M');
const targetUrl = req.protocol + '://' + req.get('host') + '/fetchCrtFile?type=' + fileType;
const targetUrl = req.protocol + '://' + req.get('host') + '/downloadCrt';
const isRootCAFileExists = certMgr.isRootCAFileExists();
qr.addData(targetUrl);