Generate Auxillary conf file

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5563 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-17 18:18:54 +00:00
parent 1e2192ab2d
commit b38c69c61e
3 changed files with 62 additions and 3 deletions

View File

@ -25,6 +25,7 @@ package Shorewall::Common;
require Exporter;
use File::Basename;
use File::Temp qw/ tempfile tempdir /;
use Cwd 'abs_path';
use strict;
@ -47,6 +48,8 @@ our @EXPORT = qw(ALLIPv4
pop_indent
copy
copy1
create_temp_aux_config
finalize_aux_config
@allipv4
@rfc1918_networks
@ -102,6 +105,7 @@ sub create_temp_object( $ ) {
eval {
( $file, $dir, $suffix ) = fileparse( $objectfile );
$dir = abs_path $dir;
fatal_error "Directory $dir does not exist" unless -d $dir;
fatal_error "$dir is a Symbolic Link" if -l $dir;
fatal_error "$objectfile is a Directory" if -d $objectfile;
@ -110,7 +114,7 @@ sub create_temp_object( $ ) {
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
};
fatal_error "$@" if $@;
die if $@;
$file = "$file.$suffix" if $suffix;
$file = $dir . $file;
@ -118,6 +122,8 @@ sub create_temp_object( $ ) {
}
sub finalize_object() {
close $object;
$object = 0;
rename $tempfile, $file or fatal_error "Cannot Rename $tempfile to $file: $!";
chmod 0700, $file;
}
@ -247,4 +253,21 @@ sub copy1( $ ) {
}
}
sub create_temp_aux_config() {
eval {
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
};
die if $@;
}
sub finalize_aux_config() {
close $object;
$object = 0;
rename $tempfile, "$file.conf" or fatal_error "Cannot Rename $tempfile to $file.conf: $!";
progress_message3 "Shorewall configuration compiled to $file";
}
1;

View File

@ -28,7 +28,7 @@ use warnings;
use Shorewall::Common;
our @ISA = qw(Exporter);
our @EXPORT = qw(find_file get_configuration report_capabilities propagateconfig append_file %config %env %capabilities );
our @EXPORT = qw(find_file get_configuration report_capabilities propagateconfig append_file generate_aux_config %config %env %capabilities );
our @EXPORT_OK = ();
our @VERSION = 1.00;
@ -525,4 +525,39 @@ sub append_file( $ ) {
}
}
;
sub generate_aux_config() {
sub conditionally_add_option( $ ) {
my $option = $_[0];
my $value = $config{$option};
emit "[ -n \"\${$option:=$value}\" ]" if $value;
}
sub conditionally_add_option1( $ ) {
my $option = $_[0];
my $value = $config{$option};
emit "$option=\"$value\"" if $value;
}
create_temp_aux_config;
my $date = localtime;
emit "#
# Shorewall auxiliary configuration file created by Shorewall version $ENV{VERSION} - $date
#";
for my $option qw(VERBOSITY LOGFILE LOGFORMAT IPTABLES PATH SHOREWALL_SHELL SUBSYSLOCK RESTOREFILE SAVE_IPSETS) {
conditionally_add_option $option;
}
conditionally_add_option1 'TC_ENABLED';
finalize_aux_config;
}
1;

View File

@ -710,6 +710,7 @@ sub compile_firewall( $ ) {
dump_chain_table if $ENV{DEBUG};
generate_script_3;
finalize_object;
generate_aux_config;
}
}