Subversion Repositories ALCASAR

Rev

Rev 2810 | Rev 2818 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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