Subversion Repositories ALCASAR

Rev

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

Rev 2527 Rev 2810
1
<?php
1
<?php
2
# $Id: security.php 2527 2018-04-16 08:49:00Z fabien.rako $
2
# $Id: security.php 2810 2020-04-14 11:30:11Z rexy $
3
 
-
 
4
//gestion de la langue
-
 
5
require('../lib/langues.php');
-
 
6
 
3
 
7
$language = 'en';
4
$language = 'en';
8
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
5
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
9
	$langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
6
	$langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
10
	$language = strtolower(substr(chop($langue[0]), 0, 2));
7
	$language = strtolower(substr(chop($langue[0]), 0, 2));
11
}
8
}
12
if ($language === 'fr') {
9
if ($language === 'fr') {
13
	$l_title = 'Sécurité';
10
	$l_title = 'Sécurité';
-
 
11
    $l_spoofing = "Adresse(s) MAC usurpée(s) (Watchdog)";
-
 
12
    $l_virus = "Virus bloqué(s) (HAVP)";
-
 
13
    $l_fail2ban = "Adresse(s) IP bloquée(s) (Fail2Ban)";
-
 
14
    $l_ipAddress="Adresse IP";
-
 
15
    $l_user = "L'utilisateur";
-
 
16
    $l_empty="Vide";
-
 
17
    $l_rule="Règle";
14
} else {
18
} else {
15
	$l_title = 'Security';
19
	$l_title = 'Security';
-
 
20
	$l_spoofing = "MAC address spoofed (Watchdog)";
-
 
21
    $l_virus = "Virus blocked (HAVP)";
-
 
22
    $l_fail2ban = "IP address blocked (Fail2Ban)";
-
 
23
    $l_ipAddress="IP address";
-
 
24
    $l_user = "User";
-
 
25
    $l_empty="Empty";
-
 
26
    $l_rule="Rule";
16
}
27
}
17
 
-
 
18
$tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1;
28
$tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1;
19
 
-
 
20
?>
29
?>
21
 
-
 
22
 
-
 
-
 
30
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
23
<html>
31
<html>
24
<head>
32
<head>
25
	<meta charset="UTF-8">
33
	<meta charset="UTF-8">
26
	<title><?= $l_title ?></title>
34
	<title><?= $l_title ?></title>
27
	<link rel="stylesheet" href="/css/bootstrap.min.css">
35
	<link rel="stylesheet" href="/css/bootstrap.min.css">
28
	<script src="/js/jquery.min.js"></script>
36
	<script src="/js/jquery.min.js"></script>
29
	<script src="/js/bootstrap.min.js"></script>
37
	<script src="/js/bootstrap.min.js"></script>
30
	<link rel="stylesheet" href="style.css">
38
	<link rel="stylesheet" href="style.css">
31
	<style>
39
	<style>
32
		body {
40
		body {
33
			background-color: #EFEFEF;
41
			background-color: #EFEFEF;
34
		}
42
		}
35
	</style>
43
	</style>
36
</head>
44
</head>
37
 
-
 
38
<body>
45
<body>
39
<table  class="tableTop" border=0 cellspacing=0 cellpadding=0 >
46
<table  class="tableTop" border=0 cellspacing=0 cellpadding=0 >
40
	<tbody >	
47
	<tbody >	
41
		<tr>
48
		<tr>
42
			<th class="thBasicACC">
49
			<th class="thBasicACC">
43
				<?echo "$l_title";?>
50
				<?echo "$l_title";?>
44
			</th>
51
			</th>
45
		</tr>
52
		</tr>
46
		<tr bgcolor="#FFCC66" class="trSizeACC">
53
		<tr bgcolor="#FFCC66" class="trSizeACC">
47
			<td class="tdSizeACC">
54
			<td class="tdSizeACC">
48
				<img src="/images/pix.gif" width=1 height=2>
55
				<img src="/images/pix.gif" width=1 height=2>
49
			</td>
56
			</td>
50
		</tr>
57
		</tr>
51
	</tbody>
58
	</tbody>
52
</table>
59
</table>
53
 
-
 
54
<div class="frameBorderACC">
60
<div class="frameBorderACC">
55
 
-
 
56
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
61
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
57
	<a href="security.php?tab=1" class="btn btn-default<?= (($tab === 1) ? ' active' : '') ?>" role="button"><?= $l_spoofing ?></a> 
62
	<a href="security.php?tab=1" class="btn btn-default<?= (($tab === 1) ? ' active' : '') ?>" role="button"><?= $l_spoofing ?></a>
58
	<a href="security.php?tab=2" class="btn btn-default<?= (($tab === 2) ? ' active' : '') ?>" role="button"><?= $l_virus ?></a>
63
	<a href="security.php?tab=2" class="btn btn-default<?= (($tab === 2) ? ' active' : '') ?>" role="button"><?= $l_virus ?></a>
59
	<a href="security.php?tab=3" class="btn btn-default<?= (($tab === 3) ? ' active' : '') ?>" role="button"><?= $l_fail2ban ?></a>  
64
	<a href="security.php?tab=3" class="btn btn-default<?= (($tab === 3) ? ' active' : '') ?>" role="button"><?= $l_fail2ban ?></a>
60
</div>
65
</div>
61
<br>
66
<br>
62
 
-
 
63
 
-
 
64
<?php
67
<?php
65
if ($tab === 1) {
68
if ($tab === 1) {
66
	$spoofs = [];
69
	$spoofs = [];
67
	$regex = '/^\[(?P<date>[0-9\/\-: ]+)\] : alcasar-watchdog : (?P<ip>(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])) is usurped \((?P<mac>(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2})\)\. Alcasar disconnect the user \((?P<user>.+)\)\.$/';
70
	$regex = '/^\[(?P<date>[0-9\/\-: ]+)\] : alcasar-watchdog : (?P<ip>(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])) is usurped \((?P<mac>(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2})\)\. Alcasar disconnect the user \((?P<user>.+)\)\.$/';
68
	$file = fopen('/var/Save/security/watchdog.log', 'r');
71
	$file = fopen('/var/Save/security/watchdog.log', 'r');
69
	if ($file) {
72
	if ($file) {
70
		while (!feof($file)) {
73
		while (!feof($file)) {
71
			$line = fgets($file);
74
			$line = fgets($file);
72
 
75
 
73
			if (preg_match($regex, $line, $matches)) {
76
			if (preg_match($regex, $line, $matches)) {
74
				if (preg_match('/[0-9]{2}\/[0-9]{2}\/[0-9]{4}-[0-9]{2}:[0-9]{2}:[0-9]{2}/', $matches['date'], $matches_date)) {
77
				if (preg_match('/[0-9]{2}\/[0-9]{2}\/[0-9]{4}-[0-9]{2}:[0-9]{2}:[0-9]{2}/', $matches['date'], $matches_date)) {
75
					$matches['date'] = DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s');
78
					$matches['date'] = DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s');
76
				}
79
				}
77
				$spoofs[] = (object) [
80
				$spoofs[] = (object) [
78
					'date' => $matches['date'],
81
					'date' => $matches['date'],
79
					'ip'   => $matches['ip'],
82
					'ip'   => $matches['ip'],
80
					'mac'  => $matches['mac'],
83
					'mac'  => $matches['mac'],
81
					'user' => $matches['user']
84
					'user' => $matches['user']
82
				];
85
				];
83
			}
86
			}
84
		}
87
		}
85
		fclose($file);
88
		fclose($file);
86
	}
89
	}
87
 
-
 
88
	$spoofs = array_reverse($spoofs);
90
	$spoofs = array_reverse($spoofs);
89
?>
91
?>
90
<h3 style="text-align: center;"><?= $l_spoofing ?></h3>
92
<h3 style="text-align: center;"><?= $l_spoofing ?></h3>
91
	<div class="container">
93
	<div class="container">
92
		<table style='font-family: "DejaVu Sans";font-size: small;color: #666650;' class="table table-striped  tableBis table-hover" border="1">		
94
		<table style='font-family: "DejaVu Sans";font-size: small;color: #666650;' class="table table-striped  tableBis table-hover" border="1">		
93
				<tr>
95
				<tr>
94
					<th class="thSecurityBis" >
96
					<th class="thSecurityBis" >
95
						Date
97
						Date
96
					</th>
98
					</th>
97
					<th class="thSecurityBis">
99
					<th class="thSecurityBis">
98
						<?= $l_ipAddress ?>	
100
						<?= $l_ipAddress ?>	
99
					</th>
101
					</th>
100
					<th class="thSecurityBis">
102
					<th class="thSecurityBis">
101
						MAC
103
						MAC
102
					</th>
104
					</th>
103
					<th class="thSecurityBis">
105
					<th class="thSecurityBis">
104
						<?= $l_user ?>
106
						<?= $l_user ?>
105
					</th>
107
					</th>
106
				</tr>
108
				</tr>
107
			<tbody>
109
			<tbody>
108
				<?php if (!empty($spoofs)): ?>
110
				<?php if (!empty($spoofs)): ?>
109
					<?php foreach ($spoofs as $spoof): ?>
111
					<?php foreach ($spoofs as $spoof): ?>
110
						<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
112
						<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
111
					<?php endforeach; ?>
113
					<?php endforeach; ?>
112
				<?php else: ?>
114
				<?php else: ?>
113
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
115
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
114
				<?php endif; ?>
116
				<?php endif; ?>
115
			</tbody>
117
			</tbody>
116
		</table>
118
		</table>
117
	</div>
119
	</div>
118
</table>
120
</table>
119
<?php
121
<?php
120
} else if ($tab === 2) {
122
} else if ($tab === 2) {
121
	$filePath = '/var/log/havp/access.log';
123
	$filePath = '/var/log/havp/access.log';
122
	$lines = file($filePath);
124
	$lines = file($filePath);
123
	if ($lines === false) {
125
	if ($lines === false) {
124
		exit("Cannot open '$filePath'.");
126
		exit("Cannot open '$filePath'.");
125
	}
127
	}
126
 
128
 
127
	$lines = array_reverse($lines);
129
	$lines = array_reverse($lines);
128
?>
130
?>
129
	<h3 style="text-align: center;"><?= $l_virus ?></h3>
131
	<h3 style="text-align: center;"><?= $l_virus ?></h3>
130
	<div class="container">
132
	<div class="container">
131
 
133
 
132
		<table class="table table-striped table-hover">
134
		<table class="table table-striped table-hover">
133
			<tbody>
135
			<tbody>
134
				<?php if (!empty($lines)): ?>
136
				<?php if (!empty($lines)): ?>
135
					<?php foreach ($lines as $line): ?>
137
					<?php foreach ($lines as $line): ?>
136
						<tr><td><?= $line ?></td></tr>
138
						<tr><td><?= $line ?></td></tr>
137
					<?php endforeach; ?>
139
					<?php endforeach; ?>
138
				<?php else: ?>
140
				<?php else: ?>
139
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
141
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
140
				<?php endif; ?>
142
				<?php endif; ?>
141
			</tbody>
143
			</tbody>
142
		</table>
144
		</table>
143
	</div>
145
	</div>
144
<?php
146
<?php
145
} else if ($tab === 3) {
147
} else if ($tab === 3) {
146
	$bans = [];
148
	$bans = [];
147
	$regex = '/^(?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}),[0-9]{3} fail2ban\.actions\[[0-9]+\]: WARNING \[(?P<rule>[a-zA-Z0-9_-]+)\] (?P<type>Ban|Unban) (?P<ip>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/';
149
	$regex = '/^(?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}),[0-9]{3} fail2ban\.actions\[[0-9]+\]: WARNING \[(?P<rule>[a-zA-Z0-9_-]+)\] (?P<type>Ban|Unban) (?P<ip>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/';
148
	$file = fopen('/var/log/fail2ban.log', 'r');
150
	$file = fopen('/var/log/fail2ban.log', 'r');
149
	if ($file) {
151
	if ($file) {
150
		while (!feof($file)) {
152
		while (!feof($file)) {
151
			$line = fgets($file);
153
			$line = fgets($file);
152
 
154
 
153
			if (preg_match($regex, $line, $matches)) {
155
			if (preg_match($regex, $line, $matches)) {
154
				if ($matches['type'] === 'Ban') {
156
				if ($matches['type'] === 'Ban') {
155
					$bans[] = (object) [
157
					$bans[] = (object) [
156
						'date_ban'   => $matches['date'],
158
						'date_ban'   => $matches['date'],
157
						'date_unban' => null,
159
						'date_unban' => null,
158
						'rule'       => $matches['rule'],
160
						'rule'       => $matches['rule'],
159
						'ip'         => $matches['ip']
161
						'ip'         => $matches['ip']
160
					];
162
					];
161
				} else if ($matches['type'] === 'Unban') {
163
				} else if ($matches['type'] === 'Unban') {
162
					foreach (array_reverse($bans) as $ban) {
164
					foreach (array_reverse($bans) as $ban) {
163
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
165
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
164
							$ban->date_unban = $matches['date'];
166
							$ban->date_unban = $matches['date'];
165
							break;
167
							break;
166
						}
168
						}
167
					}
169
					}
168
				}
170
				}
169
			}
171
			}
170
		}
172
		}
171
		fclose($file);
173
		fclose($file);
172
	}
174
	}
173
 
-
 
174
	$bans = array_reverse($bans);
175
	$bans = array_reverse($bans);
175
?>
176
?>
176
	<h3 style="text-align: center;"><?= $l_fail2ban ?></h3>
177
	<h3 style="text-align: center;"><?= $l_fail2ban ?></h3>
177
	<div class="container" border="1">
178
	<div class="container" border="1">
178
		<table  class="table tableBis table-striped table-hover" border="1">
179
		<table  class="table tableBis table-striped table-hover" border="1">
179
				<tr >
180
				<tr >
180
					<th class="thSecurityBis" >
181
					<th class="thSecurityBis" >
181
						Date
182
						Date
182
					</th>
183
					</th>
183
					<th class="thSecurityBis" >
184
					<th class="thSecurityBis" >
184
						Date Unban
185
						Date Unban
185
					</th>
186
					</th>
186
					<th class="thSecurityBis" >
187
					<th class="thSecurityBis" >
187
						<?= $l_rule ?>
188
						<?= $l_rule ?>
188
					</th>
189
					</th>
189
					<th class="thSecurityBis" >
190
					<th class="thSecurityBis" >
190
						<?= $l_ipAddress ?>
191
						<?= $l_ipAddress ?>
191
					</th>
192
					</th>
192
				</tr>
193
				</tr>
193
				<?php if (!empty($bans)): ?>
194
				<?php if (!empty($bans)): ?>
194
					<?php foreach ($bans as $ban): ?>
195
					<?php foreach ($bans as $ban): ?>
195
						<tr>
196
						<tr>
196
							<td>
197
							<td>
197
								<?= $ban->date_ban ?>
198
								<?= $ban->date_ban ?>
198
							</td>
199
							</td>
199
							<td>
200
							<td>
200
								<?= $ban->date_unban ?>
201
								<?= $ban->date_unban ?>
201
							</td>
202
							</td>
202
							<td>
203
							<td>
203
								<?= $ban->rule ?>
204
								<?= $ban->rule ?>
204
							</td>
205
							</td>
205
							<td>
206
							<td>
206
								<?= $ban->ip ?>
207
								<?= $ban->ip ?>
207
							</td>
208
							</td>
208
						</tr>
209
						</tr>
209
					<?php endforeach; ?>
210
					<?php endforeach; ?>
210
				<?php else: ?>
211
				<?php else: ?>
211
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
212
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
212
				<?php endif; ?>
213
				<?php endif; ?>
213
		</table>
214
		</table>
214
	</div>
215
	</div>
215
<?php
216
<?php
216
} else {
217
} else {
217
	echo 'Unknown tab';
218
	echo 'Unknown tab';
218
}
219
}
219
?>
220
?>
220
</div>
221
</div>
221
</body>
222
</body>
222
</html>
223
</html>
223
 
224