2007-06-21 00:46:10 +02:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
#
|
2007-06-21 16:40:40 +02:00
|
|
|
# Tool for building Shorewall::Ports.
|
2007-06-21 00:46:10 +02:00
|
|
|
#
|
|
|
|
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# buildports.pl [ <directory> ] > /usr/share/shorewall-perl/Shorewall/Ports.pm
|
|
|
|
#
|
|
|
|
# Where:
|
|
|
|
#
|
|
|
|
# <directory> is the directory where the 'protocols' and 'services' files are
|
|
|
|
# located. If not specified, /etc is assumed.
|
|
|
|
#
|
|
|
|
use strict;
|
|
|
|
use lib '/usr/share/shorewall-perl';
|
2007-06-25 21:34:20 +02:00
|
|
|
use Shorewall::Config qw( open_file
|
|
|
|
read_a_line1
|
|
|
|
split_line
|
|
|
|
fatal_error
|
|
|
|
%globals
|
|
|
|
ensure_config_path
|
2007-06-27 00:49:16 +02:00
|
|
|
set_shorewall_dir
|
|
|
|
set_config_path );
|
2007-06-21 00:46:10 +02:00
|
|
|
|
|
|
|
our $offset = "\t\t ";
|
|
|
|
|
|
|
|
our %service_hash;
|
|
|
|
|
|
|
|
sub print_it( $$ ) {
|
|
|
|
my ( $name, $number ) = @_;
|
|
|
|
my $tabs;
|
|
|
|
my $length = length $name;
|
|
|
|
|
|
|
|
if ( $name =~ /\W/ || $name =~ /^\d/ ) {
|
2007-06-21 19:44:41 +02:00
|
|
|
my $repeat = int ( ( 27 - $length ) / 8 );
|
|
|
|
$tabs = $repeat > 0 ? "\t" x $repeat : ' ';
|
2007-06-21 00:46:10 +02:00
|
|
|
print "${offset}'${name}'${tabs}=> $number,\n";
|
|
|
|
} else {
|
2007-06-21 19:44:41 +02:00
|
|
|
my $repeat = int ( ( 29 - $length ) / 8 );
|
|
|
|
$tabs = $repeat > 0 ? "\t" x $repeat : ' ';
|
2007-06-21 00:46:10 +02:00
|
|
|
print "${offset}${name}${tabs}=> $number,\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_service( $$ ) {
|
|
|
|
my ( $service, $number ) = @_;
|
|
|
|
|
|
|
|
unless ( exists $service_hash{$service} ) {
|
|
|
|
print_it( $service, $number );
|
|
|
|
$service_hash{$service} = $number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-27 00:49:16 +02:00
|
|
|
set_config_path( '/etc/shorewall:/usr/share/shorewall' );
|
|
|
|
|
2007-06-21 00:46:10 +02:00
|
|
|
set_shorewall_dir($ARGV[0] || '/etc');
|
|
|
|
|
|
|
|
our $date = localtime;
|
|
|
|
|
|
|
|
print <<"EOF";
|
|
|
|
#
|
|
|
|
# Shorewall-perl 4.0 -- /usr/share/shorewall-perl/Shorewall/Ports.pm
|
|
|
|
#
|
|
|
|
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
|
|
|
|
#
|
|
|
|
# (c) 2007 - Tom Eastep (teastep\@shorewall.net)
|
|
|
|
#
|
|
|
|
# Complete documentation is available at http://shorewall.net
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
|
|
|
|
#
|
2007-06-21 16:40:40 +02:00
|
|
|
# This module exports the %protocols and %services hashes built from
|
|
|
|
# /etc/protocols and /etc/services respectively.
|
2007-06-21 00:46:10 +02:00
|
|
|
#
|
2007-06-21 16:40:40 +02:00
|
|
|
# Module generated using buildports.pl $globals{VERSION} - $date
|
2007-06-21 00:46:10 +02:00
|
|
|
#
|
|
|
|
EOF
|
|
|
|
|
2007-06-21 16:40:40 +02:00
|
|
|
print <<'EOF';
|
2007-06-21 00:46:10 +02:00
|
|
|
package Shorewall::Ports;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
|
|
|
our @EXPORT = qw( %protocols %services );
|
|
|
|
our @EXPORT_OK = qw();
|
2007-06-21 16:40:40 +02:00
|
|
|
our $VERSION = '1.00';
|
2007-06-21 00:46:10 +02:00
|
|
|
|
|
|
|
our %protocols = (
|
|
|
|
EOF
|
|
|
|
|
|
|
|
open_file 'protocols' or fatal_error "Cannot open protocols: $!";
|
|
|
|
|
|
|
|
while ( read_a_line1 ) {
|
2007-06-27 01:06:34 +02:00
|
|
|
my ( $proto1, $number, @aliases ) = split_line( 2, 10, '/etc/protocols entry');
|
2007-06-21 00:46:10 +02:00
|
|
|
|
|
|
|
print_it( $proto1, $number );
|
2007-06-27 01:06:34 +02:00
|
|
|
|
|
|
|
for my $alias ( @aliases ) {
|
|
|
|
last if $alias eq '-';
|
|
|
|
print_it( $alias, $number );
|
|
|
|
}
|
2007-06-21 00:46:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print "\t\t );\n\n";
|
|
|
|
|
2007-06-21 16:40:40 +02:00
|
|
|
print "our %services = (\n";
|
2007-06-21 00:46:10 +02:00
|
|
|
|
|
|
|
open_file 'services' or fatal_error "Cannot open services: $!";
|
|
|
|
|
|
|
|
while ( read_a_line1 ) {
|
|
|
|
my ( $name1, $proto_number, @names ) = split_line( 2, 10, '/etc/services entry');
|
|
|
|
|
|
|
|
my ( $number, $proto ) = split '/', $proto_number;
|
|
|
|
|
2007-06-27 02:48:56 +02:00
|
|
|
next unless $proto && ($proto eq 'tcp' || $proto eq 'udp');
|
2007-06-21 01:33:40 +02:00
|
|
|
|
2007-06-21 00:46:10 +02:00
|
|
|
print_service( $name1 , $number );
|
|
|
|
|
|
|
|
while ( defined ( $name1 = shift @names ) && $name1 ne '-' ) {
|
|
|
|
print_service ($name1, $number );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print "\t\t );\n\n1;\n";
|