2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
|
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
include "root.php";
|
2013-07-06 08:03:27 +02:00
|
|
|
require_once "resources/require.php";
|
2013-07-06 07:50:55 +02:00
|
|
|
require_once "resources/check_auth.php";
|
2012-12-23 09:18:15 +01:00
|
|
|
if (permission_exists('gateway_delete')) {
|
2012-06-04 16:58:40 +02:00
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-23 09:18:15 +01:00
|
|
|
//add multi-lingual support
|
2015-01-18 11:06:08 +01:00
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
2012-12-23 09:18:15 +01:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($_GET["id"])>0) {
|
|
|
|
|
//set the variable
|
2012-12-23 09:18:15 +01:00
|
|
|
$id = check_str($_GET["id"]);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//get the gateway name
|
2012-11-24 01:59:49 +01:00
|
|
|
$sql = "select * from v_gateways ";
|
2015-01-22 12:26:06 +01:00
|
|
|
$sql .= "where gateway_uuid = '$id' ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach ($result as &$row) {
|
2013-12-06 09:12:48 +01:00
|
|
|
$gateway_uuid = $row["gateway_uuid"];
|
2012-06-04 16:58:40 +02:00
|
|
|
$gateway = $row["gateway"];
|
|
|
|
|
$profile = $row["profile"];
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
|
2015-05-18 18:44:38 +02:00
|
|
|
//remove gateway from session variable
|
|
|
|
|
unset($_SESSION['gateways'][$gateway_uuid]);
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//delete the xml file
|
2014-08-14 00:08:39 +02:00
|
|
|
if ($_SESSION['switch']['sip_profiles']['dir'] != '') {
|
2014-03-22 01:54:56 +01:00
|
|
|
$gateway_xml_file = $_SESSION['switch']['sip_profiles']['dir']."/".$profile."/v_".$gateway_uuid.".xml";
|
2014-08-14 00:08:39 +02:00
|
|
|
if (file_exists($gateway_xml_file)) {
|
|
|
|
|
unlink($gateway_xml_file);
|
|
|
|
|
}
|
2013-11-27 17:47:06 +01:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//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']);
|
|
|
|
|
}
|
2013-11-27 17:47:06 +01:00
|
|
|
|
|
|
|
|
//send the api gateway stop command over event socket
|
2013-12-06 09:12:48 +01:00
|
|
|
$cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid;
|
2013-11-27 17:47:06 +01:00
|
|
|
$response = event_socket_request($fp, $cmd);
|
|
|
|
|
unset($cmd);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2013-11-27 17:47:06 +01:00
|
|
|
//delete the gateway
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql = "delete from v_gateways ";
|
2015-01-22 12:26:06 +01:00
|
|
|
$sql .= "where gateway_uuid = '$id' ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$db->query($sql);
|
|
|
|
|
unset($sql);
|
|
|
|
|
|
|
|
|
|
//syncrhonize configuration
|
|
|
|
|
save_gateway_xml();
|
|
|
|
|
|
2013-01-16 01:26:48 +01:00
|
|
|
//delete the gateways from memcache
|
|
|
|
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
|
|
|
|
if ($fp) {
|
2013-11-27 17:47:06 +01:00
|
|
|
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
|
|
|
|
$switch_cmd = "memcache delete configuration:sofia.conf:".$hostname;
|
2013-01-16 01:26:48 +01:00
|
|
|
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//rescan the sip profile to look for new or stopped gateways
|
|
|
|
|
//create the event socket connection and send a command
|
|
|
|
|
if (!$fp) {
|
|
|
|
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
|
|
|
|
}
|
|
|
|
|
if ($fp) {
|
|
|
|
|
//send the api commandover event socket
|
2013-11-27 17:47:06 +01:00
|
|
|
$cmd = 'api sofia profile '.$profile.' rescan';
|
|
|
|
|
$response = event_socket_request($fp, $cmd);
|
|
|
|
|
unset($cmd);
|
2012-06-04 16:58:40 +02:00
|
|
|
//close the connection
|
|
|
|
|
fclose($fp);
|
|
|
|
|
}
|
|
|
|
|
usleep(1000);
|
|
|
|
|
|
|
|
|
|
//clear the apply settings reminder
|
|
|
|
|
$_SESSION["reload_xml"] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//redirect the users
|
2014-02-23 08:15:37 +01:00
|
|
|
$_SESSION["message"] = $text['message-delete'];
|
|
|
|
|
header("Location: gateways.php");
|
2012-06-04 16:58:40 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
?>
|