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>
|
2016-04-30 00:04:10 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2016
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
2017-03-14 21:56:23 +01:00
|
|
|
|
|
|
|
|
//includes
|
|
|
|
|
require_once "root.php";
|
|
|
|
|
require_once "resources/require.php";
|
|
|
|
|
require_once "resources/check_auth.php";
|
|
|
|
|
|
|
|
|
|
//check permissions
|
|
|
|
|
if (permission_exists('domain_delete')) {
|
|
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2013-05-14 07:34:04 +02:00
|
|
|
//add multi-lingual support
|
2015-01-18 10:22:07 +01:00
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
2013-05-14 07:34:04 +02:00
|
|
|
|
2015-01-18 10:22:07 +01:00
|
|
|
//get the id
|
|
|
|
|
if (count($_GET)>0) {
|
|
|
|
|
$id = check_str($_GET["id"]);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete domain data and files
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($id) > 0) {
|
|
|
|
|
//get the domain using the id
|
|
|
|
|
$sql = "select * from v_domains ";
|
|
|
|
|
$sql .= "where domain_uuid = '$id' ";
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
2016-04-30 00:04:10 +02:00
|
|
|
if (isset($result)) foreach ($result as &$row) {
|
2012-06-04 16:58:40 +02:00
|
|
|
$domain_name = $row["domain_name"];
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
|
|
|
|
|
//get the domain settings
|
|
|
|
|
$sql = "select * from v_domain_settings ";
|
|
|
|
|
$sql .= "where domain_uuid = '".$id."' ";
|
|
|
|
|
$sql .= "and domain_setting_enabled = 'true' ";
|
|
|
|
|
$prep_statement = $db->prepare($sql);
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
2016-04-30 00:04:10 +02:00
|
|
|
if (isset($result)) foreach($result as $row) {
|
2012-06-04 16:58:40 +02:00
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
2013-05-14 07:34:04 +02:00
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($subcategory) == 0) {
|
2014-03-22 02:00:46 +01:00
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][$subcategory][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$subcategory]['uuid'] = $row['default_setting_uuid'];
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the $apps array from the installed apps from the core and mod directories
|
|
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
|
|
|
|
$x=0;
|
2016-04-30 00:04:10 +02:00
|
|
|
if (isset($config_list)) foreach ($config_list as &$config_path) {
|
2012-06-04 16:58:40 +02:00
|
|
|
include($config_path);
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete the domain data from all tables in the database
|
|
|
|
|
$db->beginTransaction();
|
2016-04-30 00:04:10 +02:00
|
|
|
if (isset($apps)) foreach ($apps as &$app) {
|
|
|
|
|
if (isset($app['db'])) foreach ($app['db'] as $row) {
|
2017-05-23 00:04:46 +02:00
|
|
|
if (is_array($row['table'])) {
|
|
|
|
|
$table_name = $row['table']['name'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$table_name = $row['table'];
|
|
|
|
|
}
|
|
|
|
|
if ($table_name !== "v" && isset($row['fields'])) {
|
|
|
|
|
foreach ($row['fields'] as $field) {
|
|
|
|
|
if ($field['name'] == "domain_uuid") {
|
|
|
|
|
$sql = "delete from $table_name where domain_uuid = '$id' ";
|
|
|
|
|
$db->query($sql);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$db->commit();
|
|
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete the directories
|
|
|
|
|
if (strlen($domain_name) > 0) {
|
2012-06-04 16:58:40 +02:00
|
|
|
//set the needle
|
|
|
|
|
if (count($_SESSION["domains"]) > 1) {
|
|
|
|
|
$v_needle = 'v_'.$domain_name.'_';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$v_needle = 'v_';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete the dialplan
|
|
|
|
|
unlink($_SESSION['switch']['dialplan']['dir'].'/'.$domain_name.'.xml');
|
|
|
|
|
if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
|
|
|
|
|
system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/'.$domain_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete the dialplan public
|
|
|
|
|
unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name.'.xml');
|
|
|
|
|
if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
|
2013-05-14 07:34:04 +02:00
|
|
|
system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete the extension
|
2017-03-14 21:56:23 +01:00
|
|
|
unlink($_SESSION['switch']['extensions']['dir'].'/'.$domain_name.'.xml');
|
|
|
|
|
if (strlen($_SESSION['switch']['extensions']['dir']) > 0) {
|
|
|
|
|
system('rm -rf '.$_SESSION['switch']['extensions']['dir'].'/'.$domain_name);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete fax
|
|
|
|
|
if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
|
|
|
|
|
system('rm -rf '.$_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete the gateways
|
|
|
|
|
if($dh = opendir($_SESSION['switch']['sip_profiles']['dir'])) {
|
|
|
|
|
$files = Array();
|
|
|
|
|
while($file = readdir($dh)) {
|
|
|
|
|
if($file != "." && $file != ".." && $file[0] != '.') {
|
|
|
|
|
if(is_dir($dir . "/" . $file)) {
|
|
|
|
|
//this is a directory do nothing
|
|
|
|
|
} else {
|
|
|
|
|
//check if file extension is xml
|
|
|
|
|
if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
|
|
|
|
|
unlink($_SESSION['switch']['sip_profiles']['dir']."/".$file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-03-14 21:56:23 +01:00
|
|
|
closedir($dh);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete the ivr menu
|
|
|
|
|
if($dh = opendir($_SESSION['switch']['conf']['dir']."/ivr_menus/")) {
|
|
|
|
|
$files = Array();
|
|
|
|
|
while($file = readdir($dh)) {
|
|
|
|
|
if($file != "." && $file != ".." && $file[0] != '.') {
|
|
|
|
|
if(is_dir($dir . "/" . $file)) {
|
|
|
|
|
//this is a directory
|
|
|
|
|
} else {
|
|
|
|
|
if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
|
|
|
|
|
unlink($_SESSION['switch']['conf']['dir']."/ivr_menus/".$file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-03-14 21:56:23 +01:00
|
|
|
closedir($dh);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete the recordings
|
|
|
|
|
if (strlen($_SESSION['switch'][recordings]['dir']) > 0) {
|
|
|
|
|
system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//delete voicemail
|
|
|
|
|
if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
|
|
|
|
|
system('rm -rf '.$_SESSION['switch']['voicemail']['dir'].'/'.$domain_name);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//apply settings reminder
|
|
|
|
|
$_SESSION["reload_xml"] = true;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
//clear the domains session array to update it
|
|
|
|
|
unset($_SESSION["domains"]);
|
|
|
|
|
unset($_SESSION["domain_uuid"]);
|
|
|
|
|
unset($_SESSION["domain_name"]);
|
|
|
|
|
unset($_SESSION['domain']);
|
|
|
|
|
unset($_SESSION['switch']);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//redirect the browser
|
2017-06-10 04:13:40 +02:00
|
|
|
messages::add($text['message-delete']);
|
2014-02-23 10:12:38 +01:00
|
|
|
header("Location: domains.php");
|
2012-06-04 16:58:40 +02:00
|
|
|
return;
|
|
|
|
|
|
2017-03-14 21:56:23 +01:00
|
|
|
?>
|