Skip to content

Commit 28548bf

Browse files
author
latham
committed
Add IPTables to monitoring data and monitoring interface
1 parent 52bfee1 commit 28548bf

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

interface/web/monitor/lib/lang/en.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ $wb['monitor_title_mailq_txt'] = 'Mail Queue';
139139
$wb['monitor_title_raidstate_txt'] = 'RAID Status';
140140
$wb['monitor_title_rkhunterlog_txt'] = 'RKHunter Log';
141141
$wb['monitor_title_fail2ban_txt'] = 'Fail2Ban Log';
142+
$wb['monitor_title_iptables_txt'] = 'IPTables Rules';
142143
$wb['monitor_title_beancounter_txt'] = 'OpenVz VE BeanCounter';
143144
$wb['monitor_updates_nosupport_txt'] = 'Your distribution is not supported for this monitoring';
144145
$wb['monitor_beancounter_nosupport_txt'] = 'This server is not a OpenVz VE and has no beancounter information';

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@
180180
'link' => 'monitor/show_data.php?type=fail2ban',
181181
'html_id' => 'fai2ban');
182182

183+
$items[] = array( 'title' => "Show IPTables",
184+
'target' => 'content',
185+
'link' => 'monitor/show_data.php?type=iptables',
186+
'html_id' => 'iptables');
187+
183188
$module["nav"][] = array( 'title' => 'Logfiles',
184189
'open' => 1,
185190
'items' => $items);

interface/web/monitor/show_data.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
$title = $app->lng("monitor_title_fail2ban_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')';
125125
$description = '';
126126
break;
127+
case 'iptables':
128+
$template = 'templates/show_data.htm';
129+
$output .= showIPTables();
130+
$time = getDataTime('iptables_rules');
131+
$title = $app->lng("monitor_title_iptables_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')';
132+
$description = '';
133+
break;
127134
default:
128135
$template = '';
129136
break;

interface/web/monitor/tools.inc.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,28 @@ function showFail2ban() {
450450
return $html;
451451
}
452452

453+
function showIPTables() {
454+
global $app;
455+
$record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'iptables_rules' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
456+
if(isset($record['data'])) {
457+
$html =
458+
'<div class="systemmonitor-state state-'.$record['state'].'">
459+
<div class="systemmonitor-content icons32 ico-'.$record['state'].'">';
460+
$data = unserialize($record['data']);
461+
if ($data == '') {
462+
$html .= '<p>Problem, there are no rules listed for the server</p>';
463+
}
464+
else {
465+
$html = nl2br($data['output']);
466+
}
467+
$html .= '</div></div>';
468+
} else {
469+
$html = '<p>There is no data available at the moment.</p>';
470+
}
471+
return $html;
472+
}
473+
474+
453475
function showMailq() {
454476
global $app;
455477

server/lib/classes/monitor_tools.inc.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,40 @@ public function monitorFail2ban() {
11271127
return $res;
11281128
}
11291129

1130+
public function monitorIPTables() {
1131+
global $conf;
1132+
1133+
/* the id of the server as int */
1134+
$server_id = intval($conf['server_id']);
1135+
1136+
/** The type of the data */
1137+
$type = 'iptables_rules';
1138+
1139+
/* This monitoring is only available if fail2ban is installed */
1140+
system('which iptables', $retval); // Debian, Ubuntu, Fedora
1141+
if ($retval === 0) {
1142+
/* Get the data of the log */
1143+
$data['output'] = shell_exec('iptables -S');
1144+
1145+
/*
1146+
* At this moment, there is no state (maybe later)
1147+
*/
1148+
$state = 'no_state';
1149+
} else {
1150+
$state = 'no_state';
1151+
$data = '';
1152+
}
1153+
1154+
/*
1155+
* Return the Result
1156+
*/
1157+
$res['server_id'] = $server_id;
1158+
$res['type'] = $type;
1159+
$res['data'] = $data;
1160+
$res['state'] = $state;
1161+
return $res;
1162+
}
1163+
11301164
public function monitorSysLog() {
11311165
global $app;
11321166
global $conf;

server/mods-available/monitor_core_module.inc.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private function _doMonitor() {
112112
$this->_monitorRaid();
113113
$this->_monitorRkHunter();
114114
$this->_monitorFail2ban();
115+
$this->_monitorIPTables();
115116
$this->_monitorSysLog();
116117
}
117118

@@ -509,12 +510,38 @@ private function _monitorRkHunter() {
509510
}
510511

511512
private function _monitorFail2ban() {
513+
global $app;
514+
515+
/*
516+
* First we get the Monitoring-data from the tools
517+
*/
518+
$res = $this->_tools->monitorFail2ban();
519+
520+
/*
521+
* Insert the data into the database
522+
*/
523+
$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
524+
'VALUES (' .
525+
$res['server_id'] . ', ' .
526+
"'" . $app->dbmaster->quote($res['type']) . "', " .
527+
'UNIX_TIMESTAMP(), ' .
528+
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
529+
"'" . $res['state'] . "'" .
530+
')';
531+
$app->dbmaster->query($sql);
532+
533+
/* The new data is written, now we can delete the old one */
534+
$this->_delOldRecords($res['type'], $res['server_id']);
535+
}
536+
537+
538+
private function _monitorIPTables() {
512539
global $app;
513540

514541
/*
515542
* First we get the Monitoring-data from the tools
516543
*/
517-
$res = $this->_tools->monitorFail2ban();
544+
$res = $this->_tools->monitorIPTables();
518545

519546
/*
520547
* Insert the data into the database

0 commit comments

Comments
 (0)