device_logs.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. /*
  3. Copyright (c) 2019-2022 Mark J Crane <[email protected]>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
  13. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  16. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. SUCH DAMAGE.
  23. */
  24. //set the include path
  25. $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
  26. set_include_path(parse_ini_file($conf[0])['document.root']);
  27. //includes files
  28. require_once "resources/require.php";
  29. require_once "resources/check_auth.php";
  30. require_once "resources/paging.php";
  31. //check permissions
  32. if (permission_exists('device_log_view')) {
  33. //access granted
  34. }
  35. else {
  36. echo "access denied";
  37. exit;
  38. }
  39. //add multi-lingual support
  40. $language = new text;
  41. $text = $language->get();
  42. //get the http post data
  43. if (is_array($_POST['device_logs'])) {
  44. $action = $_POST['action'];
  45. $search = $_POST['search'];
  46. $device_logs = $_POST['device_logs'];
  47. }
  48. //process the http post data by action
  49. if ($action != '' && is_array($device_logs) && @sizeof($device_logs) != 0) {
  50. switch ($action) {
  51. case 'copy':
  52. if (permission_exists('device_log_add')) {
  53. $obj = new device_logs;
  54. $obj->copy($device_logs);
  55. }
  56. break;
  57. case 'toggle':
  58. if (permission_exists('device_log_edit')) {
  59. $obj = new device_logs;
  60. $obj->toggle($device_logs);
  61. }
  62. break;
  63. case 'delete':
  64. if (permission_exists('device_log_delete')) {
  65. $obj = new device_logs;
  66. $obj->delete($device_logs);
  67. }
  68. break;
  69. }
  70. header('Location: device_logs.php'.($search != '' ? '?search='.urlencode($search) : null));
  71. exit;
  72. }
  73. //get order and order by
  74. $order_by = $_GET["order_by"];
  75. $order = $_GET["order"];
  76. //add the search string
  77. if (isset($_GET["search"])) {
  78. $search = strtolower($_GET["search"]);
  79. $sql_search = " (";
  80. $sql_search .= " lower(device_mac_address) like :search ";
  81. $sql_search .= " or lower(request_scheme) like :search ";
  82. $sql_search .= " or lower(http_host) like :search ";
  83. $sql_search .= " or lower(server_port) like :search ";
  84. $sql_search .= " or lower(server_protocol) like :search ";
  85. $sql_search .= " or lower(query_string) like :search ";
  86. $sql_search .= " or lower(remote_address) like :search ";
  87. $sql_search .= " or lower(http_user_agent) like :search ";
  88. $sql_search .= " or lower(http_status) like :search ";
  89. $sql_search .= " or lower(http_status_code) like :search ";
  90. $sql_search .= ") ";
  91. $parameters['search'] = '%'.$search.'%';
  92. }
  93. //get the count
  94. $sql = "select count(device_log_uuid) from v_device_logs ";
  95. if ($_GET['show'] == "all" && permission_exists('device_log_all')) {
  96. if (isset($sql_search)) {
  97. $sql .= "where ".$sql_search;
  98. }
  99. }
  100. else {
  101. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  102. if (isset($sql_search)) {
  103. $sql .= "and ".$sql_search;
  104. }
  105. $parameters['domain_uuid'] = $domain_uuid;
  106. }
  107. $database = new database;
  108. $num_rows = $database->select($sql, $parameters, 'column');
  109. //prepare to page the results
  110. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  111. $param = $search ? "&search=".$search : null;
  112. $param = ($_GET['show'] == 'all' && permission_exists('device_log_all')) ? "&show=all" : null;
  113. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  114. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  115. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  116. $offset = $rows_per_page * $page;
  117. //get the list
  118. $sql = str_replace('count(device_log_uuid)', '*', $sql);
  119. $sql .= order_by($order_by, $order, 'timestamp', 'desc');
  120. $sql .= limit_offset($rows_per_page, $offset);
  121. $database = new database;
  122. $device_logs = $database->select($sql, $parameters, 'all');
  123. unset($sql, $parameters);
  124. //create token
  125. $object = new token;
  126. $token = $object->create($_SERVER['PHP_SELF']);
  127. //include the header
  128. $document['title'] = $text['title-device_logs'];
  129. require_once "resources/header.php";
  130. //show the content
  131. echo "<div class='action_bar' id='action_bar'>\n";
  132. echo " <div class='heading'><b>".$text['title-device_logs']." (".$num_rows.")</b></div>\n";
  133. echo " <div class='actions'>\n";
  134. if (permission_exists('device_log_add')) {
  135. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'device_log_edit.php']);
  136. }
  137. if (permission_exists('device_log_add') && $device_logs) {
  138. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','onclick'=>"modal_open('modal-copy','btn_copy');"]);
  139. }
  140. if (permission_exists('device_log_edit') && $device_logs) {
  141. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'name'=>'btn_toggle','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
  142. }
  143. if (permission_exists('device_log_delete') && $device_logs) {
  144. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  145. }
  146. echo "<form id='form_search' class='inline' method='get'>\n";
  147. if (permission_exists('device_log_all')) {
  148. if ($_GET['show'] == 'all') {
  149. echo " <input type='hidden' name='show' value='all'>\n";
  150. }
  151. else {
  152. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
  153. }
  154. }
  155. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
  156. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
  157. echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'device_logs.php','style'=>($search == '' ? 'display: none;' : null)]);
  158. if ($paging_controls_mini != '') {
  159. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  160. }
  161. echo " </form>\n";
  162. echo " </div>\n";
  163. echo " <div style='clear: both;'></div>\n";
  164. echo "</div>\n";
  165. if (permission_exists('device_log_add') && $device_logs) {
  166. echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
  167. }
  168. if (permission_exists('device_log_edit') && $device_logs) {
  169. 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');"])]);
  170. }
  171. if (permission_exists('device_log_delete') && $device_logs) {
  172. 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');"])]);
  173. }
  174. echo $text['description-device_logs']."\n";
  175. echo "<br /><br />\n";
  176. echo "<form id='form_list' method='post'>\n";
  177. echo "<input type='hidden' id='action' name='action' value=''>\n";
  178. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  179. echo "<table class='list'>\n";
  180. echo "<tr class='list-header'>\n";
  181. if (permission_exists('device_log_add') || permission_exists('device_log_edit') || permission_exists('device_log_delete')) {
  182. echo " <th class='checkbox'>\n";
  183. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($device_logs ?: "style='visibility: hidden;'").">\n";
  184. echo " </th>\n";
  185. }
  186. if ($_GET['show'] == 'all' && permission_exists('device_log_all')) {
  187. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  188. }
  189. echo th_order_by('timestamp', $text['label-timestamp'], $order_by, $order);
  190. echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by, $order);
  191. echo th_order_by('request_scheme', $text['label-request_scheme'], $order_by, $order);
  192. echo th_order_by('http_host', $text['label-http_host'], $order_by, $order);
  193. echo th_order_by('server_port', $text['label-server_port'], $order_by, $order);
  194. echo th_order_by('server_protocol', $text['label-server_protocol'], $order_by, $order);
  195. echo th_order_by('query_string', $text['label-query_string'], $order_by, $order);
  196. echo th_order_by('remote_address', $text['label-remote_address'], $order_by, $order);
  197. echo th_order_by('http_user_agent', $text['label-http_user_agent'], $order_by, $order);
  198. echo th_order_by('http_status', $text['label-http_status'], $order_by, $order);
  199. echo th_order_by('http_status_code', $text['label-http_status_code'], $order_by, $order);
  200. if (permission_exists('device_log_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  201. echo " <td class='action-button'>&nbsp;</td>\n";
  202. }
  203. echo "</tr>\n";
  204. if (is_array($device_logs) && @sizeof($device_logs) != 0) {
  205. $x = 0;
  206. foreach ($device_logs as $row) {
  207. if (permission_exists('device_log_edit')) {
  208. $list_row_url = "device_log_edit.php?id=".urlencode($row['device_log_uuid']);
  209. }
  210. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  211. if (permission_exists('device_log_add') || permission_exists('device_log_edit') || permission_exists('device_log_delete')) {
  212. echo " <td class='checkbox'>\n";
  213. echo " <input type='checkbox' name='device_logs[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  214. echo " <input type='hidden' name='device_logs[$x][uuid]' value='".escape($row['device_log_uuid'])."' />\n";
  215. echo " </td>\n";
  216. }
  217. if ($_GET['show'] == 'all' && permission_exists('device_log_all')) {
  218. echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
  219. }
  220. echo " <td>".escape($row['timestamp'])."</td>\n";
  221. echo " <td>".escape($row['device_mac_address'])."</td>\n";
  222. echo " <td>".escape($row['request_scheme'])."</td>\n";
  223. echo " <td>".escape($row['http_host'])."</td>\n";
  224. echo " <td>".escape($row['server_port'])."</td>\n";
  225. echo " <td>".escape($row['server_protocol'])."</td>\n";
  226. echo " <td>".escape($row['query_string'])."</td>\n";
  227. echo " <td>".escape($row['remote_address'])."</td>\n";
  228. echo " <td>".escape($row['http_user_agent'])."</td>\n";
  229. echo " <td>".escape($row['http_status'])."</td>\n";
  230. echo " <td>".escape($row['http_status_code'])."</td>\n";
  231. if (permission_exists('device_log_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  232. echo " <td class='action-button'>\n";
  233. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  234. echo " </td>\n";
  235. }
  236. echo "</tr>\n";
  237. $x++;
  238. }
  239. unset($device_logs);
  240. }
  241. echo "</table>\n";
  242. echo "<br />\n";
  243. echo "<div align='center'>".$paging_controls."</div>\n";
  244. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  245. echo "</form>\n";
  246. //include the footer
  247. require_once "resources/footer.php";
  248. ?>