mirror of
https://gitlab.com/shorewall/code.git
synced 2025-06-20 17:58:07 +02:00
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:
parent
ef18b475c1
commit
d7ab9421bf
@ -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 {
|
sub progress_message2 {
|
||||||
if ( $ENV{VERBOSE} > 0 ) {
|
if ( $ENV{VERBOSE} > 0 ) {
|
||||||
my $ts = '';
|
timestamp if $ENV{TIMESTAMP};
|
||||||
$ts = ( localtime ) . ' ' if $ENV{TIMESTAMP};
|
print "@_\n";
|
||||||
print "${ts}@_\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub progress_message3 {
|
sub progress_message3 {
|
||||||
if ( $ENV{VERBOSE} >= 0 ) {
|
if ( $ENV{VERBOSE} >= 0 ) {
|
||||||
my $ts = '';
|
timestamp if $ENV{TIMESTAMP};
|
||||||
$ts = ( localtime ) . ' ' if $ENV{TIMESTAMP};
|
print "@_\n";
|
||||||
print "${ts}@_\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5188,8 +5191,8 @@ sub generate_matrix() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub create_iptables_restore_file() {
|
sub create_netfilter_load() {
|
||||||
emit 'restore_iptables()';
|
emit 'setup_netfilter()';
|
||||||
emit '{';
|
emit '{';
|
||||||
emit ' iptables-restore << __EOF__';
|
emit ' iptables-restore << __EOF__';
|
||||||
|
|
||||||
@ -5892,7 +5895,7 @@ sub setup_route_marking() {
|
|||||||
sub setup_traffic_shaping() {
|
sub setup_traffic_shaping() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub generate_object () {
|
sub generate_script_1 {
|
||||||
copy find_file 'prog.header';
|
copy find_file 'prog.header';
|
||||||
|
|
||||||
my $date = localtime;
|
my $date = localtime;
|
||||||
@ -5931,7 +5934,7 @@ sub generate_object () {
|
|||||||
emit 'initialize()';
|
emit 'initialize()';
|
||||||
emit '{';
|
emit '{';
|
||||||
|
|
||||||
$indent = ' ';
|
push_indent;
|
||||||
|
|
||||||
if ( $ENV{EXPORT} ) {
|
if ( $ENV{EXPORT} ) {
|
||||||
emit '#';
|
emit '#';
|
||||||
@ -5989,16 +5992,19 @@ sub generate_object () {
|
|||||||
emit '#';
|
emit '#';
|
||||||
emit '[ -d ${VARDIR} ] || mkdir -p ${VARDIR}';
|
emit '[ -d ${VARDIR} ] || mkdir -p ${VARDIR}';
|
||||||
|
|
||||||
$indent = '';
|
pop_indent;
|
||||||
|
|
||||||
emit "}\n";
|
emit "}\n";
|
||||||
|
|
||||||
copy find_file 'prog.functions';
|
copy find_file 'prog.functions';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub generate_script_2 () {
|
||||||
emit '#';
|
emit '#';
|
||||||
emit '# Start/Restart/Reload the firewall';
|
emit '# Setup Routing and Traffic Shaping';
|
||||||
emit '#';
|
emit '#';
|
||||||
emit 'define_firewall() {';
|
emit 'setup_routing_and_traffic_shaping() {';
|
||||||
|
|
||||||
$indent = ' ';
|
$indent = ' ';
|
||||||
|
|
||||||
@ -6062,21 +6068,12 @@ sub generate_object () {
|
|||||||
emit 'restore_default_route';
|
emit 'restore_default_route';
|
||||||
}
|
}
|
||||||
|
|
||||||
emit "restore_iptables\n";
|
|
||||||
|
|
||||||
emit "restore_dynamic_rules\n";
|
|
||||||
|
|
||||||
setup_traffic_shaping if -s "$ENV{TMP_DIR}/tcdevices";
|
setup_traffic_shaping if -s "$ENV{TMP_DIR}/tcdevices";
|
||||||
|
|
||||||
$indent = '';
|
$indent = '';
|
||||||
|
|
||||||
emit "}\n";;
|
emit "}\n";;
|
||||||
|
|
||||||
progress_message2 "Creating iptables-restore input...";
|
|
||||||
|
|
||||||
create_iptables_restore_file;
|
|
||||||
|
|
||||||
copy find_file 'prog.footer';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub report_capability( $ ) {
|
sub report_capability( $ ) {
|
||||||
@ -6105,6 +6102,14 @@ sub compile_firewall( $ ) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fatal_error "$@" if $@;
|
fatal_error "$@" if $@;
|
||||||
|
|
||||||
|
eval {
|
||||||
|
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
|
||||||
|
};
|
||||||
|
|
||||||
|
fatal_error "$@" if $@;
|
||||||
|
|
||||||
|
generate_script_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $ENV{VERBOSE} > 1 ) {
|
if ( $ENV{VERBOSE} > 1 ) {
|
||||||
@ -6196,21 +6201,29 @@ sub compile_firewall( $ ) {
|
|||||||
#
|
#
|
||||||
# Do the BIG UGLY...
|
# 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};
|
progress_message2 "Generating Rule Matrix..."; generate_matrix; dump_chain_table if $ENV{DEBUG};
|
||||||
#
|
#
|
||||||
# Create the script.
|
# Finish the script.
|
||||||
#
|
#
|
||||||
if ( $command eq 'check' ) {
|
progress_message2 "Compiling Routing and Traffic Shaping";
|
||||||
setup_providers if -s "$ENV{TMP_DIR}/providers";
|
generate_script_2;
|
||||||
} else {
|
progress_message2 "Creating iptables-restore input...";
|
||||||
eval {
|
create_netfilter_load;
|
||||||
( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir );
|
emit "#\n# Start/Restart the Firewall\n#";
|
||||||
};
|
emit 'define_firewall() {';
|
||||||
|
emit ' setup_routing_and_traffic_shaping;';
|
||||||
fatal_error "$@" if $@;
|
emit ' setup_netfilter';
|
||||||
|
emit ' [ $COMMAND = restore ] || restore_dynamic_rules';
|
||||||
generate_object;
|
emit "}\n";
|
||||||
|
|
||||||
|
copy find_file 'prog.footer';
|
||||||
$file = "$dir/$file";
|
$file = "$dir/$file";
|
||||||
rename $tempfile, $file;
|
rename $tempfile, $file;
|
||||||
chmod 0700, $file;
|
chmod 0700, $file;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user