mirror of
https://gitlab.com/shorewall/code.git
synced 2024-11-15 04:04:10 +01:00
Convert the Accounting and Actions modules to use the new INCLUDE-aware file read routines
git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5743 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
parent
de26cbb9a1
commit
2de234316b
@ -110,17 +110,15 @@ sub process_accounting_rule( $$$$$$$$ ) {
|
||||
|
||||
sub setup_accounting() {
|
||||
|
||||
open ACC, "$ENV{TMP_DIR}/accounting" or fatal_error "Unable to open stripped accounting file: $!";
|
||||
open_file 'accounting';
|
||||
|
||||
while ( $line = <ACC> ) {
|
||||
while ( read_a_line ) {
|
||||
|
||||
my ( $action, $chain, $source, $dest, $proto, $ports, $sports, $user ) = split_line 8, 'Accounting File';
|
||||
|
||||
process_accounting_rule $action, $chain, $source, $dest, $proto, $ports, $sports, $user;
|
||||
}
|
||||
|
||||
close ACC;
|
||||
|
||||
if ( $filter_table->{accounting} ) {
|
||||
for my $chain qw/INPUT FORWARD OUTPUT/ {
|
||||
insert_rule $filter_table->{$chain}, 1, '-j accounting';
|
||||
|
@ -243,11 +243,11 @@ sub process_actions1() {
|
||||
for my $act ( grep $targets{$_} & ACTION , keys %targets ) {
|
||||
new_action $act;
|
||||
}
|
||||
|
||||
for my $file ( qw/actions.std actions/ ) {
|
||||
open_file $file;
|
||||
|
||||
for my $file qw/actions.std actions/ {
|
||||
open F, "$ENV{TMP_DIR}/$file" or fatal_error "Unable to open stripped $file file: $!";
|
||||
|
||||
while ( $line = <F> ) {
|
||||
while ( read_a_line ) {
|
||||
my ( $action ) = split_line 1, 'action file';
|
||||
|
||||
if ( $action =~ /:/ ) {
|
||||
@ -274,13 +274,9 @@ sub process_actions1() {
|
||||
|
||||
progress_message2 " Pre-processing $actionfile...";
|
||||
|
||||
open A, $actionfile or fatal_error "Unable to open $actionfile: $!";
|
||||
push_open( $actionfile );
|
||||
|
||||
while ( $line = <A> ) {
|
||||
chomp $line;
|
||||
next if $line =~ /^\s*#/;
|
||||
next if $line =~ /^\s*$/;
|
||||
$line =~ s/#.*$//;
|
||||
while ( read_a_line ) {
|
||||
|
||||
my ($wholetarget, $source, $dest, $proto, $ports, $sports, $rate, $users ) = split_line 8, 'action file';
|
||||
|
||||
@ -304,13 +300,9 @@ sub process_actions1() {
|
||||
|
||||
progress_message " ..Expanding Macro $macrofile...";
|
||||
|
||||
open M, $macrofile or fatal_error "Unable to open $macrofile: $!";
|
||||
|
||||
while ( $line = <M> ) {
|
||||
next if $line =~ /^\s*#/;
|
||||
$line =~ s/#.*$//;
|
||||
next if $line =~ /^\s*$/;
|
||||
push_open( $macrofile );
|
||||
|
||||
while ( read_a_line ) {
|
||||
my ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $ mrate, $muser ) = split_line 8, 'macro file';
|
||||
|
||||
$mtarget =~ s/:.*$//;
|
||||
@ -324,15 +316,16 @@ sub process_actions1() {
|
||||
}
|
||||
|
||||
progress_message " ..End Macro";
|
||||
close M;
|
||||
|
||||
pop_open;
|
||||
} else {
|
||||
fatal_error "Invalid TARGET ($target) in rule \"$line\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
close A;
|
||||
|
||||
pop_open;
|
||||
}
|
||||
close F;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,11 @@ use warnings;
|
||||
use Shorewall::Common;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(find_file
|
||||
our @EXPORT = ( qw(find_file
|
||||
open_file
|
||||
push_open
|
||||
pop_open
|
||||
read_a_line
|
||||
expand_shell_variables
|
||||
get_configuration
|
||||
require_capability
|
||||
@ -40,7 +44,7 @@ our @EXPORT = qw(find_file
|
||||
|
||||
%config
|
||||
%env
|
||||
%capabilities );
|
||||
%capabilities ) );
|
||||
our @EXPORT_OK = ();
|
||||
our @VERSION = 1.00;
|
||||
|
||||
@ -283,8 +287,42 @@ sub expand_shell_variables( $ ) {
|
||||
my @openstack;
|
||||
my $currentfile;
|
||||
|
||||
#
|
||||
# Open a file, setting $currentfile.
|
||||
#
|
||||
sub open_file( $ ) {
|
||||
my $fname = find_file $_[0];
|
||||
|
||||
fatal_error 'Internal Error in open_file()' if defined $currentfile;
|
||||
|
||||
if ( -f $fname ) {
|
||||
open $currentfile, '<', $fname or fatal_error "Unable to open $fname: $!";
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Allow nested opens
|
||||
#
|
||||
my @pushstack;
|
||||
|
||||
sub push_open( $ ) {
|
||||
|
||||
push @openstack, $currentfile;
|
||||
my @a = @openstack;
|
||||
push @pushstack, \@a;
|
||||
@openstack = ();
|
||||
$currentfile = undef;
|
||||
open_file( $_[0] );
|
||||
|
||||
}
|
||||
|
||||
sub pop_open() {
|
||||
@openstack = @{pop @pushstack};
|
||||
$currentfile = pop @openstack;
|
||||
}
|
||||
|
||||
sub read_a_line {
|
||||
while ( 1 ) {
|
||||
while ( $currentfile ) {
|
||||
while ( $line = <$currentfile> ) {
|
||||
next if $line =~ /^\s*#/;
|
||||
next if $line =~ /^\s*$/;
|
||||
@ -322,8 +360,6 @@ sub read_a_line {
|
||||
|
||||
close $currentfile;
|
||||
|
||||
return 0 unless @openstack;
|
||||
|
||||
$currentfile = pop @openstack;
|
||||
}
|
||||
}
|
||||
|
@ -180,9 +180,9 @@ sub determine_zones()
|
||||
{
|
||||
my @z;
|
||||
|
||||
open ZONES, "$ENV{TMP_DIR}/zones" or fatal_error "Unable to open stripped zones file: $!";
|
||||
open_file 'zones';
|
||||
|
||||
while ( $line = <ZONES> ) {
|
||||
while ( read_a_line ) {
|
||||
|
||||
my @parents;
|
||||
|
||||
@ -244,8 +244,6 @@ sub determine_zones()
|
||||
push @z, $zone;
|
||||
}
|
||||
|
||||
close ZONES;
|
||||
|
||||
my $pushed = 1;
|
||||
my %ordered;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user