-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadlog.php
146 lines (137 loc) · 5.07 KB
/
readlog.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
<?php
/*
* readlog.php
*
* Copyright 2021 Jim Richardson <jim@noideersoftware.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* Requires PHP > 7.4
*
* utility for console app
*/
//header('Access-Control-Allow-Origin: *');
$version = "2.01";
$build = "5169-2686274782";
require_once 'includes/master.inc.php';
define ('cr', PHP_EOL);
define ('br','<br/>');
if(is_cli()) {
//die('running from command'.cr);
$file= $argv[1];
$id = $argv[2];
$_GET['lines'] = $argv[3];
$filename = $file.'/log/console/'.$id.'-console.log';
}
if(!isset($file)) {
$file = $_GET['path'];
$filename = $file.'/log/console/'.$_GET['id'].'-console.log';
}
$result = array();
clearstatcache(true, $filename);
$data['time'] = filemtime($file);
$data['content'] = $_GET['time'] < $data['time']
? getLastLines($filename,$_GET['lines'])
: false;
print_r($data['content']);
foreach ($data['content'] as $k => $v ) {
$x = strpos($v,'" connected, address "');
if ($x >0 ) {
//echo 'new ';
preg_match('/U:[0-9]:\d+/', $v, $t); // get steam id
$id = trim($t[0]);
file_put_contents('logs/dbug.txt','new '.$id.PHP_EOL);
}
$v = preg_replace('/<.*?>/', '', $v); //user number ?
$v = preg_replace('@\(.*?\)@','',$v); // bracket content
$v = preg_replace('/Console<0><Console><Console>/','Console',$v);
$v = preg_replace('/<[U:1:[0-9]+]>/', ' ', $v);
$v = preg_replace('/</',' ',$v);
$v = preg_replace('/>/',' ',$v);
//$v = preg_replace('/L .. /', '', $v);
$date ='L '. date("m/d/Y");
$pattern = ' /L (\w+)\/(\d+)\/(\d+)/i';
$replacement = '<span style="color:yellow;"><b>${2}/$1/$3</b></span>';
//display the result returned by preg_replace
$v = preg_replace($pattern, $replacement, $v,-1,$count);
$replacement = '<span style="color:yellow;"><b>${1}:$2:$3</b></span>';
$pattern = '/(\d+):(\d+):(\d+)/';
$v = preg_replace($pattern, $replacement, $v,-1,$count);
//if (empty($count)) {continue;} // clears non dated rows
$v = preg_replace('/"/','',$v);
$v = preg_replace('/<[0-9]+>/', ' ', $v);
$v = trim($v);
// run replace line here
$tuni = strpos($v,'team Unassigned');
$v = str_replace('Unassigned','',$v);
$v = str_replace('#SDK_Team_','',$v);
$v = str_replace(' say ',' <span style="color:magenta;"><b> say </b></span>',$v);
$v = str_replace(' killed ',' <span style="color:red;"><b> killed </b></span>',$v);
$v = str_replace(' Console ',' <span style="color:#328ba8;"><b> Console </b></span>',$v);
$v = str_replace('committed suicide',' <span style="color:red;"><b> committed suicide </b></span>',$v);
$v =str_replace('This command can only be used in-game.','<span style="color:red;">This command can only be used in-game.</span>',$v);
$v = str_replace('Server logging enabled',' <span style="color:green;"><b>Server logging enabled</b></span> ',$v);
$v = str_replace('disconnected (reason "Kicked from server")','<span style="color:#ffbf00;"><b>disconnected (reason "Kicked from server")</b></span>',$v);
$v = str_replace('disconnected',' <span style="color:#ffbf00;"><b>dissconnected</b></span> ',$v);
$v = str_replace('Writing ','<span style="color:green"><b>Writing </b></span>',$v);
//$v = str_replace('Writing cfg/banned_user.cfg.','<span style="color:red;"></span><b>Writing cfg/banned_user.cfg.</b></span>',$v);
$v = str_replace('fof_cripplecreek','<span style="color:#0d1f54;"><b>fof_cripplecreek</b></span>',$v);
$v = str_replace('validated','<span style="color:green;"><b>validated</b></span>',$v);
//$v = str_replace('Console','',$v,2);
if ($tuni >0 ) {
$v = str_replace('team ','team Unassigned',$v);
}
$v = str_replace('"','',$v);
echo $v.PHP_EOL;
}
//print_r($data['content']);
function getLastLines($path, $totalLines) {
$lines = array();
$fp = fopen($path, 'r');
fseek($fp, -1, SEEK_END);
$pos = ftell($fp);
$lastLine = "";
// Loop backword until we have our lines or we reach the start
while($pos > 0 && count($lines) < $totalLines) {
$C = fgetc($fp);
if($C == "\n") {
// skip empty lines
if(trim($lastLine) != "") {
$lines[] = $lastLine;
}
$lastLine = '';
} else {
$lastLine = $C.$lastLine;
}
fseek($fp, $pos--);
}
$lines = array_reverse($lines);
return $lines;
}
/*
*
* name: replace_line
* @param
* $data = line to adjust
* $game_id = game this log belongs to , allows different formats per game id
* @return
* formatted line
*
*/
function replace_line($data,$game_id) {
return $line;
}
?>