Subversion Repositories ALCASAR

Rev

Rev 1867 | Rev 2455 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 1867 Rev 2292
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
# $Id: security.php 2292 2017-06-20 14:09:37Z tom.houdayer $
-
 
3
 
2
//gestion de la langue
4
//gestion de la langue
3
if (is_file("../lib/langues.php"))
5
require('../lib/langues.php');
-
 
6
 
-
 
7
$language = 'en';
-
 
8
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
-
 
9
	$langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
-
 
10
	$language = strtolower(substr(chop($langue[0]), 0, 2));
-
 
11
}
-
 
12
if ($language === 'fr') {
-
 
13
	$l_title = 'Sécurité';
-
 
14
} else {
4
	include("../lib/langues.php");
15
	$l_title = 'Security';
-
 
16
}
-
 
17
 
-
 
18
$tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1;
5
?>
19
?>
6
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN//2.0">
20
<!DOCTYPE html>
7
<HTML>
21
<html>
8
<!-- written by Crox -->
-
 
9
<HEAD>
22
<head>
10
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
23
	<meta charset="UTF-8">
11
<TITLE>menu</TITLE>
24
	<title><?= $l_title ?></title>
12
<link rel="stylesheet" href="../../../css/bootstrap.min.css">
25
	<link rel="stylesheet" href="/css/bootstrap.min.css">
13
  <script src="../../../js/jquery.min.js"></script>
26
	<script src="/js/jquery.min.js"></script>
14
  <script src="../../../js/bootstrap.min.js"></script>
27
	<script src="/js/bootstrap.min.js"></script>
15
  <style>
28
	<style>
16
 body {
29
		body {
17
    background-color: #EFEFEF;
30
			background-color: #EFEFEF;
18
	}
31
		}
19
  </style>
32
	</style>
20
</HEAD>
33
</head>
21
<body>
34
<body>
-
 
35
<br>
-
 
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> 
-
 
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>  
-
 
40
</div>
22
 
41
<br>
23
 
42
 
24
 
43
 
25
<?php
44
<?php
26
	$table = 1;
45
if ($tab === 1) {
-
 
46
	$filePath = '/var/Save/security/watchdog.log';
-
 
47
	$lines = file($filePath);
27
	if(isset($_GET['table'])){
48
	if ($lines === false) {
28
		$table = $_GET['table'];
49
		exit("Cannot open '$filePath'.");
29
	}
50
	}
30
?>
-
 
31
 
-
 
32
 
51
 
33
<?php
52
	$lines = array_reverse($lines);
34
 
53
?>
-
 
54
	<h3 style="text-align: center;"><?= $l_spoofing ?></h3>
35
echo'
55
	<div class="container">
-
 
56
		<table class="table table-striped table-hover">
36
	<br />
57
			<tbody>
37
			<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
58
				<?php if (!empty($lines)): ?>
38
			<a href="./security.php?table=1" class="btn btn-default" role="button">'.$l_spoofing.'</a> 
59
					<?php foreach ($lines as $line): ?>
39
			<a href="./security.php?table=2" class="btn btn-default" role="button">'.$l_virus.'</a>
60
						<tr><td><?= $line ?></td></tr>
-
 
61
					<?php endforeach; ?>
-
 
62
				<?php else: ?>
40
			<a href="./security.php?table=3" class="btn btn-default" role="button">'.$l_fail2ban.'</a>  
63
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
-
 
64
				<?php endif; ?>
-
 
65
			</tbody>
-
 
66
		</table>
41
			</div>
67
	</div>
42
	<br />';
68
<?php
-
 
69
} else if ($tab === 2) {
-
 
70
	$filePath = '/var/log/havp/access.log';
-
 
71
	$lines = file($filePath);
-
 
72
	if ($lines === false) {
-
 
73
		exit("Cannot open '$filePath'.");
43
 
74
	}
44
 
75
 
-
 
76
	$lines = array_reverse($lines);
45
?>
77
?>
-
 
78
	<h3 style="text-align: center;"><?= $l_virus ?></h3>
-
 
79
	<div class="container">
-
 
80
		<table class="table table-striped table-hover">
46
 
81
			<tbody>
-
 
82
				<?php if (!empty($lines)): ?>
-
 
83
					<?php foreach ($lines as $line): ?>
-
 
84
						<tr><td><?= $line ?></td></tr>
-
 
85
					<?php endforeach; ?>
-
 
86
				<?php else: ?>
-
 
87
					<tr><td style="text-align: center;"><?= $l_empty ?></td></tr>
-
 
88
				<?php endif; ?>
-
 
89
			</tbody>
-
 
90
		</table>
47
 
91
	</div>
48
<?php
92
<?php
-
 
93
} else if ($tab === 3) {
-
 
94
	$bans = [];
-
 
95
	$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})$/';
-
 
96
	$file = fopen('/var/log/fail2ban.log', 'r');
-
 
97
	if ($file) {
-
 
98
		while (!feof($file)) {
-
 
99
			$line = fgets($file);
49
 
100
 
50
if ( $table == 1){
101
			if (preg_match($regex, $line, $matches)) {
51
 
-
 
52
	echo '<center><h3>';
102
				if ($matches['type'] === 'Ban') {
53
	echo "$l_spoofing";
103
					$bans[] = (object) [
54
	echo '</h3></center><div class="container"><table class="table table-striped"><tbody>';
104
						'date_ban'   => $matches['date'],
55
 
-
 
-
 
105
						'date_unban' => null,
56
	$fichier='/var/Save/security/watchdog.log';
106
						'rule'       => $matches['rule'],
57
	$pointeur=fopen($fichier,"r");
107
						'ip'         => $matches['ip']
58
	if ($pointeur){
108
					];
59
	while (!feof($pointeur)){
109
				} else if ($matches['type'] === 'Unban') {
60
		$ligne=fgets($pointeur);
110
					foreach (array_reverse($bans) as $ban) {
-
 
111
						if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) {
61
		echo "<tr><td>$ligne</td></tr>";
112
							$ban->date_unban = $matches['date'];
-
 
113
							break;
62
		}
114
						}
63
	}
115
					}
64
	else
-
 
65
	{
-
 
66
		echo '<tr><center>Empty</center></tr>';
-
 
67
	}
116
				}
68
	fclose($pointeur);
-
 
69
	echo '</tbody></table></div>';
-
 
70
 
-
 
71
 
-
 
72
} elseif ($table == 2){
-
 
73
	echo '<center><h3>';
-
 
74
	echo "$l_virus";
-
 
75
	echo '</h3></center><div class="container"><table class="table table-striped"><tbody>';
-
 
76
				
-
 
77
	$fichier='/var/log/havp/access.log';
-
 
78
	$pointeur=fopen($fichier,"r");
-
 
79
	if ($pointeur){
-
 
80
	while (!feof($pointeur)){
-
 
81
		$ligne=fgets($pointeur);
-
 
82
		echo "<tr><td>$ligne</td></tr>";
-
 
83
		}
117
			}
84
	}
118
		}
85
	else
119
		fclose($file);
86
	{
-
 
87
		echo '<tr><center>Empty</center></tr>';
-
 
88
	}
120
	}
89
	fclose($pointeur);
-
 
90
	echo '</tbody></table></div>';
-
 
91
	
-
 
92
} elseif ($table == 3){
-
 
93
	echo '<center><h3>';
-
 
94
	echo "$l_fail2ban";
-
 
95
	echo '</h3></center><div class="container"><table class="table table-striped"><tbody>';
-
 
96
 
121
 
97
	$fichier='/var/log/fail2ban.log';
122
	$bans = array_reverse($bans);
-
 
123
?>
-
 
124
	<h3 style="text-align: center;"><?= $l_fail2ban ?></h3>
98
	$unban="/Unban/";
125
	<div class="container">
-
 
126
		<table class="table table-striped table-hover">
99
	$ban="/Ban/";
127
			<thead>
100
	$pointeur=fopen($fichier,"r");
128
				<tr><th>Date</th><th>Date Unban</th><th><?= $l_rule ?></th><th><?= $l_ipAddress ?></th></tr>
101
	if ($pointeur){
129
			</thead>
102
		while (!feof($pointeur)){
130
			<tbody>
103
			$ligne=fgets($pointeur);
131
				<?php if (!empty($bans)): ?>
104
			if(preg_match($ban,$ligne,$r)){
132
					<?php foreach ($bans as $ban): ?>
105
				echo "<tr><td><font color='red'>$ligne</font></td></tr>";
133
						<tr><td><?= $ban->date_ban ?></td><td><?= $ban->date_unban ?></td><td><?= $ban->rule ?></td><td><?= $ban->ip ?></td></tr>
106
			}
134
					<?php endforeach; ?>
107
			if(preg_match($unban,$ligne,$r)){
135
				<?php else: ?>
108
				echo "<tr><td><font color='orange'>$ligne</font></td></tr>";
136
					<tr><td colspan="4" style="text-align: center;"><?= $l_empty ?></td></tr>
109
			}
-
 
110
		}
-
 
111
			fclose($pointeur);
137
				<?php endif; ?>
112
	}
138
			</tbody>
113
	else
139
		</table>
114
	{
140
	</div>
115
		echo '<tr><center>Empty</center></tr>';
-
 
116
	}
141
<?php
117
	echo '</tbody></table></div>';
-
 
118
} else {
142
} else {
119
	echo 'Do not exist';
143
	echo 'Unknown tab';
120
}
144
}
121
 
-
 
122
?>
145
?>
123
</body>
146
</body>
124
</HTML>
147
</html>