NAME

Net::Firewall::BlockerHelper::backends::shell - A shell backend for Net::Firewall::BlockHelper.

VERSION

Version 0.0.1

SYNOPSIS

use Net::Firewall::BlockerHelper;

my $fw_helper;
eval {
    $fw_helper = Net::Firewall::BlockerHelper->new(
            backend=>'shell',
            name=>'derp',
            options=>{
                      init=>'mkdir /tmp/fw_helper_example/',
                      teardown=>'rm -rf /tmp/fw_helper_example/',
                      unban=>'rm -rf /tmp/fw_helper_example/%%%BAN%%%',
                      ban=>'touch /tmp/fw_helper_example/%%%BAN%%%',
                      },
        );
};
if ($@) {
    print 'Error: '
        . $Error::Helper::error
        . "\nError String: "
        . $Error::Helper::errorString
        . "\nError Flag: "
        . $Error::Helper::errorFlag . "\n";
}

$fw_helper->init;

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

$fw_helper->unban(ban => '5.6.7.8');

$fw_helper->teardown;

METHODS

new

Initiates the the object. Unlike other backends, this only takes uses the options hash.

- options :: A hash of options to pass to the backend.
    Default :: {}

- name :: Not used but is required by Net::Firewall::BlockerHelper.
    Default :: undef

The values used for options is as below. All must be defined and can't be ''. '2>&1' is appended to the end of the commands.

- init :: The command to run to init the blocking.
     Default :: undef

- teardown :: The command to run to teardown the blocking.
     Default :: undef

- ban :: The command to run to ban a IP. %%%BAN%%% is replaced with the IP.
     Default :: undef

- unban :: The command to run to un ban a IP. %%%BAN%%% is replaced with the IP.
     Default :: undef

All errors are considered fatal, meaning if new fails it will die.

my $fw_helper;
eval {
    $fw_helper = Net::Firewall::BlockerHelper->new(
            backend=>'shell',
            name=>'derp',
            options=>{
                      init=>'mkdir /tmp/fw_helper_example/',
                      teardown=>'rm -rf /tmp/fw_helper_example/',
                      unban=>'rm -rf /tmp/fw_helper_example/%%%BAN%%%',
                      ban=>'touch /tmp/fw_helper_example/%%%BAN%%%',
                      },
        );
};
if ($@) {
    print 'Error: '
        . $Error::Helper::error
        . "\nError String: "
        . $Error::Helper::errorString
        . "\nError Flag: "
        . $Error::Helper::errorFlag . "\n";
}

init

Initiates the backend.

No arguments are taken.

ban

Bans the IP.

$fw_helper->ban(ban => $ip);

unban

Unbans the an IP.

$fw_helper->ban(ban => $ip);

list

List banned IPs.

my @banned = $fw_helper->list;

re_init

Tells the backend to re-init it's self.

teardown

Tears down the setup for the backend.

ERROR CODES / FLAGS

1, notInited

Backend has not been initted yet.

2, initInvalid

'init' for options hash is invalid. Either undef or blank.

Options is not a hash.

4, teardownInvalid

'teardown' for options hash is invalid. Either undef or blank.

5, banInvalid

'ban' for options hash is invalid. Either undef or blank.

6, unbanInvalid

'unban' for options hash is invalid. Either undef or blank.

8, optionsNotHash

The item passed to new for options is not a hash.

9, noBanItem

No IP specified to ban.

10, banItemNotIP

The item to ban is not an IP. Either wrong ref type or regexp test using Regexp::IPv4 and Regexp::IPv6 failed.

11, invalidBackend

The specified backend failed to pass a basic sanity check of making sure it matches the regexp /^[a-zA-Z0-9\_]+$/.

12, backendInitError

Failed to init the backend.

13, banFailed

Failed to ban the item.

14, unbanFailed

Failed to unban the item.

15, listFailed

Failed get a list of bans.

16, reInitFailed

Failed to re_init the backend.

17, teardownFailed

Failed to teardown the backend.

18, alreadyInited

Backend has already been initiated.

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.ent>

BUGS

Please report any bugs or feature requests to bug-net-firewall-blockerhelper at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Net::Firewall::BlockerHelper

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2023 by Zane C. Bowers-Hadley.

This is free software, licensed under:

The GNU Lesser General Public License, Version 2.1, February 1999

1 POD Error

The following errors were encountered while parsing the POD:

Around line 468:

Unknown directive: =head