Gateways: Database class integration.
This commit is contained in:
@@ -43,13 +43,13 @@
|
||||
$text = $language->get();
|
||||
|
||||
//action add or update
|
||||
if (isset($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
|
||||
if (is_uuid($_REQUEST["id"])) {
|
||||
$action = "update";
|
||||
if (isset($_POST["id"])) {
|
||||
$gateway_uuid = check_str($_REQUEST["id"]);
|
||||
if (is_uuid($_POST["id"])) {
|
||||
$gateway_uuid = $_REQUEST["id"];
|
||||
}
|
||||
if (isset($_POST["gateway_uuid"])) {
|
||||
$gateway_uuid = check_str($_POST["gateway_uuid"]);
|
||||
if (is_uuid($_POST["gateway_uuid"])) {
|
||||
$gateway_uuid = $_POST["gateway_uuid"];
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -59,59 +59,52 @@
|
||||
|
||||
//get total gateway count from the database, check limit, if defined
|
||||
if ($action == 'add') {
|
||||
if ($_SESSION['limit']['gateways']['numeric'] != '') {
|
||||
$sql = "select count(gateway_uuid) as num_rows from v_gateways ";
|
||||
$sql .= "where ( domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
if (permission_exists('gateway_domain')) {
|
||||
$sql .= "or domain_uuid is null ";
|
||||
}
|
||||
$sql .= ");";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
$total_gateways = $row['num_rows'];
|
||||
}
|
||||
unset($prep_statement, $row);
|
||||
if (is_numeric($_SESSION['limit']['gateways']['numeric'])) {
|
||||
$sql = "select count(gateway_uuid) from v_gateways ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") ";
|
||||
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
$database = new database;
|
||||
$total_gateways = $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
if ($total_gateways >= $_SESSION['limit']['gateways']['numeric']) {
|
||||
message::add($text['message-maximum_gateways'].' '.$_SESSION['limit']['gateways']['numeric'], 'negative');
|
||||
header('Location: gateways.php');
|
||||
return;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//get http post variables and set them to php variables
|
||||
if (count($_POST) > 0) {
|
||||
$domain_uuid = check_str($_POST["domain_uuid"]);
|
||||
$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"]);
|
||||
$hostname = check_str($_POST["hostname"]);
|
||||
$enabled = check_str($_POST["enabled"]);
|
||||
$description = check_str($_POST["description"]);
|
||||
$domain_uuid = $_POST["domain_uuid"];
|
||||
$gateway = $_POST["gateway"];
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["password"];
|
||||
$distinct_to = $_POST["distinct_to"];
|
||||
$auth_username = $_POST["auth_username"];
|
||||
$realm = $_POST["realm"];
|
||||
$from_user = $_POST["from_user"];
|
||||
$from_domain = $_POST["from_domain"];
|
||||
$proxy = $_POST["proxy"];
|
||||
$register_proxy = $_POST["register_proxy"];
|
||||
$outbound_proxy = $_POST["outbound_proxy"];
|
||||
$expire_seconds = $_POST["expire_seconds"];
|
||||
$register = $_POST["register"];
|
||||
$register_transport = $_POST["register_transport"];
|
||||
$retry_seconds = $_POST["retry_seconds"];
|
||||
$extension = $_POST["extension"];
|
||||
$ping = $_POST["ping"];
|
||||
$channels = $_POST["channels"];
|
||||
$caller_id_in_from = $_POST["caller_id_in_from"];
|
||||
$supress_cng = $_POST["supress_cng"];
|
||||
$sip_cid_type = $_POST["sip_cid_type"];
|
||||
$codec_prefs = $_POST["codec_prefs"];
|
||||
$extension_in_contact = $_POST["extension_in_contact"];
|
||||
$context = $_POST["context"];
|
||||
$profile = $_POST["profile"];
|
||||
$hostname = $_POST["hostname"];
|
||||
$enabled = $_POST["enabled"];
|
||||
$description = $_POST["description"];
|
||||
}
|
||||
|
||||
//prevent the domain_uuid from not being set by someone without this permission
|
||||
@@ -158,12 +151,7 @@
|
||||
|
||||
//build the gateway array
|
||||
$x = 0;
|
||||
if (strlen($domain_uuid) == 0) {
|
||||
$array['gateways'][$x]["domain_uuid"] = null;
|
||||
}
|
||||
else {
|
||||
$array['gateways'][$x]["domain_uuid"] = $domain_uuid;
|
||||
}
|
||||
$array['gateways'][$x]["domain_uuid"] = is_uuid($domain_uuid) ? $domain_uuid : null;
|
||||
$array['gateways'][$x]["gateway_uuid"] = $gateway_uuid;
|
||||
$array['gateways'][$x]["gateway"] = $gateway;
|
||||
$array['gateways'][$x]["username"] = $username;
|
||||
@@ -190,12 +178,7 @@
|
||||
$array['gateways'][$x]["extension_in_contact"] = $extension_in_contact;
|
||||
$array['gateways'][$x]["context"] = $context;
|
||||
$array['gateways'][$x]["profile"] = $profile;
|
||||
if (strlen($hostname) == 0) {
|
||||
$array['gateways'][$x]["hostname"] = null;
|
||||
}
|
||||
else {
|
||||
$array['gateways'][$x]["hostname"] = $hostname;
|
||||
}
|
||||
$array['gateways'][$x]["hostname"] = strlen($hostname) != 0 ? $hostname : null;
|
||||
$array['gateways'][$x]["enabled"] = $enabled;
|
||||
$array['gateways'][$x]["description"] = $description;
|
||||
|
||||
@@ -211,7 +194,7 @@
|
||||
$database = new database;
|
||||
$database->app_name = 'gateways';
|
||||
$database->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8';
|
||||
if (strlen($gateway_uuid) > 0) {
|
||||
if (is_uuid($gateway_uuid)) {
|
||||
$database->uuid($gateway_uuid);
|
||||
}
|
||||
$database->save($array);
|
||||
@@ -246,7 +229,7 @@
|
||||
//clear the apply settings reminder
|
||||
$_SESSION["reload_xml"] = false;
|
||||
|
||||
} //if ($_POST["persistformvar"] != "true")
|
||||
}
|
||||
|
||||
//redirect the user
|
||||
if (isset($action)) {
|
||||
@@ -257,19 +240,19 @@
|
||||
message::add($text['message-update']);
|
||||
}
|
||||
header("Location: gateways.php");
|
||||
return;
|
||||
exit;
|
||||
}
|
||||
} //(count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0)
|
||||
}
|
||||
|
||||
//pre-populate the form
|
||||
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
|
||||
$gateway_uuid = check_str($_GET["id"]);
|
||||
if (count($_GET) > 0 && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") {
|
||||
$gateway_uuid = $_GET["id"];
|
||||
$sql = "select * from v_gateways ";
|
||||
$sql .= "where 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) {
|
||||
$sql .= "where gateway_uuid = :gateway_uuid ";
|
||||
$parameters['gateway_uuid'] = $gateway_uuid;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
$domain_uuid = $row["domain_uuid"];
|
||||
$gateway = $row["gateway"];
|
||||
$username = $row["username"];
|
||||
@@ -300,17 +283,16 @@
|
||||
$enabled = $row["enabled"];
|
||||
$description = $row["description"];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters, $row);
|
||||
}
|
||||
|
||||
//get the sip profiles
|
||||
$sql = "select sip_profile_name from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_enabled = 'true' ";
|
||||
$sql .= "order by sip_profile_name asc ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$sip_profiles = $prep_statement->fetchAll();
|
||||
unset ($prep_statement, $sql);
|
||||
$database = new database;
|
||||
$sip_profiles = $database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
|
||||
//set defaults
|
||||
if (strlen($enabled) == 0) { $enabled = "true"; }
|
||||
|
||||
Reference in New Issue
Block a user