Retrieve gateway names with variables and failover (#4004)

Previously, if a bridge statement was written with prepended variables to be passed, the gateway name would not be parsed and replaced. Additionally, if multiple bridges were used in failover in a single bridge statement separated by a pipe, only the first would be parsed and replaced.

I noticed this after upgrade to FreeSWITCH 1.8.5 (from 1.6.20) which changed failover behavior with multiple separate bridge statements. When network returns 486 BUSY, it will proceed to second bridge statement, initiating a second call. To allow failover and not have this behavior, you must write a single statement and separate your failover bridges with a pipe, this change allows the UI to show all gateway names on the line once saved.

Examples:
{fax_use_ecm=on}sofia/gateway/99b1234c-667c-4b31-9d2f-31d4f396abfa/$1
=> {fax_use_ecm=on}sofia/gateway/Gateway_Name/$1

sofia/gateway/0e70e123-00fd-4f0c-b525-bc7f6283cfa1/$1|sofia/gateway/99b1234c-667c-4b31-9d2f-31d4f396abfa/1$1
=> sofia/gateway/Gateway_One/$1|sofia/gateway/Gateway_Two/1$1
This commit is contained in:
emaktech 2019-03-03 13:10:15 -05:00 committed by FusionPBX
parent b6533eadbd
commit a5ff016ef5
1 changed files with 23 additions and 12 deletions

View File

@ -730,19 +730,30 @@
if ($element['hidden']) {
$dialplan_detail_data_mod = $dialplan_detail_data;
if ($dialplan_detail_type == 'bridge') {
// parse out gateway uuid
$bridge_statement = explode('/', $dialplan_detail_data);
if ($bridge_statement[0] == 'sofia' && $bridge_statement[1] == 'gateway' && is_uuid($bridge_statement[2])) {
// retrieve gateway name from db
$sql = "select gateway from v_gateways where gateway_uuid = '".$bridge_statement[2]."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (is_array($gateways)) {
$gateway_name = $gateways[0]['gateway'];
$dialplan_detail_data_mod = str_replace($bridge_statement[2], $gateway_name, $dialplan_detail_data);
// split up failover bridges and get variables in statement
$failover_bridges = explode('|', $dialplan_detail_data);
preg_match('/^\{.*\}/', $failover_bridges[0], $bridge_vars);
$bridge_vars = $bridge_vars[0];
// rename parse and rename each gateway
foreach ($failover_bridges as $bridge_statement_exploded) {
// parse out gateway uuid
$bridge_statement = str_replace($bridge_vars, '', explode('/', $bridge_statement_exploded));
array_unshift($bridge_statement, $bridge_vars);
if ($bridge_statement[1] == 'sofia' && $bridge_statement[2] == 'gateway' && is_uuid($bridge_statement[3])) {
// retrieve gateway name from db
$sql = "select gateway from v_gateways where gateway_uuid = '".$bridge_statement[3]."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (is_array($gateways)) {
$gateway_name = $gateways[0]['gateway'];
$bridge_statement_exploded_mod = str_replace($bridge_statement[3], $gateway_name, $bridge_statement_exploded);
}
$dialplan_detail_data_mod = str_replace($bridge_statement_exploded, $bridge_statement_exploded_mod, $dialplan_detail_data_mod);
unset ($prep_statement, $sql, $bridge_statement, $gateways, $bridge_statement_exploded, $bridge_statement_exploded_mod);
}
unset ($prep_statement, $sql, $bridge_statement, $gateways);
}
}
echo " <label id=\"label_dialplan_detail_data_".$x."\">".escape($dialplan_detail_data_mod)."</label>\n";