-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.js
46 lines (35 loc) · 1.18 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
'use strict' ;
var drachtio = require('drachtio') ;
var app = drachtio() ;
var Srf = require('drachtio-srf') ;
var srf = new Srf(app) ;
var config = require('./lib/config') ;
var logger = app.logger = require('./lib/logger');
var rangeCheck = require('range_check');
var blacklist = require('./lib/blacklist') ;
var _ = require('lodash') ;
srf.connect(config.drachtioServer) ;
srf.on('connect', function(err, hostport) {
logger.info('connected to drachtio listening for SIP on %s', hostport) ;
})
.on('error', function(err){
logger.error('srf error: %s', err.message ) ;
}) ;
function checkSender(req, res, next) {
if( !rangeCheck.inRange( req.source_address, config.authorizedSources) ) {
return res.send(403) ;
}
next() ;
}
/* optionally provide access control */
if( _.isArray( config.authorizedSources ) && config.authorizedSources.length > 1 ) {
srf.use(checkSender) ;
}
// optionally detect SIP scanners and blackhole them
if( config.blacklist && config.blacklist.chain ) {
srf.use(blacklist({logger: logger, chain: config.blacklist.chain, realm: config.blacklist.chain})) ;
}
// Expose app
exports = module.exports = app;
//load routes
require('./lib/proxy')(srf) ;