A little code reorg

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5720 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-28 00:28:21 +00:00
parent 0c6b0db56f
commit 7592f5cb2f
3 changed files with 11 additions and 15 deletions

View File

@ -28,7 +28,7 @@ use warnings;
use Shorewall::Common; use Shorewall::Common;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw(find_file get_configuration report_capabilities propagateconfig append_file run_user_exit generate_aux_config %config %env %capabilities ); our @EXPORT = qw(find_file expand_shell_variables get_configuration report_capabilities propagateconfig append_file run_user_exit generate_aux_config %config %env %capabilities );
our @EXPORT_OK = (); our @EXPORT_OK = ();
our @VERSION = 1.00; our @VERSION = 1.00;
@ -251,6 +251,13 @@ sub report_capabilities() {
} }
} }
#
# Some files can have shell variables embedded. This function expands them from %ENV.
#
sub expand_shell_variables( $ ) {
my $line = $_[0]; $line = $1 . ( $ENV{$2} || '' ) . $3 while $line =~ /^(.*?)\$([a-zA-Z]\w*)(.*)$/; $line;
}
# #
# Read the shorewall.conf file and establish global hashes %config and %env. # Read the shorewall.conf file and establish global hashes %config and %env.
# #
@ -265,7 +272,8 @@ sub get_configuration() {
chomp $line; chomp $line;
next if $line =~ /^\s*#/; next if $line =~ /^\s*#/;
next if $line =~ /^\s*$/; next if $line =~ /^\s*$/;
$line = $1 . ( $ENV{$2} || '' ) . $3 while $line =~ /^(.*?)\$([a-zA-Z]\w*)(.*)$/;
expand_shell_variables( $line );
if ( $line =~ /^([a-zA-Z]\w*)\s*=\s*(.*)$/ ) { if ( $line =~ /^([a-zA-Z]\w*)\s*=\s*(.*)$/ ) {
my ($var, $val) = ($1, $2); my ($var, $val) = ($1, $2);

View File

@ -32,7 +32,6 @@ use strict;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( find_macro our @EXPORT = qw( find_macro
expand_shell_variables
split_action split_action
substitute_action substitute_action
merge_macro_source_dest merge_macro_source_dest
@ -61,13 +60,6 @@ sub find_macro( $ )
} }
} }
#
# Macro and action files can have shell variables embedded. This function expands them from %ENV.
#
sub expand_shell_variables( $ ) {
my $line = $_[0]; $line = $1 . ( $ENV{$2} || '' ) . $3 while $line =~ /^(.*?)\$([a-zA-Z]\w*)(.*)$/; $line;
}
# #
# Return ( action, level[:tag] ) from passed full action # Return ( action, level[:tag] ) from passed full action
# #

View File

@ -80,10 +80,6 @@ use Shorewall::Proxyarp;
# It's color theme drives my eyes crazy. # It's color theme drives my eyes crazy.
# It's indentation scheme is unfathomable. # It's indentation scheme is unfathomable.
# #
# Now I could spend my time trying to configure cperl-mode to do what I want; but why?
# Like most Open Source Software, it's documentation is pathetic. I would rather spend
# my time making Shorewall better as opposed to working around braindead editing modes.
#
# Bottom line. I use quoting techinques other than 'here documents'. # Bottom line. I use quoting techinques other than 'here documents'.
# #
@ -92,7 +88,7 @@ sub generate_script_1 {
my $date = localtime; my $date = localtime;
emit join ( '', "#\n# Compiled firewall script generated by Shorewall-pl ", $env{VERSION}, " - $date\n#" ); emit "#\n# Compiled firewall script generated by Shorewall-pl $env{VERSION} - $date\n#";
if ( $ENV{EXPORT} ) { if ( $ENV{EXPORT} ) {
emitj ( 'SHAREDIR=/usr/share/shorewall-lite', emitj ( 'SHAREDIR=/usr/share/shorewall-lite',