Subversion Repositories ALCASAR

Rev

Rev 2865 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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