Subversion Repositories ALCASAR

Rev

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

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