Update domain_delete.php

This commit is contained in:
FusionPBX 2019-02-27 12:43:05 -07:00 committed by GitHub
parent a43c92195e
commit 7cf3dfae76
1 changed files with 121 additions and 115 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2016 Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -43,159 +43,165 @@
$text = $language->get(); $text = $language->get();
//get the id //get the id
if (count($_GET)>0) { if (is_array($_GET)) {
$id = check_str($_GET["id"]); $id = check_str($_GET["id"]);
} }
//delete domain data and files //delete domain data and files
if (strlen($id) > 0) { if (is_uuid($id)) {
//get the domain using the id //get the domain using the id
$sql = "select * from v_domains "; $sql = "select * from v_domains ";
$sql .= "where domain_uuid = '$id' "; $sql .= "where domain_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);
if (isset($result)) foreach ($result as &$row) { if (isset($result)) {
$domain_name = $row["domain_name"]; foreach ($result as &$row) {
} $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);
if (isset($result)) foreach($result as $row) {
$name = $row['domain_setting_name'];
$category = $row['domain_setting_category'];
$subcategory = $row['domain_setting_subcategory'];
if (strlen($subcategory) == 0) {
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'];
} }
} }
} unset ($prep_statement);
//get the $apps array from the installed apps from the core and mod directories //get the domain settings
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); $sql = "select * from v_domain_settings ";
$x=0; $sql .= "where domain_uuid = '".$id."' ";
if (isset($config_list)) foreach ($config_list as &$config_path) { $sql .= "and domain_setting_enabled = 'true' ";
include($config_path); $prep_statement = $db->prepare($sql);
$x++; $prep_statement->execute();
} $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (isset($result)) foreach($result as $row) {
$name = $row['domain_setting_name'];
$category = $row['domain_setting_category'];
$subcategory = $row['domain_setting_subcategory'];
if (strlen($subcategory) == 0) {
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'];
}
}
}
//delete the domain data from all tables in the database //get the $apps array from the installed apps from the core and mod directories
$db->beginTransaction(); $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
if (isset($apps)) foreach ($apps as &$app) { $x=0;
if (isset($app['db'])) foreach ($app['db'] as $row) { if (isset($config_list)) foreach ($config_list as &$config_path) {
if (is_array($row['table'])) { include($config_path);
$table_name = $row['table']['name']; $x++;
} }
else {
$table_name = $row['table']; //delete the domain data from all tables in the database
} $db->beginTransaction();
if ($table_name !== "v" && isset($row['fields'])) { if (isset($apps)) foreach ($apps as &$app) {
foreach ($row['fields'] as $field) { if (isset($app['db'])) foreach ($app['db'] as $row) {
if ($field['name'] == "domain_uuid") { if (is_array($row['table']['name'])) {
$sql = "delete from $table_name where domain_uuid = '$id' "; $table_name = $row['table']['name']['text'];
$db->query($sql); echo "<pre>";
print_r($table_name);
echo "<pre>\n";
}
else {
$table_name = $row['table']['name'];
}
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'; ";
//echo $sql."<br />\n";
$db->query($sql);
}
} }
} }
} }
} }
} $db->commit();
$db->commit();
//delete the directories //delete the directories
if (strlen($domain_name) > 0) { if (strlen($domain_name) > 0) {
//set the needle //set the needle
if (count($_SESSION["domains"]) > 1) { if (count($_SESSION["domains"]) > 1) {
$v_needle = 'v_'.$domain_name.'_'; $v_needle = 'v_'.$domain_name.'_';
} }
else { else {
$v_needle = 'v_'; $v_needle = 'v_';
} }
//delete the dialplan //delete the dialplan
unlink($_SESSION['switch']['dialplan']['dir'].'/'.$domain_name.'.xml'); unlink($_SESSION['switch']['dialplan']['dir'].'/'.$domain_name.'.xml');
if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/'.$domain_name); system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/'.$domain_name);
} }
//delete the dialplan public //delete the dialplan public
unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name.'.xml'); unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name.'.xml');
if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name); system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name);
} }
//delete the extension //delete the extension
unlink($_SESSION['switch']['extensions']['dir'].'/'.$domain_name.'.xml'); unlink($_SESSION['switch']['extensions']['dir'].'/'.$domain_name.'.xml');
if (strlen($_SESSION['switch']['extensions']['dir']) > 0) { if (strlen($_SESSION['switch']['extensions']['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['extensions']['dir'].'/'.$domain_name); system('rm -rf '.$_SESSION['switch']['extensions']['dir'].'/'.$domain_name);
} }
//delete fax //delete fax
if (strlen($_SESSION['switch']['storage']['dir']) > 0) { if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name); system('rm -rf '.$_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name);
} }
//delete the gateways //delete the gateways
if($dh = opendir($_SESSION['switch']['sip_profiles']['dir'])) { if($dh = opendir($_SESSION['switch']['sip_profiles']['dir'])) {
$files = Array(); $files = Array();
while($file = readdir($dh)) { while($file = readdir($dh)) {
if($file != "." && $file != ".." && $file[0] != '.') { if($file != "." && $file != ".." && $file[0] != '.') {
if(is_dir($dir . "/" . $file)) { if(is_dir($dir . "/" . $file)) {
//this is a directory do nothing //this is a directory do nothing
} else { } else {
//check if file extension is xml //check if file extension is xml
if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') { if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
unlink($_SESSION['switch']['sip_profiles']['dir']."/".$file); unlink($_SESSION['switch']['sip_profiles']['dir']."/".$file);
}
} }
} }
} }
closedir($dh);
} }
closedir($dh);
}
//delete the ivr menu //delete the ivr menu
if($dh = opendir($_SESSION['switch']['conf']['dir']."/ivr_menus/")) { if($dh = opendir($_SESSION['switch']['conf']['dir']."/ivr_menus/")) {
$files = Array(); $files = Array();
while($file = readdir($dh)) { while($file = readdir($dh)) {
if($file != "." && $file != ".." && $file[0] != '.') { if($file != "." && $file != ".." && $file[0] != '.') {
if(is_dir($dir . "/" . $file)) { if(is_dir($dir . "/" . $file)) {
//this is a directory //this is a directory
} else { } else {
if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') { if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
unlink($_SESSION['switch']['conf']['dir']."/ivr_menus/".$file); unlink($_SESSION['switch']['conf']['dir']."/ivr_menus/".$file);
}
} }
} }
} }
closedir($dh);
} }
closedir($dh);
}
//delete the recordings //delete the recordings
if (strlen($_SESSION['switch'][recordings]['dir']) > 0) { if (strlen($_SESSION['switch'][recordings]['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name); system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name);
} }
//delete voicemail //delete voicemail
if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
system('rm -rf '.$_SESSION['switch']['voicemail']['dir'].'/'.$domain_name); system('rm -rf '.$_SESSION['switch']['voicemail']['dir'].'/'.$domain_name);
} }
} }
//apply settings reminder //apply settings reminder