This commit is contained in:
guox191 2019-03-13 21:26:40 +08:00
parent d44ce7fd08
commit 59e05850fa
4 changed files with 16 additions and 20 deletions

View File

@ -221,7 +221,7 @@ function getWsReqInfo(wsReq) {
// TODO 如果是windows机器url是不是全路径需要对其过滤取出 // TODO 如果是windows机器url是不是全路径需要对其过滤取出
const path = wsReq.url || '/'; const path = wsReq.url || '/';
const isEncript = true && wsReq.connection && wsReq.connection.encrypted; const isEncript = wsReq.connection && wsReq.connection.encrypted;
/** /**
* construct the request headers based on original connection, * construct the request headers based on original connection,
* but delete the `sec-websocket-*` headers as they are already consumed by AnyProxy * but delete the `sec-websocket-*` headers as they are already consumed by AnyProxy

View File

@ -56,7 +56,7 @@ class webInterface extends events.EventEmitter {
*/ */
getServer() { getServer() {
const self = this; const self = this;
const recorder = self.recorder; const recorder = self.recorder;
const ipAddress = ip.address(), const ipAddress = ip.address(),
// userRule = proxyInstance.proxyRule, // userRule = proxyInstance.proxyRule,
webBasePath = 'web'; webBasePath = 'web';
@ -68,10 +68,9 @@ class webInterface extends events.EventEmitter {
customMenu = ''; // userRule._getCustomMenu(); customMenu = ''; // userRule._getCustomMenu();
} catch (e) { } } catch (e) { }
const myAbsAddress = 'http://' + ipAddress + ':' + self.webPort + '/', const staticDir = path.join(__dirname, '../', webBasePath);
staticDir = path.join(__dirname, '../', webBasePath);
const app = express(); const app = express();
app.use(compress()); //invoke gzip app.use(compress()); //invoke gzip
app.use((req, res, next) => { app.use((req, res, next) => {
res.setHeader('note', 'THIS IS A REQUEST FROM ANYPROXY WEB INTERFACE'); res.setHeader('note', 'THIS IS A REQUEST FROM ANYPROXY WEB INTERFACE');
@ -217,35 +216,32 @@ class webInterface extends events.EventEmitter {
//make qr code //make qr code
app.get('/qr', (req, res) => { app.get('/qr', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Origin', '*');
const qr = qrCode.qrcode(4, 'M'), res.setHeader('Content-Type', 'text/html');
targetUrl = myAbsAddress;
const qr = qrCode.qrcode(4, 'M');
const targetUrl = req.protocol + '://' + req.get('host');
qr.addData(targetUrl); qr.addData(targetUrl);
qr.make(); qr.make();
const qrImageTag = qr.createImgTag(4); const qrImageTag = qr.createImgTag(4);
const resDom = '<a href="__url"> __img <br> click or scan qr code to start client </a>'.replace(/__url/, targetUrl).replace(/__img/, qrImageTag); const resDom = '<a href="__url"> __img <br> click or scan qr code to start client </a>'.replace(/__url/, targetUrl).replace(/__img/, qrImageTag);
res.setHeader('Content-Type', 'text/html');
res.end(resDom); res.end(resDom);
}); });
app.get('/api/getQrCode', (req, res) => { app.get('/api/getQrCode', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Origin', '*');
const qr = qrCode.qrcode(4, 'M'),
targetUrl = myAbsAddress + 'fetchCrtFile'; const qr = qrCode.qrcode(4, 'M');
const targetUrl = req.protocol + '://' + req.get('host') + '/fetchCrtFile';
const isRootCAFileExists = certMgr.isRootCAFileExists();
qr.addData(targetUrl); qr.addData(targetUrl);
qr.make(); qr.make();
const qrImageTag = qr.createImgTag(4);
// resDom = '<a href="__url"> __img <br> click or scan qr code to download rootCA.crt </a>'.replace(/__url/,targetUrl).replace(/__img/,qrImageTag);
// res.setHeader("Content-Type", "text/html");
// res.end(resDom);
const isRootCAFileExists = certMgr.isRootCAFileExists();
res.json({ res.json({
status: 'success', status: 'success',
url: targetUrl, url: targetUrl,
isRootCAFileExists, isRootCAFileExists,
qrImgDom: qrImageTag qrImgDom: qr.createImgTag(4)
}); });
}); });

View File

@ -72,7 +72,7 @@ class wsServer {
clientTracking: true, clientTracking: true,
}); });
resolve(); resolve();
// the queue of the messages to be delivered // the queue of the messages to be delivered
let messageQueue = []; let messageQueue = [];
// the flat to indicate wheter to broadcast the record // the flat to indicate wheter to broadcast the record
@ -102,7 +102,7 @@ class wsServer {
try { try {
data = JSON.stringify(data); data = JSON.stringify(data);
} catch (e) { } catch (e) {
console.error('==> errorr when do broadcast ', e, data); console.error('==> error when do broadcast ', e, data);
} }
} }
for (const client of wss.clients) { for (const client of wss.clients) {

View File

@ -67,7 +67,7 @@ function KoaServer() {
this.logWsRequest = function (wsReq) { this.logWsRequest = function (wsReq) {
const headers = wsReq.headers; const headers = wsReq.headers;
const host = headers.host; const host = headers.host;
const isEncript = true && wsReq.connection && wsReq.connection.encrypted; const isEncript = wsReq.connection && wsReq.connection.encrypted;
const protocol = isEncript ? 'wss' : 'ws'; const protocol = isEncript ? 'wss' : 'ws';
let key = `${protocol}://${host}${wsReq.url}`; let key = `${protocol}://${host}${wsReq.url}`;
// take proxy data with 'proxy-' + url // take proxy data with 'proxy-' + url