Subversion Repositories ALCASAR

Rev

Rev 2191 | Rev 2268 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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