-
Notifications
You must be signed in to change notification settings - Fork 6
/
log-viewer.php
206 lines (170 loc) · 5.39 KB
/
log-viewer.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
require_once("includes.php");
$server = v($_GET['server']);
$log = v($_GET['view']);
// -----------------------------------------------------------------------
// If no log is specified, get a list of logs and then exit:
// No logs? Get logs.
if (!$log) {
$logs = get_logs();
print list_available_logs($logs);
die();
}
// -----------------------------------------------------------------------
// If given a log to view, on the other hand:
$ms = preg_match('#^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}\.html$#', $log);
if (!$ms) {
die("You are doing something weird.");
} elseif (!isset($config['servers'][$server])) {
die("That... isn't a server we have listed. What?");
}
if (isset($_GET['redownload'])) {
$file = get_log($server, $log, true);
if ($file) {
header("Location: ?server=". $server ."&view=". $log ."");
die();
}
}
$file = get_log($server, $log);
if (!$file) {
die("Error opening log. Sorry. It broke. Oh well.");
}
$title = $server . " - " . $log;
require("html/log_header.php");
// thankfully nobody wille ver abuse this.
if (strpos($file, "the emergency shuttle has arrived at centcom") === false && strpos($file, "The round is now over. Round time:") === false) {
echo "<div style='font-size: 200%; margin-right:300px;'>It looks like this log might be incomplete. This might be because the round wasn't over when it was downloaded (or it might still be going on, who knows). <a href='?redownload=1&server=". $_GET['server'] ."&view=". $_GET['view'] ."'>Redownload?</a></div>";
}
?>
<div id="controls">
<button id="filter-button" disabled>Show/Hide Options</button>
<div id="options">
<br>
<div id="filters" class="faded">
<label class='opt'><input type='checkbox' id="filter-all" checked disabled> ALL</label>
<?php
$types = [
'station',
'admin',
'debug',
'diary',
'ahelp',
'mhelp',
'ooc',
'say',
'whisper',
'emote',
'pdamsg',
'combat',
'chemistry',
'vehicle',
'gamemode',
'pathology',
'bombing',
'telepathy',
'tgui',
'topic',
];
$unchecked_types = [
'tgui',
'topic',
];
foreach ($types as $type) {
print "<label class='opt opt-$type'><input type='checkbox' name='$type' ". (in_array($type, $unchecked_types) ? "" : "checked") ." disabled> $type</label>\n";
}
?>
</div>
<br><label id="show-ckeys" class="faded"><input type="checkbox" checked disabled> Show ckeys</label>
<br><label id="show-reltime" class="faded"><input type="checkbox" disabled> Relative timestamps</label>
<br>
<br>
<strong>Filter by text:</strong><br>
<span style="font-size: 70%;">one term per line<br><strong>!term</strong>: match must include<br><strong>-term</strong>: ignore<br><strong>term</strong>: must match <em>any</em></span><br>
<form method="get">
<input type="hidden" name="server" value="<?php print $_GET['server']; ?>">
<input type="hidden" name="view" value="<?php print $_GET['view']; ?>">
<textarea name="search-string" style="display: block; height: 7em;" placeholder="ckey1
ckey2
!with the
-Shitty Bill"><?php if (isset($_GET['search-string'])) echo htmlspecialchars($_GET['search-string']); ?></textarea>
<input type="submit" value="Filter">
</form>
<br>
</div>
<a href='?' style="display: block; text-align: center;">← back to list</a>
</div>
<div id="log" class="show-realtime">
<?php
//$file = file_get_contents($file);
$lines = explode("\n", $file);
$search = [];
$skip_tgui = true;
if (isset($_GET['search-string'])) {
$skip_tgui = false;
$s = trim(str_replace("\r", "", $_GET['search-string']));
$sterm = explode("\n", $s);
foreach ($sterm as $term)
if ($term = trim($term)) $search[] = $term;
}
$n = 0;
$fuck = 2;
$print = true;
foreach ($lines as $line) {
$n++;
if (!empty($search)) {
$has_required = 0;
$matched_any = 0;
$print = false;
foreach ($search as $term) {
if ($term[0] === "!") {
$has_required = 1;
if (stripos($line, substr($term, 1)) === false) {
$print = false;
break;
}
// Continue to see if another term matches somewhere
continue;
} elseif ($term[0] === "-" && stripos($line, substr($term, 1)) !== false) {
// Has ignored term; ignore line
$print = false;
break;
}
if ($term[0] === "+" || $term[0] === "-") {
$term = substr($term, 1);
$print = ($print === null ? true : false);
}
if (stripos($line, $term) !== false) {
$print = true;
}
}
}
if (
stripos($line, "Current round begins") !== false
|| stripos($line, "called the emergency shuttle") !== false
|| stripos($line, "the emergency shuttle has arrived at centcom") !== false
) {
$print = true;
}
if ($print) {
$bits = [];
if ($mOld = preg_match('/^\[([0-9:]+)\] \[([^]]+)\] (.*)(?:<br>)$/i', trim($line), $bits)) {
pretty_log($n, $bits[1], $bits[2], $bits[3]);
} elseif ($mNew = preg_match('/^\[([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+)\] \[([^]]+)\] (.*)(?:<br>)$/i', trim($line), $bits)) {
pretty_log($n, $bits[1], $bits[2], $bits[3]);
} else {
print "<p>$line</p>";
}
}
}
?>
</div>
<script>
const filters = document.getElementById('filters');
const inputs = filters.getElementsByTagName('input');
const log = document.getElementById('log');
for (let input of inputs)
if (input.checked != true)
log.classList.add('hide-' + input.name);
</script>
<?php
require("html/log_footer.php");