Subversion Repositories ALCASAR

Rev

Rev 2191 | Rev 2268 | 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 2267 2017-06-04 09:28:36Z richard $
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 = [];
2267 richard 18
$accessLogFilename = '/var/Save/security/acc_access.log';
2182 tom.houday 19
$filePtn = fopen($accessLogFilename, 'r');
20
if ($filePtn !== false){
21
	while (!feof($filePtn)) {
22
		$ligne = fgets($filePtn);
23
		if (empty($ligne)) {
24
			continue;
25
		}
2267 richard 26
		$infos = explode('|', $ligne);
2182 tom.houday 27
		$accessLogs[] = (object) [
2267 richard 28
			'date'     	=> trim($infos[0]),
29
			'username' 	=> trim($infos[1]),
30
			'ip'       	=> trim($infos[2]),
31
			'user_agent'	=> trim($infos[3])
2182 tom.houday 32
		];
2093 raphael.pi 33
	}
2182 tom.houday 34
	fclose($filePtn);
2093 raphael.pi 35
}
2182 tom.houday 36
$accessLogs = array_reverse($accessLogs);
2093 raphael.pi 37
 
2191 tom.houday 38
// Remove access before startTime
39
if (isset($_GET['startTime'])) {
40
	$startTime = intval($_GET['startTime']);
41
	foreach ($accessLogs as $key => $access) {
42
		$timestamp = date_timestamp_get(date_create_from_format('d/m/Y H:i:s', $access->date));
43
		if ($timestamp < $startTime) {
44
			$accessLogs = array_slice($accessLogs, 0, $key);
45
			break;
46
		}
47
	}
48
}
49
 
2093 raphael.pi 50
?>
2182 tom.houday 51
<!doctype html>
52
<html>
53
<head>
54
	<meta charset="utf-8">
55
	<title>Admin Logs</title>
56
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
57
	<style>
58
	body {
59
		background-color: #EFEFEF;
60
	}
61
	</style>
62
	<script src="../js/jquery.min.js"></script>
63
	<script src="../js/bootstrap.min.js"></script>
64
</head>
65
<body>
66
	<div class="container">
67
		<center>
68
			<h3><?= $l_title_amdin_log ?></h3>
69
		</center>
70
		<table class="table table-striped">
71
			<thead>
72
				<tr>
73
					<th>Date</th>
74
					<th>User</th>
75
					<th>IP address</th>
2267 richard 76
					<th>Agent</th>
2182 tom.houday 77
				</tr>
78
			</thead>
79
			<tbody>
80
				<?php if (empty($accessLogs)): ?>
81
					<tr>
82
						<td colspan="3"><center>Empty</center></td>
83
					</tr>
84
				<?php else: ?>
85
					<?php foreach ($accessLogs as $access): ?>
86
						<tr>
87
							<td><?= $access->date ?></td>
88
							<td><?= $access->username ?></td>
89
							<td><?= $access->ip ?></td>
2267 richard 90
							<td><?= $access->user_agent ?></td>
2182 tom.houday 91
						</tr>
92
					<?php endforeach; ?>
93
				<?php endif; ?>
94
			</tbody>
95
		</table>
96
	</div>
2093 raphael.pi 97
</body>
2182 tom.houday 98
</html>