Subversion Repositories ALCASAR

Rev

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

Rev 2841 Rev 2845
1
<?php
1
<?php
2
# $Id: security.php 2841 2020-06-28 21:49:00Z rexy $
2
# $Id: security.php 2845 2020-07-04 17:54:03Z 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_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 (CLAMAV)";
21
    $l_virus = "Virus blocked (CLAMAV)";
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>
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="/css/acc.css">
38
		<link rel="stylesheet" href="/css/acc.css">
39
	</head>
39
	</head>
40
	<body>
40
	<body>
41
		<div class="panel">
41
		<div class="panel">
42
			<div class="panel-header"><?= $l_title ?></div>
42
			<div class="panel-header"><?= $l_title ?></div>
43
			<div class="panel-row">
43
			<div class="panel-row">
44
				<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"> 
45
					<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>
46
					<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>
47
					<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>
48
				</div>
48
				</div>
49
<?php
49
<?php
50
if ($tab === 1) {
50
if ($tab === 1) {
51
	$spoofs = [];
51
	$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>.+)\)\.$/';
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>.+)\)\.$/';
53
	$file = fopen('/var/Save/security/watchdog.log', 'r');
53
	$file = fopen('/var/Save/security/watchdog.log', 'r');
54
	if ($file) {
54
	if ($file) {
55
		while (!feof($file)) {
55
		while (!feof($file)) {
56
			$line = fgets($file);
56
			$line = fgets($file);
57
 
57
 
58
			if (preg_match($regex, $line, $matches)) {
58
			if (preg_match($regex, $line, $matches)) {
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)) {
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)) {
60
					$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');
61
				}
61
				}
62
				$spoofs[] = (object) [
62
				$spoofs[] = (object) [
63
					'date' => $matches['date'],
63
					'date' => $matches['date'],
64
					'ip'   => $matches['ip'],
64
					'ip'   => $matches['ip'],
65
					'mac'  => $matches['mac'],
65
					'mac'  => $matches['mac'],
66
					'user' => $matches['user']
66
					'user' => $matches['user']
67
				];
67
				];
68
			}
68
			}
69
		}
69
		}
70
		fclose($file);
70
		fclose($file);
71
	}
71
	}
72
	$spoofs = array_reverse($spoofs);
72
	$spoofs = array_reverse($spoofs);
73
?>
73
?>
74
			<h3><?= $l_spoofing ?></h3>
74
			<h3><?= $l_spoofing ?></h3>
75
			<div class="container">
75
			<div class="container">
76
				<table class="table table-striped table-hover" border="1">
76
				<table class="table table-striped table-hover" border="1">
77
				<tr>
77
				<tr>
78
					<th>
78
					<th>
79
						Date
79
						Date
80
					</th>
80
					</th>
81
					<th>
81
					<th>
82
						<?= $l_ipAddress ?>	
82
						<?= $l_ipAddress ?>	
83
					</th>
83
					</th>
84
					<th>
84
					<th>
85
						MAC
85
						MAC
86
					</th>
86
					</th>
87
					<th>
87
					<th>
88
						<?= $l_user ?>
88
						<?= $l_user ?>
89
					</th>
89
					</th>
90
				</tr>
90
				</tr>
91
				<tbody>
91
				<tbody>
92
					<?php if (!empty($spoofs)): ?>
92
					<?php if (!empty($spoofs)): ?>
93
					<?php foreach ($spoofs as $spoof): ?>
93
					<?php foreach ($spoofs as $spoof): ?>
94
					<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>
95
					<?php endforeach; ?>
95
					<?php endforeach; ?>
96
					<?php else: ?>
96
					<?php else: ?>
97
					<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>
98
					<?php endif; ?>
98
					<?php endif; ?>
99
				</tbody>
99
				</tbody>
100
				</table>
100
				</table>
101
			</div>
101
			</div>
102
<?php
102
<?php
103
} else if ($tab === 2) {
103
} else if ($tab === 2) {
104
	$filePath = '/var/log/clamav/clamd.log';
104
	$filePath = '/var/log/clamav/clamd.log';
-
 
105
	$pattern = "/\bfound\b/i";
105
	$lines = file($filePath);
106
	$lines = preg_grep ($pattern, file($filePath));
106
	if ($lines === false) {
107
	if ($lines === false) {
107
		exit("Cannot open '$filePath'.");
108
		exit("Cannot open '$filePath'.");
108
	}
109
	}
109
	$lines = array_reverse($lines);
110
	$lines = array_reverse($lines);
110
?>
111
?>
111
	<h3><?= $l_virus ?></h3>
112
	<h3><?= $l_virus ?></h3>
112
	<div class="container">
113
	<div class="container">
113
		<table class="table table-striped table-hover">
114
		<table class="table table-striped table-hover">
114
			<tbody>
115
			<tbody>
115
				<?php if (!empty($lines)): ?>
116
				<?php if (!empty($lines)): ?>
116
					<?php foreach ($lines as $line): ?>
117
					<?php foreach ($lines as $line): ?>
117
						<tr><td><?= $line ?></td></tr>
118
						<tr><td><?= $line ?></td></tr>
118
					<?php endforeach; ?>
119
					<?php endforeach; ?>
119
				<?php else: ?>
120
				<?php else: ?>
120
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
121
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
121
				<?php endif; ?>
122
				<?php endif; ?>
122
			</tbody>
123
			</tbody>
123
		</table>
124
		</table>
124
	</div>
125
	</div>
125
<?php
126
<?php
126
} else if ($tab === 3) {
127
} else if ($tab === 3) {
127
	$bans = [];
128
	$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]+\]: 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})$/';
129
	$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})$/';
129
	$file = fopen('/var/log/fail2ban.log', 'r');
130
	$file = fopen('/var/log/fail2ban.log', 'r');
130
	if ($file) {
131
	if ($file) {
131
		while (!feof($file)) {
132
		while (!feof($file)) {
132
			$line = fgets($file);
133
			$line = fgets($file);
133
 
134
 
134
			if (preg_match($regex, $line, $matches)) {
135
			if (preg_match($regex, $line, $matches)) {
135
				if ($matches['type'] === 'Ban') {
136
				if ($matches['type'] === 'Ban') {
136
					$bans[] = (object) [
137
					$bans[] = (object) [
137
						'date_ban'   => $matches['date'],
138
						'date_ban'   => $matches['date'],
138
						'date_unban' => null,
139
						'date_unban' => null,
139
						'rule'       => $matches['rule'],
140
						'rule'       => $matches['rule'],
140
						'ip'         => $matches['ip']
141
						'ip'         => $matches['ip']
141
					];
142
					];
142
				} else if ($matches['type'] === 'Unban') {
143
				} else if ($matches['type'] === 'Unban') {
143
					foreach (array_reverse($bans) as $ban) {
144
					foreach (array_reverse($bans) as $ban) {
144
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
145
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
145
							$ban->date_unban = $matches['date'];
146
							$ban->date_unban = $matches['date'];
146
							break;
147
							break;
147
						}
148
						}
148
					}
149
					}
149
				}
150
				}
150
			}
151
			}
151
		}
152
		}
152
		fclose($file);
153
		fclose($file);
153
	}
154
	}
154
	$bans = array_reverse($bans);
155
	$bans = array_reverse($bans);
155
?>
156
?>
156
	<h3><?= $l_fail2ban ?></h3>
157
	<h3><?= $l_fail2ban ?></h3>
157
	<div class="container" border="1">
158
	<div class="container" border="1">
158
		<table  class="table table-striped table-hover" border="1">
159
		<table  class="table table-striped table-hover" border="1">
159
				<tr >
160
				<tr >
160
					<th>
161
					<th>
161
						Date
162
						Date
162
					</th>
163
					</th>
163
					<th>
164
					<th>
164
						Date Unban
165
						Date Unban
165
					</th>
166
					</th>
166
					<th>
167
					<th>
167
						<?= $l_rule ?>
168
						<?= $l_rule ?>
168
					</th>
169
					</th>
169
					<th>
170
					<th>
170
						<?= $l_ipAddress ?>
171
						<?= $l_ipAddress ?>
171
					</th>
172
					</th>
172
				</tr>
173
				</tr>
173
				<?php if (!empty($bans)): ?>
174
				<?php if (!empty($bans)): ?>
174
					<?php foreach ($bans as $ban): ?>
175
					<?php foreach ($bans as $ban): ?>
175
						<tr>
176
						<tr>
176
							<td>
177
							<td>
177
								<?= $ban->date_ban ?>
178
								<?= $ban->date_ban ?>
178
							</td>
179
							</td>
179
							<td>
180
							<td>
180
								<?= $ban->date_unban ?>
181
								<?= $ban->date_unban ?>
181
							</td>
182
							</td>
182
							<td>
183
							<td>
183
								<?= $ban->rule ?>
184
								<?= $ban->rule ?>
184
							</td>
185
							</td>
185
							<td>
186
							<td>
186
								<?= $ban->ip ?>
187
								<?= $ban->ip ?>
187
							</td>
188
							</td>
188
						</tr>
189
						</tr>
189
					<?php endforeach; ?>
190
					<?php endforeach; ?>
190
				<?php else: ?>
191
				<?php else: ?>
191
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
192
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
192
				<?php endif; ?>
193
				<?php endif; ?>
193
		</table>
194
		</table>
194
	</div>
195
	</div>
195
<?php
196
<?php
196
} else {
197
} else {
197
	echo 'Unknown tab';
198
	echo 'Unknown tab';
198
}
199
}
199
?>
200
?>
200
	</div>
201
	</div>
201
</div>
202
</div>
202
</body>
203
</body>
203
</html>
204
</html>
204
 
205