mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2025-12-19 04:37:43 +00:00
use system_information.private_network_cidr (#158)
* use system_information.private_network_cidr * lint
This commit is contained in:
19
app.js
19
app.js
@@ -55,7 +55,8 @@ const {
|
||||
lookupAccountBySid,
|
||||
lookupAccountCapacitiesBySid,
|
||||
queryCallLimits,
|
||||
lookupClientByAccountAndUsername
|
||||
lookupClientByAccountAndUsername,
|
||||
lookupSystemInformation
|
||||
} = require('@jambonz/db-helpers')({
|
||||
host: process.env.JAMBONES_MYSQL_HOST,
|
||||
port: process.env.JAMBONES_MYSQL_PORT || 3306,
|
||||
@@ -91,6 +92,7 @@ srf.locals = {...srf.locals,
|
||||
AlertType,
|
||||
activeCallIds: new Map(),
|
||||
getRtpEngine,
|
||||
privateNetworkCidr: process.env.PRIVATE_VOIP_NETWORK_CIDR || null,
|
||||
dbHelpers: {
|
||||
pool,
|
||||
ping,
|
||||
@@ -102,7 +104,8 @@ srf.locals = {...srf.locals,
|
||||
lookupAccountBySipRealm,
|
||||
lookupAccountCapacitiesBySid,
|
||||
queryCallLimits,
|
||||
lookupClientByAccountAndUsername
|
||||
lookupClientByAccountAndUsername,
|
||||
lookupSystemInformation
|
||||
},
|
||||
realtimeDbHelpers: {
|
||||
createSet,
|
||||
@@ -273,10 +276,18 @@ if (process.env.K8S || process.env.HTTP_PORT) {
|
||||
});
|
||||
}
|
||||
if ('test' !== process.env.NODE_ENV) {
|
||||
/* update call stats periodically */
|
||||
setInterval(() => {
|
||||
/* update call stats periodically as well as definition of private network cidr */
|
||||
setInterval(async() => {
|
||||
stats.gauge('sbc.sip.calls.count', activeCallIds.size,
|
||||
['direction:inbound', `instance_id:${process.env.INSTANCE_ID || 0}`]);
|
||||
|
||||
const r = await lookupSystemInformation();
|
||||
if (r) {
|
||||
if (r.private_network_cidr !== srf.locals.privateNetworkCidr) {
|
||||
logger.info(`updating private network cidr from ${srf.locals.privateNetworkCidr} to ${r.private_network_cidr}`);
|
||||
srf.locals.privateNetworkCidr = r.private_network_cidr;
|
||||
}
|
||||
}
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
|
||||
13
lib/utils.js
13
lib/utils.js
@@ -202,9 +202,16 @@ const isMSTeamsCIDR = (ip) => {
|
||||
};
|
||||
|
||||
const isPrivateVoipNetwork = (ip) => {
|
||||
if (process.env.PRIVATE_VOIP_NETWORK_CIDR) {
|
||||
const matcher = new CIDRMatcher(process.env.PRIVATE_VOIP_NETWORK_CIDR.split(','));
|
||||
return matcher.contains(ip);
|
||||
const {srf, logger} = require('..');
|
||||
const {privateNetworkCidr} = srf.locals;
|
||||
if (privateNetworkCidr) {
|
||||
try {
|
||||
const matcher = new CIDRMatcher(privateNetworkCidr.split(','));
|
||||
return matcher.contains(ip);
|
||||
} catch (err) {
|
||||
logger.info({err, privateNetworkCidr},
|
||||
'Error checking private network CIDR, probably misconfigured must be a comma separated list of CIDRs');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -11,7 +11,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-auto-scaling": "^3.549.0",
|
||||
"@aws-sdk/client-sns": "^3.549.0",
|
||||
"@jambonz/db-helpers": "^0.9.4",
|
||||
"@jambonz/db-helpers": "^0.9.7",
|
||||
"@jambonz/digest-utils": "^0.0.5",
|
||||
"@jambonz/http-health-check": "^0.0.1",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||
@@ -1410,13 +1410,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/db-helpers": {
|
||||
"version": "0.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.6.tgz",
|
||||
"integrity": "sha512-uvtkqdP6GP6KSaM7eo2jcU1k0R6Ymodhl0RH/XiNESgIhZ7sx7ZnMQtrZQVVmzrJ429H7q8dQqgcB2YhAyEK+A==",
|
||||
"version": "0.9.7",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.7.tgz",
|
||||
"integrity": "sha512-5qN/CJZJXpbMkMn+8gFn8PpQ0ZImZxp1EjKyxLUlmMn+xgjeNb29c3pjeVt/6EQnBB65jAax6TNsVzVIfpvE2w==",
|
||||
"dependencies": {
|
||||
"cidr-matcher": "^2.1.1",
|
||||
"debug": "^4.3.4",
|
||||
"mysql2": "^3.10.3",
|
||||
"mysql2": "^3.11.0",
|
||||
"node-object-hash": "^2.3.10",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
@@ -7889,13 +7889,13 @@
|
||||
"dev": true
|
||||
},
|
||||
"@jambonz/db-helpers": {
|
||||
"version": "0.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.6.tgz",
|
||||
"integrity": "sha512-uvtkqdP6GP6KSaM7eo2jcU1k0R6Ymodhl0RH/XiNESgIhZ7sx7ZnMQtrZQVVmzrJ429H7q8dQqgcB2YhAyEK+A==",
|
||||
"version": "0.9.7",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.7.tgz",
|
||||
"integrity": "sha512-5qN/CJZJXpbMkMn+8gFn8PpQ0ZImZxp1EjKyxLUlmMn+xgjeNb29c3pjeVt/6EQnBB65jAax6TNsVzVIfpvE2w==",
|
||||
"requires": {
|
||||
"cidr-matcher": "^2.1.1",
|
||||
"debug": "^4.3.4",
|
||||
"mysql2": "^3.10.3",
|
||||
"mysql2": "^3.11.0",
|
||||
"node-object-hash": "^2.3.10",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"jslint:fix": "npm run jslint --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jambonz/db-helpers": "^0.9.4",
|
||||
"@jambonz/db-helpers": "^0.9.7",
|
||||
"@jambonz/http-health-check": "^0.0.1",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||
"@jambonz/rtpengine-utils": "^0.4.4",
|
||||
|
||||
Reference in New Issue
Block a user