revamp to mysql for gateway configuration and major code refactor

This commit is contained in:
Dave Horton
2019-12-13 10:20:27 -05:00
parent c22b6f9c08
commit 5a529b2bb9
23 changed files with 1152 additions and 187 deletions
+25 -9
View File
@@ -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
};
};