Gateways: Database class integration.

This commit is contained in:
Nate
2019-08-08 20:11:33 -06:00
parent 8a0f849fe1
commit 7133afc059
5 changed files with 215 additions and 261 deletions
+20
View File
@@ -761,6 +761,26 @@ $text['label-action']['ru-ru'] = "Действие";
$text['label-action']['sv-se'] = "Åtgärd"; $text['label-action']['sv-se'] = "Åtgärd";
$text['label-action']['uk-ua'] = "Дія"; $text['label-action']['uk-ua'] = "Дія";
$text['label-copy']['en-us'] = "Copy";
$text['label-copy']['ar-eg'] = "Copy";
$text['label-copy']['de-at'] = "Copy";
$text['label-copy']['de-ch'] = "Copy";
$text['label-copy']['de-de'] = "Copy";
$text['label-copy']['es-cl'] = "Copy";
$text['label-copy']['es-mx'] = "Copy";
$text['label-copy']['fr-ca'] = "Copy";
$text['label-copy']['fr-fr'] = "Copy";
$text['label-copy']['he-il'] = "Copy";
$text['label-copy']['it-it'] = "Copy";
$text['label-copy']['nl-nl'] = "Copy";
$text['label-copy']['pl-pl'] = "Copy";
$text['label-copy']['pt-br'] = "Copy";
$text['label-copy']['pt-pt'] = "Copy";
$text['label-copy']['ro-ro'] = "Copy";
$text['label-copy']['ru-ru'] = "Copy";
$text['label-copy']['sv-se'] = "Copy";
$text['label-copy']['uk-ua'] = "Copy";
$text['description-username']['en-us'] = "Enter the username here."; $text['description-username']['en-us'] = "Enter the username here.";
$text['description-username']['ar-eg'] = "أدخل اسم المستخدم هنا"; $text['description-username']['ar-eg'] = "أدخل اسم المستخدم هنا";
$text['description-username']['de-at'] = "Geben Sie den Benutzernamen an."; //copied from de-de $text['description-username']['de-at'] = "Geben Sie den Benutzernamen an."; //copied from de-de
+97 -128
View File
@@ -44,141 +44,110 @@
$text = $language->get(); $text = $language->get();
//set the http get/post variable(s) to a php variable //set the http get/post variable(s) to a php variable
if (isset($_REQUEST["id"])) { if (is_uuid($_REQUEST["id"])) {
$gateway_uuid = check_str($_REQUEST["id"]); $gateway_uuid = $_REQUEST["id"];
}
//get the data //get the data
$sql = "select * from v_gateways "; $sql = "select * from v_gateways ";
$sql .= "where gateway_uuid = '$gateway_uuid' "; $sql .= "where gateway_uuid = :gateway_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['gateway_uuid'] = $gateway_uuid;
$prep_statement->execute(); $database = new database;
$gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED); $row = $database->select($sql, $parameters, 'row');
foreach ($gateways as &$row) { if (is_array($row) && @sizeof($row) != 0) {
$domain_uuid = $row["domain_uuid"]; $domain_uuid = $row["domain_uuid"];
$gateway = $row["gateway"]; $gateway = $row["gateway"];
$username = $row["username"]; $username = $row["username"];
$password = $row["password"]; $password = $row["password"];
$auth_username = $row["auth_username"]; $auth_username = $row["auth_username"];
$realm = $row["realm"]; $realm = $row["realm"];
$from_user = $row["from_user"]; $from_user = $row["from_user"];
$from_domain = $row["from_domain"]; $from_domain = $row["from_domain"];
$proxy = $row["proxy"]; $proxy = $row["proxy"];
$register_proxy = $row["register_proxy"]; $register_proxy = $row["register_proxy"];
$outbound_proxy = $row["outbound_proxy"]; $outbound_proxy = $row["outbound_proxy"];
$expire_seconds = $row["expire_seconds"]; $expire_seconds = $row["expire_seconds"];
$register = $row["register"]; $register = $row["register"];
$register_transport = $row["register_transport"]; $register_transport = $row["register_transport"];
$retry_seconds = $row["retry_seconds"]; $retry_seconds = $row["retry_seconds"];
$extension = $row["extension"]; $extension = $row["extension"];
$codec_prefs = $row["codec_prefs"]; $codec_prefs = $row["codec_prefs"];
$ping = $row["ping"]; $ping = $row["ping"];
$channels = $row["channels"]; $channels = $row["channels"];
$caller_id_in_from = $row["caller_id_in_from"]; $caller_id_in_from = $row["caller_id_in_from"];
$supress_cng = $row["supress_cng"]; $supress_cng = $row["supress_cng"];
$extension_in_contact = $row["extension_in_contact"]; $extension_in_contact = $row["extension_in_contact"];
$effective_caller_id_name = $row["effective_caller_id_name"]; $effective_caller_id_name = $row["effective_caller_id_name"];
$effective_caller_id_number = $row["effective_caller_id_number"]; $effective_caller_id_number = $row["effective_caller_id_number"];
$outbound_caller_id_name = $row["outbound_caller_id_name"]; $outbound_caller_id_name = $row["outbound_caller_id_name"];
$outbound_caller_id_number = $row["outbound_caller_id_number"]; $outbound_caller_id_number = $row["outbound_caller_id_number"];
$context = $row["context"]; $context = $row["context"];
$enabled = $row["enabled"]; $enabled = $row["enabled"];
$description = 'copy: '.$row["description"]; $description = $row["description"]." (".$text['label-copy'].")";
} }
unset ($prep_statement); unset($sql, $parameters, $row);
//set defaults //set defaults
if (strlen($expire_seconds) == 0) { if (strlen($expire_seconds) == 0) {
$expire_seconds = '800'; $expire_seconds = '800';
} }
if (strlen($retry_seconds) == 0) { if (strlen($retry_seconds) == 0) {
$retry_seconds = '30'; $retry_seconds = '30';
} }
//copy the gateways //copy the gateways
$gateway_uuid = uuid(); $gateway_uuid = uuid();
$sql = "insert into v_gateways "; $array['gateways'][0]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null;
$sql .= "("; $array['gateways'][0]['gateway_uuid'] = $gateway_uuid;
$sql .= "domain_uuid, "; $array['gateways'][0]['gateway'] = $gateway;
$sql .= "gateway_uuid, "; $array['gateways'][0]['username'] = $username;
$sql .= "gateway, "; $array['gateways'][0]['password'] = $password;
$sql .= "username, "; $array['gateways'][0]['auth_username'] = $auth_username;
$sql .= "password, "; $array['gateways'][0]['realm'] = $realm;
$sql .= "auth_username, "; $array['gateways'][0]['from_user'] = $from_user;
$sql .= "realm, "; $array['gateways'][0]['from_domain'] = $from_domain;
$sql .= "from_user, "; $array['gateways'][0]['proxy'] = $proxy;
$sql .= "from_domain, "; $array['gateways'][0]['register_proxy'] = $register_proxy;
$sql .= "proxy, "; $array['gateways'][0]['outbound_proxy'] = $outbound_proxy;
$sql .= "register_proxy, "; $array['gateways'][0]['expire_seconds'] = $expire_seconds;
$sql .= "outbound_proxy, "; $array['gateways'][0]['register'] = $register;
$sql .= "expire_seconds, "; $array['gateways'][0]['register_transport'] = $register_transport;
$sql .= "register, "; $array['gateways'][0]['retry_seconds'] = $retry_seconds;
$sql .= "register_transport, "; $array['gateways'][0]['extension'] = $extension;
$sql .= "retry_seconds, "; $array['gateways'][0]['codec_prefs'] = $codec_prefs;
$sql .= "extension, "; $array['gateways'][0]['ping'] = $ping;
$sql .= "codec_prefs, "; //$array['gateways'][0]['channels'] = $channels;
$sql .= "ping, "; $array['gateways'][0]['caller_id_in_from'] = $caller_id_in_from;
//$sql .= "channels, "; $array['gateways'][0]['supress_cng'] = $supress_cng;
$sql .= "caller_id_in_from, "; $array['gateways'][0]['extension_in_contact'] = $extension_in_contact;
$sql .= "supress_cng, "; $array['gateways'][0]['context'] = $context;
$sql .= "extension_in_contact, "; $array['gateways'][0]['enabled'] = $enabled;
$sql .= "context, "; $array['gateways'][0]['description'] = $description;
$sql .= "enabled, ";
$sql .= "description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
if (strlen($domain_uuid) > 0) {
$sql .= "'$domain_uuid', ";
}
else {
$sql .= "null, ";
}
$sql .= "'$gateway_uuid', ";
$sql .= "'$gateway', ";
$sql .= "'$username', ";
$sql .= "'$password', ";
$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 .= "'$codec_prefs', ";
$sql .= "'$ping', ";
//$sql .= "'$channels', ";
$sql .= "'$caller_id_in_from', ";
$sql .= "'$supress_cng', ";
$sql .= "'$extension_in_contact', ";
$sql .= "'$context', ";
$sql .= "'$enabled', ";
$sql .= "'$description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//add new gateway to session variable $database = new database;
if ($enabled == 'true') { $database->app_name = 'gateways';
$_SESSION['gateways'][$gateway_uuid] = $gateway; $database->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8';
$database->save($array);
unset($array);
//add new gateway to session variable
if ($enabled == 'true') {
$_SESSION['gateways'][$gateway_uuid] = $gateway;
}
//synchronize the xml config
save_gateway_xml();
//clear the cache
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
$hostname = trim(event_socket_request($fp, 'api switchname'));
$cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname);
//set message
message::add($text['message-copy']);
} }
//synchronize the xml config
save_gateway_xml();
//clear the cache
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
$hostname = trim(event_socket_request($fp, 'api switchname'));
$cache = new cache;
$cache->delete("configuration:sofia.conf:".$hostname);
//redirect the user //redirect the user
message::add($text['message-copy']);
header("Location: gateways.php"); header("Location: gateways.php");
return; return;
+18 -13
View File
@@ -44,20 +44,20 @@
//delete the gateway //delete the gateway
if (is_uuid($_GET["id"])) { if (is_uuid($_GET["id"])) {
//set the variable //set the variable
$id = check_str($_GET["id"]); $id = $_GET["id"];
//get the gateway name //get the gateway name
$sql = "select * from v_gateways "; $sql = "select * from v_gateways ";
$sql .= "where gateway_uuid = '$id' "; $sql .= "where gateway_uuid = :gateway_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['gateway_uuid'] = $id;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $row = $database->select($sql, $parameters, 'row');
foreach ($result as &$row) { if (is_array($row) && @sizeof($row) != 0) {
$gateway_uuid = $row["gateway_uuid"]; $gateway_uuid = $row["gateway_uuid"];
$gateway = $row["gateway"]; $gateway = $row["gateway"];
$profile = $row["profile"]; $profile = $row["profile"];
} }
unset ($prep_statement); unset($sql, $parameters, $row);
//remove gateway from session variable //remove gateway from session variable
unset($_SESSION['gateways'][$gateway_uuid]); unset($_SESSION['gateways'][$gateway_uuid]);
@@ -81,10 +81,13 @@
unset($cmd); unset($cmd);
//delete the gateway //delete the gateway
$sql = "delete from v_gateways "; $array['gateways'][0]['gateway_uuid'] = $id;
$sql .= "where gateway_uuid = '$id' ";
$db->query($sql); $database = new database;
unset($sql); $database->app_name = 'gateways';
$database->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8';
$database->delete($array);
unset($array);
//syncrhonize configuration //syncrhonize configuration
save_gateway_xml(); save_gateway_xml();
@@ -114,11 +117,13 @@
//clear the apply settings reminder //clear the apply settings reminder
$_SESSION["reload_xml"] = false; $_SESSION["reload_xml"] = false;
//set message
message::add($text['message-delete']);
} }
//redirect the users //redirect the users
message::add($text['message-delete']);
header("Location: gateways.php"); header("Location: gateways.php");
return; exit;
?> ?>
+59 -77
View File
@@ -43,13 +43,13 @@
$text = $language->get(); $text = $language->get();
//action add or update //action add or update
if (isset($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { if (is_uuid($_REQUEST["id"])) {
$action = "update"; $action = "update";
if (isset($_POST["id"])) { if (is_uuid($_POST["id"])) {
$gateway_uuid = check_str($_REQUEST["id"]); $gateway_uuid = $_REQUEST["id"];
} }
if (isset($_POST["gateway_uuid"])) { if (is_uuid($_POST["gateway_uuid"])) {
$gateway_uuid = check_str($_POST["gateway_uuid"]); $gateway_uuid = $_POST["gateway_uuid"];
} }
} }
else { else {
@@ -59,59 +59,52 @@
//get total gateway count from the database, check limit, if defined //get total gateway count from the database, check limit, if defined
if ($action == 'add') { if ($action == 'add') {
if ($_SESSION['limit']['gateways']['numeric'] != '') { if (is_numeric($_SESSION['limit']['gateways']['numeric'])) {
$sql = "select count(gateway_uuid) as num_rows from v_gateways "; $sql = "select count(gateway_uuid) from v_gateways ";
$sql .= "where ( domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") ";
if (permission_exists('gateway_domain')) { $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$sql .= "or domain_uuid is null "; $database = new database;
} $total_gateways = $database->select($sql, $parameters, 'column');
$sql .= ");"; unset($sql, $parameters);
$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 ($total_gateways >= $_SESSION['limit']['gateways']['numeric']) { if ($total_gateways >= $_SESSION['limit']['gateways']['numeric']) {
message::add($text['message-maximum_gateways'].' '.$_SESSION['limit']['gateways']['numeric'], 'negative'); message::add($text['message-maximum_gateways'].' '.$_SESSION['limit']['gateways']['numeric'], 'negative');
header('Location: gateways.php'); header('Location: gateways.php');
return; exit;
} }
} }
} }
//get http post variables and set them to php variables //get http post variables and set them to php variables
if (count($_POST) > 0) { if (count($_POST) > 0) {
$domain_uuid = check_str($_POST["domain_uuid"]); $domain_uuid = $_POST["domain_uuid"];
$gateway = check_str($_POST["gateway"]); $gateway = $_POST["gateway"];
$username = check_str($_POST["username"]); $username = $_POST["username"];
$password = check_str($_POST["password"]); $password = $_POST["password"];
$distinct_to = check_str($_POST["distinct_to"]); $distinct_to = $_POST["distinct_to"];
$auth_username = check_str($_POST["auth_username"]); $auth_username = $_POST["auth_username"];
$realm = check_str($_POST["realm"]); $realm = $_POST["realm"];
$from_user = check_str($_POST["from_user"]); $from_user = $_POST["from_user"];
$from_domain = check_str($_POST["from_domain"]); $from_domain = $_POST["from_domain"];
$proxy = check_str($_POST["proxy"]); $proxy = $_POST["proxy"];
$register_proxy = check_str($_POST["register_proxy"]); $register_proxy = $_POST["register_proxy"];
$outbound_proxy = check_str($_POST["outbound_proxy"]); $outbound_proxy = $_POST["outbound_proxy"];
$expire_seconds = check_str($_POST["expire_seconds"]); $expire_seconds = $_POST["expire_seconds"];
$register = check_str($_POST["register"]); $register = $_POST["register"];
$register_transport = check_str($_POST["register_transport"]); $register_transport = $_POST["register_transport"];
$retry_seconds = check_str($_POST["retry_seconds"]); $retry_seconds = $_POST["retry_seconds"];
$extension = check_str($_POST["extension"]); $extension = $_POST["extension"];
$ping = check_str($_POST["ping"]); $ping = $_POST["ping"];
$channels = check_str($_POST["channels"]); $channels = $_POST["channels"];
$caller_id_in_from = check_str($_POST["caller_id_in_from"]); $caller_id_in_from = $_POST["caller_id_in_from"];
$supress_cng = check_str($_POST["supress_cng"]); $supress_cng = $_POST["supress_cng"];
$sip_cid_type = check_str($_POST["sip_cid_type"]); $sip_cid_type = $_POST["sip_cid_type"];
$codec_prefs = check_str($_POST["codec_prefs"]); $codec_prefs = $_POST["codec_prefs"];
$extension_in_contact = check_str($_POST["extension_in_contact"]); $extension_in_contact = $_POST["extension_in_contact"];
$context = check_str($_POST["context"]); $context = $_POST["context"];
$profile = check_str($_POST["profile"]); $profile = $_POST["profile"];
$hostname = check_str($_POST["hostname"]); $hostname = $_POST["hostname"];
$enabled = check_str($_POST["enabled"]); $enabled = $_POST["enabled"];
$description = check_str($_POST["description"]); $description = $_POST["description"];
} }
//prevent the domain_uuid from not being set by someone without this permission //prevent the domain_uuid from not being set by someone without this permission
@@ -158,12 +151,7 @@
//build the gateway array //build the gateway array
$x = 0; $x = 0;
if (strlen($domain_uuid) == 0) { $array['gateways'][$x]["domain_uuid"] = is_uuid($domain_uuid) ? $domain_uuid : null;
$array['gateways'][$x]["domain_uuid"] = null;
}
else {
$array['gateways'][$x]["domain_uuid"] = $domain_uuid;
}
$array['gateways'][$x]["gateway_uuid"] = $gateway_uuid; $array['gateways'][$x]["gateway_uuid"] = $gateway_uuid;
$array['gateways'][$x]["gateway"] = $gateway; $array['gateways'][$x]["gateway"] = $gateway;
$array['gateways'][$x]["username"] = $username; $array['gateways'][$x]["username"] = $username;
@@ -190,12 +178,7 @@
$array['gateways'][$x]["extension_in_contact"] = $extension_in_contact; $array['gateways'][$x]["extension_in_contact"] = $extension_in_contact;
$array['gateways'][$x]["context"] = $context; $array['gateways'][$x]["context"] = $context;
$array['gateways'][$x]["profile"] = $profile; $array['gateways'][$x]["profile"] = $profile;
if (strlen($hostname) == 0) { $array['gateways'][$x]["hostname"] = strlen($hostname) != 0 ? $hostname : null;
$array['gateways'][$x]["hostname"] = null;
}
else {
$array['gateways'][$x]["hostname"] = $hostname;
}
$array['gateways'][$x]["enabled"] = $enabled; $array['gateways'][$x]["enabled"] = $enabled;
$array['gateways'][$x]["description"] = $description; $array['gateways'][$x]["description"] = $description;
@@ -211,7 +194,7 @@
$database = new database; $database = new database;
$database->app_name = 'gateways'; $database->app_name = 'gateways';
$database->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8'; $database->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8';
if (strlen($gateway_uuid) > 0) { if (is_uuid($gateway_uuid)) {
$database->uuid($gateway_uuid); $database->uuid($gateway_uuid);
} }
$database->save($array); $database->save($array);
@@ -246,7 +229,7 @@
//clear the apply settings reminder //clear the apply settings reminder
$_SESSION["reload_xml"] = false; $_SESSION["reload_xml"] = false;
} //if ($_POST["persistformvar"] != "true") }
//redirect the user //redirect the user
if (isset($action)) { if (isset($action)) {
@@ -257,19 +240,19 @@
message::add($text['message-update']); message::add($text['message-update']);
} }
header("Location: gateways.php"); header("Location: gateways.php");
return; exit;
} }
} //(count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) }
//pre-populate the form //pre-populate the form
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { if (count($_GET) > 0 && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") {
$gateway_uuid = check_str($_GET["id"]); $gateway_uuid = $_GET["id"];
$sql = "select * from v_gateways "; $sql = "select * from v_gateways ";
$sql .= "where gateway_uuid = '".$gateway_uuid."' "; $sql .= "where gateway_uuid = :gateway_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['gateway_uuid'] = $gateway_uuid;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $row = $database->select($sql, $parameters, 'row');
foreach ($result as &$row) { if (is_array($row) && @sizeof($row) != 0) {
$domain_uuid = $row["domain_uuid"]; $domain_uuid = $row["domain_uuid"];
$gateway = $row["gateway"]; $gateway = $row["gateway"];
$username = $row["username"]; $username = $row["username"];
@@ -300,17 +283,16 @@
$enabled = $row["enabled"]; $enabled = $row["enabled"];
$description = $row["description"]; $description = $row["description"];
} }
unset ($prep_statement); unset($sql, $parameters, $row);
} }
//get the sip profiles //get the sip profiles
$sql = "select sip_profile_name from v_sip_profiles "; $sql = "select sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' "; $sql .= "where sip_profile_enabled = 'true' ";
$sql .= "order by sip_profile_name asc "; $sql .= "order by sip_profile_name asc ";
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
$prep_statement->execute(); $sip_profiles = $database->select($sql, null, 'all');
$sip_profiles = $prep_statement->fetchAll(); unset($sql);
unset ($prep_statement, $sql);
//set defaults //set defaults
if (strlen($enabled) == 0) { $enabled = "true"; } if (strlen($enabled) == 0) { $enabled = "true"; }
+21 -43
View File
@@ -47,19 +47,19 @@
require_once "resources/paging.php"; require_once "resources/paging.php";
//get variables used to control the order //get variables used to control the order
$order_by = check_str($_GET["order_by"]); $order_by = $_GET["order_by"];
$order = check_str($_GET["order"]); $order = $_GET["order"];
//connect to event socket //connect to event socket
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) { if ($fp) {
if (strlen($_GET["a"]) > 0) { if (strlen($_GET["a"]) > 0 && is_uuid($_GET["gateway"])) {
$profile = check_str($_GET["profile"]); $profile = $_GET["profile"];
if (strlen($profile) == 0) { if (strlen($profile) == 0) {
$profile = 'external'; $profile = 'external';
} }
if ($_GET["a"] == "stop") { if ($_GET["a"] == "stop") {
$gateway_uuid = check_str($_GET["gateway"]); $gateway_uuid = $_GET["gateway"];
$cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid; $cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid;
$response = trim(event_socket_request($fp, $cmd)); $response = trim(event_socket_request($fp, $cmd));
$msg = '<strong>Stop Gateway:</strong><pre>'.$response.'</pre>'; $msg = '<strong>Stop Gateway:</strong><pre>'.$response.'</pre>';
@@ -113,19 +113,13 @@
echo "<br />\n"; echo "<br />\n";
//get total gateway count from the database //get total gateway count from the database
$sql = "select count(*) as num_rows from v_gateways "; $sql = "select count(*) from v_gateways ";
$sql .= "where ( domain_uuid = '".$_SESSION['domain_uuid']."' "; if (!($_GET['show'] == "all" && permission_exists('gateway_all'))) {
if (permission_exists('gateway_domain')) { $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") ";
$sql .= "or domain_uuid is null "; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
} }
$sql .= ");"; $database = new database;
$prep_statement = $db->prepare($sql); $total_gateways = $database->select($sql, $parameters, 'column');
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$total_gateways = $row['num_rows'];
}
unset($sql, $prep_statement, $row);
//prepare to page the results //prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
@@ -136,28 +130,12 @@
$offset = $rows_per_page * $_GET['page']; $offset = $rows_per_page * $_GET['page'];
//get the list //get the list
$sql = "select * from v_gateways "; $sql = str_replace('count(*)', '*', $sql);
if ($_GET['show'] == "all" && permission_exists('gateway_all')) { $sql .= order_by($order_by, $order, 'gateway', 'asc');
//show all gateways $sql .= limit_offset($rows_per_page, $offset);
} else { $database = new database;
$sql .= "where (\n"; $gateways = $database->select($sql, $parameters, 'all');
$sql .= " domain_uuid = '".$_SESSION['domain_uuid']."'\n"; unset($sql, $parameters);
if (permission_exists('gateway_domain')) {
$sql .= " or domain_uuid is null\n";
}
$sql .= ") ";
}
if (strlen($order_by) == 0) {
$sql .= "order by gateway asc\n";
}
else {
$sql .= "order by $order_by $order\n";
}
$sql .= "limit $rows_per_page offset $offset\n";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
$c = 0; $c = 0;
$row_style["0"] = "row_style0"; $row_style["0"] = "row_style0";
@@ -255,10 +233,10 @@
echo " </td>\n"; echo " </td>\n";
echo "</tr>\n"; echo "</tr>\n";
} }
if ($c==0) { $c=1; } else { $c=0; } $c = $c ? 0 : 1;
} //end foreach }
unset($sql, $gateways, $row_count); }
} //end if results unset($gateways, $row);
echo "<tr>\n"; echo "<tr>\n";
echo "</table>\n"; echo "</table>\n";