Добавлена возможность доступа по паролю
This commit is contained in:
@@ -15,6 +15,7 @@ module.exports = {
|
||||
logDir: `${dataDir}/log`,
|
||||
publicDir: `${dataDir}/public`,
|
||||
|
||||
accessPassword: '',
|
||||
loggingEnabled: true,
|
||||
|
||||
maxFilesDirSize: 1024*1024*1024,//1Gb
|
||||
|
||||
@@ -4,6 +4,7 @@ const fs = require('fs-extra');
|
||||
const branchFilename = __dirname + '/application_env';
|
||||
|
||||
const propsToSave = [
|
||||
'accessPassword',
|
||||
'loggingEnabled',
|
||||
'maxFilesDirSize',
|
||||
'queryCacheEnabled',
|
||||
|
||||
@@ -13,6 +13,9 @@ class WebSocketController {
|
||||
constructor(wss, config) {
|
||||
this.config = config;
|
||||
this.isDevelopment = (config.branch == 'development');
|
||||
this.accessToken = '';
|
||||
if (config.accessPassword)
|
||||
this.accessToken = utils.getBufHash(config.accessPassword, 'sha256', 'hex');
|
||||
|
||||
this.workerState = new WorkerState();
|
||||
this.webWorker = new WebWorker(config);
|
||||
@@ -59,6 +62,11 @@ class WebSocketController {
|
||||
//pong for WebSocketConnection
|
||||
this.send({_rok: 1}, req, ws);
|
||||
|
||||
if (this.accessToken && req.accessToken !== this.accessToken) {
|
||||
await utils.sleep(1000);
|
||||
throw new Error('need_access_token');
|
||||
}
|
||||
|
||||
switch (req.action) {
|
||||
case 'test':
|
||||
await this.test(req, ws); break;
|
||||
|
||||
Reference in New Issue
Block a user