errors.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. */
  21. //includes files
  22. require dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (!permission_exists('errors_view')) {
  26. echo "access denied";
  27. exit;
  28. }
  29. //add multi-lingual support
  30. $language = new text;
  31. $text = $language->get();
  32. //set defaults
  33. if (empty($_POST['line_number'])) { $_POST['line_number'] = 0; }
  34. if (!empty($_POST['sort']) && $_POST['sort'] != 'asc' && $_POST['sort'] != 'desc') { $_POST['sort'] = 'asc'; }
  35. if (empty($_POST['lines'])) { $_POST['lines'] = '10'; }
  36. if (empty($_POST['filter'])) { $_POST['filter'] = ''; }
  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'].(!empty($_POST['log']) && $_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 "<div class='action_bar' id='action_bar'>\n";
  52. echo " <div class='heading'><b>".$text['header-server_errors']."</b></div>\n";
  53. echo " <div class='actions'>\n";
  54. echo "<form name='frm' id='frm' class='inline' method='post'>\n";
  55. echo " ".$text['label-log'];
  56. echo " <select class='formfld' name='log' style='margin-right: 20px; margin-top: 4px;'>\n";
  57. echo "<option value='current'>".$text['label-current']."</option>\n";
  58. if (file_exists($_SESSION['server']['error']['text'].'.1')) {
  59. echo "<option value='previous' ".(!empty($_POST['log']) && $_POST['log'] == 'previous' ? 'selected' : null).">".$text['label-previous']."</option>\n";
  60. }
  61. echo "</select>\n";
  62. 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();'>";
  63. 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>";
  64. echo "<label style='margin-right: 20px; margin-top: 4px;'><input type='checkbox' name='sort' id='sort' value='desc' ".(!empty($_POST['sort']) && $_POST['sort'] == 'desc' ? 'checked' : null)."> ".$text['label-sort']."</label>";
  65. echo $text['label-display']." <input type='text' class='formfld' style='width: 50px; text-align: center;' name='lines' maxlength='5' value=\"".escape($_POST['lines'])."\" onclick='this.select();'> : ".count($file_lines)." ".$text['label-lines'];
  66. echo button::create(['type'=>'submit','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'style'=>'margin-left: 15px;','name'=>'submit']);
  67. echo "</form>\n";
  68. echo " </div>\n";
  69. echo " <div style='clear: both;'></div>\n";
  70. echo "</div>\n";
  71. echo "<div class='card'>\n";
  72. echo " <div id='file_content' style='max-height: 800px; overflow: auto; color: #aaa; background-color: #1c1c1c; border-radius: 4px; padding: 8px; text-align: left;'>\n";
  73. if (!empty($file_lines) && sizeof($file_lines) > 0) {
  74. echo " <span style='font-family: monospace;'>\n";
  75. if (!empty($_POST['filter'])) {
  76. foreach ($file_lines as $index => $line) {
  77. if (strpos($line, $_POST['filter']) == false) {
  78. unset($file_lines[$index]);
  79. }
  80. }
  81. }
  82. if (!empty($_POST['lines'])) {
  83. $file_lines = array_slice($file_lines, -$_POST['lines'], $_POST['lines'], true);
  84. }
  85. if (!empty($_POST['sort']) && $_POST['sort'] == 'desc') {
  86. $file_lines = array_reverse($file_lines, true);
  87. }
  88. foreach ($file_lines as $index => $line) {
  89. foreach ($filters as $filter) {
  90. $pos = strpos($line, $filter['pattern']);
  91. $filter_beg = '';
  92. $filter_end = '';
  93. if ($pos !== false){
  94. $filter_beg = "<span style='color: ".$filter['color'].";'>";
  95. $line = str_replace($_POST['filter'],"<span style='background-color: #ffd800; color: #ff6600; font-weight: bold;'>".$_POST['filter']."</span>", $line);
  96. $filter_end = "</span>";
  97. }
  98. }
  99. $line_num = '';
  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. echo "</div>\n";
  113. }
  114. else {
  115. if (!empty($_SESSION['server']['error']['text'])) {
  116. echo "Server error log file not found at: ".$_SESSION['server']['error']['text'];
  117. }
  118. else {
  119. echo "Server error log file path not defined in Settings.";
  120. }
  121. }
  122. //scroll to bottom of displayed lines, when appropriate
  123. if (!empty($_POST['sort']) && $_POST['sort'] != 'desc') {
  124. echo "<script>\n";
  125. //note: the order of the two lines below matters!
  126. echo " $('#file_content').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
  127. echo " $('span#bottom')[0].scrollIntoView(true);\n"; //others
  128. echo "</script>\n";
  129. }
  130. //include the footer
  131. require_once "resources/footer.php";
  132. ?>