From 4f8ab969d9fa385f80a1fd6a1eac6a86e66b64c7 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Fri, 6 Dec 2013 12:36:52 +0000 Subject: [PATCH] Fix that code that writes the gateway xml to the file system so that it will use the gateway uuid for the filename and gateway name. Benefit of using the XML is that it is a major step closer to renaming tenants, or changing the gateway name without hurting the outbound routes. --- resources/switch.php | 192 +++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 100 deletions(-) diff --git a/resources/switch.php b/resources/switch.php index 0014725c29..0dafc59049 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -1725,116 +1725,108 @@ function save_gateway_xml() { $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); foreach ($result as &$row) { if ($row['enabled'] != "false") { - //remove invalid characters from the file names - $gateway = $row['gateway']; - $gateway = str_replace(" ", "_", $gateway); - $gateway = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $gateway); //set the default profile as external $profile = $row['profile']; if (strlen($profile) == 0) { $profile = "external"; } - if (count($_SESSION["domains"]) > 1) { - $fout = fopen($_SESSION['switch']['gateways']['dir']."/".$profile."/v_".$_SESSION['domain_name'].'-'.$gateway.".xml","w"); + //open the xml file + $fout = fopen($_SESSION['switch']['gateways']['dir']."/".$profile."/v_".$row['gateway_uuid'].".xml","w"); + //build the xml $xml .= "\n"; - $xml .= " \n"; - } - else { - $fout = fopen($_SESSION['switch']['gateways']['dir']."/".$profile."/v_".$gateway.".xml","w"); - $xml .= "\n"; - $xml .= " \n"; - } - if (strlen($row['username']) > 0) { - $xml .= " \n"; - } - else { - $xml .= " \n"; - } - if (strlen($row['distinct_to']) > 0) { - $xml .= " \n"; - } - if (strlen($row['auth_username']) > 0) { - $xml .= " \n"; - } - if (strlen($row['password']) > 0) { - $xml .= " \n"; - } - else { - $xml .= " \n"; - } - if (strlen($row['realm']) > 0) { - $xml .= " \n"; - } - if (strlen($row['from_user']) > 0) { - $xml .= " \n"; - } - if (strlen($row['from_domain']) > 0) { - $xml .= " \n"; - } - if (strlen($row['proxy']) > 0) { - $xml .= " \n"; - } - if (strlen($row['register_proxy']) > 0) { - $xml .= " \n"; - } - if (strlen($row['outbound_proxy']) > 0) { - $xml .= " \n"; - } - if (strlen($row['expire_seconds']) > 0) { - $xml .= " \n"; - } - if (strlen($row['register']) > 0) { - $xml .= " \n"; - } - - if (strlen($row['register_transport']) > 0) { - switch ($row['register_transport']) { - case "udp": - $xml .= " \n"; - break; - case "tcp": - $xml .= " \n"; - break; - case "tls": - $xml .= " \n"; - $xml .= " \n"; - break; - default: - $xml .= " \n"; + $xml .= " \n"; + if (strlen($row['username']) > 0) { + $xml .= " \n"; + } + else { + $xml .= " \n"; + } + if (strlen($row['distinct_to']) > 0) { + $xml .= " \n"; + } + if (strlen($row['auth_username']) > 0) { + $xml .= " \n"; + } + if (strlen($row['password']) > 0) { + $xml .= " \n"; + } + else { + $xml .= " \n"; + } + if (strlen($row['realm']) > 0) { + $xml .= " \n"; + } + if (strlen($row['from_user']) > 0) { + $xml .= " \n"; + } + if (strlen($row['from_domain']) > 0) { + $xml .= " \n"; + } + if (strlen($row['proxy']) > 0) { + $xml .= " \n"; + } + if (strlen($row['register_proxy']) > 0) { + $xml .= " \n"; + } + if (strlen($row['outbound_proxy']) > 0) { + $xml .= " \n"; + } + if (strlen($row['expire_seconds']) > 0) { + $xml .= " \n"; + } + if (strlen($row['register']) > 0) { + $xml .= " \n"; } - } - if (strlen($row['retry_seconds']) > 0) { - $xml .= " \n"; - } - if (strlen($row['extension']) > 0) { - $xml .= " \n"; - } - if (strlen($row['ping']) > 0) { - $xml .= " \n"; - } - if (strlen($row['context']) > 0) { - $xml .= " \n"; - } - if (strlen($row['caller_id_in_from']) > 0) { - $xml .= " \n"; - } - if (strlen($row['supress_cng']) > 0) { - $xml .= " \n"; - } - if (strlen($row['sip_cid_type']) > 0) { - $xml .= " \n"; - } - if (strlen($row['extension_in_contact']) > 0) { - $xml .= " \n"; - } + if (strlen($row['register_transport']) > 0) { + switch ($row['register_transport']) { + case "udp": + $xml .= " \n"; + break; + case "tcp": + $xml .= " \n"; + break; + case "tls": + $xml .= " \n"; + $xml .= " \n"; + break; + default: + $xml .= " \n"; + } + } - $xml .= " \n"; - $xml .= ""; + if (strlen($row['retry_seconds']) > 0) { + $xml .= " \n"; + } + if (strlen($row['extension']) > 0) { + $xml .= " \n"; + } + if (strlen($row['ping']) > 0) { + $xml .= " \n"; + } + if (strlen($row['context']) > 0) { + $xml .= " \n"; + } + if (strlen($row['caller_id_in_from']) > 0) { + $xml .= " \n"; + } + if (strlen($row['supress_cng']) > 0) { + $xml .= " \n"; + } + if (strlen($row['sip_cid_type']) > 0) { + $xml .= " \n"; + } + if (strlen($row['extension_in_contact']) > 0) { + $xml .= " \n"; + } - fwrite($fout, $xml); - unset($xml); - fclose($fout); + $xml .= " \n"; + $xml .= ""; + + //write the xml + fwrite($fout, $xml); + unset($xml); + fclose($fout); } } //end foreach