domain_edit.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. Luis Daniel Lucio Quiroz <[email protected]>
  21. */
  22. //includes
  23. require_once "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. //check permissions
  27. if (permission_exists('domain_all') && permission_exists('domain_edit')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //action add or update
  38. if (!permission_exists('domain_add') || (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/") && !permission_exists('domain_parent') && permission_exists('domain_descendants'))) {
  39. //admin editing own domain/settings
  40. $domain_uuid = $_SESSION['domain_uuid'];
  41. $action = "update";
  42. }
  43. else {
  44. if (is_uuid($_REQUEST["id"])) {
  45. $action = "update";
  46. $domain_uuid = $_REQUEST["id"];
  47. }
  48. else {
  49. $action = "add";
  50. }
  51. }
  52. //get http post variables and set them to php variables
  53. if (count($_POST) > 0) {
  54. $domain_name = $_POST["domain_name"];
  55. $domain_enabled = $_POST["domain_enabled"];
  56. $domain_description = $_POST["domain_description"];
  57. }
  58. //process the data
  59. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  60. //get the domain_uuid
  61. if ($action == "update" && $_POST["domain_uuid"]) {
  62. $domain_uuid = $_POST["domain_uuid"];
  63. }
  64. //delete the domain
  65. if (permission_exists('domain_delete')) {
  66. if ($_POST['action'] == 'delete' && is_uuid($domain_uuid)) {
  67. //prepare
  68. $array[0]['checked'] = 'true';
  69. $array[0]['uuid'] = $domain_uuid;
  70. //delete
  71. $obj = new domains;
  72. $obj->delete($array);
  73. //redirect
  74. header('Location: domains.php');
  75. exit;
  76. }
  77. }
  78. //validate the token
  79. $token = new token;
  80. if (!$token->validate($_SERVER['PHP_SELF'])) {
  81. message::add($text['message-invalid_token'],'negative');
  82. header('Location: domains.php');
  83. exit;
  84. }
  85. //check for all required data
  86. $msg = '';
  87. if (strlen($domain_name) == 0) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
  88. //if (strlen($domain_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  89. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  90. require_once "resources/header.php";
  91. require_once "resources/persist_form_var.php";
  92. echo "<div align='center'>\n";
  93. echo "<table><tr><td>\n";
  94. echo $msg."<br />";
  95. echo "</td></tr></table>\n";
  96. persistformvar($_POST);
  97. echo "</div>\n";
  98. require_once "resources/footer.php";
  99. return;
  100. }
  101. //add or update the database
  102. if ($_POST["persistformvar"] != "true") {
  103. if ($action == "add" && permission_exists('domain_add')) {
  104. $sql = "select count(*) from v_domains ";
  105. $sql .= "where domain_name = :domain_name ";
  106. $parameters['domain_name'] = $domain_name;
  107. $database = new database;
  108. $num_rows = $database->select($sql, $parameters, 'column');
  109. unset($sql, $parameters);
  110. if ($num_rows == 0) {
  111. //add the domain name
  112. $domain_enabled = 'true';
  113. $domain_uuid = uuid();
  114. $array['domains'][0]['domain_uuid'] = $domain_uuid;
  115. $array['domains'][0]['domain_name'] = $domain_name;
  116. $array['domains'][0]['domain_enabled'] = $domain_enabled;
  117. $array['domains'][0]['domain_description'] = $domain_description;
  118. $database = new database;
  119. $database->app_name = 'domains';
  120. $database->app_uuid = '8b91605b-f6d2-42e6-a56d-5d1ded01bb44';
  121. $database->save($array);
  122. //add dialplans to the domain
  123. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/dialplans/app_config.php")) {
  124. //import the dialplans
  125. $dialplan = new dialplan;
  126. $dialplan->import($array['domains']);
  127. unset($array);
  128. //add xml for each dialplan where the dialplan xml is empty
  129. $dialplans = new dialplan;
  130. $dialplans->source = "details";
  131. $dialplans->destination = "database";
  132. $dialplans->context = $domain_name;
  133. $dialplans->is_empty = "dialplan_xml";
  134. $array = $dialplans->xml();
  135. }
  136. }
  137. }
  138. if ($action == "update" && permission_exists('domain_edit')) {
  139. // get original domain name
  140. $sql = "select domain_name from v_domains ";
  141. $sql .= "where domain_uuid = :domain_uuid ";
  142. $parameters['domain_uuid'] = $domain_uuid;
  143. $database = new database;
  144. $original_domain_name = $database->select($sql, $parameters, 'column');
  145. unset($sql, $parameters);
  146. // update domain name, description
  147. $array['domains'][0]['domain_uuid'] = $domain_uuid;
  148. $array['domains'][0]['domain_name'] = $domain_name;
  149. $array['domains'][0]['domain_enabled'] = $domain_enabled;
  150. $array['domains'][0]['domain_description'] = $domain_description;
  151. $database = new database;
  152. $database->app_name = 'domains';
  153. $database->app_uuid = '8b91605b-f6d2-42e6-a56d-5d1ded01bb44';
  154. $database->save($array);
  155. // add dialplans to the domain
  156. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/dialplans/app_config.php")) {
  157. //import the dialplans
  158. $dialplan = new dialplan;
  159. $dialplan->import($array['domains']);
  160. unset($array);
  161. //add xml for each dialplan where the dialplan xml is empty
  162. $dialplans = new dialplan;
  163. $dialplans->source = "details";
  164. $dialplans->destination = "database";
  165. $dialplans->context = $domain_name;
  166. $dialplans->is_empty = "dialplan_xml";
  167. $array = $dialplans->xml();
  168. }
  169. if ($original_domain_name != $domain_name) {
  170. // update dialplans
  171. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/dialplans/app_config.php")) {
  172. $sql = "update v_dialplans set ";
  173. $sql .= "dialplan_context = replace(dialplan_context, :domain_name_old, :domain_name_new), ";
  174. $sql .= "dialplan_xml = replace(dialplan_xml, :domain_name_old, :domain_name_new) ";
  175. $sql .= "where domain_uuid = :domain_uuid ";
  176. $parameters['domain_name_old'] = $original_domain_name;
  177. $parameters['domain_name_new'] = $domain_name;
  178. $parameters['domain_uuid'] = $domain_uuid;
  179. $database = new database;
  180. $database->execute($sql, $parameters);
  181. unset($sql, $parameters);
  182. $sql = "update v_dialplan_details set ";
  183. $sql .= "dialplan_detail_data = replace(dialplan_detail_data, :domain_name_old, :domain_name_new) ";
  184. $sql .= "where domain_uuid = :domain_uuid ";
  185. $parameters['domain_name_old'] = $original_domain_name;
  186. $parameters['domain_name_new'] = $domain_name;
  187. $parameters['domain_uuid'] = $domain_uuid;
  188. $database = new database;
  189. $database->execute($sql, $parameters);
  190. unset($sql, $parameters);
  191. }
  192. // update destinations
  193. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/destinations/app_config.php")) {
  194. $sql = "update v_destinations set ";
  195. $sql .= "destination_data = replace(destination_data, :destination_data_old, :destination_data_new) ";
  196. $sql .= "where domain_uuid = :domain_uuid ";
  197. $parameters['destination_data_old'] = $original_domain_name;
  198. $parameters['destination_data_new'] = $domain_name;
  199. $parameters['domain_uuid'] = $domain_uuid;
  200. $database = new database;
  201. $database->execute($sql, $parameters);
  202. unset($sql, $parameters);
  203. }
  204. // update extensions (accountcode, user_context, dial_domain)
  205. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/extensions/app_config.php")) {
  206. $sql = "update v_extensions set ";
  207. $sql .= "user_context = replace(user_context, :domain_name_old, :domain_name_new), ";
  208. $sql .= "accountcode = replace(accountcode, :domain_name_old, :domain_name_new), ";
  209. $sql .= "dial_domain = replace(dial_domain, :domain_name_old, :domain_name_new) ";
  210. $sql .= "where domain_uuid = :domain_uuid ";
  211. $parameters['domain_name_old'] = $original_domain_name;
  212. $parameters['domain_name_new'] = $domain_name;
  213. $parameters['domain_uuid'] = $domain_uuid;
  214. $database = new database;
  215. $database->execute($sql, $parameters);
  216. unset($sql, $parameters);
  217. }
  218. // update ivr_menus (ivr_menu_context, ivr_menu_greet_long, ivr_menu_greet_short) and ivr_menu_options (ivr_menu_option_param)
  219. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ivr_menus/app_config.php")) {
  220. $sql = "update v_ivr_menus set ";
  221. $sql .= "ivr_menu_context = replace(ivr_menu_context, :domain_name_old, :domain_name_new), ";
  222. $sql .= "ivr_menu_greet_long = replace(ivr_menu_greet_long, :domain_name_old, :domain_name_new), ";
  223. $sql .= "ivr_menu_greet_short = replace(ivr_menu_greet_short, :domain_name_old, :domain_name_new) ";
  224. $sql .= "where domain_uuid = :domain_uuid ";
  225. $parameters['domain_name_old'] = $original_domain_name;
  226. $parameters['domain_name_new'] = $domain_name;
  227. $parameters['domain_uuid'] = $domain_uuid;
  228. $database = new database;
  229. $database->execute($sql, $parameters);
  230. unset($sql, $parameters);
  231. $sql = "update v_ivr_menu_options set ";
  232. $sql .= "ivr_menu_option_param = replace(ivr_menu_option_param, :domain_name_old, :domain_name_new) ";
  233. $sql .= "where domain_uuid = :domain_uuid ";
  234. $parameters['domain_name_old'] = $original_domain_name;
  235. $parameters['domain_name_new'] = $domain_name;
  236. $parameters['domain_uuid'] = $domain_uuid;
  237. $database = new database;
  238. $database->execute($sql, $parameters);
  239. unset($sql, $parameters);
  240. }
  241. // update ring_groups (ring_group_context, ring_group_forward_destination, ring_group_timeout_data)
  242. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ring_groups/app_config.php")) {
  243. $sql = "update v_ring_groups set ";
  244. $sql .= "ring_group_context = replace(ring_group_context, :domain_name_old, :domain_name_new), ";
  245. $sql .= "ring_group_forward_destination = replace(ring_group_forward_destination, :domain_name_old, :domain_name_new), ";
  246. $sql .= "ring_group_timeout_data = replace(ring_group_timeout_data, :domain_name_old, :domain_name_new) ";
  247. $sql .= "where domain_uuid = :domain_uuid ";
  248. $parameters['domain_name_old'] = $original_domain_name;
  249. $parameters['domain_name_new'] = $domain_name;
  250. $parameters['domain_uuid'] = $domain_uuid;
  251. $database = new database;
  252. $database->execute($sql, $parameters);
  253. unset($sql, $parameters);
  254. }
  255. // update cdr records (domain_name, context)
  256. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/xml_cdr/app_config.php")){
  257. $sql = "update v_xml_cdr set ";
  258. $sql .= "domain_name = :domain_name_new ";
  259. $sql .= "where domain_name = :domain_name_old ";
  260. $sql .= "and domain_uuid = :domain_uuid ";
  261. $parameters['domain_name_old'] = $original_domain_name;
  262. $parameters['domain_name_new'] = $domain_name;
  263. $parameters['domain_uuid'] = $domain_uuid;
  264. $database = new database;
  265. $database->execute($sql, $parameters);
  266. unset($sql, $parameters);
  267. $sql = "update v_xml_cdr set ";
  268. $sql .= "context = replace(user_context, :context_old, :context_new), ";
  269. $sql .= "where context = :context_old ";
  270. $sql .= "and domain_uuid = :domain_uuid ";
  271. $parameters['context_old'] = $original_domain_name;
  272. $parameters['context_new'] = $domain_name;
  273. $parameters['domain_uuid'] = $domain_uuid;
  274. $database = new database;
  275. $database->execute($sql, $parameters);
  276. unset($sql, $parameters);
  277. }
  278. // update billing, if installed
  279. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){
  280. $sql = "update v_billings set ";
  281. $sql .= "type_value = :type_value_new ";
  282. $sql .= "where type_value = :type_value_old ";
  283. $sql .= "and domain_uuid = :domain_uuid ";
  284. $parameters['type_value_old'] = $original_domain_name;
  285. $parameters['type_value_new'] = $domain_name;
  286. $parameters['domain_uuid'] = $domain_uuid;
  287. $database = new database;
  288. $database->execute($sql, $parameters);
  289. unset($sql, $parameters);
  290. }
  291. // update conference session recording paths
  292. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/conference_centers/app_config.php")) {
  293. $sql = "update v_conference_sessions set ";
  294. $sql .= "recording = replace(recording, :domain_name_old, :domain_name_new) ";
  295. $sql .= "where domain_uuid = :domain_uuid ";
  296. $parameters['domain_name_old'] = $original_domain_name;
  297. $parameters['domain_name_new'] = $domain_name;
  298. $parameters['domain_uuid'] = $domain_uuid;
  299. $database = new database;
  300. $database->execute($sql, $parameters);
  301. unset($sql, $parameters);
  302. }
  303. // update conference center greetings
  304. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/conference_centers/app_config.php")) {
  305. $sql = "update v_conference_centers set ";
  306. $sql .= "conference_center_greeting = replace(conference_center_greeting, :domain_name_old, :domain_name_new) ";
  307. $sql .= "where domain_uuid = :domain_uuid ";
  308. $parameters['domain_name_old'] = $original_domain_name;
  309. $parameters['domain_name_new'] = $domain_name;
  310. $parameters['domain_uuid'] = $domain_uuid;
  311. $database = new database;
  312. $database->execute($sql, $parameters);
  313. unset($sql, $parameters);
  314. }
  315. // update call center queue record templates
  316. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_center/app_config.php")) {
  317. $sql = "update v_call_center_queues set ";
  318. $sql .= "queue_record_template = replace(queue_record_template, :domain_name_old, :domain_name_new) ";
  319. $sql .= "where domain_uuid = :domain_uuid ";
  320. $parameters['domain_name_old'] = $original_domain_name;
  321. $parameters['domain_name_new'] = $domain_name;
  322. $parameters['domain_uuid'] = $domain_uuid;
  323. $database = new database;
  324. $database->execute($sql, $parameters);
  325. unset($sql, $parameters);
  326. }
  327. // update call center agent contacts
  328. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_center/app_config.php")) {
  329. $sql = "update v_call_center_agents set ";
  330. $sql .= "agent_contact = replace(agent_contact, :domain_name_old, :domain_name_new) ";
  331. $sql .= "where domain_uuid = :domain_uuid ";
  332. $parameters['domain_name_old'] = $original_domain_name;
  333. $parameters['domain_name_new'] = $domain_name;
  334. $parameters['domain_uuid'] = $domain_uuid;
  335. $database = new database;
  336. $database->execute($sql, $parameters);
  337. unset($sql, $parameters);
  338. }
  339. // update call flows data, alternate-data and contexts
  340. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_flows/app_config.php")) {
  341. $sql = "update v_call_flows set ";
  342. $sql .= "call_flow_data = replace(call_flow_data, :domain_name_old, :domain_name_new), ";
  343. $sql .= "call_flow_alternate_data = replace(call_flow_alternate_data, :domain_name_old, :domain_name_new), ";
  344. $sql .= "call_flow_context = replace(call_flow_context, :domain_name_old, :domain_name_new) ";
  345. $sql .= "where domain_uuid = :domain_uuid ";
  346. $parameters['domain_name_old'] = $original_domain_name;
  347. $parameters['domain_name_new'] = $domain_name;
  348. $parameters['domain_uuid'] = $domain_uuid;
  349. $database = new database;
  350. $database->execute($sql, $parameters);
  351. unset($sql, $parameters);
  352. }
  353. // update device lines server_address, server_address_primary, server_address_secondary, outbound_proxy_primary, outbound_proxy_secondary
  354. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/devices/app_config.php")) {
  355. $sql = "update v_device_lines set ";
  356. $sql .= "server_address = replace(server_address, :domain_name_old, :domain_name_new), ";
  357. $sql .= "server_address_primary = replace(server_address_primary, :domain_name_old, :domain_name_new), ";
  358. $sql .= "server_address_secondary = replace(server_address_secondary, :domain_name_old, :domain_name_new), ";
  359. $sql .= "outbound_proxy_primary = replace(outbound_proxy_primary, :domain_name_old, :domain_name_new), ";
  360. $sql .= "outbound_proxy_secondary = replace(outbound_proxy_secondary, :domain_name_old, :domain_name_new) ";
  361. $sql .= "where domain_uuid = :domain_uuid ";
  362. $parameters['domain_name_old'] = $original_domain_name;
  363. $parameters['domain_name_new'] = $domain_name;
  364. $parameters['domain_uuid'] = $domain_uuid;
  365. $database = new database;
  366. $database->execute($sql, $parameters);
  367. unset($sql, $parameters);
  368. }
  369. // rename switch/storage/voicemail/default/[domain] (folder)
  370. if (isset($_SESSION['switch']['voicemail']['dir']) && file_exists($_SESSION['switch']['voicemail']['dir']."/default/".$original_domain_name)) {
  371. @rename($_SESSION['switch']['voicemail']['dir']."/default/".$original_domain_name, $_SESSION['switch']['voicemail']['dir']."/default/".$domain_name); // folder
  372. }
  373. // rename switch/storage/fax/[domain] (folder)
  374. if (isset($_SESSION['switch']['storage']['dir']) && file_exists($_SESSION['switch']['storage']['dir']."/fax/".$original_domain_name)) {
  375. @rename($_SESSION['switch']['storage']['dir']."/fax/".$original_domain_name, $_SESSION['switch']['storage']['dir']."/fax/".$domain_name); // folder
  376. }
  377. // rename switch/conf/dialplan/[domain] (folder/file)
  378. if (isset($_SESSION['switch']['dialplan']['dir'])) {
  379. if (file_exists($_SESSION['switch']['dialplan']['dir']."/".$original_domain_name)) {
  380. @rename($_SESSION['switch']['dialplan']['dir']."/".$original_domain_name, $_SESSION['switch']['dialplan']['dir']."/".$domain_name); // folder
  381. }
  382. if (file_exists($_SESSION['switch']['dialplan']['dir']."/".$original_domain_name.".xml")) {
  383. @rename($_SESSION['switch']['dialplan']['dir']."/".$original_domain_name.".xml", $_SESSION['switch']['dialplan']['dir']."/".$domain_name.".xml"); // file
  384. }
  385. }
  386. // rename switch/conf/dialplan/public/[domain] (folder/file)
  387. if (isset($_SESSION['switch']['dialplan']['dir'])) {
  388. if (file_exists($_SESSION['switch']['dialplan']['dir']."/public/".$original_domain_name)) {
  389. @rename($_SESSION['switch']['dialplan']['dir']."/public/".$original_domain_name, $_SESSION['switch']['dialplan']['dir']."/public/".$domain_name); // folder
  390. }
  391. if (file_exists($_SESSION['switch']['dialplan']['dir']."/public/".$original_domain_name.".xml")) {
  392. @rename($_SESSION['switch']['dialplan']['dir']."/public/".$original_domain_name.".xml", $_SESSION['switch']['dialplan']['dir']."/public/".$domain_name.".xml"); // file
  393. }
  394. }
  395. // rename switch/conf/directory/[domain] (folder/file)
  396. if (isset($_SESSION['switch']['extensions']['dir'])) {
  397. if (file_exists($_SESSION['switch']['extensions']['dir']."/".$original_domain_name)) {
  398. @rename($_SESSION['switch']['extensions']['dir']."/".$original_domain_name, $_SESSION['switch']['extensions']['dir']."/".$domain_name); // folder
  399. }
  400. if (file_exists($_SESSION['switch']['extensions']['dir']."/".$original_domain_name.".xml")) {
  401. @rename($_SESSION['switch']['extensions']['dir']."/".$original_domain_name.".xml", $_SESSION['switch']['extensions']['dir']."/".$domain_name.".xml"); // file
  402. }
  403. }
  404. // rename switch/recordings/[domain] (folder)
  405. if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'])) {
  406. $switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']);
  407. if (file_exists($switch_recordings_dir."/".$original_domain_name)) {
  408. @rename($switch_recordings_dir."/".$original_domain_name, $switch_recordings_dir."/".$domain_name); // folder
  409. }
  410. }
  411. // update dialplan, dialplan/public xml files
  412. $dialplan_xml = file_get_contents($_SESSION['switch']['dialplan']['dir']."/".$domain_name.".xml");
  413. $dialplan_xml = str_replace($original_domain_name, $domain_name, $dialplan_xml);
  414. file_put_contents($_SESSION['switch']['dialplan']['dir']."/".$domain_name.".xml", $dialplan_xml);
  415. unset($dialplan_xml);
  416. $dialplan_public_xml = file_get_contents($_SESSION['switch']['dialplan']['dir']."/public/".$domain_name.".xml");
  417. $dialplan_public_xml = str_replace($original_domain_name, $domain_name, $dialplan_public_xml);
  418. file_put_contents($_SESSION['switch']['dialplan']['dir']."/public/".$domain_name.".xml", $dialplan_public_xml);
  419. unset($dialplan_public_xml);
  420. // update session domain name
  421. $_SESSION['domains'][$domain_uuid]['domain_name'] = $domain_name;
  422. // recreate dialplan and extension xml files
  423. if (is_readable($_SESSION['switch']['dialplan']['dir'])) {
  424. save_dialplan_xml();
  425. }
  426. if (is_readable($_SESSION['switch']['extensions']['dir'])) {
  427. require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php";
  428. $extension = new extension;
  429. $extension->xml();
  430. }
  431. // if single-tenant and variables exist, update variables > domain value to match new domain
  432. if (count($_SESSION['domains']) == 1 && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/vars/")) {
  433. $sql = "update v_vars set ";
  434. $sql .= "var_value = :var_value ";
  435. $sql .= "where var_name = 'domain' ";
  436. $parameters['var_value'] = $domain_name;
  437. $database = new database;
  438. $database->app_name = 'domains';
  439. $database->app_uuid = '8b91605b-f6d2-42e6-a56d-5d1ded01bb44';
  440. $database->execute($sql, $parameters);
  441. unset($sql, $parameters);
  442. }
  443. }
  444. }
  445. //clear the domains session array to update it
  446. unset($_SESSION["domains"]);
  447. unset($_SESSION["domain_uuid"]);
  448. unset($_SESSION["domain_name"]);
  449. unset($_SESSION['domain']);
  450. unset($_SESSION['switch']);
  451. //redirect the browser
  452. if ($action == "update") {
  453. message::add($text['message-update']);
  454. if (!permission_exists('domain_add')) { //admin, updating own domain
  455. header("Location: domain_edit.php");
  456. }
  457. else {
  458. header("Location: domains.php"); //superadmin
  459. }
  460. }
  461. if ($action == "add") {
  462. message::add($text['message-add']);
  463. header("Location: domains.php");
  464. }
  465. return;
  466. } //if ($_POST["persistformvar"] != "true")
  467. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  468. //pre-populate the form (admin won't have domain_add permissions, but domain_uuid will already be set above)
  469. if ((count($_GET) > 0 || (!permission_exists('domain_add') && $domain_uuid != '')) && $_POST["persistformvar"] != "true") {
  470. $sql = "select * from v_domains ";
  471. $sql .= "where domain_uuid = :domain_uuid ";
  472. $parameters['domain_uuid'] = $domain_uuid;
  473. $database = new database;
  474. $row = $database->select($sql, $parameters, 'row');
  475. if (is_array($row) && sizeof($row) != 0) {
  476. $domain_name = strtolower($row["domain_name"]);
  477. $domain_enabled = $row["domain_enabled"];
  478. $domain_description = $row["domain_description"];
  479. }
  480. unset($sql, $parameters, $row);
  481. }
  482. //create token
  483. $object = new token;
  484. $token = $object->create($_SERVER['PHP_SELF']);
  485. //show the header
  486. require_once "resources/header.php";
  487. if ($action == "update") {
  488. $document['title'] = $text['title-domain-edit'];
  489. }
  490. if ($action == "add") {
  491. $document['title'] = $text['title-domain-add'];
  492. }
  493. //copy settings javascript
  494. if (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) {
  495. echo "<script language='javascript' type='text/javascript'>\n";
  496. echo " var fade_speed = 400;\n";
  497. echo " function show_domains() {\n";
  498. echo " document.getElementById('action').value = 'copy';\n";
  499. echo " $('#button_copy').fadeOut(fade_speed, function() {\n";
  500. echo " $('#button_back').fadeIn(fade_speed);\n";
  501. echo " $('#target_domain_uuid').fadeIn(fade_speed);\n";
  502. echo " $('#button_paste').fadeIn(fade_speed);\n";
  503. echo " });";
  504. echo " }";
  505. echo " function hide_domains() {\n";
  506. echo " document.getElementById('action').value = '';\n";
  507. echo " $('#button_back').fadeOut(fade_speed);\n";
  508. echo " $('#target_domain_uuid').fadeOut(fade_speed);\n";
  509. echo " $('#button_paste').fadeOut(fade_speed, function() {\n";
  510. echo " $('#button_copy').fadeIn(fade_speed);\n";
  511. echo " document.getElementById('target_domain_uuid').selectedIndex = 0;\n";
  512. echo " });\n";
  513. echo " }\n";
  514. echo "\n";
  515. echo " $(document).ready(function() {\n";
  516. echo " $('#domain_setting_search').trigger('focus');\n";
  517. if ($search == '') {
  518. echo " // scroll to previous category\n";
  519. echo " var category_span_id;\n";
  520. echo " var url = document.location.href;\n";
  521. echo " var hashindex = url.indexOf('#');\n";
  522. echo " if (hashindex == -1) { }\n";
  523. echo " else {\n";
  524. echo " category_span_id = url.substr(hashindex + 1);\n";
  525. echo " }\n";
  526. echo " if (category_span_id) {\n";
  527. echo " $('#page').animate({scrollTop: $('#anchor_'+category_span_id).offset().top - 200}, 'slow');\n";
  528. echo " }\n";
  529. }
  530. echo " });\n";
  531. echo "</script>";
  532. }
  533. //show the content
  534. echo "<form method='post' id='frm' action=''>\n";
  535. echo "<div class='action_bar' id='action_bar'>\n";
  536. echo " <div class='heading'>";
  537. if ($action == "update") {
  538. echo "<b>".$text['header-domain']."</b>";
  539. }
  540. if ($action == "add") {
  541. echo "<b>".$text['header-domain-add']."</b>";
  542. }
  543. echo " </div>\n";
  544. echo " <div class='actions'>\n";
  545. if (permission_exists('domain_add')) { //only for superadmin, not admin editing their own domain
  546. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'domains.php']);
  547. }
  548. if (permission_exists('domain_delete') && is_array($_SESSION['domains']) && @sizeof($_SESSION['domains']) > 1 && $domain_uuid != $_SESSION['domain_uuid']) {
  549. echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'action','value'=>'delete','onclick'=>"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }"]);
  550. }
  551. if (permission_exists("domain_select") && is_array($_SESSION['domains']) && @sizeof($_SESSION['domains']) > 1) {
  552. echo "<select id='domains' class='formfld' style='width: auto;' onchange=\"window.location.href='?id=' + document.getElementById('domains').options[document.getElementById('domains').selectedIndex].value;\">\n";
  553. foreach ($_SESSION['domains'] as $domain) {
  554. $selected = $domain["domain_uuid"] == $domain_uuid ? "selected='selected'" : null;
  555. echo " <option value='".escape($domain["domain_uuid"])."' ".$selected.">".escape($domain["domain_name"])."</option>\n";
  556. }
  557. echo "</select>";
  558. }
  559. if (permission_exists('domain_export')) {
  560. echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'link'=>PROJECT_PATH."/app/domain_export/index.php?id=".escape($domain_uuid)]);
  561. }
  562. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'style'=>'margin-left: 15px;']);
  563. echo " </div>\n";
  564. echo " <div style='clear: both;'></div>\n";
  565. echo "</div>\n";
  566. if ($action == "update") {
  567. echo $text['description-domain-edit']."\n";
  568. }
  569. if ($action == "add") {
  570. echo $text['description-domain-add']."\n";
  571. }
  572. echo "<br /><br />\n";
  573. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  574. echo "<tr>\n";
  575. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  576. echo " ".$text['label-name']."\n";
  577. echo "</td>\n";
  578. echo "<td class='vtable' align='left'>\n";
  579. echo " <input class='formfld' type='text' name='domain_name' maxlength='255' value=\"".escape($domain_name)."\">\n";
  580. echo "<br />\n";
  581. echo $text['description-name']."\n";
  582. echo "</td>\n";
  583. echo "</tr>\n";
  584. echo "<tr>\n";
  585. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  586. echo " ".$text['label-enabled']."\n";
  587. echo "</td>\n";
  588. echo "<td class='vtable' align='left'>\n";
  589. echo " <select class='formfld' name='domain_enabled'>\n";
  590. echo " <option value='true' ".(($domain_enabled == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  591. echo " <option value='false' ".(($domain_enabled == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
  592. echo " </select>\n";
  593. echo "<br />\n";
  594. echo $text['description-domain_enabled']."\n";
  595. echo "</td>\n";
  596. echo "</tr>\n";
  597. echo "<tr>\n";
  598. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  599. echo " ".$text['label-description']."\n";
  600. echo "</td>\n";
  601. echo "<td class='vtable' align='left'>\n";
  602. echo " <input class='formfld' type='text' name='domain_description' maxlength='255' value=\"".escape($domain_description)."\">\n";
  603. echo "<br />\n";
  604. echo $text['description-description']."\n";
  605. echo "</td>\n";
  606. echo "</tr>\n";
  607. echo "</table>";
  608. echo "<br /><br />";
  609. if ($action == "update") {
  610. echo "<input type='hidden' name='domain_uuid' value='".escape($domain_uuid)."'>\n";
  611. }
  612. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  613. echo "</form>";
  614. if ($action == "update" && permission_exists('domain_setting_view')) {
  615. require $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/core/domain_settings/domain_settings.php";
  616. echo "<br /><br />\n";
  617. }
  618. //include the footer
  619. require_once "resources/footer.php";
  620. ?>