Net-Firewall-BlockerHelper

Helps manage (un)blocking IPs via various firewalls.

Currently included local backends are and all should be well tested, especially pf and ipfw...

The following remote/API backends are available. These use LWP::UserAgent, which is only loaded if they are used. Please note these have been built based of existing samples else where or docs and not tested due to lack of access to systems to test against at this time.

The following cloud backends are available. These drive the provider's CLI. Please note these have been built based of existing samples else where or docs and not tested due to lack of access to systems to test against at this time.

The following other remote backends are available.

The following generic backends are available.

And the following example/testing backends are available.

    use Net::Firewall::BlockerHelper;

    # create a instance named ssh with a ipfw backend for port 22 tcp
    my $fw_helper;
    eval {
        $fw_helper = Net::Firewall::BlockerHelper->new(
                backend => 'ipfw',
                ports => ['22'],
                protocols => ['tcp'],
                name => 'ssh',
            );
    };
    if ($@) {
        print 'Error: '
            . $Error::Helper::error
            . "\nError String: "
            . $Error::Helper::errorString
            . "\nError Flag: "
            . $Error::Helper::errorFlag . "\n";
    }

    # start the backend
    $fw_helper->init_backend;

    # ban some IPs
    $fw_helper->ban(ban => '1.2.3.4');
    $fw_helper->ban(ban => '5.6.7.8');

    # unban a IP
    $fw_helper->unban(ban => '1.2.3.4');

    # ban/unban a CIDR range (backends that support it; others raise
    # the cidrNotSupported error)
    $fw_helper->ban_cidr(ban => '1.2.3.0/24');
    $fw_helper->unban_cidr(ban => '1.2.3.0/24');

    # get a list of banned IPs
    my @banned = $fw_helper->list;
    foreach my $ip (@banned) {
        print 'Banned IP: '.$ip."\n";
    }

    # get a list of banned CIDR ranges
    my @banned_cidrs = $fw_helper->list_cidr;

    # write out state the backend holds back from persistent storage
    # (only openwrt implements this; others raise commitNotSupported)
    $fw_helper->commit;

    # teardown the backend, re-init, and re-ban everything
    $fw_helper->re_init;

    # teardown the backend
    $fw_helper->teardown;

Install

Requirements...

And if using any of the HTTP backends...

cpanm

cpanm Net::Firewall::BlockerHelper LWP::UserAgent LWP::Protocol::https

From source

Clone the repo or grab and extract the tarball, then in it...

perl Makefile.PL
make
make test
make install

The requirements need installed first, either via packages as below or cpanm.

FreeBSD

Regexp::IPv4 is not ported, so cpanm is used for the final step.

pkg install perl5 p5-App-cpanminus p5-Error-Helper p5-Regexp-IPv6 p5-libwww p5-LWP-Protocol-https
cpanm Net::Firewall::BlockerHelper

Debian

Regexp::IPv4 and Error::Helper are not packaged, so cpanm is used for the final step.

apt-get install perl make cpanminus libregexp-ipv6-perl libwww-perl liblwp-protocol-https-perl
cpanm Net::Firewall::BlockerHelper