Rev 1867 | Rev 2405 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log
Rev | Author | Line No. | Line |
---|---|---|---|
1163 | crox53 | 1 | <?php |
2292 | tom.houday | 2 | # $Id: security.php 2292 2017-06-20 14:09:37Z tom.houdayer $ |
3 | |||
1163 | crox53 | 4 | //gestion de la langue |
2292 | tom.houday | 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 { |
||
15 | $l_title = 'Security'; |
||
16 | } |
||
17 | |||
18 | $tab = (isset($_GET['tab'])) ? intval($_GET['tab']) : 1; |
||
1163 | crox53 | 19 | ?> |
2292 | tom.houday | 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> |
||
1163 | crox53 | 34 | <body> |
2292 | tom.houday | 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> |
||
1410 | richard | 42 | |
43 | |||
44 | <?php |
||
2292 | tom.houday | 45 | if ($tab === 1) { |
46 | $filePath = '/var/Save/security/watchdog.log'; |
||
47 | $lines = file($filePath); |
||
48 | if ($lines === false) { |
||
49 | exit("Cannot open '$filePath'."); |
||
1410 | richard | 50 | } |
2292 | tom.houday | 51 | |
52 | $lines = array_reverse($lines); |
||
1410 | richard | 53 | ?> |
2292 | tom.houday | 54 | <h3 style="text-align: center;"><?= $l_spoofing ?></h3> |
55 | <div class="container"> |
||
56 | <table class="table table-striped table-hover"> |
||
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> |
||
67 | </div> |
||
1410 | richard | 68 | <?php |
2292 | tom.houday | 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'."); |
||
74 | } |
||
1410 | richard | 75 | |
2292 | tom.houday | 76 | $lines = array_reverse($lines); |
1410 | richard | 77 | ?> |
2292 | tom.houday | 78 | <h3 style="text-align: center;"><?= $l_virus ?></h3> |
79 | <div class="container"> |
||
80 | <table class="table table-striped table-hover"> |
||
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> |
||
91 | </div> |
||
1410 | richard | 92 | <?php |
2292 | tom.houday | 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); |
||
1410 | richard | 100 | |
2292 | tom.houday | 101 | if (preg_match($regex, $line, $matches)) { |
102 | if ($matches['type'] === 'Ban') { |
||
103 | $bans[] = (object) [ |
||
104 | 'date_ban' => $matches['date'], |
||
105 | 'date_unban' => null, |
||
106 | 'rule' => $matches['rule'], |
||
107 | 'ip' => $matches['ip'] |
||
108 | ]; |
||
109 | } else if ($matches['type'] === 'Unban') { |
||
110 | foreach (array_reverse($bans) as $ban) { |
||
111 | if (($ban->ip === $matches['ip']) && ($ban->rule === $matches['rule']) && ($ban->date_unban === null)) { |
||
112 | $ban->date_unban = $matches['date']; |
||
113 | break; |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | } |
||
1858 | raphael.pi | 118 | } |
2292 | tom.houday | 119 | fclose($file); |
1858 | raphael.pi | 120 | } |
1410 | richard | 121 | |
2292 | tom.houday | 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 |
||
1410 | richard | 142 | } else { |
2292 | tom.houday | 143 | echo 'Unknown tab'; |
1410 | richard | 144 | } |
145 | ?> |
||
1163 | crox53 | 146 | </body> |
2292 | tom.houday | 147 | </html> |