From 68c30fb9fb6ddb8c062c59be54b4467dcfd9686e Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 29 Apr 2014 22:09:10 -0700 Subject: [PATCH] Work on filters page --- fail2ban/fail2ban-lib.pl | 29 +++++++++++++++++++++++++++-- fail2ban/lang/en | 14 +++++++++++--- fail2ban/list_filters.cgi | 27 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 fail2ban/list_filters.cgi diff --git a/fail2ban/fail2ban-lib.pl b/fail2ban/fail2ban-lib.pl index 078823f1c..b928982ab 100644 --- a/fail2ban/fail2ban-lib.pl +++ b/fail2ban/fail2ban-lib.pl @@ -37,19 +37,42 @@ return $pid; } # list_filters() -# Returns a list of all defined filters, each of which is a hash ref of -# options from the [Definition] block +# Returns a list of all defined filter files, each of which contains multiple +# sections like [Definition] sub list_filters { my $dir = "$config{'config_dir'}/filter.d"; +my @rv; +foreach my $f (glob("$dir/*.conf")) { + my $conf = &parse_config_file($f); + if (@$conf) { + push(@rv, $conf); + } + } +return @rv; } +# list_actions() +# Returns a list of all defined action files, each of which contains multiple +# sections like [Definition] and [Init] sub list_actions { +my $dir = "$config{'config_dir'}/action.d"; +my @rv; +foreach my $f (glob("$dir/*.conf")) { + my $conf = &parse_config_file($f); + if (@$conf) { + push(@rv, $conf); + } + } +return @rv; } +# list_jails() +# Returns a list of all sections from the jails file sub list_jails { +return &parse_config_file("$config{'config_dir'}/jail.conf"); } # parse_config_file(file) @@ -101,6 +124,8 @@ close($fh); return @rv; } +# split_directive_values(&dir) +# Populate the 'values' field by splitting up the 'value' field sub split_directive_values { my ($dir) = @_; diff --git a/fail2ban/lang/en b/fail2ban/lang/en index a64f0c176..005d39d4a 100644 --- a/fail2ban/lang/en +++ b/fail2ban/lang/en @@ -1,4 +1,4 @@ -index_title=Fail2Ban +index_title=Fail2Ban Intrusion Detector index_echeck=An error occurred detecting Fail2Ban on this system : $1. Either it is not installed, or the module configuration is incorrect. index_fail2ban=Fail2Ban index_atboot=Start at boot? @@ -12,5 +12,13 @@ index_restartdesc=Click this button to apply the current configuration by restar check_edir=The configuration directory $1 does not exist check_econf=The configuration file $2 in $1 does not exist -client_cmd=The client command $1 was not found -server_cmd=The server command $1 was not found +check_eclient=The client command $1 was not found +check_eserver=The server command $1 was not found + +filters_title=Log Filters + +actions_title=Actions + +jails_title=Jails + +config_title=Global Configuration diff --git a/fail2ban/list_filters.cgi b/fail2ban/list_filters.cgi new file mode 100644 index 000000000..2332bf893 --- /dev/null +++ b/fail2ban/list_filters.cgi @@ -0,0 +1,27 @@ +#!/usr/local/bin/perl +# Show a list of all defined filters + +use strict; +use warnings; +require './fail2ban-lib.pl'; +our (%in, %text); + +&ui_print_header(undef, $text{'filters_title'}, ""); + +my @filters = &list_filters(); +print &ui_columns_start([ $text{'filters_name'}, + $text{'filters_re'} ]); +foreach my $f (@filters) { + my ($def) = grep { $_->{'name'} eq 'Definition' } @$f; + next if (!$f); # XXX what about default? + my $fail = &find_value("failregex", $f); + my $fname = "XXX"; + print &ui_columns_row([ + &ui_link("edit_filter.cgi?file=".&urlize($def->{'file'}), + $fname), + &html_escape($fail), + ]); + } +print &ui_columns_end(); + +&ui_print_footer("", $text{'index_return'});