Subversion Repositories ALCASAR

Rev

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

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