-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.php
More file actions
440 lines (382 loc) · 13.3 KB
/
statistics.php
File metadata and controls
440 lines (382 loc) · 13.3 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<?php
session_start();
include('sessionCheck.php');
include('config.php');
if(isset($_GET['exit'])){}
// Check if $_SESSION['selected_session'] is set
if (isset($_SESSION['selected_session'])) {
// Unset (remove) $_SESSION['selected_session']
unset($_SESSION['selected_session']);
}
$username = $_SESSION['username'];
$userDataFile = $dir."users/" . $username . ".php";
// Function to get user data from file
function getUserData($userDataFile) {
$userData = array();
if (file_exists($userDataFile)) {
$lines = file($userDataFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
list($key, $value) = explode(':', $line, 2);
$userData[trim($key)] = trim($value);
}
}
return $userData;
}
$userData = getUserData($userDataFile);
?><?php
// Directory containing log files
$logDirectory = 'log/';
// Array to hold all log files found in the directory
$logFiles = glob($logDirectory . 'logfile*');
// Initialize arrays to store the statistics
$pageVisits = array();
$dateVisits = array();
$userVisits = array();
$sessionVisits = array();
// Process each log file
foreach ($logFiles as $logFile) {
// Read the CSV file into an array
$data = array_map('str_getcsv', file($logFile));
// Remove the header row
$header = array_shift($data);
// Process the data from this log file
foreach ($data as $row) {
list($datestamp, $user, $page, $session) = $row;
// Count page visits
if (!isset($pageVisits[$page])) {
$pageVisits[$page] = 0;
}
$pageVisits[$page]++;
// Count visits by date
$date = substr($datestamp, 0, 10);
if (!isset($dateVisits[$date])) {
$dateVisits[$date] = 0;
}
$dateVisits[$date]++;
// Count visits by user
if (!isset($userVisits[$user])) {
$userVisits[$user] = 0;
}
$userVisits[$user]++;
// Count visits by session
if (!empty($session)) {
if (!isset($sessionVisits[$session])) {
$sessionVisits[$session] = 0;
}
$sessionVisits[$session]++;
}
}
}
// Sort the page visits in descending order
arsort($pageVisits);
// Get the top 15 most visited pages
$topPages = array_slice($pageVisits, 0, 15, true);
// Sort the other arrays for display
ksort($dateVisits);
//arsort($dateVisits);
arsort($userVisits);
$sessionVisits = array_slice($sessionVisits , 0, 15, true);
arsort($sessionVisits);
// Output or further process the results as needed...
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
#options-container {
max-width: 800px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #333;
}
ul {
list-style: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
p {
margin: 0;
}
input[type="text"] {
padding: 8px;
width: 100%;
box-sizing: border-box;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
a {
text-decoration: none;
color: #3498db;
}
</style>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(error => {
console.error('Service Worker registration failed:', error);
});
}
</script>
<title>Log Statistics</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<?php
include('lib/nav.php');
include('lib/sus_re_dir.php');
?>
<div id="options-container">
<h2>Top 15 Most Active Pages</h2>
<canvas id="pageVisitsChart"></canvas>
<h2>Activity by Date</h2>
<canvas id="dateVisitsChart"></canvas>
<h2>Activity by User</h2>
<canvas id="userVisitsChart"></canvas>
<h2>Top 15 Records</h2>
<canvas id="sessionVisitsChart"></canvas>
<script>
// Top 15 Most Visited Pages Chart
var pageVisitsCtx = document.getElementById('pageVisitsChart').getContext('2d');
var pageVisitsChart = new Chart(pageVisitsCtx, {
type: 'bar',
data: {
labels: <?php echo json_encode(array_keys($topPages)); ?>,
datasets: [{
label: 'Page Visits',
data: <?php echo json_encode(array_values($topPages)); ?>,
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
},
x: {
ticks: {
display: false
}
}
}
}
});
// Visits by Date Chart
var dateVisitsCtx = document.getElementById('dateVisitsChart').getContext('2d');
var dateVisitsChart = new Chart(dateVisitsCtx, {
type: 'line',
data: {
labels: <?php echo json_encode(array_keys($dateVisits)); ?>,
datasets: [{
label: 'Visits by Date',
data: <?php echo json_encode(array_values($dateVisits)); ?>,
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
// Visits by User Chart
var userVisitsCtx = document.getElementById('userVisitsChart').getContext('2d');
var userVisitsChart = new Chart(userVisitsCtx, {
type: 'pie',
data: {
labels: <?php echo json_encode(array_keys($userVisits)); ?>,
datasets: [{
label: 'Visits by User',
data: <?php echo json_encode(array_values($userVisits)); ?>,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
// Visits by Session Chart
var sessionVisitsCtx = document.getElementById('sessionVisitsChart').getContext('2d');
var sessionVisitsChart = new Chart(sessionVisitsCtx, {
type: 'doughnut',
data: {
labels: <?php echo json_encode(array_keys($sessionVisits)); ?>,
datasets: [{
label: 'Visits by Record',
data: <?php echo json_encode(array_values($sessionVisits)); ?>,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</div> </div>
<script>
const searchInput = document.getElementById('searchInput');
const filePreview = document.getElementById('filePreview');
const textarea = filePreview.querySelector('textarea');
const originalContent = textarea.value;
searchInput.addEventListener('input', filterFileContent);
function filterFileContent() {
const searchTerm = searchInput.value.trim().toLowerCase();
const fileContent = textarea.value.toLowerCase();
const lines = fileContent.split('\n');
let filteredContent = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.includes(searchTerm)) {
filteredContent += `${line}\n`;
}
}
textarea.value = filteredContent;
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const tickCheckbox = document.getElementById('tickCheckbox');
// Check the stored checkbox state on page load
const storedCheckboxState = localStorage.getItem('tickCheckboxState');
if (storedCheckboxState === 'checked') {
tickCheckbox.checked = true;
}
// Function to reload the page after 10 seconds
function reloadPage() {
location.reload(); // Reload the current page
}
// Check if the checkbox is ticked every second
setInterval(function() {
if (tickCheckbox.checked) {
// Store the checkbox state in localStorage
localStorage.setItem('tickCheckboxState', 'checked');
setTimeout(reloadPage, 5000); // 10000 milliseconds = 10 seconds
} else {
// Remove the stored checkbox state if not checked
localStorage.removeItem('tickCheckboxState');
}
}, 1000); // Check every 1 second (1000 milliseconds)
});
</script>
</div> </div>
<script>
const searchInput = document.getElementById('searchInput');
const filePreview = document.getElementById('filePreview');
const textarea = filePreview.querySelector('textarea');
const originalContent = textarea.value;
searchInput.addEventListener('input', filterFileContent);
function filterFileContent() {
const searchTerm = searchInput.value.trim().toLowerCase();
const fileContent = textarea.value.toLowerCase();
const lines = fileContent.split('\n');
let filteredContent = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.includes(searchTerm)) {
filteredContent += `${line}\n`;
}
}
textarea.value = filteredContent;
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const tickCheckbox = document.getElementById('tickCheckbox');
// Check the stored checkbox state on page load
const storedCheckboxState = localStorage.getItem('tickCheckboxState');
if (storedCheckboxState === 'checked') {
tickCheckbox.checked = true;
}
// Function to reload the page after 10 seconds
function reloadPage() {
location.reload(); // Reload the current page
}
// Check if the checkbox is ticked every second
setInterval(function() {
if (tickCheckbox.checked) {
// Store the checkbox state in localStorage
localStorage.setItem('tickCheckboxState', 'checked');
setTimeout(reloadPage, 5000); // 10000 milliseconds = 10 seconds
} else {
// Remove the stored checkbox state if not checked
localStorage.removeItem('tickCheckboxState');
}
}, 1000); // Check every 1 second (1000 milliseconds)
});
</script>
</body> </html>