Subversion Repositories ALCASAR

Rev

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 2818 2020-05-10 21:53:28Z rexy $
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
}
2182 tom.houday 9
if ($Language === 'fr') {
2268 richard 10
	$l_title	= "Connexion à l'ALCASAR Control Center (ACC)";
11
	$l_user		= "Utilisateur";
12
	$l_ip_address	= "Adresse IP";
2182 tom.houday 13
} else {
2268 richard 14
	$l_title	= "Connection to ALCASAR Control Center (ACC)";
15
	$l_user		= "User";
16
	$l_ip_address	= "IP address";
2093 raphael.pi 17
}
2182 tom.houday 18
// Read access log
19
$accessLogs = [];
2267 richard 20
$accessLogFilename = '/var/Save/security/acc_access.log';
2182 tom.houday 21
$filePtn = fopen($accessLogFilename, 'r');
22
if ($filePtn !== false){
23
	while (!feof($filePtn)) {
24
		$ligne = fgets($filePtn);
25
		if (empty($ligne)) {
26
			continue;
27
		}
2267 richard 28
		$infos = explode('|', $ligne);
2182 tom.houday 29
		$accessLogs[] = (object) [
2267 richard 30
			'date'     	=> trim($infos[0]),
31
			'username' 	=> trim($infos[1]),
32
			'ip'       	=> trim($infos[2]),
33
			'user_agent'	=> trim($infos[3])
2182 tom.houday 34
		];
2093 raphael.pi 35
	}
2182 tom.houday 36
	fclose($filePtn);
2093 raphael.pi 37
}
2182 tom.houday 38
$accessLogs = array_reverse($accessLogs);
2093 raphael.pi 39
 
2191 tom.houday 40
// Remove access before startTime
41
if (isset($_GET['startTime'])) {
42
	$startTime = intval($_GET['startTime']);
43
	foreach ($accessLogs as $key => $access) {
44
		$timestamp = date_timestamp_get(date_create_from_format('d/m/Y H:i:s', $access->date));
45
		if ($timestamp < $startTime) {
46
			$accessLogs = array_slice($accessLogs, 0, $key);
47
			break;
48
		}
49
	}
50
}
51
 
2093 raphael.pi 52
?>
2818 rexy 53
<!DOCTYPE html>
2182 tom.houday 54
<html>
55
<head>
2818 rexy 56
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2182 tom.houday 57
	<title>Admin Logs</title>
2818 rexy 58
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
2182 tom.houday 59
</head>
60
<body>
2818 rexy 61
<div class="panel">
62
	<div class="panel-header"><?= $l_title ?></div>
63
	<div class="panel-row">
64
		<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
65
		<tr><td>
66
			<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
2268 richard 67
			<tr>
2818 rexy 68
				<th>Date</th>
69
				<th><?=$l_user?></th>
70
				<th><?=$l_ip_address?></th>
71
				<th>Agent</th>
72
			</tr>
73
			<?php if (empty($accessLogs)): ?>
74
			<tr>
2268 richard 75
				<td colspan="4"><center>Empty</center></td>
76
			</tr>
2818 rexy 77
			<?php else: ?>
2268 richard 78
			<?php foreach ($accessLogs as $access): ?>
79
			<tr>
2818 rexy 80
				<td><?= $access->date ?></td>
81
				<td><?= $access->username ?></td>
82
				<td><?= $access->ip ?></td>
83
				<td><?= $access->user_agent ?></td>
84
			</tr>
2268 richard 85
			<?php endforeach; ?>
2818 rexy 86
			<?php endif; ?>
87
			</table>
88
		</table>
89
	</div>
90
</div>
2093 raphael.pi 91
</body>
2182 tom.houday 92
</html>