ACL-Regex
view release on metacpan or search on metacpan
lib/ACL/Regex.pm view on Meta::CPAN
package ACL::Regex;
# This is a little package used to handle ACLs in a friendly,
# sysadmin like regex enabled manner.
use strict;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
@EXPORT = qw( new parse_acl_from_file match );
$VERSION = '0.0002';
sub new {
my $type = shift;
bless {}, $type;
}
# This variable stores all of the required fields
# for the ACL. If a required field is not in a
# given ACL or action, then it is autogenerated
# with the defaults (enabled).
my @required = qw(
account
action
ip
group
dow
time
);
sub generate_required( $$ ){
my ( $acl, $required_file ) = @_;
open FD, "<$required_file" or die("Cannot open $required_file: $!\n" );
while( <FD> ){
next if /^#/;
if( /(\S+?)=(\S+)/ ){
my @a = split( /,/, $2 );
$acl->{req}->{$1} = \@a;
}
}
return ($acl);
}
sub sanitize_acl ($$) {
my ( $self, $acl ) = @_;
# Split up the ACL
my %hash = $acl =~ /(\S+?)=\[([^\[^\]].+?)\]/g;
my @acl_array;
my @local_required = sort( keys %hash );
my $action = $hash{action};
return -1,'ERR','Action not defined'
unless defined $hash{action};
#return 0,'WARN','Action not defined in required fields'
# unless defined $self->{req}->{$action};
if( defined $self->{req}->{$action} ){
#print "Using pre-defined requirements for $action from file\n";
@local_required = @{$self->{req}->{$action}};
}
# Regenerate the hash
for my $key ( sort ( @local_required ) ) {
unless ( defined $hash{$key} ) {
# Uh-oh, it wasn't specified
my $acl_element = "$key=\\\[(.*?)\\\]";
push ( @acl_array, $acl_element );
} else {
my $acl_element = "$key=\\\[$hash{$key}\\\]";
push ( @acl_array, $acl_element );
( run in 1.846 second using v1.01-cache-2.11-cpan-39bf76dae61 )