Subversion Repositories ALCASAR

Rev

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

Rev 2405 Rev 2455
1
<?php
1
<?php
2
# $Id: security.php 2405 2017-08-28 18:20:43Z tom.houdayer $
2
# $Id: security.php 2455 2017-12-09 19:14:05Z tom.houdayer $
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
<!DOCTYPE html>
20
<!DOCTYPE html>
21
<html>
21
<html>
22
<head>
22
<head>
23
	<meta charset="UTF-8">
23
	<meta charset="UTF-8">
24
	<title><?= $l_title ?></title>
24
	<title><?= $l_title ?></title>
25
	<link rel="stylesheet" href="/css/bootstrap.min.css">
25
	<link rel="stylesheet" href="/css/bootstrap.min.css">
26
	<script src="/js/jquery.min.js"></script>
26
	<script src="/js/jquery.min.js"></script>
27
	<script src="/js/bootstrap.min.js"></script>
27
	<script src="/js/bootstrap.min.js"></script>
28
	<style>
28
	<style>
29
		body {
29
		body {
30
			background-color: #EFEFEF;
30
			background-color: #EFEFEF;
31
		}
31
		}
32
	</style>
32
	</style>
33
</head>
33
</head>
34
<body>
34
<body>
35
<br>
35
<br>
36
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
36
<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> 
37
	<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>
38
	<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>  
39
	<a href="security.php?tab=3" class="btn btn-default<?= (($tab === 3) ? ' active' : '') ?>" role="button"><?= $l_fail2ban ?></a>  
40
</div>
40
</div>
41
<br>
41
<br>
42
 
42
 
43
 
43
 
44
<?php
44
<?php
45
if ($tab === 1) {
45
if ($tab === 1) {
46
	$spoofs = [];
46
	$spoofs = [];
47
	$regex = '/^\[(?P<date>[0-9]{2}\/[0-9]{2}\/[0-9]{4}-[0-9]{2}:[0-9]{2}:[0-9]{2})\] : 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>.+)\)\.$/';
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>.+)\)\.$/';
48
	$file = fopen('/var/Save/security/watchdog.log', 'r');
48
	$file = fopen('/var/Save/security/watchdog.log', 'r');
49
	if ($file) {
49
	if ($file) {
50
		while (!feof($file)) {
50
		while (!feof($file)) {
51
			$line = fgets($file);
51
			$line = fgets($file);
52
 
52
 
53
			if (preg_match($regex, $line, $matches)) {
53
			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)) {
-
 
55
					$matches['date'] = DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s');
-
 
56
				}
54
				$spoofs[] = (object) [
57
				$spoofs[] = (object) [
55
					'date' => DateTime::createFromFormat('d/m/Y-H:i:s', $matches['date'])->format('Y-m-d H:i:s'),
58
					'date' => $matches['date'],
56
					'ip'   => $matches['ip'],
59
					'ip'   => $matches['ip'],
57
					'mac'  => $matches['mac'],
60
					'mac'  => $matches['mac'],
58
					'user' => $matches['user']
61
					'user' => $matches['user']
59
				];
62
				];
60
			}
63
			}
61
		}
64
		}
62
		fclose($file);
65
		fclose($file);
63
	}
66
	}
64
 
67
 
65
	$spoofs = array_reverse($spoofs);
68
	$spoofs = array_reverse($spoofs);
66
?>
69
?>
67
	<h3 style="text-align: center;"><?= $l_spoofing ?></h3>
70
	<h3 style="text-align: center;"><?= $l_spoofing ?></h3>
68
	<div class="container">
71
	<div class="container">
69
		<table class="table table-striped table-hover">
72
		<table class="table table-striped table-hover">
70
			<thead>
73
			<thead>
71
				<tr><th>Date</th><th><?= $l_ipAddress ?></th><th>MAC</th><th><?= $l_user ?></th></tr>
74
				<tr><th>Date</th><th><?= $l_ipAddress ?></th><th>MAC</th><th><?= $l_user ?></th></tr>
72
			</thead>
75
			</thead>
73
			<tbody>
76
			<tbody>
74
				<?php if (!empty($spoofs)): ?>
77
				<?php if (!empty($spoofs)): ?>
75
					<?php foreach ($spoofs as $spoof): ?>
78
					<?php foreach ($spoofs as $spoof): ?>
76
						<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
79
						<tr><td><?= $spoof->date ?></td><td><?= $spoof->ip ?></td><td><?= $spoof->mac ?></td><td><?= $spoof->user ?></td></tr>
77
					<?php endforeach; ?>
80
					<?php endforeach; ?>
78
				<?php else: ?>
81
				<?php else: ?>
79
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
82
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
80
				<?php endif; ?>
83
				<?php endif; ?>
81
			</tbody>
84
			</tbody>
82
		</table>
85
		</table>
83
	</div>
86
	</div>
84
<?php
87
<?php
85
} else if ($tab === 2) {
88
} else if ($tab === 2) {
86
	$filePath = '/var/log/havp/access.log';
89
	$filePath = '/var/log/havp/access.log';
87
	$lines = file($filePath);
90
	$lines = file($filePath);
88
	if ($lines === false) {
91
	if ($lines === false) {
89
		exit("Cannot open '$filePath'.");
92
		exit("Cannot open '$filePath'.");
90
	}
93
	}
91
 
94
 
92
	$lines = array_reverse($lines);
95
	$lines = array_reverse($lines);
93
?>
96
?>
94
	<h3 style="text-align: center;"><?= $l_virus ?></h3>
97
	<h3 style="text-align: center;"><?= $l_virus ?></h3>
95
	<div class="container">
98
	<div class="container">
96
		<table class="table table-striped table-hover">
99
		<table class="table table-striped table-hover">
97
			<tbody>
100
			<tbody>
98
				<?php if (!empty($lines)): ?>
101
				<?php if (!empty($lines)): ?>
99
					<?php foreach ($lines as $line): ?>
102
					<?php foreach ($lines as $line): ?>
100
						<tr><td><?= $line ?></td></tr>
103
						<tr><td><?= $line ?></td></tr>
101
					<?php endforeach; ?>
104
					<?php endforeach; ?>
102
				<?php else: ?>
105
				<?php else: ?>
103
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
106
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
104
				<?php endif; ?>
107
				<?php endif; ?>
105
			</tbody>
108
			</tbody>
106
		</table>
109
		</table>
107
	</div>
110
	</div>
108
<?php
111
<?php
109
} else if ($tab === 3) {
112
} else if ($tab === 3) {
110
	$bans = [];
113
	$bans = [];
111
	$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})$/';
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})$/';
112
	$file = fopen('/var/log/fail2ban.log', 'r');
115
	$file = fopen('/var/log/fail2ban.log', 'r');
113
	if ($file) {
116
	if ($file) {
114
		while (!feof($file)) {
117
		while (!feof($file)) {
115
			$line = fgets($file);
118
			$line = fgets($file);
116
 
119
 
117
			if (preg_match($regex, $line, $matches)) {
120
			if (preg_match($regex, $line, $matches)) {
118
				if ($matches['type'] === 'Ban') {
121
				if ($matches['type'] === 'Ban') {
119
					$bans[] = (object) [
122
					$bans[] = (object) [
120
						'date_ban'   => $matches['date'],
123
						'date_ban'   => $matches['date'],
121
						'date_unban' => null,
124
						'date_unban' => null,
122
						'rule'       => $matches['rule'],
125
						'rule'       => $matches['rule'],
123
						'ip'         => $matches['ip']
126
						'ip'         => $matches['ip']
124
					];
127
					];
125
				} else if ($matches['type'] === 'Unban') {
128
				} else if ($matches['type'] === 'Unban') {
126
					foreach (array_reverse($bans) as $ban) {
129
					foreach (array_reverse($bans) as $ban) {
127
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
130
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
128
							$ban->date_unban = $matches['date'];
131
							$ban->date_unban = $matches['date'];
129
							break;
132
							break;
130
						}
133
						}
131
					}
134
					}
132
				}
135
				}
133
			}
136
			}
134
		}
137
		}
135
		fclose($file);
138
		fclose($file);
136
	}
139
	}
137
 
140
 
138
	$bans = array_reverse($bans);
141
	$bans = array_reverse($bans);
139
?>
142
?>
140
	<h3 style="text-align: center;"><?= $l_fail2ban ?></h3>
143
	<h3 style="text-align: center;"><?= $l_fail2ban ?></h3>
141
	<div class="container">
144
	<div class="container">
142
		<table class="table table-striped table-hover">
145
		<table class="table table-striped table-hover">
143
			<thead>
146
			<thead>
144
				<tr><th>Date</th><th>Date Unban</th><th><?= $l_rule ?></th><th><?= $l_ipAddress ?></th></tr>
147
				<tr><th>Date</th><th>Date Unban</th><th><?= $l_rule ?></th><th><?= $l_ipAddress ?></th></tr>
145
			</thead>
148
			</thead>
146
			<tbody>
149
			<tbody>
147
				<?php if (!empty($bans)): ?>
150
				<?php if (!empty($bans)): ?>
148
					<?php foreach ($bans as $ban): ?>
151
					<?php foreach ($bans as $ban): ?>
149
						<tr><td><?= $ban->date_ban ?></td><td><?= $ban->date_unban ?></td><td><?= $ban->rule ?></td><td><?= $ban->ip ?></td></tr>
152
						<tr><td><?= $ban->date_ban ?></td><td><?= $ban->date_unban ?></td><td><?= $ban->rule ?></td><td><?= $ban->ip ?></td></tr>
150
					<?php endforeach; ?>
153
					<?php endforeach; ?>
151
				<?php else: ?>
154
				<?php else: ?>
152
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
155
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
153
				<?php endif; ?>
156
				<?php endif; ?>
154
			</tbody>
157
			</tbody>
155
		</table>
158
		</table>
156
	</div>
159
	</div>
157
<?php
160
<?php
158
} else {
161
} else {
159
	echo 'Unknown tab';
162
	echo 'Unknown tab';
160
}
163
}
161
?>
164
?>
162
</body>
165
</body>
163
</html>
166
</html>
164
 
167