mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-07-24 21:01:49 +00:00
revamp to mysql for gateway configuration and major code refactor
This commit is contained in:
+25
-9
@@ -1,12 +1,28 @@
|
||||
const {fromInboundTrunk} = require('./utils');
|
||||
const config = require('config');
|
||||
const authenticator = require('drachtio-http-authenticator')(config.get('authCallback'));
|
||||
const debug = require('debug')('jambonz:sbc-inbound');
|
||||
|
||||
function auth(req, res, next) {
|
||||
if (fromInboundTrunk(req)) {
|
||||
return next();
|
||||
module.exports = function(srf, logger) {
|
||||
const {lookupSipGatewayBySignalingAddress, lookupAuthHook} = srf.locals.dbHelpers;
|
||||
const authenticator = require('drachtio-http-authenticator')(lookupAuthHook, logger);
|
||||
|
||||
async function challengeDeviceCalls(req, res, next) {
|
||||
req.locals = req.locals || {};
|
||||
try {
|
||||
const gateway = await lookupSipGatewayBySignalingAddress(req.source_address, req.source_port);
|
||||
if (!gateway) {
|
||||
req.locals.originator = 'device';
|
||||
return authenticator(req, res, next);
|
||||
}
|
||||
debug(`challengeDeviceCalls: call came from gateway: ${JSON.stringify(gateway)}`);
|
||||
req.locals.originator = 'trunk';
|
||||
req.locals.carrier = gateway.name;
|
||||
next();
|
||||
} catch (err) {
|
||||
logger.error(err, `${req.get('Call-ID')} Error looking up related info for inbound call`);
|
||||
res.send(500);
|
||||
}
|
||||
}
|
||||
authenticator(req, res, next);
|
||||
}
|
||||
|
||||
module.exports = { auth };
|
||||
return {
|
||||
challengeDeviceCalls
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user