Subversion Repositories ALCASAR

Rev

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

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