errors.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. //set the include path
  22. $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
  23. set_include_path(parse_ini_file($conf[0])['document.root']);
  24. //includes files
  25. require_once "resources/require.php";
  26. require_once "resources/check_auth.php";
  27. //check permissions
  28. if (!permission_exists('errors_view')) {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //set defaults
  36. if (empty($_POST['line_number'])) { $_POST['line_number'] = 0; }
  37. if (!empty($_POST['sort']) && $_POST['sort'] != 'asc' && $_POST['sort'] != 'desc') { $_POST['sort'] = 'asc'; }
  38. if (empty($_POST['lines'])) { $_POST['lines'] = '10'; }
  39. if (empty($_POST['filter'])) { $_POST['filter'] = ''; }
  40. //include the header
  41. $document['title'] = $text['title-server_errors'];
  42. require_once "resources/header.php";
  43. //show the content
  44. $error_file = $_SESSION['server']['error']['text'].(!empty($_POST['log']) && $_POST['log'] == 'previous' ? '.1' : null);
  45. if (file_exists($error_file)) {
  46. //colored lines
  47. $x = 0;
  48. $filters[$x]['pattern'] = '[error]';
  49. $filters[$x]['color'] = '#cc0000';
  50. $x++;
  51. $filters[$x]['pattern'] = '[crit]';
  52. $filters[$x]['color'] = 'gold';
  53. $file_lines = file($error_file, FILE_SKIP_EMPTY_LINES);
  54. echo "<div class='action_bar' id='action_bar'>\n";
  55. echo " <div class='heading'><b>".$text['header-server_errors']."</b></div>\n";
  56. echo " <div class='actions'>\n";
  57. echo "<form name='frm' id='frm' class='inline' 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' ".(!empty($_POST['sort']) && $_POST['sort'] == 'desc' ? 'checked' : null)."> ".$text['label-sort']."</label>";
  68. 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'];
  69. echo button::create(['type'=>'submit','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'style'=>'margin-left: 15px;','name'=>'submit']);
  70. echo "</form>\n";
  71. echo " </div>\n";
  72. echo " <div style='clear: both;'></div>\n";
  73. echo "</div>\n";
  74. 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";
  75. if (!empty($file_lines) && sizeof($file_lines) > 0) {
  76. echo "<span style='font-family: monospace;'>\n";
  77. if (!empty($_POST['filter'])) {
  78. foreach ($file_lines as $index => $line) {
  79. if (strpos($line, $_POST['filter']) == false) {
  80. unset($file_lines[$index]);
  81. }
  82. }
  83. }
  84. if (!empty($_POST['lines'])) {
  85. $file_lines = array_slice($file_lines, -$_POST['lines'], $_POST['lines'], true);
  86. }
  87. if (!empty($_POST['sort']) && $_POST['sort'] == 'desc') {
  88. $file_lines = array_reverse($file_lines, true);
  89. }
  90. foreach ($file_lines as $index => $line) {
  91. foreach ($filters as $filter) {
  92. $pos = strpos($line, $filter['pattern']);
  93. $filter_beg = '';
  94. $filter_end = '';
  95. if ($pos !== false){
  96. $filter_beg = "<span style='color: ".$filter['color'].";'>";
  97. $line = str_replace($_POST['filter'],"<span style='background-color: #ffd800; color: #ff6600; font-weight: bold;'>".$_POST['filter']."</span>", $line);
  98. $filter_end = "</span>";
  99. }
  100. }
  101. $line_num = '';
  102. if ($_POST['line_number']) {
  103. $line_num = "<span style='font-family: courier; color: #aaa; font-size: 11px;'>".($index + 1)."&nbsp;&nbsp;&nbsp;</span>";
  104. }
  105. echo $line_num." ".$filter_beg.$line.$filter_end."<br><br>";
  106. }
  107. echo "</span>\n";
  108. }
  109. else {
  110. echo "<center style='font-family: monospace;'><br>[ EMPTY FILE ]<br><br></center>";
  111. }
  112. echo " <span id='bottom'></span>\n";
  113. echo "</div>\n";
  114. }
  115. else {
  116. if (!empty($_SESSION['server']['error']['text'])) {
  117. echo "Server error log file not found at: ".$_SESSION['server']['error']['text'];
  118. }
  119. else {
  120. echo "Server error log file path not defined in Settings.";
  121. }
  122. }
  123. //scroll to bottom of displayed lines, when appropriate
  124. if (!empty($_POST['sort']) && $_POST['sort'] != 'desc') {
  125. echo "<script>\n";
  126. //note: the order of the two lines below matters!
  127. echo " $('#file_content').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
  128. echo " $('span#bottom')[0].scrollIntoView(true);\n"; //others
  129. echo "</script>\n";
  130. }
  131. //include the footer
  132. require_once "resources/footer.php";
  133. ?>