-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.js
45 lines (35 loc) · 1.19 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const NodeMediaServer = require('./');
const config = require('./config');
const CryptoJS = require("crypto-js");
const fs = require('fs');
const path = require('path');
var nms = new NodeMediaServer(config)
nms.run();
nms.on('prePublish', (id, StreamPath, args) => {
let file = path.join(__dirname + '/blacklist.json');
let blacklist;
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.log(`Error reading file from disk: ${err}`);
} else {
blacklist = JSON.parse(data);
blacklist.forEach(ip => {
console.log(ip);
});
}
let session = nms.getSession(id);
if(blacklist.includes(session.socket.remoteAddress)){
console.log("####### USER IP IS BANNED",session.socket.remoteAddress)
session.reject();
}
});
var encrypted = CryptoJS.SHA256(config.passphrase+StreamPath).toString();
var encshort = encrypted.substring(0,6);
if(encshort != args["pwd"]){
let session = nms.getSession(id);
session.reject();
console.log('[Rejected]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
} else {
console.log('[Connected]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
}
});