bulk_account_settings_devices.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. require_once "resources/paging.php";
  25. //check permissions
  26. require_once "resources/check_auth.php";
  27. if (permission_exists('bulk_account_settings_devices')) {
  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. //get the http values and set them as variables
  38. $order_by = check_str($_GET["order_by"]);
  39. $order = check_str($_GET["order"]);
  40. $option_selected = check_str($_GET["option_selected"]);
  41. // if (count($_POST)>0) {
  42. // $option_selected = check_str($_POST["option_selected"]);
  43. // }
  44. //handle search term
  45. $search = check_str($_GET["search"]);
  46. if (strlen($search) > 0) {
  47. $sql_mod = "and ( ";
  48. $sql_mod .= "device_mac_address ILIKE '%".$search."%' ";
  49. $sql_mod .= "or device_label ILIKE '%".$search."%' ";
  50. $sql_mod .= "or device_vendor ILIKE '%".$search."%' ";
  51. $sql_mod .= "or device_model ILIKE '%".$search."%' ";
  52. $sql_mod .= "or device_description ILIKE '%".$search."%' ";
  53. $sql_mod .= "or device_template ILIKE '%".$search."%' ";
  54. $sql_mod .= ") ";
  55. }
  56. if (strlen($order_by) < 1) {
  57. $order_by = "device_label";
  58. $order = "ASC";
  59. }
  60. $domain_uuid = $_SESSION['domain_uuid'];
  61. //get total device count from the database
  62. $sql = "select count(*) as num_rows from v_devices where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
  63. $prep_statement = $db->prepare($sql);
  64. if ($prep_statement) {
  65. $prep_statement->execute();
  66. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  67. $total_devices = $row['num_rows'];
  68. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  69. $numeric_devices = $row['num_rows'];
  70. }
  71. }
  72. unset($prep_statement, $row);
  73. //prepare to page the results
  74. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  75. $param = "&search=".$search."&option_selected=".$option_selected;
  76. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  77. $_GET['page'] = check_str($_GET['page']);
  78. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_devices, $param, $rows_per_page, true); //top
  79. list($paging_controls, $rows_per_page, $var_3) = paging($total_devices, $param, $rows_per_page); //bottom
  80. $offset = $rows_per_page * $_GET['page'];
  81. //get all the devices from the database
  82. $sql = "SELECT \n";
  83. $sql .= "d.device_uuid, \n";
  84. $sql .= "d.device_label, \n";
  85. $sql .= "d.device_mac_address, \n";
  86. $sql .= "d.device_vendor, \n";
  87. $sql .= "d.device_template, \n";
  88. $sql .= "d.device_enabled, \n";
  89. $sql .= "d.device_description, \n";
  90. $sql .= "(\n";
  91. $sql .= "select dp.device_profile_name from v_device_profiles as dp \n";
  92. $sql .= "where d.device_profile_uuid = dp.device_profile_uuid \n";
  93. $sql .= ") as device_profile_name \n";
  94. $sql .= "FROM v_devices as d \n";
  95. $sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' \n";
  96. $sql .= $sql_mod; //add search mod from above
  97. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  98. $sql .= "limit $rows_per_page offset $offset ";
  99. $database = new database;
  100. $directory = $database->select($sql, 'all');
  101. unset($database);
  102. //lookup the lines
  103. $x = 0;
  104. foreach ($directory as $key => $row) {
  105. $sql = "SELECT * \n";
  106. $sql .= "FROM v_device_lines \n";
  107. $sql .= "WHERE domain_uuid = '$domain_uuid' \n";
  108. $sql .= "and device_uuid = '".$row['device_uuid']."' ";
  109. $sql .= "and line_number = '1' ";
  110. $database = new database;
  111. $sqlview1 = $sql;
  112. $result = $database->select($sql, 'all');
  113. $directory[$key]['line_1_server_address'] = $result[0]['server_address'];
  114. $directory[$key]['line_1_server_address_primary'] = $result[0]['server_address_primary'];
  115. $directory[$key]['line_1_server_address_secondary'] = $result[0]['server_address_secondary'];
  116. $directory[$key]['line_1_outbound_proxy_primary'] = $result[0]['outbound_proxy_primary'];
  117. $directory[$key]['line_1_outbound_proxy_secondary'] = $result[0]['outbound_proxy_secondary'];
  118. $directory[$key]['line_1_sip_port'] = $result[0]['sip_port'];
  119. $directory[$key]['line_1_sip_transport'] = $result[0]['sip_transport'];
  120. $directory[$key]['line_1_register_expires'] = $result[0]['register_expires'];
  121. unset($result, $database);
  122. $x++;
  123. }
  124. //additional includes
  125. require_once "resources/header.php";
  126. $document['title'] = $text['title-devices_settings'];
  127. //set the alternating styles
  128. $c = 0;
  129. $row_style["0"] = "row_style0";
  130. $row_style["1"] = "row_style1";
  131. //show the content
  132. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  133. echo " <tr>\n";
  134. echo " <td align='left' width='100%'>\n";
  135. echo " <b>".$text['header-devices']." (".$numeric_devices.")</b><br>\n";
  136. //options list
  137. echo "<form name='frm' method='get' id=option_selected>\n";
  138. echo " <select class='formfld' name='option_selected' onchange=\"this.form.submit();\">\n";
  139. echo " <option value=''>".$text['label-devices_null']."</option>\n";
  140. //Enabled
  141. if ($option_selected == "device_enabled") {
  142. echo " <option value='device_enabled' selected='selected'>".$text['label-enabled']."</option>\n";
  143. }
  144. else {
  145. echo " <option value='device_enabled'>".$text['label-enabled']."</option>\n";
  146. }
  147. //Device Profile
  148. if ($option_selected == "device_profile_uuid") {
  149. echo " <option value='device_profile_uuid' selected='selected'>".$text['label-device_profile']."</option>\n";
  150. }
  151. else {
  152. echo " <option value='device_profile_uuid'>".$text['label-device_profile']."</option>\n";
  153. }
  154. //Device Template
  155. if ($option_selected == "device_template") {
  156. echo " <option value='device_template' selected='selected'>".$text['label-device_template']."</option>\n";
  157. }
  158. else {
  159. echo " <option value='device_template'>".$text['label-device_template']."</option>\n";
  160. }
  161. //Line 1 - Server Address
  162. if ($option_selected == "line_1_server_address") {
  163. echo " <option value='line_1_server_address' selected='selected'>".$text['label-line_1_server_address']."</option>\n";
  164. }
  165. else {
  166. echo " <option value='line_1_server_address'>".$text['label-line_1_server_address']."</option>\n";
  167. }
  168. //Line 1 - Server Address Primary
  169. if ($option_selected == "line_1_server_address_primary") {
  170. echo " <option value='line_1_server_address_primary' selected='selected'>".$text['label-line_1_server_address_primary']."</option>\n";
  171. }
  172. else {
  173. echo " <option value='line_1_server_address_primary'>".$text['label-line_1_server_address_primary']."</option>\n";
  174. }
  175. //Line 1 - Server Address Secondary
  176. if ($option_selected == "line_1_server_address_secondary") {
  177. echo " <option value='line_1_server_address_secondary' selected='selected'>".$text['label-line_1_server_address_secondary']."</option>\n";
  178. }
  179. else {
  180. echo " <option value='line_1_server_address_secondary'>".$text['label-line_1_server_address_secondary']."</option>\n";
  181. }
  182. //Line 1 - Outbound Proxy Primary
  183. if ($option_selected == "line_1_outbound_proxy_primary") {
  184. echo " <option value='line_1_outbound_proxy_primary' selected='selected'>".$text['label-line_1_outbound_proxy_primary']."</option>\n";
  185. }
  186. else {
  187. echo " <option value='line_1_outbound_proxy_primary'>".$text['label-line_1_outbound_proxy_primary']."</option>\n";
  188. }
  189. //Line 1 - Outbound Proxy Secondary
  190. if ($option_selected == "line_1_outbound_proxy_secondary") {
  191. echo " <option value='line_1_outbound_proxy_secondary' selected='selected'>".$text['label-line_1_outbound_proxy_secondary']."</option>\n";
  192. }
  193. else {
  194. echo " <option value='line_1_outbound_proxy_secondary'>".$text['label-line_1_outbound_proxy_secondary']."</option>\n";
  195. }
  196. //Line 1 - SIP Port
  197. if ($option_selected == "line_1_sip_port") {
  198. echo " <option value='line_1_sip_port' selected='selected'>".$text['label-line_1_sip_port']."</option>\n";
  199. }
  200. else {
  201. echo " <option value='line_1_sip_port'>".$text['label-line_1_sip_port']."</option>\n";
  202. }
  203. //Line 1 - SIP Transport
  204. if ($option_selected == "line_1_sip_transport") {
  205. echo " <option value='line_1_sip_transport' selected='selected'>".$text['label-line_1_sip_transport']."</option>\n";
  206. }
  207. else {
  208. echo " <option value='line_1_sip_transport'>".$text['label-line_1_sip_transport']."</option>\n";
  209. }
  210. //Line 1 - Register Expires
  211. if ($option_selected == "line_1_register_expires") {
  212. echo " <option value='line_1_register_expires' selected='selected'>".$text['label-line_1_register_expires']."</option>\n";
  213. }
  214. else {
  215. echo " <option value='line_1_register_expires'>".$text['label-line_1_register_expires']."</option>\n";
  216. }
  217. echo " </select>\n";
  218. echo " </form>\n";
  219. echo "<br />\n";
  220. echo $text['description-device_settings_description']."\n";
  221. echo "</td>\n";
  222. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  223. echo " <form method='get' action=''>\n";
  224. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  225. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='bulk_account_settings.php'\" value='".$text['button-back']."'>\n";
  226. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  227. echo " <input type='hidden' class='txt' style='width: 150px' name='option_selected' id='option_selected' value='".$option_selected."'>";
  228. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  229. if ($paging_controls_mini != '') {
  230. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  231. }
  232. echo " </td>\n";
  233. echo " </form>\n";
  234. echo " </tr>\n";
  235. echo " <tr>\n";
  236. echo " <td colspan='2'>\n";
  237. echo " ".$text['description-devices_settings']."\n";
  238. echo " </td>\n";
  239. echo " </tr>\n";
  240. echo "</table>\n";
  241. echo "<br />";
  242. if (strlen($option_selected) > 0) {
  243. echo "<form name='devices' method='post' action='bulk_account_settings_devices_update.php'>\n";
  244. echo "<input class='formfld' type='hidden' name='option_selected' maxlength='255' value=\"".escape($option_selected)."\">\n";
  245. echo "<table width='auto' border='0' cellpadding='0' cellspacing='0'>\n";
  246. echo "<tr>\n";
  247. //option is Enabled
  248. if($option_selected == 'device_enabled') {
  249. echo "<td class='vtable' align='left'>\n";
  250. echo " <select class='formfld' name='new_setting'>\n";
  251. echo " <option value='true'>".$text['label-true']."</option>\n";
  252. echo " <option value='false'>".$text['label-false']."</option>\n";
  253. echo " </select>\n";
  254. echo " <br />\n";
  255. echo $text["description-".$option_selected.""]."\n";
  256. echo "</td>\n";
  257. }
  258. //option is Device Profile
  259. if($option_selected == 'device_profile_uuid' && permission_exists('device_profile_edit')) {
  260. $sql = "select * from v_device_profiles ";
  261. $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
  262. $sql .= "order by device_profile_name asc ";
  263. $prep_statement = $db->prepare(check_sql($sql));
  264. $prep_statement->execute();
  265. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  266. $result_count = count($result);
  267. unset ($prep_statement, $sql);
  268. if ($result_count > 0) {
  269. echo "<td class='vtable' align='left'>\n";
  270. echo " <select class='formfld' name='new_setting'>\n";
  271. echo " <option value=''></option>\n";
  272. foreach($result as $row) {
  273. echo " <option value='".escape($row['device_profile_uuid'])."' ".(($row['device_profile_uuid'] == $device_profile_uuid) ? "selected='selected'" : null).">".escape($row['device_profile_name'])." ".(($row['domain_uuid'] == '') ? "&nbsp;&nbsp;(".$text['select-global'].")" : null)."</option>\n";
  274. }
  275. //echo " </select>\n";
  276. echo " </select>\n";
  277. echo " <br />\n";
  278. echo $text["description-".$option_selected.""]."\n";
  279. echo "</td>\n";
  280. }
  281. }
  282. //option is Device Templates
  283. if($option_selected == 'device_template' && permission_exists('device_template')) {
  284. $device = new device;
  285. $template_dir = $device->get_template_dir();
  286. echo "<td class='vtable' align='left'>\n";
  287. echo " <select class='formfld' name='new_setting'>\n";
  288. echo "<option value=''></option>\n";
  289. if (is_dir($template_dir)) {
  290. $templates = scandir($template_dir);
  291. foreach($templates as $dir) {
  292. if($file != "." && $dir != ".." && $dir[0] != '.') {
  293. if(is_dir($template_dir . "/" . $dir)) {
  294. echo "<optgroup label='$dir'>";
  295. $dh_sub=$template_dir . "/" . $dir;
  296. if(is_dir($dh_sub)) {
  297. $templates_sub = scandir($dh_sub);
  298. foreach($templates_sub as $dir_sub) {
  299. if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
  300. if(is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) {
  301. if ($device_template == $dir."/".$dir_sub) {
  302. echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n";
  303. }
  304. else {
  305. echo "<option value='".$dir."/".$dir_sub."'>".$dir."/".$dir_sub."</option>\n";
  306. }
  307. }
  308. }
  309. }
  310. }
  311. echo "</optgroup>";
  312. }
  313. }
  314. }
  315. }
  316. echo "</select>\n";
  317. echo " <br />\n";
  318. echo $text["description-".$option_selected.""]."\n";
  319. echo "</td>\n";
  320. }
  321. //options with a free form input
  322. if($option_selected == 'line_1_server_address' || $option_selected == 'line_1_server_address_primary' || $option_selected == 'line_1_server_address_secondary' || $option_selected == 'line_1_outbound_proxy_primary' || $option_selected == 'line_1_outbound_proxy_secondary' || $option_selected == 'line_1_sip_port' || $option_selected == 'line_1_register_expires') {
  323. echo "<td class='vtable' align='left'>\n";
  324. echo " <input class='formfld' type='text' name='new_setting' maxlength='255' value=\"".escape($new_setting)."\">\n";
  325. echo "<br />\n";
  326. echo $text["description-".escape($option_selected).""]."\n";
  327. echo "</td>\n";
  328. }
  329. //option is transport
  330. if($option_selected == 'line_1_sip_transport') {
  331. echo "<td class='vtable' align='left'>\n";
  332. echo " <select class='formfld' name='new_setting'>\n";
  333. echo " <option value='tcp'>TCP</option>\n";
  334. echo " <option value='udp'>UDP</option>\n";
  335. echo " <option value='tls'>TLS</option>\n";
  336. echo " <option value='dns srv'>DNS SRV</option>\n";
  337. echo " </select>\n";
  338. echo " <br />\n";
  339. echo $text["description-".escape($option_selected).""]."\n";
  340. echo "</td>\n";
  341. }
  342. echo "<td align='left'>\n";
  343. echo "<input type='button' class='btn' alt='".$text['button-submit']."' onclick=\"if (confirm('".$text['confirm-update']."')) { document.forms.devices.submit(); }\" value='".$text['button-submit']."'>\n";
  344. echo "</td>\n";
  345. echo "</tr>\n";
  346. echo "</table>";
  347. echo "<br />";
  348. }
  349. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  350. echo "<tr>\n";
  351. if (is_array($directory)) {
  352. echo "<th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' id='chk_all' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
  353. }
  354. echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
  355. echo th_order_by('device_label', $text['label-device_label'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  356. if (preg_match ('/line_(.)/',$option_selected)) {
  357. echo th_order_by($option_selected, $text["label-".$option_selected.""], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
  358. }
  359. echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  360. echo th_order_by('device_template', $text['label-device_template'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  361. echo th_order_by('device_label', $text['label-device_profile'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  362. echo th_order_by('device_enabled', $text['label-device_enabled'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  363. echo th_order_by('device_description', $text['label-device_description'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  364. echo "</tr>\n";
  365. if (is_array($directory)) {
  366. foreach($directory as $key => $row) {
  367. $tr_link = (permission_exists('device_edit')) ? " href='/app/devices/device_edit.php?id=".$row['device_uuid']."'" : null;
  368. echo "<tr ".$tr_link.">\n";
  369. echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='text-align: center; vertical-align: middle; padding: 0px;'>";
  370. echo " <input type='checkbox' name='id[]' id='checkbox_".escape($row['device_uuid'])."' value='".escape($row['device_uuid'])."' onclick=\"if (!this.checked) { document.getElementById('chk_all').checked = false; }\">";
  371. echo " </td>";
  372. $device_ids[] = 'checkbox_'.$row['device_uuid'];
  373. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_mac_address'])."&nbsp;</td>\n";
  374. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_label'])."&nbsp;</td>\n";
  375. if (preg_match ('/line_/',$option_selected)) {
  376. echo " <td valign='top' class='".$row_style[$c]."'> ".$row[$option_selected]."&nbsp;</td>\n";
  377. }
  378. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_vendor'])."&nbsp;</td>\n";
  379. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_template'])."&nbsp;</td>\n";
  380. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_profile_name'])."&nbsp;</td>\n";
  381. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_enabled'])."&nbsp;</td>\n";
  382. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['device_description'])."&nbsp;</td>\n";
  383. echo "</tr>\n";
  384. $c = ($c) ? 0 : 1;
  385. }
  386. unset($directory, $row);
  387. }
  388. echo "</table>";
  389. echo "</form>";
  390. if (strlen($paging_controls) > 0) {
  391. echo "<br />";
  392. echo $paging_controls."\n";
  393. }
  394. echo "<br /><br />".((is_array($directory)) ? "<br /><br />" : null);
  395. // check or uncheck all checkboxes
  396. if (sizeof($device_ids) > 0) {
  397. echo "<script>\n";
  398. echo " function check(what) {\n";
  399. echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
  400. foreach ($device_ids as $device_id) {
  401. echo " document.getElementById('".$device_id."').checked = (what == 'all') ? true : false;\n";
  402. }
  403. echo " }\n";
  404. echo "</script>\n";
  405. }
  406. if (is_array($directory)) {
  407. // check all checkboxes
  408. key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true);
  409. // delete checked
  410. key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true);
  411. }
  412. //show the footer
  413. require_once "resources/footer.php";
  414. ?>