domains_delete.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. require_once "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (if_group("admin") || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. if (count($_GET)>0) {
  32. $id = check_str($_GET["id"]);
  33. }
  34. if (strlen($id) > 0) {
  35. //get the domain using the id
  36. $sql = "select * from v_domains ";
  37. $sql .= "where domain_uuid = '$id' ";
  38. $prep_statement = $db->prepare(check_sql($sql));
  39. $prep_statement->execute();
  40. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  41. foreach ($result as &$row) {
  42. $domain_name = $row["domain_name"];
  43. }
  44. unset ($prep_statement);
  45. //get the domain settings
  46. $sql = "select * from v_domain_settings ";
  47. $sql .= "where domain_uuid = '".$id."' ";
  48. $sql .= "and domain_setting_enabled = 'true' ";
  49. $prep_statement = $db->prepare($sql);
  50. $prep_statement->execute();
  51. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  52. foreach($result as $row) {
  53. $name = $row['domain_setting_name'];
  54. $category = $row['domain_setting_category'];
  55. $subcategory = $row['domain_setting_subcategory'];
  56. if (strlen($subcategory) == 0) {
  57. //$$category[$name] = $row['domain_setting_value'];
  58. $_SESSION[$category][$name] = $row['domain_setting_value'];
  59. }
  60. else {
  61. //$$category[$subcategory][$name] = $row['domain_setting_value'];
  62. $_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
  63. }
  64. }
  65. //get the $apps array from the installed apps from the core and mod directories
  66. $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
  67. $x=0;
  68. foreach ($config_list as &$config_path) {
  69. include($config_path);
  70. $x++;
  71. }
  72. //delete the domain data from all tables in the database
  73. $db->beginTransaction();
  74. foreach ($apps as &$app) {
  75. foreach ($app['db'] as $row) {
  76. $table_name = $row['table'];
  77. foreach ($row['fields'] as $field) {
  78. if ($field['name'] == "domain_uuid") {
  79. $sql = "delete from $table_name where domain_uuid = '$id' ";
  80. $db->query($sql);
  81. }
  82. }
  83. }
  84. }
  85. $db->commit();
  86. if (strlen($domain_name) > 0) {
  87. //set the needle
  88. if (count($_SESSION["domains"]) > 1) {
  89. $v_needle = 'v_'.$domain_name.'_';
  90. }
  91. else {
  92. $v_needle = 'v_';
  93. }
  94. //delete the dialplan
  95. unlink($_SESSION['switch']['dialplan']['dir'].'/'.$domain_name.'.xml');
  96. if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
  97. system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/'.$domain_name);
  98. }
  99. //delete the dialplan public
  100. unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name.'.xml');
  101. if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
  102. system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name);
  103. }
  104. //delete the extension
  105. unlink($_SESSION['switch']['extensions']['dir'].'/'.$domain_name.'.xml');
  106. if (strlen($_SESSION['switch']['extensions']['dir']) > 0) {
  107. system('rm -rf '.$_SESSION['switch']['extensions']['dir'].'/'.$domain_name);
  108. }
  109. //delete fax
  110. if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
  111. system('rm -rf '.$_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name);
  112. }
  113. //delete the gateways
  114. if($dh = opendir($_SESSION['switch']['gateways']['dir'])) {
  115. $files = Array();
  116. while($file = readdir($dh)) {
  117. if($file != "." && $file != ".." && $file[0] != '.') {
  118. if(is_dir($dir . "/" . $file)) {
  119. //this is a directory do nothing
  120. } else {
  121. //check if file extension is xml
  122. if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
  123. unlink($_SESSION['switch']['gateways']['dir']."/".$file);
  124. }
  125. }
  126. }
  127. }
  128. closedir($dh);
  129. }
  130. //delete the ivr menu
  131. if($dh = opendir($_SESSION['switch']['conf']['dir']."/ivr_menus/")) {
  132. $files = Array();
  133. while($file = readdir($dh)) {
  134. if($file != "." && $file != ".." && $file[0] != '.') {
  135. if(is_dir($dir . "/" . $file)) {
  136. //this is a directory
  137. } else {
  138. if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
  139. unlink($_SESSION['switch']['conf']['dir']."/ivr_menus/".$file);
  140. }
  141. }
  142. }
  143. }
  144. closedir($dh);
  145. }
  146. //delete the recordings
  147. if (strlen($_SESSION['switch'][recordings]['dir']) > 0) {
  148. system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$domain_name);
  149. }
  150. //delete voicemail
  151. if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
  152. system('rm -rf '.$_SESSION['switch']['voicemail']['dir'].'/'.$domain_name);
  153. }
  154. }
  155. //apply settings reminder
  156. $_SESSION["reload_xml"] = true;
  157. //clear the domains session array to update it
  158. unset($_SESSION["domains"]);
  159. unset($_SESSION["domain_uuid"]);
  160. unset($_SESSION["domain_name"]);
  161. unset($_SESSION['domain']);
  162. unset($_SESSION['switch']);
  163. }
  164. //redirect the browser
  165. require_once "includes/header.php";
  166. echo "<meta http-equiv=\"refresh\" content=\"2;url=domains.php\">\n";
  167. echo "<div align='center'>\n";
  168. echo "Delete Complete\n";
  169. echo "</div>\n";
  170. require_once "includes/footer.php";
  171. return;
  172. ?>