-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogs_parser.php
More file actions
48 lines (32 loc) · 883 Bytes
/
Copy pathlogs_parser.php
File metadata and controls
48 lines (32 loc) · 883 Bytes
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
<?php
// Examples
//
// showGroupedStats($nginxLogPath);
//
// showDetailedStats($nginxLogPath, '213.138.68.93');
$nginxLogPath = '';
$apacheLogPath = '';
function showGroupedStats($logFilepath, $linesNumToProcess = 0) {
$logLinesArr = file($logFilepath);
$i = 0;
foreach($logLinesArr as $lineStr) {
if (!empty($linesNumToProcess) && $i > $linesNumToProcess) break;
preg_match('|(\d+\.\d+\.\d+\.\d+)|is', $lineStr, $pock);
$ipLines[$pock[1]] += 1;
$i++;
}
arsort($ipLines);
}
function showDetailedStats($logFilepath, $ip, $linesToShow = 0) {
$logLinesArr = file($logFilepath);
$i = 1;
foreach($logLinesArr as $lineStr) {
preg_match('|(\d+\.\d+\.\d+\.\d+)|is', $lineStr, $pock);
if ($pock[1] == $ip) {
if (!empty($linesToShow) && $i > $linesToShow) break;
$ipLines[$pock[1]][] = $lineStr;
$i++;
}
}
}
?>