-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.php
153 lines (132 loc) · 6.01 KB
/
errors.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <[email protected]>
Portions created by the Initial Developer are Copyright (C) 2008-2020
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <[email protected]>
*/
//includes files
require dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (!permission_exists('errors_view')) {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//set defaults
if (empty($_POST['line_number'])) { $_POST['line_number'] = 0; }
if (!empty($_POST['sort']) && $_POST['sort'] != 'asc' && $_POST['sort'] != 'desc') { $_POST['sort'] = 'asc'; }
if (empty($_POST['lines'])) { $_POST['lines'] = '10'; }
if (empty($_POST['filter'])) { $_POST['filter'] = ''; }
//include the header
$document['title'] = $text['title-server_errors'];
require_once "resources/header.php";
//show the content
$error_file = $_SESSION['server']['error']['text'].(!empty($_POST['log']) && $_POST['log'] == 'previous' ? '.1' : null);
if (file_exists($error_file)) {
//colored lines
$x = 0;
$filters[$x]['pattern'] = '[error]';
$filters[$x]['color'] = '#cc0000';
$x++;
$filters[$x]['pattern'] = '[crit]';
$filters[$x]['color'] = 'gold';
$file_lines = file($error_file, FILE_SKIP_EMPTY_LINES);
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-server_errors']."</b></div>\n";
echo " <div class='actions'>\n";
echo "<form name='frm' id='frm' class='inline' method='post'>\n";
echo " ".$text['label-log'];
echo " <select class='formfld' name='log' style='margin-right: 20px; margin-top: 4px;'>\n";
echo "<option value='current'>".$text['label-current']."</option>\n";
if (file_exists($_SESSION['server']['error']['text'].'.1')) {
echo "<option value='previous' ".(!empty($_POST['log']) && $_POST['log'] == 'previous' ? 'selected' : null).">".$text['label-previous']."</option>\n";
}
echo "</select>\n";
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();'>";
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>";
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>";
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'];
echo button::create(['type'=>'submit','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'style'=>'margin-left: 15px;','name'=>'submit']);
echo "</form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<div class='card'>\n";
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";
if (!empty($file_lines) && sizeof($file_lines) > 0) {
echo " <span style='font-family: monospace;'>\n";
if (!empty($_POST['filter'])) {
foreach ($file_lines as $index => $line) {
if (strpos($line, $_POST['filter']) == false) {
unset($file_lines[$index]);
}
}
}
if (!empty($_POST['lines'])) {
$file_lines = array_slice($file_lines, -$_POST['lines'], $_POST['lines'], true);
}
if (!empty($_POST['sort']) && $_POST['sort'] == 'desc') {
$file_lines = array_reverse($file_lines, true);
}
foreach ($file_lines as $index => $line) {
foreach ($filters as $filter) {
$pos = strpos($line, $filter['pattern']);
$filter_beg = '';
$filter_end = '';
if ($pos !== false){
$filter_beg = "<span style='color: ".$filter['color'].";'>";
$line = str_replace($_POST['filter'],"<span style='background-color: #ffd800; color: #ff6600; font-weight: bold;'>".$_POST['filter']."</span>", $line);
$filter_end = "</span>";
}
}
$line_num = '';
if ($_POST['line_number']) {
$line_num = "<span style='font-family: courier; color: #aaa; font-size: 11px;'>".($index + 1)." </span>";
}
echo $line_num." ".$filter_beg.$line.$filter_end."<br><br>";
}
echo " </span>\n";
}
else {
echo " <center style='font-family: monospace;'><br>[ EMPTY FILE ]<br><br></center>";
}
echo " <span id='bottom'></span>\n";
echo " </div>\n";
echo "</div>\n";
}
else {
if (!empty($_SESSION['server']['error']['text'])) {
echo "Server error log file not found at: ".$_SESSION['server']['error']['text'];
}
else {
echo "Server error log file path not defined in Settings.";
}
}
//scroll to bottom of displayed lines, when appropriate
if (!empty($_POST['sort']) && $_POST['sort'] != 'desc') {
echo "<script>\n";
//note: the order of the two lines below matters!
echo " $('#file_content').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
echo " $('span#bottom')[0].scrollIntoView(true);\n"; //others
echo "</script>\n";
}
//include the footer
require_once "resources/footer.php";
?>