Subversion Repositories ALCASAR

Rev

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

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