Reorganize Script Generation

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5512 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-13 22:03:59 +00:00
parent ef18b475c1
commit d7ab9421bf

View File

@ -424,19 +424,22 @@ sub progress_message {
}
}
sub timestamp() {
my ($sec, $min, $hr) = ( localtime ) [0,1,2];
printf '%02d:%02d:%02d ', $hr, $min, $sec;
}
sub progress_message2 {
if ( $ENV{VERBOSE} > 0 ) {
my $ts = '';
$ts = ( localtime ) . ' ' if $ENV{TIMESTAMP};
print "${ts}@_\n";
timestamp if $ENV{TIMESTAMP};
print "@_\n";
}
}
sub progress_message3 {
if ( $ENV{VERBOSE} >= 0 ) {
my $ts = '';
$ts = ( localtime ) . ' ' if $ENV{TIMESTAMP};
print "${ts}@_\n";
timestamp if $ENV{TIMESTAMP};
print "@_\n";
}
}
@ -5188,8 +5191,8 @@ sub generate_matrix() {
}
}
sub create_iptables_restore_file() {
emit 'restore_iptables()';
sub create_netfilter_load() {
emit 'setup_netfilter()';
emit '{';
emit ' iptables-restore << __EOF__';
@ -5892,7 +5895,7 @@ sub setup_route_marking() {
sub setup_traffic_shaping() {
}
sub generate_object () {
sub generate_script_1 {
copy find_file 'prog.header';
my $date = localtime;
@ -5931,7 +5934,7 @@ sub generate_object () {
emit 'initialize()';
emit '{';
$indent = ' ';
push_indent;
if ( $ENV{EXPORT} ) {
emit '#';
@ -5989,16 +5992,19 @@ sub generate_object () {
emit '#';
emit '[ -d ${VARDIR} ] || mkdir -p ${VARDIR}';
$indent = '';
pop_indent;
emit "}\n";
copy find_file 'prog.functions';
}
sub generate_script_2 () {
emit '#';
emit '# Start/Restart/Reload the firewall';
emit '# Setup Routing and Traffic Shaping';
emit '#';
emit 'define_firewall() {';
emit 'setup_routing_and_traffic_shaping() {';
$indent = ' ';
@ -6062,21 +6068,12 @@ sub generate_object () {
emit 'restore_default_route';
}
emit "restore_iptables\n";
emit "restore_dynamic_rules\n";
setup_traffic_shaping if -s "$ENV{TMP_DIR}/tcdevices";
$indent = '';
emit "}\n";;
progress_message2 "Creating iptables-restore input...";
create_iptables_restore_file;
copy find_file 'prog.footer';
}
sub report_capability( $ ) {
@ -6105,6 +6102,14 @@ sub compile_firewall( $ ) {
};
fatal_error "$@" if $@;
eval {
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
};
fatal_error "$@" if $@;
generate_script_1;
}
if ( $ENV{VERBOSE} > 1 ) {
@ -6196,21 +6201,29 @@ sub compile_firewall( $ ) {
#
# Do the BIG UGLY...
#
if ( $command eq 'check' ) {
if ( -s "$ENV{TMP_DIR}/providers" ) {
progress_message2 'Checking Routing...';
setup_providers;
setup_route_marking if $routemarked_interfaces;
}
} else {
progress_message2 "Generating Rule Matrix..."; generate_matrix; dump_chain_table if $ENV{DEBUG};
#
# Create the script.
# Finish the script.
#
if ( $command eq 'check' ) {
setup_providers if -s "$ENV{TMP_DIR}/providers";
} else {
eval {
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
};
fatal_error "$@" if $@;
generate_object;
progress_message2 "Compiling Routing and Traffic Shaping";
generate_script_2;
progress_message2 "Creating iptables-restore input...";
create_netfilter_load;
emit "#\n# Start/Restart the Firewall\n#";
emit 'define_firewall() {';
emit ' setup_routing_and_traffic_shaping;';
emit ' setup_netfilter';
emit ' [ $COMMAND = restore ] || restore_dynamic_rules';
emit "}\n";
copy find_file 'prog.footer';
$file = "$dir/$file";
rename $tempfile, $file;
chmod 0700, $file;