Skip to content

Commit

Permalink
fix(privateIp): added private ip fallback to physical phones (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: tonyco97 <[email protected]>
  • Loading branch information
edospadoni and tonyco97 authored Nov 15, 2024
1 parent 7afd1c0 commit 77b79c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/plugins_command_13/pjsipDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @submodule plugins_command_13
*/
var action = require('../action');
var util = require('../util');
var AST_EXTEN_PJSIP_STATUS_2_STR_ADAPTER = require('../proxy_logic_13/exten_pjsip_status_adapter_13.js').AST_EXTEN_PJSIP_STATUS_2_STR_ADAPTER;

/**
Expand Down Expand Up @@ -126,6 +127,10 @@ var IDLOG = '[pjsipDetails]';
list[data.actionid].ip = (data.uri.split('@')[1]).split(':')[0];
list[data.actionid].port = (data.uri.split('@')[1]).split(':')[1];
}
// check if the IP is private otherwise get it from callid
if (!util.isPrivateIP(list[data.actionid].ip)){
list[data.actionid].ip = data.callid.split('@')[1];
}
list[data.actionid].sipuseragent = data.useragent;

} else if (data.event === 'EndpointDetail') {
Expand Down
27 changes: 27 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Provides common utilities functions.
*
* @class util
* @static
*/

/**
* Checks if an IP address is private.
*
* @method isPrivateIP
* @static
* @param {string} ip The IP address to check
* @return {boolean} True if the IP is private, otherwise False.
*/
function isPrivateIP(ip) {
const privateRanges = [
/^10\./,
/^172\.(1[6-9]|2[0-9]|3[0-1])\./,
/^192\.168\./,
];

return privateRanges.some((range) => range.test(ip));
}

// public interface
exports.isPrivateIP = isPrivateIP;

0 comments on commit 77b79c4

Please sign in to comment.