Uniform mechanism for inserting conversion comments

Signed-off-by: Tom Eastep <teastep@shorewall.net>

Conflicts:
	Shorewall/Perl/Shorewall/Tc.pm
This commit is contained in:
Tom Eastep 2015-08-31 11:21:18 -07:00
parent 9b886a99af
commit 53223e1440
3 changed files with 62 additions and 15 deletions

View File

@ -124,6 +124,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
set_shorewall_dir set_shorewall_dir
set_debug set_debug
find_file find_file
find_writable_file
split_list split_list
split_list1 split_list1
split_list2 split_list2
@ -1861,6 +1862,20 @@ sub find_file($)
"$config_path[0]$filename"; "$config_path[0]$filename";
} }
sub find_writable_file($) {
my ( $filename, $nosearch ) = @_;
return $filename if $filename =~ '/';
for my $directory ( @config_path ) {
next if $directory =~ m|^$globals{SHAREDIR}/configfiles/?$| || $directory =~ m|^$shorewallrc{SHAREDIR}/doc/default-config/?$|;
my $file = "$directory$filename";
return $file if -f $file && -w _;
}
"$config_path[0]$filename";
}
# #
# Split a comma-separated list into a Perl array # Split a comma-separated list into a Perl array
# #
@ -4751,6 +4766,12 @@ sub conditional_quote( $ ) {
# #
# Update the shorewall[6].conf file. Save the current file with a .bak suffix. # Update the shorewall[6].conf file. Save the current file with a .bak suffix.
# #
sub update_default($$) {
my ( $var, $val ) = @_;
$config{$var} = $val unless defined $config{$var};
}
sub update_config_file( $$ ) { sub update_config_file( $$ ) {
my ( $annotate, $directives ) = @_; my ( $annotate, $directives ) = @_;
@ -4802,9 +4823,8 @@ sub update_config_file( $$ ) {
} }
} }
$config{USE_DEFAULT_RT} = 'No' unless defined $config{USE_DEFAULT_RT}; update_default( 'USE_DEFAULT_RT', 'No' );
update_default( 'EXPORTMODULES', 'No' );
$config{EXPORTMODULES} = 'No' unless defined $config{EXPORTMODULES};
my $fn; my $fn;

View File

@ -281,7 +281,7 @@ sub convert_blacklist() {
} }
if ( @rules ) { if ( @rules ) {
my $fn1 = find_file( 'blrules' ); my $fn1 = find_writable_file( 'blrules' );
my $blrules; my $blrules;
my $date = localtime; my $date = localtime;
@ -378,7 +378,7 @@ sub convert_routestopped() {
my ( $stoppedrules, $fn1 ); my ( $stoppedrules, $fn1 );
if ( -f ( $fn1 = find_file( 'stoppedrules' ) ) ) { if ( -f ( $fn1 = find_writable_file( 'stoppedrules' ) ) ) {
open $stoppedrules, '>>', $fn1 or fatal_error "Unable to open $fn1: $!"; open $stoppedrules, '>>', $fn1 or fatal_error "Unable to open $fn1: $!";
} else { } else {
open $stoppedrules, '>', $fn1 or fatal_error "Unable to open $fn1: $!"; open $stoppedrules, '>', $fn1 or fatal_error "Unable to open $fn1: $!";
@ -400,12 +400,16 @@ sub convert_routestopped() {
EOF EOF
} }
first_entry(
sub {
my $date = localtime;
progress_message2 "$doing $fn...";
print( $stoppedrules print( $stoppedrules
"#\n" , "#\n" ,
"# Rules generated from routestopped file $fn by Shorewall $globals{VERSION} - $date\n" , "# Rules generated from routestopped file $fn by Shorewall $globals{VERSION} - $date\n" ,
"#\n" ); "#\n" );
}
first_entry "$doing $fn..."; );
while ( read_a_line ( NORMAL_READ ) ) { while ( read_a_line ( NORMAL_READ ) ) {

View File

@ -3155,6 +3155,16 @@ sub convert_tos($$) {
} }
if ( my $fn = open_file 'tos' ) { if ( my $fn = open_file 'tos' ) {
first_entry
sub {
my $date = localtime;
progress_message2 "Converting $fn...";
print( $mangle
"#\n" ,
"# Rules generated from tos file $fn by Shorewall $globals{VERSION} - $date\n" ,
"#\n" );
};
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line( NORMAL_READ ) ) {
$have_tos = 1; $have_tos = 1;
@ -3217,10 +3227,10 @@ sub convert_tos($$) {
sub open_mangle_for_output() { sub open_mangle_for_output() {
my ( $mangle, $fn1 ); my ( $mangle, $fn1 );
if ( -f ( find_file( 'mangle' ) ) ) { if ( -f ( $fn1 = find_writeable_file( 'mangle' ) ) ) {
open( $mangle , '>>', $fn1 = find_file('mangle') ) || fatal_error "Unable to open $fn1:$!"; open( $mangle , '>>', $fn1 ) || fatal_error "Unable to open $fn1:$!";
} else { } else {
open( $mangle , '>', $fn1 = find_file('mangle') ) || fatal_error "Unable to open $fn1:$!"; open( $mangle , '>', $fn1 ) || fatal_error "Unable to open $fn1:$!";
print $mangle <<'EOF'; print $mangle <<'EOF';
# #
# Shorewall version 4 - Mangle File # Shorewall version 4 - Mangle File
@ -3310,7 +3320,20 @@ sub setup_tc( $ ) {
directive_callback( sub () { print $mangle "$_[1]\n" unless $_[0] eq 'FORMAT'; 0; } ); directive_callback( sub () { print $mangle "$_[1]\n" unless $_[0] eq 'FORMAT'; 0; } );
first_entry "$doing $fn...";
first_entry
sub {
if ( $convert ) {
my $date = localtime;
progress_message2 "Converting $fn...";
print( $mangle
"#\n" ,
"# Rules generated from tcrules file $fn by Shorewall $globals{VERSION} - $date\n" ,
"#\n" );
} else {
progress_message2 "$doing $fn...";
}
};
process_tc_rule, $have_tcrules++ while read_a_line( NORMAL_READ ); process_tc_rule, $have_tcrules++ while read_a_line( NORMAL_READ );