server: add --authentication option
This commit is contained in:
parent
48807e9f85
commit
7cb729ff79
6 changed files with 57 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
var EventEmitter = require('events').EventEmitter,
|
||||
WebSocketServer = require('ws').Server,
|
||||
Client = require('./client')
|
||||
Client = require('./client'),
|
||||
settings = require('../settings')
|
||||
|
||||
class Ipc extends EventEmitter {
|
||||
|
||||
|
|
@ -15,6 +16,17 @@ class Ipc extends EventEmitter {
|
|||
|
||||
this.server.on('connection', (socket, req)=>{
|
||||
|
||||
if (settings.read('authentication')) {
|
||||
if (!req.headers.authorization) return;
|
||||
if (req.headers.authorization.search('Basic ') !== 0) return;
|
||||
var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString()
|
||||
if (settings.read('authentication') !== auth) {
|
||||
console.log(`(WARNING) Client connexion refused for ${req.connection.remoteAddress} (authentication failed)`)
|
||||
socket.close()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var id = req.url.split('/').pop()
|
||||
|
||||
if (!id) return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue