Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

308 lines
12 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2018 - 2022
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //redirect admin to app instead
  27. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all') && !is_cli()) {
  28. header("Location: ".PROJECT_PATH."/app/domains/domains.php");
  29. exit;
  30. }
  31. //change the domain
  32. if (is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true") {
  33. if (permission_exists('domain_select')) {
  34. //get the domain_uuid
  35. $sql = "select * from v_domains ";
  36. $sql .= "order by domain_name asc ";
  37. $database = new database;
  38. $result = $database->select($sql, null, 'all');
  39. if (is_array($result) && sizeof($result) != 0) {
  40. foreach($result as $row) {
  41. if (count($result) == 0) {
  42. $_SESSION["domain_uuid"] = $row["domain_uuid"];
  43. $_SESSION["domain_name"] = $row['domain_name'];
  44. }
  45. else {
  46. if ($row['domain_name'] == $domain_array[0] || $row['domain_name'] == 'www.'.$domain_array[0]) {
  47. $_SESSION["domain_uuid"] = $row["domain_uuid"];
  48. $_SESSION["domain_name"] = $row['domain_name'];
  49. }
  50. }
  51. }
  52. }
  53. unset($sql, $result);
  54. //update the domain session variables
  55. $domain_uuid = $_GET["domain_uuid"];
  56. $_SESSION["previous_domain_uuid"] = $_SESSION['domain_uuid'];
  57. $_SESSION['domain_uuid'] = $domain_uuid;
  58. $_SESSION["domain_name"] = $_SESSION['domains'][$domain_uuid]['domain_name'];
  59. $_SESSION['domain']['template']['name'] = $_SESSION['domains'][$domain_uuid]['template_name'];
  60. $_SESSION["context"] = $_SESSION["domain_name"];
  61. //clear the extension array so that it is regenerated for the selected domain
  62. unset($_SESSION['extension_array']);
  63. //set the setting arrays
  64. $domain = new domains();
  65. $domain->db = $db;
  66. $domain->set();
  67. //redirect the user
  68. if ($_SESSION["login"]["destination"] != '') {
  69. // to default, or domain specific, login destination
  70. header("Location: ".PROJECT_PATH.$_SESSION["login"]["destination"]["url"]);
  71. }
  72. else {
  73. header("Location: ".PROJECT_PATH."/core/dashboard/");
  74. }
  75. exit;
  76. }
  77. }
  78. //check permission
  79. if (permission_exists('domain_all') && permission_exists('domain_view')) {
  80. //access granted
  81. }
  82. else {
  83. echo "access denied";
  84. exit;
  85. }
  86. //add multi-lingual support
  87. $language = new text;
  88. $text = $language->get();
  89. //get the http post data
  90. if (is_array($_POST['domains'])) {
  91. $action = $_POST['action'];
  92. $search = $_POST['search'];
  93. $domains = $_POST['domains'];
  94. }
  95. //process the http post data by action
  96. if ($action != '' && is_array($domains) && @sizeof($domains) != 0) {
  97. switch ($action) {
  98. case 'copy':
  99. if (permission_exists('domain_add')) {
  100. $obj = new domains;
  101. $obj->copy($domains);
  102. }
  103. break;
  104. case 'toggle':
  105. if (permission_exists('domain_edit')) {
  106. $obj = new domains;
  107. $obj->toggle($domains);
  108. }
  109. break;
  110. case 'delete':
  111. if (permission_exists('domain_delete')) {
  112. $obj = new domains;
  113. $obj->delete($domains);
  114. }
  115. break;
  116. }
  117. header('Location: domains.php'.($search != '' ? '?search='.urlencode($search) : null));
  118. exit;
  119. }
  120. //get order and order by
  121. $order_by = $_GET["order_by"];
  122. $order = $_GET["order"];
  123. //add the search string
  124. if (isset($_GET["search"])) {
  125. $search = strtolower($_GET["search"]);
  126. $sql_search = " (";
  127. $sql_search .= " lower(domain_name) like :search ";
  128. $sql_search .= " or lower(domain_description) like :search ";
  129. $sql_search .= ") ";
  130. $parameters['search'] = '%'.$search.'%';
  131. }
  132. //get the count
  133. $sql = "select count(domain_uuid) from v_domains ";
  134. if (isset($sql_search)) {
  135. $sql .= "where ".$sql_search;
  136. }
  137. $database = new database;
  138. $num_rows = $database->select($sql, $parameters, 'column');
  139. //prepare to page the results
  140. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  141. $param = $search ? "&search=".$search : null;
  142. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  143. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  144. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  145. $offset = $rows_per_page * $page;
  146. //get the list
  147. $sql = "select domain_uuid, domain_name, cast(domain_enabled as text), domain_description ";
  148. $sql .= "from v_domains ";
  149. if (isset($sql_search)) {
  150. $sql .= "where ".$sql_search;
  151. }
  152. $sql .= order_by($order_by, $order, 'domain_name', 'asc');
  153. $sql .= limit_offset($rows_per_page, $offset);
  154. $database = new database;
  155. $domains = $database->select($sql, $parameters, 'all');
  156. unset($sql, $parameters);
  157. //create token
  158. $object = new token;
  159. $token = $object->create($_SERVER['PHP_SELF']);
  160. //include the header
  161. $document['title'] = $text['title-domains'];
  162. require_once "resources/header.php";
  163. //show the content
  164. echo "<div class='action_bar' id='action_bar'>\n";
  165. echo " <div class='heading'><b>".$text['title-domains']." (".$num_rows.")</b></div>\n";
  166. echo " <div class='actions'>\n";
  167. if (permission_exists('domain_add')) {
  168. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'domain_edit.php']);
  169. }
  170. if (permission_exists('domain_edit') && $domains) {
  171. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
  172. }
  173. if (permission_exists('domain_delete') && $domains) {
  174. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete_domain');"]);
  175. }
  176. echo "<form id='form_search' class='inline' method='get'>\n";
  177. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  178. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  179. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'domains.php','style'=>($search == '' ? 'display: none;' : null)]);
  180. if ($paging_controls_mini != '') {
  181. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  182. }
  183. echo " </form>\n";
  184. echo " </div>\n";
  185. echo " <div style='clear: both;'></div>\n";
  186. echo "</div>\n";
  187. if (permission_exists('domain_edit') && $domains) {
  188. echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
  189. }
  190. if (permission_exists('domain_delete') && $domains) {
  191. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
  192. }
  193. echo $text['description-domains']."\n";
  194. echo "<br /><br />\n";
  195. echo "<form id='form_list' method='post'>\n";
  196. echo "<input type='hidden' id='action' name='action' value=''>\n";
  197. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  198. echo "<table class='list'>\n";
  199. echo "<tr class='list-header'>\n";
  200. if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
  201. echo " <th class='checkbox'>\n";
  202. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($domains ?: "style='visibility: hidden;'").">\n";
  203. echo " </th>\n";
  204. }
  205. if ($_GET['show'] == 'all' && permission_exists('domain_all')) {
  206. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  207. }
  208. echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order);
  209. echo "<th class='center'>".$text['label-tools']."</th>";
  210. echo th_order_by('domain_enabled', $text['label-domain_enabled'], $order_by, $order, null, "class='center'");
  211. echo " <th class='hide-sm-dn'>".$text['label-domain_description']."</th>\n";
  212. if (permission_exists('domain_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  213. echo " <td class='action-button'>&nbsp;</td>\n";
  214. }
  215. echo "</tr>\n";
  216. if (is_array($domains) && @sizeof($domains) != 0) {
  217. $x = 0;
  218. foreach ($domains as $row) {
  219. if (permission_exists('domain_edit')) {
  220. $list_row_url = "domain_edit.php?id=".urlencode($row['domain_uuid']);
  221. }
  222. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  223. if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
  224. echo " <td class='checkbox'>\n";
  225. echo " <input type='checkbox' name='domains[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  226. echo " <input type='hidden' name='domains[$x][uuid]' value='".escape($row['domain_uuid'])."' />\n";
  227. echo " </td>\n";
  228. }
  229. if ($_GET['show'] == 'all' && permission_exists('domain_all')) {
  230. echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
  231. }
  232. echo " <td>\n";
  233. if (permission_exists('domain_edit')) {
  234. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['domain_name'])."</a>\n";
  235. }
  236. else {
  237. echo " ".escape($row['domain_name']);
  238. }
  239. echo " </td>\n";
  240. echo " <td class='no-link center'>\n";
  241. echo " <a href='".PROJECT_PATH."/core/domains/domains.php?domain_uuid=".escape($row['domain_uuid'])."&domain_change=true'>".$text['label-manage']."</a>";
  242. if (permission_exists('domain_setting_view')) {
  243. $list_setting_url = PROJECT_PATH."/core/domain_settings/domain_settings.php?id=".urlencode($row['domain_uuid']);
  244. echo "&nbsp;&nbsp; <a href='".$list_setting_url."'\">".$text['button-settings'];
  245. }
  246. echo " </td>\n";
  247. if (permission_exists('domain_edit')) {
  248. echo " <td class='no-link center'>\n";
  249. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['domain_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  250. echo " </td>\n";
  251. }
  252. else {
  253. echo " <td class='center'>\n";
  254. echo $text['label-'.$row['domain_enabled']];
  255. echo " </td>\n";
  256. }
  257. echo " <td class='description overflow hide-sm-dn'>".escape($row['domain_description'])."</td>\n";
  258. if (permission_exists('domain_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  259. echo " <td class='action-button'>\n";
  260. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  261. echo " </td>\n";
  262. }
  263. echo "</tr>\n";
  264. $x++;
  265. }
  266. unset($domains);
  267. }
  268. echo "</table>\n";
  269. echo "<br />\n";
  270. echo "<div align='center'>".$paging_controls."</div>\n";
  271. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  272. echo "</form>\n";
  273. //include the footer
  274. require_once "resources/footer.php";
  275. ?>