Subversion Repositories ALCASAR

Rev

Rev 2182 | Rev 2267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2182 tom.houday 1
<?php
2191 tom.houday 2
# $Id: admin_log.php 2191 2017-04-28 22:00:32Z tom.houdayer $
2093 raphael.pi 3
 
2182 tom.houday 4
$Language = 'en';
5
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
6
	$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
7
	$Language = strtolower(substr(chop($Langue[0]), 0, 2)); 
2093 raphael.pi 8
}
9
 
2182 tom.houday 10
if ($Language === 'fr') {
11
	$l_title_amdin_log = "Connexion à l'ALCASAR Control Center (ACC)";
12
} else {
13
	$l_title_amdin_log = "Connection to ALCASAR Control Center (ACC)";
2093 raphael.pi 14
}
15
 
2182 tom.houday 16
// Read access log
17
$accessLogs = [];
18
$accessLogFilename = 'admin_log.txt';
19
$filePtn = fopen($accessLogFilename, 'r');
20
if ($filePtn !== false){
21
	while (!feof($filePtn)) {
22
		$ligne = fgets($filePtn);
23
		if (empty($ligne)) {
24
			continue;
25
		}
26
		$infos = explode('|||', $ligne);
27
		$accessLogs[] = (object) [
28
			'date'     => trim($infos[0]),
29
			'username' => trim($infos[1]),
30
			'ip'       => trim($infos[2])
31
		];
2093 raphael.pi 32
	}
2182 tom.houday 33
	fclose($filePtn);
2093 raphael.pi 34
}
2182 tom.houday 35
$accessLogs = array_reverse($accessLogs);
2093 raphael.pi 36
 
2191 tom.houday 37
// Remove access before startTime
38
if (isset($_GET['startTime'])) {
39
	$startTime = intval($_GET['startTime']);
40
	foreach ($accessLogs as $key => $access) {
41
		$timestamp = date_timestamp_get(date_create_from_format('d/m/Y H:i:s', $access->date));
42
		if ($timestamp < $startTime) {
43
			$accessLogs = array_slice($accessLogs, 0, $key);
44
			break;
45
		}
46
	}
47
}
48
 
2093 raphael.pi 49
?>
2182 tom.houday 50
<!doctype html>
51
<html>
52
<head>
53
	<meta charset="utf-8">
54
	<title>Admin Logs</title>
55
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
56
	<style>
57
	body {
58
		background-color: #EFEFEF;
59
	}
60
	</style>
61
	<script src="../js/jquery.min.js"></script>
62
	<script src="../js/bootstrap.min.js"></script>
63
</head>
64
<body>
65
	<div class="container">
66
		<center>
67
			<h3><?= $l_title_amdin_log ?></h3>
68
		</center>
69
		<table class="table table-striped">
70
			<thead>
71
				<tr>
72
					<th>Date</th>
73
					<th>User</th>
74
					<th>IP address</th>
75
				</tr>
76
			</thead>
77
			<tbody>
78
				<?php if (empty($accessLogs)): ?>
79
					<tr>
80
						<td colspan="3"><center>Empty</center></td>
81
					</tr>
82
				<?php else: ?>
83
					<?php foreach ($accessLogs as $access): ?>
84
						<tr>
85
							<td><?= $access->date ?></td>
86
							<td><?= $access->username ?></td>
87
							<td><?= $access->ip ?></td>
88
						</tr>
89
					<?php endforeach; ?>
90
				<?php endif; ?>
91
			</tbody>
92
		</table>
93
	</div>
2093 raphael.pi 94
</body>
2182 tom.houday 95
</html>