Subversion Repositories ALCASAR

Rev

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

Rev 2864 Rev 2865
1
<?php
1
<?php
2
# $Id: security.php 2864 2020-10-18 09:06:17Z rexy $
2
# $Id: security.php 2865 2020-10-18 22:21:46Z 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) (CLAMAV)";
12
    $l_virus = "Virus bloqué(s) (CLAMAV)";
13
    $l_fail2ban = "Adresse(s) IP bloquée(s) (Fail2Ban)";
13
    $l_fail2ban = "Adresse(s) IP bloquée(s) (Fail2Ban)";
-
 
14
    $l_ban_date = "Date de bloquage";
-
 
15
    $l_unban_date = "Date de débloquage";
14
    $l_ipAddress="Adresse IP";
16
    $l_ipAddress="Adresse IP";
15
    $l_user = "L'utilisateur";
17
    $l_user = "L'utilisateur";
16
    $l_empty="Vide";
18
    $l_empty="Vide";
17
    $l_rule="Règle";
19
    $l_rule="Règle";
-
 
20
} else if ($language === 'es') {
-
 
21
    $l_title = 'Seguridad';
-
 
22
    $l_spoofing = "Direcciones MAC usurpadas (Watchdog)";
-
 
23
    $l_virus = "Virus bloqueado (CLAMAV)";
-
 
24
    $l_fail2ban = "Dirección(es) IP bloqueada(s) (Fail2Ban)";
-
 
25
    $l_ban_date = "Fecha de bloqueo"; 
-
 
26
    $l_unban_date = "Fecha de desembolso";
-
 
27
    $l_ipAddress="Dirección ip";
-
 
28
    $l_user = "El usuario";
-
 
29
    $l_empty="Vacío";
-
 
30
    $l_rule="Regla";
18
} else {
31
} else {
19
    $l_title = 'Security';
32
    $l_title = 'Security';
20
    $l_spoofing = "MAC address spoofed (Watchdog)";
33
    $l_spoofing = "MAC address spoofed (Watchdog)";
21
    $l_virus = "Virus blocked (CLAMAV)";
34
    $l_virus = "Virus blocked (CLAMAV)";
22
    $l_fail2ban = "IP address blocked (Fail2Ban)";
35
    $l_fail2ban = "IP address blocked (Fail2Ban)";
-
 
36
    $l_ban_date = "Lock date";
-
 
37
    $l_unban_date = "Unlock date";
23
    $l_ipAddress="IP address";
38
    $l_ipAddress="IP address";
24
    $l_user = "User";
39
    $l_user = "User";
25
    $l_empty="Empty";
40
    $l_empty="Empty";
26
    $l_rule="Rule";
41
    $l_rule="Rule";
27
}
42
}
28
$tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1;
43
$tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1;
29
?>
44
?>
30
<!DOCTYPE HTML>
45
<!DOCTYPE HTML>
31
<html>
46
<html>
32
	<head>
47
	<head>
33
		<meta charset="UTF-8">
48
		<meta charset="UTF-8">
34
		<title><?= $l_title ?></title>
49
		<title><?= $l_title ?></title>
35
		<link rel="stylesheet" href="/css/bootstrap.min.css">
50
		<link rel="stylesheet" href="/css/bootstrap.min.css">
36
		<script src="/js/jquery.min.js"></script>
51
		<script src="/js/jquery.min.js"></script>
37
		<script src="/js/bootstrap.min.js"></script>
52
		<script src="/js/bootstrap.min.js"></script>
38
		<link rel="stylesheet" href="/css/acc.css">
53
		<link rel="stylesheet" href="/css/acc.css">
39
	</head>
54
	</head>
40
	<body>
55
	<body>
41
		<div class="panel">
56
		<div class="panel">
42
			<div class="panel-header"><?= $l_title ?></div>
57
			<div class="panel-header"><?= $l_title ?></div>
43
			<div class="panel-row">
58
			<div class="panel-row">
44
				<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
59
				<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
45
					<a href="security.php?tab=1" class="btn btn-default<?= (($tab === 1) ? ' active' : '') ?>" role="button"><?= $l_spoofing ?></a>
60
					<a href="security.php?tab=1" class="btn btn-default<?= (($tab === 1) ? ' active' : '') ?>" role="button"><?= $l_spoofing ?></a>
46
					<a href="security.php?tab=2" class="btn btn-default<?= (($tab === 2) ? ' active' : '') ?>" role="button"><?= $l_virus ?></a>
61
					<a href="security.php?tab=2" class="btn btn-default<?= (($tab === 2) ? ' active' : '') ?>" role="button"><?= $l_virus ?></a>
47
					<a href="security.php?tab=3" class="btn btn-default<?= (($tab === 3) ? ' active' : '') ?>" role="button"><?= $l_fail2ban ?></a>
62
					<a href="security.php?tab=3" class="btn btn-default<?= (($tab === 3) ? ' active' : '') ?>" role="button"><?= $l_fail2ban ?></a>
48
				</div>
63
				</div>
49
<?php
64
<?php
50
if ($tab === 1) {
65
if ($tab === 1) {
51
	$spoofs = [];
66
	$spoofs = [];
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>.+)\)\.$/';
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>.+)\)\.$/';
53
	$file = fopen('/var/Save/security/watchdog.log', 'r');
68
	$file = fopen('/var/Save/security/watchdog.log', 'r');
54
	if ($file) {
69
	if ($file) {
55
		while (!feof($file)) {
70
		while (!feof($file)) {
56
			$line = fgets($file);
71
			$line = fgets($file);
-
 
72
 
57
			if (preg_match($regex, $line, $matches)) {
73
			if (preg_match($regex, $line, $matches)) {
58
				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)) {
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)) {
59
					$matches['date'] = DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s');
75
					$matches['date'] = DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s');
60
				}
76
				}
61
				$spoofs[] = (object) [
77
				$spoofs[] = (object) [
62
					'date' => $matches['date'],
78
					'date' => $matches['date'],
63
					'ip'   => $matches['ip'],
79
					'ip'   => $matches['ip'],
64
					'mac'  => $matches['mac'],
80
					'mac'  => $matches['mac'],
65
					'user' => $matches['user']
81
					'user' => $matches['user']
66
				];
82
				];
67
			}
83
			}
68
		}
84
		}
69
		fclose($file);
85
		fclose($file);
70
	}
86
	}
71
	$spoofs = array_reverse($spoofs);
87
	$spoofs = array_reverse($spoofs);
72
?>
88
?>
73
			<h3><?= $l_spoofing ?></h3>
89
			<h3><?= $l_spoofing ?></h3>
74
			<div class="container">
90
			<div class="container">
75
				<table class="table table-striped table-hover" border="1">
91
				<table class="table table-striped table-hover" border="1">
76
				<tr>
92
				<tr>
77
					<th>
93
					<th>
78
						Date
94
						Date
79
					</th>
95
					</th>
80
					<th>
96
					<th>
81
						<?= $l_ipAddress ?>	
97
						<?= $l_ipAddress ?>	
82
					</th>
98
					</th>
83
					<th>
99
					<th>
84
						MAC
100
						MAC
85
					</th>
101
					</th>
86
					<th>
102
					<th>
87
						<?= $l_user ?>
103
						<?= $l_user ?>
88
					</th>
104
					</th>
89
				</tr>
105
				</tr>
90
				<tbody>
106
				<tbody>
91
					<?php if (!empty($spoofs)): ?>
107
					<?php if (!empty($spoofs)): ?>
92
					<?php foreach ($spoofs as $spoof): ?>
108
					<?php foreach ($spoofs as $spoof): ?>
93
					<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
109
					<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
94
					<?php endforeach; ?>
110
					<?php endforeach; ?>
95
					<?php else: ?>
111
					<?php else: ?>
96
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
112
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
97
					<?php endif; ?>
113
					<?php endif; ?>
98
				</tbody>
114
				</tbody>
99
				</table>
115
				</table>
100
			</div>
116
			</div>
101
<?php
117
<?php
102
} else if ($tab === 2) {
118
} else if ($tab === 2) {
103
	$filePath = '/var/log/clamav/clamd.log';
119
	$filePath = '/var/log/clamav/clamd.log';
104
	$pattern = "/\bfound\b/i";
120
	$pattern = "/\bfound\b/i";
105
	$lines = preg_grep ($pattern, file($filePath));
121
	$lines = preg_grep ($pattern, file($filePath));
106
	if ($lines === false) {
122
	if ($lines === false) {
107
		exit("Cannot open '$filePath'.");
123
		exit("Cannot open '$filePath'.");
108
	}
124
	}
109
	$lines = array_reverse($lines);
125
	$lines = array_reverse($lines);
110
?>
126
?>
111
	<h3><?= $l_virus ?></h3>
127
	<h3><?= $l_virus ?></h3>
112
	<div class="container">
128
	<div class="container">
113
		<table class="table table-striped table-hover">
129
		<table class="table table-striped table-hover">
114
			<tbody>
130
			<tbody>
115
				<?php if (!empty($lines)): ?>
131
				<?php if (!empty($lines)): ?>
116
					<?php foreach ($lines as $line): ?>
132
					<?php foreach ($lines as $line): ?>
117
						<tr><td><?= $line ?></td></tr>
133
						<tr><td><?= $line ?></td></tr>
118
					<?php endforeach; ?>
134
					<?php endforeach; ?>
119
				<?php else: ?>
135
				<?php else: ?>
120
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
136
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
121
				<?php endif; ?>
137
				<?php endif; ?>
122
			</tbody>
138
			</tbody>
123
		</table>
139
		</table>
124
	</div>
140
	</div>
125
<?php
141
<?php
126
} else if ($tab === 3) {
142
} else if ($tab === 3) {
127
	$bans = [];
143
	$bans = [];
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]+\]: NOTICE \[(?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
	$regex = '/^(?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2}[ \t]+[0-9]{2}:[0-9]{2}:[0-9]{2}),[0-9]{3}[ \t]+fail2ban\.actions[ \t]+\[[0-9]+\]:[ \t]+NOTICE[ \t]+\[(?P<rule>[a-zA-Z0-9_-]+)\][ \t]+(?P<type>Ban|Unban)[ \t]+(?P<ip>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/';
129
	$file = fopen('/var/log/fail2ban.log', 'r');
145
	$file = fopen('/var/log/fail2ban.log', 'r');
130
	if ($file) {
146
	if ($file) {
131
		while (!feof($file)) {
147
		while (!feof($file)) {
132
			$line = fgets($file);
148
			$line = fgets($file);
133
 
-
 
134
			if (preg_match($regex, $line, $matches)) {
149
			if (preg_match($regex, $line, $matches)) {
135
				if ($matches['type'] === 'Ban') {
150
				if ($matches['type'] === 'Ban') {
136
					$bans[] = (object) [
151
					$bans[] = (object) [
137
						'date_ban'   => $matches['date'],
152
						'date_ban'   => $matches['date'],
138
						'date_unban' => null,
153
						'date_unban' => null,
139
						'rule'       => $matches['rule'],
154
						'rule'       => $matches['rule'],
140
						'ip'         => $matches['ip']
155
						'ip'         => $matches['ip']
141
					];
156
					];
142
				} else if ($matches['type'] === 'Unban') {
157
				} else if ($matches['type'] === 'Unban') {
143
					foreach (array_reverse($bans) as $ban) {
158
					foreach (array_reverse($bans) as $ban) {
144
						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)) {
145
							$ban->date_unban = $matches['date'];
160
							$ban->date_unban = $matches['date'];
146
							break;
161
							break;
147
						}
162
						}
148
					}
163
					}
149
				}
164
				}
150
			}
165
			}
151
		}
166
		}
152
		fclose($file);
167
		fclose($file);
153
	}
168
	}
154
	$bans = array_reverse($bans);
169
	$bans = array_reverse($bans);
155
?>
170
?>
156
	<h3><?= $l_fail2ban ?></h3>
171
	<h3><?= $l_fail2ban ?></h3>
157
	<div class="container" border="1">
172
	<div class="container" border="1">
158
		<table  class="table table-striped table-hover" border="1">
173
		<table  class="table table-striped table-hover" border="1">
159
				<tr >
174
				<tr >
160
					<th>
175
					<th>
161
						Date
176
						<?= $l_ban_date ?>
162
					</th>
177
					</th>
163
					<th>
178
					<th>
164
						Date Unban
179
						<?= $l_unban_date ?>
165
					</th>
180
					</th>
166
					<th>
181
					<th>
167
						<?= $l_rule ?>
182
						<?= $l_rule ?>
168
					</th>
183
					</th>
169
					<th>
184
					<th>
170
						<?= $l_ipAddress ?>
185
						<?= $l_ipAddress ?>
171
					</th>
186
					</th>
172
				</tr>
187
				</tr>
173
				<?php if (!empty($bans)): ?>
188
				<?php if (!empty($bans)): ?>
174
					<?php foreach ($bans as $ban): ?>
189
					<?php foreach ($bans as $ban): ?>
175
						<tr>
190
						<tr>
176
							<td>
191
							<td>
177
								<?= $ban->date_ban ?>
192
								<?= $ban->date_ban ?>
178
							</td>
193
							</td>
179
							<td>
194
							<td>
180
								<?= $ban->date_unban ?>
195
								<?= $ban->date_unban ?>
181
							</td>
196
							</td>
182
							<td>
197
							<td>
183
								<?= $ban->rule ?>
198
								<?= $ban->rule ?>
184
							</td>
199
							</td>
185
							<td>
200
							<td>
186
								<?= $ban->ip ?>
201
								<?= $ban->ip ?>
187
							</td>
202
							</td>
188
						</tr>
203
						</tr>
189
					<?php endforeach; ?>
204
					<?php endforeach; ?>
190
				<?php else: ?>
205
				<?php else: ?>
191
					<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>
192
				<?php endif; ?>
207
				<?php endif; ?>
193
		</table>
208
		</table>
194
	</div>
209
	</div>
195
<?php
210
<?php
196
} else {
211
} else {
197
	echo 'Unknown tab';
212
	echo 'Unknown tab';
198
}
213
}
199
?>
214
?>
200
	</div>
215
	</div>
201
</div>
216
</div>
202
</body>
217
</body>
203
</html>
218
</html>
204
 
219