Skip to content

Commit 476a609

Browse files
author
vogelor
committed
Added fail2ban - Log to the monitor (if installed at the server).
Updated installation-Instruction for debian
1 parent 690cfe9 commit 476a609

File tree

6 files changed

+150
-40
lines changed

6 files changed

+150
-40
lines changed

INSTALL_DEBIAN_4.0.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,34 @@ make
133133
make install
134134
rm -rf jailkit-2.5*
135135

136+
8) Install fail2ban (optional but recomended, because the monitor tries to show the log)
137+
More info at: http://www.howtoforge.com/fail2ban_debian_etch
136138

137-
8) Install ISPConfig 3
139+
apt-get install fail2ban
140+
141+
142+
9) Install ISPConfig 3
138143

139144
There are two possile scenarios, but not both:
140-
8.1) Install the latest released version
141-
8.2) Install directly from SVN
145+
9.1) Install the latest released version
146+
9.2) Install directly from SVN
142147

143-
8.1) Installation of last version from tar.gz
148+
9.1) Installation of last version from tar.gz
144149

145150
cd /tmp
146151
wget http://www.ispconfig.org/downloads/ISPConfig-3.0.0.8-rc1.tar.gz
147152
tar xvfz ISPConfig-3.0.0.8-rc1.tar.gz
148153
cd ispconfig3_install/install/
149154

150-
8.2) Installation from SVN
155+
9.2) Installation from SVN
151156

152157
apt-get install subversion
153158
cd /tmp
154159
svn export svn://svn.ispconfig.org/ispconfig3/trunk/
155160
cd trunk/install
156161

157162

158-
8.1+8.2) Now proceed with the ISPConfig installation.
163+
9.1+9.2) Now proceed with the ISPConfig installation.
159164

160165
Now start the installation process by executing:
161166

@@ -205,5 +210,4 @@ done
205210
Optional packages recommended:
206211

207212
denyhosts - a utility to help sys admins thwart ssh crackers
208-
fail2ban - Preventing Brute Force Attacks - http://www.howtoforge.com/fail2ban_debian_etch
209213
rsync - fast remote file copy program (for backup)

INSTALL_DEBIAN_LENNY.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,45 @@ update-rc.d mydns defaults
232232

233233
apt-get install vlogger webalizer
234234

235+
7) Install Jailkit (optional, only needed if you want to use chrroting for SSH users)
235236

236-
7) Install ISPConfig 3
237+
apt-get install build-essential autoconf automake1.9 libtool flex bison
238+
cd /tmp
239+
wget http://olivier.sessink.nl/jailkit/jailkit-2.5.tar.gz
240+
tar xvfz jailkit-2.5.tar.gz
241+
cd jailkit-2.5
242+
./configure
243+
make
244+
make install
245+
rm -rf jailkit-2.5*
246+
247+
8) Install fail2ban (optional but recomended, because the monitor tries to show the log)
248+
More info at: http://www.howtoforge.com/fail2ban_debian_etch
249+
250+
apt-get install fail2ban
251+
252+
9) Install ISPConfig 3
237253

238254
# There are two possile scenarios, but not both:
239-
7.1) Install the latest released version
240-
7.2) Install directly from SVN
255+
9.1) Install the latest released version
256+
9.2) Install directly from SVN
241257

242-
7.1) Installation of last version from tar.gz
258+
9.1) Installation of last version from tar.gz
243259

244260
cd /tmp
245261
wget http://www.ispconfig.org/downloads/ISPConfig-3.0.0.8-rc1.tar.gz
246262
tar xvfz ISPConfig-3.0.0.8-rc1.tar.gz
247263
cd ispconfig3_install/install/
248264

249-
7.2) Installation from SVN
265+
9.2) Installation from SVN
250266

251267
apt-get install subversion
252268
cd /tmp
253269
svn export svn://svn.ispconfig.org/ispconfig3/trunk/
254270
cd trunk/install
255271

256272

257-
7.1+7.2) Now proceed with the ISPConfig installation.
273+
9.1+9.2) Now proceed with the ISPConfig installation.
258274

259275
# Now start the installation process by executing:
260276

@@ -304,21 +320,8 @@ done
304320

305321
----------------------------------------------------------------------------------------------------------
306322

307-
Installing Jailkit:
308-
309-
apt-get install build-essential autoconf automake1.9 libtool flex bison
310-
cd /tmp
311-
wget http://olivier.sessink.nl/jailkit/jailkit-2.5.tar.gz
312-
tar xvfz jailkit-2.5.tar.gz
313-
cd jailkit-2.5
314-
./configure
315-
make
316-
make install
317-
rm -rf jailkit-2.5*
318-
----------------------------------------------------------------------------------------------------------
319323

320324
Optional recommended packages:
321325

322326
denyhosts - a utility to help sys admins thwart ssh crackers
323-
fail2ban - Like denyhosts but updates firewall rules to reject/drop the IP address and supports many more apps
324327
rsync - fast remote file copy program (for backup)

interface/web/monitor/lib/module.conf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@
150150
'target' => 'content',
151151
'link' => 'monitor/show_data.php?type=rkhunter');
152152

153+
$items[] = array( 'title' => "Show fail2ban-Log",
154+
'target' => 'content',
155+
'link' => 'monitor/show_data.php?type=fail2ban');
156+
153157
$module["nav"][] = array( 'title' => 'Logfiles',
154158
'open' => 1,
155159
'items' => $items);

interface/web/monitor/show_data.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@
110110
$title = $app->lng("monitor_title_rkhunterlog_txt"). ' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
111111
$description = '';
112112
break;
113+
case 'fail2ban':
114+
$template = 'templates/show_data.htm';
115+
$output .= showFail2ban();
116+
$time = getDataTime('fail2ban');
117+
$title = 'fail2ban - Log (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')';
118+
$description = '';
119+
break;
113120
default:
114121
$template = '';
115122
break;

interface/web/monitor/tools.inc.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function showRKHunter()
374374

375375
/*
376376
* First, we have to detect, if there is any monitoring-data.
377-
* If not (because the destribution is not supported) show this.
377+
* If not (because rkhunter is not installed) show this.
378378
*/
379379
$data = unserialize($record['data']);
380380
if ($data['output'] == ''){
@@ -392,6 +392,42 @@ function showRKHunter()
392392
return $html;
393393
}
394394

395+
function showFail2ban()
396+
{
397+
global $app;
398+
399+
/* fetch the Data from the DB */
400+
$record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'log_fail2ban' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
401+
402+
if(isset($record['data'])) {
403+
$html =
404+
'<div class="systemmonitor-state state-'.$record['state'].'">
405+
<div class="systemmonitor-content icons32 ico-'.$record['state'].'">';
406+
407+
/*
408+
* First, we have to detect, if there is any monitoring-data.
409+
* If not (because fail2ban is not installed) show this.
410+
*/
411+
$data = unserialize($record['data']);
412+
if ($data == ''){
413+
$html .= '<p>'.
414+
'fail2ban is not installed at this server.<br />' .
415+
'See more (for debian) <a href="http://www.howtoforge.net/fail2ban_debian_etch" target="htf">here...</a>'.
416+
'</p>';
417+
}
418+
else {
419+
$html .= nl2br($data);
420+
}
421+
$html .= '</div></div>';
422+
423+
} else {
424+
$html = '<p>There is no data available at the moment.</p>';
425+
}
426+
427+
return $html;
428+
}
429+
430+
395431
function showMailq()
396432
{
397433
global $app;

server/mods-available/monitor_core_module.inc.php

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function doMonitor()
121121
$this->monitorMailQueue();
122122
$this->monitorRaid();
123123
$this->monitorRkHunter();
124+
$this->monitorFail2ban();
124125
$this->monitorSysLog();
125126
}
126127

@@ -748,6 +749,58 @@ function monitorRkHunter(){
748749
$this->_delOldRecords($type, 0, 2);
749750
}
750751

752+
function monitorFail2ban(){
753+
global $app;
754+
global $conf;
755+
756+
/* the id of the server as int */
757+
$server_id = intval($conf["server_id"]);
758+
759+
/** The type of the data */
760+
$type = 'log_fail2ban';
761+
762+
/* This monitoring is only available if fail2ban is installed */
763+
$location = shell_exec('which fail2ban-client');
764+
if($location != ''){
765+
/* Get the data of the log */
766+
$data = $this->_getLogData($type);
767+
768+
/*
769+
* At this moment, there is no state (maybe later)
770+
*/
771+
$state = 'no_state';
772+
}
773+
else {
774+
/*
775+
* fail2ban is not installed, so there is no data and no state
776+
*
777+
* no_state, NOT unknown, because "unknown" is shown as state
778+
* inside the GUI. no_state is hidden.
779+
*
780+
* We have to write NO DATA inside the DB, because the GUI
781+
* could not know, if there is any dat, or not...
782+
*/
783+
$state = 'no_state';
784+
$data = '';
785+
}
786+
787+
/*
788+
* Insert the data into the database
789+
*/
790+
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
791+
"VALUES (".
792+
$server_id . ", " .
793+
"'" . $app->dbmaster->quote($type) . "', " .
794+
time() . ", " .
795+
"'" . $app->dbmaster->quote(serialize($data)) . "', " .
796+
"'" . $state . "'" .
797+
")";
798+
$app->dbmaster->query($sql);
799+
800+
/* The new data is written, now we can delete the old one */
801+
$this->_delOldRecords($type, 10);
802+
}
803+
751804
function monitorSysLog(){
752805
global $app;
753806
global $conf;
@@ -758,19 +811,19 @@ function monitorSysLog(){
758811
/** The type of the data */
759812
$type = 'sys_log';
760813

761-
/*
762-
* is there any warning or error for this server?
763-
*/
764-
$state = 'ok';
814+
/*
815+
* is there any warning or error for this server?
816+
*/
817+
$state = 'ok';
765818
$dbData = $app->dbmaster->queryAllRecords("SELECT loglevel FROM sys_log WHERE server_id = " . $server_id . " AND loglevel > 0");
766-
if (is_array($dbData)) {
767-
foreach($dbData as $item){
768-
if ($item['loglevel'] == 1) $state = $this->_setState($state, 'warning');
769-
if ($item['loglevel'] == 2) $state = $this->_setState($state, 'error');
770-
}
771-
}
772-
773-
/** There is no monitor-data because the data is in the sys_log table */
819+
if (is_array($dbData)) {
820+
foreach($dbData as $item){
821+
if ($item['loglevel'] == 1) $state = $this->_setState($state, 'warning');
822+
if ($item['loglevel'] == 2) $state = $this->_setState($state, 'error');
823+
}
824+
}
825+
826+
/** There is no monitor-data because the data is in the sys_log table */
774827
$data['output']= '';
775828

776829
/*
@@ -790,7 +843,7 @@ function monitorSysLog(){
790843
$this->_delOldRecords($type, 10);
791844
}
792845

793-
function monitorMailLog()
846+
function monitorMailLog()
794847
{
795848
global $app;
796849
global $conf;
@@ -1140,6 +1193,9 @@ function _getLogData($log){
11401193
case 'log_clamav':
11411194
$logfile = '/var/log/clamav/clamav.log';
11421195
break;
1196+
case 'log_fail2ban':
1197+
$logfile = '/var/log/fail2ban.log';
1198+
break;
11431199
case 'log_ispconfig':
11441200
$logfile = '/var/log/ispconfig/ispconfig.log';
11451201
break;

0 commit comments

Comments
 (0)