Portions created by the Initial Developer are Copyright (C) 2008-2013 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('gateway_add') || permission_exists('gateway_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $gateway_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (count($_POST) > 0) { $gateway = check_str($_POST["gateway"]); $username = check_str($_POST["username"]); $password = check_str($_POST["password"]); $distinct_to = check_str($_POST["distinct_to"]); $auth_username = check_str($_POST["auth_username"]); $realm = check_str($_POST["realm"]); $from_user = check_str($_POST["from_user"]); $from_domain = check_str($_POST["from_domain"]); $proxy = check_str($_POST["proxy"]); $register_proxy = check_str($_POST["register_proxy"]); $outbound_proxy = check_str($_POST["outbound_proxy"]); $expire_seconds = check_str($_POST["expire_seconds"]); $register = check_str($_POST["register"]); $register_transport = check_str($_POST["register_transport"]); $retry_seconds = check_str($_POST["retry_seconds"]); $extension = check_str($_POST["extension"]); $ping = check_str($_POST["ping"]); $channels = check_str($_POST["channels"]); $caller_id_in_from = check_str($_POST["caller_id_in_from"]); $supress_cng = check_str($_POST["supress_cng"]); $sip_cid_type = check_str($_POST["sip_cid_type"]); $codec_prefs = check_str($_POST["codec_prefs"]); $extension_in_contact = check_str($_POST["extension_in_contact"]); $context = check_str($_POST["context"]); $profile = check_str($_POST["profile"]); $enabled = check_str($_POST["enabled"]); $description = check_str($_POST["description"]); } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $gateway_uuid = check_str($_POST["gateway_uuid"]); } //check for all required data //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } if (strlen($gateway) == 0) { $msg .= $text['message-required']." ".$text['label-gateway']."
\n"; } if ($register == "true") { if (strlen($username) == 0) { $msg .= $text['message-required']." ".$text['label-username']."
\n"; } if (strlen($password) == 0) { $msg .= $text['message-required']." ".$text['label-password']."
\n"; } } //if (strlen($distinct_to) == 0) { $msg .= $text['message-required']." ".$text['label-distinct_to']."
\n"; } //if (strlen($auth_username) == 0) { $msg .= $text['message-required']." ".$text['label-auth_username']."
\n"; } //if (strlen($realm) == 0) { $msg .= $text['message-required']." ".$text['label-realm']."
\n"; } //if (strlen($from_user) == 0) { $msg .= $text['message-required']." ".$text['label-from_user']."
\n"; } //if (strlen($from_domain) == 0) { $msg .= $text['message-required']." ".$text['label-from_domain']."
\n"; } //if (strlen($proxy) == 0) { $msg .= $text['message-required']." ".$text['label-proxy']."
\n"; } //if (strlen($register_proxy) == 0) { $msg .= $text['message-required']." ".$text['label-register_proxy']."
\n"; } //if (strlen($outbound_proxy) == 0) { $msg .= $text['message-required']." ".$text['label-outbound_proxy']."
\n"; } if (strlen($expire_seconds) == 0) { $msg .= $text['message-required']." ".$text['label-expire_seconds']."
\n"; } if (strlen($register) == 0) { $msg .= $text['message-required']." ".$text['label-register']."
\n"; } //if (strlen($register_transport) == 0) { $msg .= $text['message-required']." ".$text['label-register_transport']."
\n"; } if (strlen($retry_seconds) == 0) { $msg .= $text['message-required']." ".$text['label-retry_seconds']."
\n"; } //if (strlen($extension) == 0) { $msg .= $text['message-required']." ".$text['label-extension']."
\n"; } //if (strlen($ping) == 0) { $msg .= $text['message-required']." ".$text['label-ping']."
\n"; } if (strlen($channels) == 0) { //$msg .= $text['message-required']." ".$text['label-channels']."
\n"; $channels = 0; } //if (strlen($caller_id_in_from) == 0) { $msg .= $text['message-required']." ".$text['label-caller_id_in_from']."
\n"; } //if (strlen($supress_cng) == 0) { $msg .= $text['message-required']." ".$text['label-supress_cng']."
\n"; } //if (strlen($sip_cid_type) == 0) { $msg .= $text['message-required']." ".$text['label-sip_cid_type']."
\n"; } //if (strlen($codec_prefs) == 0) { $msg .= $text['message-required']." ".$text['label-codec_prefs']."
\n"; } //if (strlen($extension_in_contact) == 0) { $msg .= $text['message-required']." ".$text['label-extension_in_contact']."
\n"; } if (strlen($context) == 0) { $msg .= $text['message-required']." ".$text['label-context']."
\n"; } if (strlen($profile) == 0) { $msg .= $text['message-required']." ".$text['label-profile']."
\n"; } if (strlen($enabled) == 0) { $msg .= $text['message-required']." ".$text['label-enabled']."
\n"; } //if (strlen($description) == 0) { $msg .= $text['message-required']." ".$text['label-description']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //remove the invalid characters from the gateway name $gateway = str_replace(" ", "_", $gateway); $gateway = str_replace("/", "", $gateway); //add or update the database if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('gateway_add')) { $gateway_uuid = uuid(); $sql = "insert into v_gateways "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "gateway_uuid, "; $sql .= "gateway, "; $sql .= "username, "; $sql .= "password, "; $sql .= "distinct_to, "; $sql .= "auth_username, "; $sql .= "realm, "; $sql .= "from_user, "; $sql .= "from_domain, "; $sql .= "proxy, "; $sql .= "register_proxy, "; $sql .= "outbound_proxy, "; $sql .= "expire_seconds, "; $sql .= "register, "; $sql .= "register_transport, "; $sql .= "retry_seconds, "; $sql .= "extension, "; $sql .= "ping, "; $sql .= "channels, "; $sql .= "caller_id_in_from, "; $sql .= "supress_cng, "; $sql .= "sip_cid_type, "; $sql .= "codec_prefs, "; $sql .= "extension_in_contact, "; $sql .= "context, "; $sql .= "profile, "; $sql .= "enabled, "; $sql .= "description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$gateway_uuid', "; $sql .= "'$gateway', "; $sql .= "'$username', "; $sql .= "'$password', "; $sql .= "'$distinct_to', "; $sql .= "'$auth_username', "; $sql .= "'$realm', "; $sql .= "'$from_user', "; $sql .= "'$from_domain', "; $sql .= "'$proxy', "; $sql .= "'$register_proxy', "; $sql .= "'$outbound_proxy', "; $sql .= "'$expire_seconds', "; $sql .= "'$register', "; $sql .= "'$register_transport', "; $sql .= "'$retry_seconds', "; $sql .= "'$extension', "; $sql .= "'$ping', "; $sql .= "'$channels', "; $sql .= "'$caller_id_in_from', "; $sql .= "'$supress_cng', "; $sql .= "'$sip_cid_type', "; $sql .= "'$codec_prefs', "; $sql .= "'$extension_in_contact', "; $sql .= "'$context', "; $sql .= "'$profile', "; $sql .= "'$enabled', "; $sql .= "'$description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //if ($action == "add") if ($action == "update" && permission_exists('gateway_edit')) { $sql = "update v_gateways set "; $sql .= "gateway = '$gateway', "; $sql .= "username = '$username', "; $sql .= "password = '$password', "; $sql .= "distinct_to = '$distinct_to', "; $sql .= "auth_username = '$auth_username', "; $sql .= "realm = '$realm', "; $sql .= "from_user = '$from_user', "; $sql .= "from_domain = '$from_domain', "; $sql .= "proxy = '$proxy', "; $sql .= "register_proxy = '$register_proxy', "; $sql .= "outbound_proxy = '$outbound_proxy', "; $sql .= "expire_seconds = '$expire_seconds', "; $sql .= "register = '$register', "; $sql .= "register_transport = '$register_transport', "; $sql .= "retry_seconds = '$retry_seconds', "; $sql .= "extension = '$extension', "; $sql .= "ping = '$ping', "; $sql .= "channels = '$channels', "; $sql .= "caller_id_in_from = '$caller_id_in_from', "; $sql .= "supress_cng = '$supress_cng', "; $sql .= "sip_cid_type = '$sip_cid_type', "; $sql .= "codec_prefs = '$codec_prefs', "; $sql .= "extension_in_contact = '$extension_in_contact', "; $sql .= "context = '$context', "; $sql .= "profile = '$profile', "; $sql .= "enabled = '$enabled', "; $sql .= "description = '$description' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and gateway_uuid = '$gateway_uuid'"; $db->exec(check_sql($sql)); unset($sql); } //if ($action == "update") //syncrhonize configuration save_gateway_xml(); //synchronize the xml config //save_dialplan_xml(); //delete the sip profiles from memcache $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $hostname = trim(event_socket_request($fp, 'api switchname')); $switch_cmd = "memcache delete configuration:sofia.conf:".$hostname; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } //rescan the external profile to look for new or stopped gateways //create the event socket connection $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $tmp_cmd = 'api sofia profile external rescan'; $response = event_socket_request($fp, $tmp_cmd); unset($tmp_cmd); usleep(1000); //close the connection fclose($fp); //clear the apply settings reminder $_SESSION["reload_xml"] = false; } //if ($_POST["persistformvar"] != "true") //redirect the user if (isset($action)) { if ($action == "add") { $_SESSION["message"] = $text['message-add']; } if ($action == "update") { $_SESSION["message"] = $text['message-update']; } header("Location: gateways.php"); return; } } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $gateway_uuid = check_str($_GET["id"]); $sql = "select * from v_gateways "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and gateway_uuid = '".$gateway_uuid."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $gateway = $row["gateway"]; $username = $row["username"]; $password = $row["password"]; $distinct_to = $row["distinct_to"]; $auth_username = $row["auth_username"]; $realm = $row["realm"]; $from_user = $row["from_user"]; $from_domain = $row["from_domain"]; $proxy = $row["proxy"]; $register_proxy = $row["register_proxy"]; $outbound_proxy = $row["outbound_proxy"]; $expire_seconds = $row["expire_seconds"]; $register = $row["register"]; $register_transport = $row["register_transport"]; $retry_seconds = $row["retry_seconds"]; $extension = $row["extension"]; $ping = $row["ping"]; $channels = $row["channels"]; $caller_id_in_from = $row["caller_id_in_from"]; $supress_cng = $row["supress_cng"]; $sip_cid_type = $row["sip_cid_type"]; $codec_prefs = $row["codec_prefs"]; $extension_in_contact = $row["extension_in_contact"]; $context = $row["context"]; $profile = $row["profile"]; $enabled = $row["enabled"]; $description = $row["description"]; } unset ($prep_statement); } //set defaults if (strlen($enabled) == 0) { $enabled = "true"; } if (strlen($register) == 0) { $register = "true"; } if (strlen($retry_seconds) == 0) { $retry_seconds = "30"; } //show the header require_once "resources/header.php"; //show the content echo ""; echo "
"; echo "\n"; echo "\n"; echo " "; echo " "; echo "
\n"; echo "
"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; //--- begin: show_advanced ----------------------- echo "\n"; echo "\n"; echo "\n"; //--- end: show_advanced ----------------------- echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
\n"; echo "\n"; echo " \n"; echo " "; echo " \n"; echo " "; echo " "; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['title-gateway']."
\n"; echo "
\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
\n"; echo " ".$text['description-gateway-edit']."\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-gateway'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-gateway-name']."\n"; echo "
\n"; echo " ".$text['label-username'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-username']."\n"; echo "
\n"; echo " ".$text['label-password'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-password']."\n"; echo "
\n"; echo " ".$text['label-from_user'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-from_user']."\n"; echo "
\n"; echo " ".$text['label-from_domain'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-from_domain']."\n"; echo "
\n"; echo " ".$text['label-proxy'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-proxy']."\n"; echo "
\n"; echo " ".$text['label-realm'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-realm']."\n"; echo "
\n"; echo " ".$text['label-expire_seconds'].":\n"; echo "\n"; if (strlen($expire_seconds) == 0) { $expire_seconds = "800"; } echo " \n"; echo "
\n"; echo $text['description-expire_seconds']."\n"; echo "
\n"; echo " ".$text['label-register'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-register']."\n"; echo "
\n"; echo " ".$text['label-retry_seconds'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-retry_seconds']."\n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['button-advanced-show']."\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-distinct_to'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-distinct_to']."\n"; echo "
\n"; echo " ".$text['label-auth_username'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-auth_username']."\n"; echo "
\n"; echo " ".$text['label-extension'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-extension']."\n"; echo "
\n"; echo " ".$text['label-register_transport'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-register_transport']."\n"; echo "
\n"; echo " ".$text['label-register_proxy'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-register_proxy']."\n"; echo "
\n"; echo " ".$text['label-outbound_proxy'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-outbound_proxy']."\n"; echo "
\n"; echo " ".$text['label-caller_id_in_from'].":\n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-caller_id_in_from']."\n"; echo "
\n"; echo " ".$text['label-supress_cng'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-supress_cng']."\n"; echo "
\n"; echo " ".$text['label-sip_cid_type'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_cid_type']."\n"; echo "
\n"; echo " ".$text['label-codec_prefs'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-codec_prefs']."\n"; echo "
\n"; echo " ".$text['label-extension_in_contact'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-extension_in_contact']."\n"; echo "
\n"; echo " ".$text['label-ping'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-ping']."\n"; echo "
\n"; echo " ".$text['label-channels'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-channels']."\n"; echo "
\n"; echo "
"; echo "
\n"; echo " ".$text['label-context'].":\n"; echo "\n"; if (strlen($context) == 0) { $context = "public"; } echo " \n"; echo "
\n"; echo $text['description-context']."\n"; echo "
\n"; echo " ".$text['label-profile'].":\n"; echo "\n"; if (strlen($profile) == 0) { $profile = "external"; } echo " \n"; echo "
\n"; echo $text['description-profile']."\n"; echo "
\n"; echo " ".$text['label-enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enabled']."\n"; echo "
\n"; echo " ".$text['label-description'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo ""; echo "
"; echo "
"; //include the footer require_once "resources/footer.php"; ?>