forked from dl7ata/svxrdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logparse.php
359 lines (333 loc) · 13.8 KB
/
logparse.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
include "config.php";
error_reporting(0);
function getdata($logfilename) {
global $lastheard_call, $LASTHEARD;
if(isset($_COOKIE["svxrdb"])) {
$LASTHEARD = $_COOKIE["svxrdb"];
}
$line_of_text = file_get_contents( $logfilename );
$logline = explode("\n", $line_of_text);
$member = array( CLIENTLIST );
for($i=0;$i<count($member);$i++){
$clients[$i] = array('CALL' => $member[$i], 'LOGINOUTTIME'=> "time", 'IP'=> "ip", 'STATUS'=> "OFFLINE", 'TX_S'=> "OFFLINE", 'TX_E'=> "OFFLINE", 'TG'=> "TG", 'MON'=> "not see" );
}
// Recovering old data logrotate issues
if ( preg_match('/'.RECOVER.'/i', 'YES') ) {
$recoveredData = file_get_contents("recover_data_".$logfilename);
$recoveredArray = unserialize($recoveredData);
$clients=array_merge($clients, $recoveredArray);
}
foreach ($logline as $value) {
$value = str_replace(" CEST:", "",$value);
if(preg_match("/Monitor TG/i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$ctg="";
for($itg=5;$itg<count($data);$itg++){
$ctg.=$data[$itg]." ";
}
// add TG Monitoring
$clients[$key]['MON']=$ctg;
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "MONITOR",
'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
}// END Monitor TG
if(preg_match("/Login OK from/i", $value)) {
$data = explode(" ",$value);
/*
Array
(
[0] => 01.09.2017
[1] => 18:02:47:
[2] => DO0SE:
[3] => Login
[4] => OK
[5] => from
[6] => 79.240.57.65:50468
)
*/
$data[2] = str_replace(":","",$data[2]);
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
//member found
$clients[$key]['LOGINOUTTIME']="$data[0] ".substr($data[1], 0, -1); //: remoed from timestring
$clients[$key]['IP']=$data[6];
$clients[$key]['STATUS']="ONLINE";
$clients[$key]['TX_S']="ONLINE";
$clients[$key]['TX_E']="ONLINE";
$clients[$key]['COMMENT']="new client ".$data[0]." ".substr($data[1], 0, -1);
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
// $clients[$key]['SID']="$data[0] ".substr($data[1], 0, -1);
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'LOGINOUTTIME'=> $data[0]." ".substr($data[1], 0, -1),
'IP'=> $data[6], 'STATUS'=> 'ONLINE',
'TX_S'=> "ONLINE", 'TX_E'=> "ONLINE", 'COMMENT'=>"new client ".$data[0]." ".substr($data[1], 0, -1),
'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
} // END Login OK from
if((preg_match("/disconnected: Connection closed/i", $value)) OR (preg_match("/disconnected: Locally ordered/i", $value))) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 01.09.2017
[1] => 18:18:31:
[2] => DB0MGN-2m:
[3] => Client
[4] => 87.166.35.47:33692
[5] => disconnected
[6] => Connection
[7] => closed
[8] => by
[9] => remote
[10] => peer
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
//member found
$clients[$key]['LOGINOUTTIME']="$data[0] ".substr($data[1], 0, -1); //: remoed from timestring
$clients[$key]['IP']=$data[4];
$clients[$key]['STATUS']="OFFLINE";
$clients[$key]['TX_S']="OFFLINE";
$clients[$key]['TX_E']="OFFLINE";
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
// $clients[$key]['SID']="$data[0] ".substr($data[1], 0, -1); //: remove from timestring
} else {
// member not found add im
// ### ReflectorClient::disconnect: Access denied Call "Client" not allowed in list :)
if ($data[2] !== "Client")
{
$clients[] = array( 'CALL'=> $data[2], 'LOGINOUTTIME'=> $data[0]." ".substr($data[1], 0, -1),
'IP'=> $data[4], 'STATUS'=> "OFFLINE",
'TX_S'=> "OFFLINE", 'TX_E'=> "OFFLINE", 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
}
}// END disconnected: Connection closed
if(preg_match("/Already connected/i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 01.09.2017
[1] => 18:13:13:
[2] => DO0SE:
[3] => Already
[4] => connected
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="ALREADY";
$clients[$key]['LOGINOUTTIME']="$data[0] ".substr($data[1], 0, -1);
$clients[$key]['TX_S']="already";
$clients[$key]['TX_E']="connected";
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
$lastheard_call = $data[2];
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "ALREADY", 'LOGINOUTTIME'=> "$data[0] ".substr($data[1], 0, -1),
'TX_S'=> "already", 'TX_E'=> "connected", 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
$lastheard_call = $data[2];
}
}// END Already connected
if(preg_match("/Talker start/i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 01.09.2017
[1] => 18:13:13:
[2] => DO0SE:
[3] => Talker
[4] => start
[5] => on
[6] => TG
[7] => #2621
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="TX";
$clients[$key]['TX_S']=substr($data[1], 0, -1); //: remove from timestring
$clients[$key]['TX_E']=substr($data[1], 0, -1); //: remove from timestring
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
$clients[$key]['TG']=$data[7];
$lastheard_call = $data[2];
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "TX",
'TX_S'=> substr($data[1], 0, -1), 'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
$lastheard_call = $data[2];
}
}// END Talker start
if(preg_match("/Talker stop/i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 01.09.2017
[1] => 18:13:17:
[2] => DO0SE:
[3] => Talker
[4] => stop
[5] =>
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="ONLINE";
$clients[$key]['TX_E']=substr($data[1], 0, -1); //: remove from timestring
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
$lastheard_call = $data[2];
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "ONLINE",
'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
$lastheard_call = $data[2];
}
}// END Talker stop
if(preg_match("/Talker audio timeout/i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 01.09.2017
[1] => 18:13:17:
[2] => V51SA:
[3] => Talker
[4] => audio
[5] => timeout
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="ONLINE";
$clients[$key]['TX_E']=substr($data[1], 0, -1); //: remove from timestring
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
$lastheard_call = $data[2];
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "ONLINE",
'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
$lastheard_call = $data[2];
}
}// END Audio timeout
if(preg_match("/is already talking.../i", $value)) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 08.09.2017
[1] => 18:30:01:
[2] => DD6LK:
[3] => DL7ATA
[4] => is
[5] => already
[6] => talking...
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="DOUBLE";
$clients[$key]['TX_E']=substr($data[1], 0, -1); //: remoed from timestring
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
// $clients[$key]['SID']="$data[0] ".substr($data[1], 0, -1);
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "DOUBLE",
'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
}// END Talker double stop
// Server Auth failure
if(preg_match("/Authentication failed for user/i", $value)) {
$data = explode(" ",$value);
$data[8] = str_replace("\"", "", $data[8]);
/*
Array
(
[0] => 02.11.2017
[1] => 12:47:04:
[2] => Client
[3] => 188.193.218.143:34184
[4] => Authentication
[5] => failed
[6] => for
[7] => user
[8] => "DB0SVX"
)
*/
if (($key = array_search($data[8], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="DENIED";
$clients[$key]['LOGINOUTTIME']="ACCESS DENIED"; //: remoed from timestring
$clients[$key]['IP']="ACCESS DENIED";
$clients[$key]['TX_S']="ACCESS DENIED";
$clients[$key]['TX_E']="ACCESS DENIED";
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
// $clients[$key]['SID']="$data[0] ".substr($data[1], 0, -1);
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[8], 'STATUS'=> "DENIED",
'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
}// END Server login failure
// Server login failure
if((preg_match("/[Access denied]{6}/", $value)) AND (strlen($value)<=57 )) {
$data = explode(" ",$value);
$data[2] = str_replace(":","",$data[2]);
/*
Array
(
[0] => 12.09.2017
[1] => 16:05:10:
[2] => DO0SE:
[3] => Access
[4] => denied
)
*/
if (($key = array_search($data[2], array_column($clients, 'CALL'))) !==FALSE) {
$clients[$key]['STATUS']="DENIED";
$clients[$key]['LOGINOUTTIME']="ACCESS DENIED"; //: remoed from timestring
$clients[$key]['IP']="ACCESS DENIED";
$clients[$key]['TX_S']="ACCESS DENIED";
$clients[$key]['TX_E']="ACCESS DENIED";
$clients[$key]['SID']=logtounixtime("$data[0]-".substr($data[1], 0, -1));
// $clients[$key]['SID']="$data[0] ".substr($data[1], 0, -1);
} else {
//member not found add im
$clients[] = array( 'CALL'=> $data[2], 'STATUS'=> "DENIED",
'TX_E'=> substr($data[1], 0, -1), 'SID'=> logtounixtime("$data[0]-".substr($data[1], 0, -1)) );
}
}// END Server Auth failure
} // END foreach ($logline as $value)
// Recovering old data logrotate issues
if ( preg_match('/'.RECOVER.'/i', 'YES') ) {
// cleanup array from CALL
for ($i=0; $i<count($clients, 0); $i++) {
if ($clients[$i]['CALL'] == "CALL")
{
unset($clients[$i]);
}
}
$serialized_data = serialize($clients);
file_put_contents("recover_data_".$logfilename, $serialized_data);
}
if (preg_match('/'.$LASTHEARD.'/i', 'TOP')) {
$last_key = array_search($lastheard_call, array_column($clients, 'CALL'));
$value = $clients[$last_key];
unset($clients[$last_key]);
$clients = array($value) + $clients;
$clients_sort = array();
foreach ($clients as $key => $value) {
$clients_sort[$key] = $value['SID'];
}
array_multisort($clients_sort, SORT_DESC, $clients);
}
return $clients;
} // END function getdata()
?>