/
index.php
87 lines (71 loc) · 1.76 KB
/
index.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
<?php
/**
* Full Name: Iszak Bryan
* ITS Username: ibryan02
* Module Name: Web Programming using PHP
* Tutor Name: Tobi Brodie
*/
require_once 'functions.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Log Statistics</title>
</head>
<body>
<h1>Log Statistics</h1>
<?php
$logs = findLogs('/home/itapps/lo/p1/tma/');
if ($logs) {
foreach($logs as $log) {
$statistics = parseLogFile($log);
// Error parsing file
if (!$statistics) {
$log = htmlentities($log);
echo <<<HTML
<p>File {$log} not readable</p>
HTML;
continue;
}
$month = htmlentities($statistics['month']);
echo <<<HTML
<h2>{$month}</h2>
<dl>
<dt>Total requests</dt>
<dd>{$statistics['totalRequests']}</dd>
<dt>Total requests for articles</dt>
<dd>{$statistics['articleRequests']}</dd>
<dt>Total bandwidth</dt>
<dd>{$statistics['totalBandwidth']} bytes</dd>
<dt>Total files not found (404)</dt>
<dd>{$statistics['totalNotFound']}</dd>\n
HTML;
if (count($statistics['filesNotFound']) > 0) {
$filesNotFound = $statistics['filesNotFound'];
echo <<<HTML
<dt>Files not Found</dt>
<dd>
<ul>\n
HTML;
foreach ($filesNotFound as $file) {
$file = htmlentities($file);
echo <<<HTML
<li>{$file}</li>\n
HTML;
}
echo <<<HTML
</ul>
</dd>
</dl>\n\n
HTML;
}
}
} else {
echo <<<HTML
<p>Error reading directory</p>
HTML;
}
?>
</body>
</html>