Update gateway_delete.php
This commit is contained in:
@@ -23,79 +23,85 @@
|
|||||||
Contributor(s):
|
Contributor(s):
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
*/
|
*/
|
||||||
include "root.php";
|
//includes
|
||||||
require_once "resources/require.php";
|
include "root.php";
|
||||||
require_once "resources/check_auth.php";
|
require_once "resources/require.php";
|
||||||
if (permission_exists('gateway_delete')) {
|
require_once "resources/check_auth.php";
|
||||||
//access granted
|
|
||||||
}
|
//check permissions
|
||||||
else {
|
if (permission_exists('gateway_delete')) {
|
||||||
echo "access denied";
|
//access granted
|
||||||
exit;
|
}
|
||||||
}
|
else {
|
||||||
|
echo "access denied";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
//add multi-lingual support
|
//add multi-lingual support
|
||||||
$language = new text;
|
$language = new text;
|
||||||
$text = $language->get();
|
$text = $language->get();
|
||||||
|
|
||||||
if (strlen($_GET["id"])>0) {
|
//delete the gateway
|
||||||
//set the variable
|
if (is_array($_GET["id"])) {
|
||||||
$id = check_str($_GET["id"]);
|
//set the variable
|
||||||
|
$id = check_str($_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 = '$id' ";
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
$prep_statement = $db->prepare(check_sql($sql));
|
||||||
$prep_statement->execute();
|
$prep_statement->execute();
|
||||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
foreach ($result as &$row) {
|
foreach ($result as &$row) {
|
||||||
$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);
|
|
||||||
|
|
||||||
//remove gateway from session variable
|
|
||||||
unset($_SESSION['gateways'][$gateway_uuid]);
|
|
||||||
|
|
||||||
//delete the xml file
|
|
||||||
if ($_SESSION['switch']['sip_profiles']['dir'] != '') {
|
|
||||||
$gateway_xml_file = $_SESSION['switch']['sip_profiles']['dir']."/".$profile."/v_".$gateway_uuid.".xml";
|
|
||||||
if (file_exists($gateway_xml_file)) {
|
|
||||||
unlink($gateway_xml_file);
|
|
||||||
}
|
}
|
||||||
}
|
unset ($prep_statement);
|
||||||
|
|
||||||
//create the event socket connection and stop the gateway
|
//remove gateway from session variable
|
||||||
if (!$fp) {
|
unset($_SESSION['gateways'][$gateway_uuid]);
|
||||||
|
|
||||||
|
//delete the xml file
|
||||||
|
if ($_SESSION['switch']['sip_profiles']['dir'] != '') {
|
||||||
|
$gateway_xml_file = $_SESSION['switch']['sip_profiles']['dir']."/".$profile."/v_".$gateway_uuid.".xml";
|
||||||
|
if (file_exists($gateway_xml_file)) {
|
||||||
|
unlink($gateway_xml_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the event socket connection and stop the gateway
|
||||||
|
if (!$fp) {
|
||||||
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//send the api gateway stop command over event socket
|
||||||
|
$cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid;
|
||||||
|
$response = event_socket_request($fp, $cmd);
|
||||||
|
unset($cmd);
|
||||||
|
|
||||||
|
//delete the gateway
|
||||||
|
$sql = "delete from v_gateways ";
|
||||||
|
$sql .= "where gateway_uuid = '$id' ";
|
||||||
|
$db->query($sql);
|
||||||
|
unset($sql);
|
||||||
|
|
||||||
|
//syncrhonize configuration
|
||||||
|
save_gateway_xml();
|
||||||
|
|
||||||
|
//clear the cache
|
||||||
$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']);
|
||||||
}
|
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||||
|
$cache = new cache;
|
||||||
|
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||||
|
|
||||||
//send the api gateway stop command over event socket
|
|
||||||
$cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid;
|
|
||||||
$response = event_socket_request($fp, $cmd);
|
|
||||||
unset($cmd);
|
|
||||||
|
|
||||||
//delete the gateway
|
|
||||||
$sql = "delete from v_gateways ";
|
|
||||||
$sql .= "where gateway_uuid = '$id' ";
|
|
||||||
$db->query($sql);
|
|
||||||
unset($sql);
|
|
||||||
|
|
||||||
//syncrhonize configuration
|
|
||||||
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);
|
|
||||||
|
|
||||||
//rescan the sip profile to look for new or stopped gateways
|
|
||||||
//create the event socket connection and send a command
|
//create the event socket connection and send a command
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
$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']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//rescan the sip profile to look for new or stopped gateways
|
||||||
if ($fp) {
|
if ($fp) {
|
||||||
//send the api commandover event socket
|
//send the api commandover event socket
|
||||||
$cmd = 'api sofia profile '.$profile.' rescan';
|
$cmd = 'api sofia profile '.$profile.' rescan';
|
||||||
@@ -108,7 +114,7 @@ if (strlen($_GET["id"])>0) {
|
|||||||
|
|
||||||
//clear the apply settings reminder
|
//clear the apply settings reminder
|
||||||
$_SESSION["reload_xml"] = false;
|
$_SESSION["reload_xml"] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//redirect the users
|
//redirect the users
|
||||||
message::add($text['message-delete']);
|
message::add($text['message-delete']);
|
||||||
|
|||||||
Reference in New Issue
Block a user