errors.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (!permission_exists('errors_view')) {
  27. echo "access denied";
  28. exit;
  29. }
  30. //add multi-lingual support
  31. $language = new text;
  32. $text = $language->get();
  33. //set defaults
  34. if (!is_numeric($_POST['line_number'])) { $_POST['line_number'] = 0; }
  35. if ($_POST['sort'] != 'asc' && $_POST['sort'] != 'desc') { $_POST['sort'] = 'asc'; }
  36. if (!is_numeric($_POST['lines'])) { $_POST['lines'] = '10'; }
  37. //include the header
  38. $document['title'] = $text['title-server_errors'];
  39. require_once "resources/header.php";
  40. //show the content
  41. $error_file = $_SESSION['server']['error']['text'].($_POST['log'] == 'previous' ? '.1' : null);
  42. if (file_exists($error_file)) {
  43. //colored lines
  44. $x = 0;
  45. $filters[$x]['pattern'] = '[error]';
  46. $filters[$x]['color'] = '#cc0000';
  47. $x++;
  48. $filters[$x]['pattern'] = '[crit]';
  49. $filters[$x]['color'] = 'gold';
  50. $file_lines = file($error_file, FILE_SKIP_EMPTY_LINES);
  51. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  52. echo " <tr>\n";
  53. echo " <td align='left' valign='top' width='100%' style='padding-right: 15px;' nowrap>\n";
  54. echo " <b>".$text['header-server_errors']."</b><br />\n";
  55. echo " </td>\n";
  56. echo " <td align='right' valign='middle' nowrap>\n";
  57. echo " <form method='post'>\n";
  58. echo " ".$text['label-log'];
  59. echo " <select class='formfld' name='log' style='margin-right: 20px; margin-top: 4px;'>\n";
  60. echo " <option value='current'>".$text['label-current']."</option>\n";
  61. if (file_exists($_SESSION['server']['error']['text'].'.1')) {
  62. echo " <option value='previous' ".($_POST['log'] == 'previous' ? 'selected' : null).">".$text['label-previous']."</option>\n";
  63. }
  64. echo " </select>\n";
  65. echo " ".$text['label-filter']." <input type='text' name='filter' class='formfld' style='width: 150px; text-align: center; margin-right: 20px;' value=\"".escape($_POST['filter'])."\" onclick='this.select();'>";
  66. echo " <label style='margin-right: 20px; margin-top: 4px;'><input type='checkbox' name='line_number' id='line_number' value='1' ".(($_POST['line_number'] == 1) ? 'checked' : null)."> ".$text['label-line_numbers']."</label>";
  67. echo " <label style='margin-right: 20px; margin-top: 4px;'><input type='checkbox' name='sort' id='sort' value='desc' ".(($_POST['sort'] == 'desc') ? 'checked' : null)."> ".$text['label-sort']."</label>";
  68. echo " ".$text['label-display']." <input type='text' class='formfld' style='min-width: 50px; max-width: 50px; width: 50px; text-align: center;' name='lines' maxlength='5' value=\"".escape($_POST['lines'])."\" onclick='this.select();'> of ".count($file_lines)." ".$text['label-lines'];
  69. echo " <input type='submit' class='btn' style='margin-left: 20px;' name='submit' value=\"".$text['button-reload']."\">";
  70. echo " </form>\n";
  71. echo " </td>\n";
  72. echo " </tr>\n";
  73. echo "</table>\n";
  74. echo "<br>\n";
  75. echo "<div id='file_content' style='max-height: 600px; overflow: auto; color: #aaa; background-color: #1c1c1c; border-radius: 4px; padding: 8px; text-align: left;'>\n";
  76. if (is_array($file_lines) && sizeof($file_lines) > 0) {
  77. echo "<span style='font-family: monospace;'>\n";
  78. if ($_POST['filter'] != '') {
  79. foreach ($file_lines as $index => $line) {
  80. if (strpos($line, $_POST['filter']) == false) {
  81. unset($file_lines[$index]);
  82. }
  83. }
  84. }
  85. if (is_numeric($_POST['lines']) && $_POST['lines'] > 0) {
  86. $file_lines = array_slice($file_lines, -$_POST['lines'], $_POST['lines'], true);
  87. }
  88. if ($_POST['sort'] == 'desc') {
  89. $file_lines = array_reverse($file_lines, true);
  90. }
  91. foreach ($file_lines as $index => $line) {
  92. foreach ($filters as $filter) {
  93. $pos = strpos($line, $filter['pattern']);
  94. if ($pos !== false){
  95. $filter_beg = "<span style='color: ".$filter['color'].";'>";
  96. $line = str_replace($_POST['filter'],"<span style='background-color: #ffd800; color: #ff6600; font-weight: bold;'>".$_POST['filter']."</span>", $line);
  97. $filter_end = "</span>";
  98. }
  99. }
  100. if ($_POST['line_number']) {
  101. $line_num = "<span style='font-family: courier; color: #aaa; font-size: 11px;'>".($index + 1)."&nbsp;&nbsp;&nbsp;</span>";
  102. }
  103. echo $line_num." ".$filter_beg.$line.$filter_end."<br><br>";
  104. }
  105. echo "</span>\n";
  106. }
  107. else {
  108. echo "<center style='font-family: monospace;'><br>[ EMPTY FILE ]<br><br></center>";
  109. }
  110. echo " <span id='bottom'></span>\n";
  111. echo "</div>\n";
  112. }
  113. else {
  114. if ($_SESSION['server']['error']['text'] != '') {
  115. echo "Server error log file not found at: ".$_SESSION['server']['error']['text'];
  116. }
  117. else {
  118. echo "Server error log file path not defined in Settings.";
  119. }
  120. }
  121. // scroll to bottom of displayed lines, when appropriate
  122. if ($_POST['sort'] != 'desc') {
  123. echo "<script>\n";
  124. //note: the order of the two lines below matters!
  125. echo " $('#file_content').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
  126. echo " $('span#bottom')[0].scrollIntoView(true);\n"; //others
  127. echo "</script>\n";
  128. }
  129. //include the footer
  130. require_once "resources/footer.php";
  131. ?>