pf-tools commit: r797 [ccaillet-guest] - in /branches/next-gen: debian/changelog filters/filter_privateresolve filters/filter_vlan2if lib/PFTools/Conf.pm lib/PFTools/Utils.pm sbin/mk_grubopt sbin/mk_interfaces sbin/mk_resolvconf sbin/mk_sourceslist
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Aug 4 09:44:24 UTC 2010
Author: ccaillet-guest
Date: Wed Aug 4 09:44:22 2010
New Revision: 797
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=797
Log:
* filter/filter_privateresolve : rewrite according to new global structure, using
Getopt::Long for handling command line option(s)
* filter/filter_vlan2if : rewrite according to new global structure, using
Getopt::Long for handling command line option(s)
Modified:
branches/next-gen/debian/changelog
branches/next-gen/filters/filter_privateresolve
branches/next-gen/filters/filter_vlan2if
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Utils.pm
branches/next-gen/sbin/mk_grubopt
branches/next-gen/sbin/mk_interfaces
branches/next-gen/sbin/mk_resolvconf
branches/next-gen/sbin/mk_sourceslist
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=797&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Wed Aug 4 09:44:22 2010
@@ -71,8 +71,12 @@
- uploaders and maintainers update
* debian/compat
- update level for avoiding warning during package build
-
- -- Christophe Caillet <quadchris at free.fr> Tue, 03 Aug 2010 12:17:34 +0200
+ * filter/filter_privateresolve : rewrite according to new global structure, using
+ Getopt::Long for handling command line option(s)
+ * filter/filter_vlan2if : rewrite according to new global structure, using
+ Getopt::Long for handling command line option(s)
+
+ -- Christophe Caillet <tof at sitadelle.com> Wed, 04 Aug 2010 11:43:05 +0200
pf-tools (0.34.0-0WIP) unstable; urgency=low
Modified: branches/next-gen/filters/filter_privateresolve
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/filters/filter_privateresolve?rev=797&op=diff
==============================================================================
--- branches/next-gen/filters/filter_privateresolve (original)
+++ branches/next-gen/filters/filter_privateresolve Wed Aug 4 09:44:22 2010
@@ -2,6 +2,7 @@
##
## $Id$
##
+## Copyright (C) 2010 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
##
@@ -23,78 +24,113 @@
use strict;
use warnings;
-use PFTools::Conf;
-use PFTools::Net;
-use PFTools::Update;
+use PFTools::Utils;
+use PFTools::Logger;
+use Getopt::Long qw( :config ignore_case_always bundling );
-my ( $src, $host, $dst, $sep ) = @ARGV;
-unless ( $src and $host and $dst ) {
- die "Usage: $0 src host dst [sep]\n";
+use Sys::Hostname;
+
+#################################
+# VARS
+my $HELP = 0;
+my $HOSTNAME = hostname;
+my $SITE = '';
+my $GLOBAL_STORE_FILE = '';
+my $PF_CONFIG_FILE = '';
+my $PF_CONFIG = {};
+my $TYPE_RESOLVE = 'cnf';
+my $SEPARATOR = " ";
+my $ZONE = "";
+my $INPUT_FILE = '';
+my $OUTPUT_FILE = '';
+my $GLOBAL_STRUCT = {};
+
+my $program = $0;
+$program =~ s%.*/%%; # cheap basename
+
+my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+
+###################################
+# Funtions
+
+sub Do_help {
+ print STDERR << "# ENDHELP";
+ $program - version $version
+
+Usage: $0 [options]
+ --help : print help and exit
+ -h --host : hostname for which we want to filter input
+ -s --site : site on which hostname is defined (optional)
+ -c --config : file where pf-tools configuration is stored e.g. /etc/pf-tools.conf (optional)
+ --store : file where global structure datas are in storable format (optional)
+ -z --zone : zone on which we want to filter input
+ -t --type : type for resolution. Allowed values are cnf (from global configuration structure) and dns
+ --sep : separator between resolved IPs
+ -i --input : input file
+ -o --output : output file
+
+# ENDHELP
}
-$sep = ' ' unless defined $sep;
+##################################
+### MAIN
-my $Z = Init_lib_net( Get_source("GLOBAL:private-network") );
-my %subst;
-Init_SUBST ( \%subst, $host, "private" );
+GetOptions (
+ 'help' => \$HELP,
+ 'host|h=s' => \$HOSTNAME,
+ 'site|s=s' => \$SITE,
+ 'config|c=s' => \$PF_CONFIG_FILE,
+ 'store=s' => \$GLOBAL_STORE_FILE,
+ 'type|t=s' => \$TYPE_RESOLVE,
+ 'sep=s' => \$SEPARATOR,
+ 'zone|z=s' => \$ZONE,
+ 'input|i=s' => \$INPUT_FILE,
+ 'output|o=s' => \$OUTPUT_FILE
+) or die "Didn't grok options (see --help).\n";
-open SRC, "<$src" or die "open: $src: $!\n";
-open DST, ">$dst" or die "open: $dst: $!\n";
+if ( $HELP ) {
+ Do_help ();
+ exit 0;
+}
-while (<SRC>) {
- my $line = $_;
- my $pos = length $line;
- while (
- substr( $line, 0, $pos )
- =~ m/^(.*[^A-Za-z0-9.-])?([A-Za-z0-9.-]+)(\\?)(\.$Z->{SOA}->{name})([^A-Za-z0-9.-].*)?$/
- )
- {
- my $before = $1;
- my $back = $3;
- my $match = $2 . $3 . $4;
- my $matchback = $2 . $4;
- my $after = $5;
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
- my $lengthbefore = defined $before ? length $before : 0;
-
- if ( $back ne '\\' ) {
-
- my $match2 = $match;
- $match2 =~ s/HOSTNAME/$host/;
- $match2 =~ s/POPNAME/$subst{'POPNAME'}/g;
-
- my @resolved = Resolv( $match2, $Z );
-
- if ( @resolved and defined $resolved[0] ) {
- if ( $sep eq "DUPLICATE" ) {
- my $templine = "";
- my $templine2;
- foreach my $res (@resolved) {
- $templine2 = $line;
- substr( $templine2, $lengthbefore, length $match )
- = $res;
- $templine .= $templine2;
- }
- $line = $templine;
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
}
else {
- substr( $line, $lengthbefore, length $match )
- = join( $sep, @resolved );
+ ( $SITE ) = @{$site_list};
}
- $pos = $lengthbefore;
- }
- else {
- $pos = $lengthbefore;
- }
}
else {
- substr( $line, $lengthbefore, length $match ) = $matchback;
- $pos = $lengthbefore;
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
}
- }
- print DST $line;
+ $ZONE = Get_zone_from_site_GLOBAL ( $SITE, $GLOBAL_STRUCT );
}
-close DST;
-close SRC;
+if ( $INPUT_FILE eq '' || $OUTPUT_FILE eq '' ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Source and/or destination file is(are) not defined on CLI" );
+}
+my $filtered_src = Search_and_replace ( $HOSTNAME, $SITE, $INPUT_FILE, 'resolver', $PF_CONFIG, $SEPARATOR, $GLOBAL_STRUCT, $TYPE_RESOLVE );
+
+unless ( open ( OUTPUT, ">".$OUTPUT_FILE ) ) {
+ Abort ( $CODE->{'OPEN'},
+ "Unable to open destination file ".$OUTPUT_FILE." : $!" );
+}
+
+print OUTPUT join ( "", @{$filtered_src} );
+close ( OUTPUT );
+
+exit 0;
Modified: branches/next-gen/filters/filter_vlan2if
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/filters/filter_vlan2if?rev=797&op=diff
==============================================================================
--- branches/next-gen/filters/filter_vlan2if (original)
+++ branches/next-gen/filters/filter_vlan2if Wed Aug 4 09:44:22 2010
@@ -27,63 +27,102 @@
use strict;
use warnings;
-use PFTools::Conf;
-use PFTools::Net;
-use PFTools::Update;
+use PFTools::Utils;
+use PFTools::Logger;
+use Getopt::Long qw( :config ignore_case_always bundling );
+use Sys::Hostname;
-my ( $src, $host, $dst ) = @ARGV;
+#################################
+# VARS
+my $HELP = 0;
+my $HOSTNAME = hostname;
+my $SITE = '';
+my $GLOBAL_STORE_FILE = '';
+my $PF_CONFIG_FILE = '';
+my $PF_CONFIG = {};
+my $INPUT_FILE = '';
+my $OUTPUT_FILE = '';
+my $GLOBAL_STRUCT = {};
-unless ( $src and $host and $dst ) {
- die "Usage: $0 src host dst\n";
+my $program = $0;
+$program =~ s%.*/%%; # cheap basename
+
+my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+
+###################################
+# Funtions
+
+sub Do_help {
+ print STDERR << "# ENDHELP";
+ $program - version $version
+
+Usage: $0 [options]
+ --help : print help and exit
+ -h --host : hostname for which we want to filter input
+ -s --site : site on which hostname is defined (optional)
+ -c --config : file where pf-tools configuration is stored e.g. /etc/pf-tools.conf (optional)
+ --store : file where global structure datas are in storable format (optional)
+ -i --input : input file
+ -o --output : output file
+
+# ENDHELP
}
-my $Z = Init_lib_net( Get_source("GLOBAL:private-network") );
-my %subst;
-Init_SUBST ( \%subst, $host, "private" );
+##################################
+### MAIN
-open SRC, "<$src" or die "open: $src: $!\n";
-open DST, ">$dst" or die "open: $dst: $!\n";
+GetOptions (
+ 'help' => \$HELP,
+ 'host|h=s' => \$HOSTNAME,
+ 'site|s=s' => \$SITE,
+ 'config|c=s' => \$PF_CONFIG_FILE,
+ 'store=s' => \$GLOBAL_STORE_FILE,
+ 'input|i=s' => \$INPUT_FILE,
+ 'output|o=s' => \$OUTPUT_FILE
+) or die "Didn't grok options (see --help).\n";
-while (<SRC>) {
- my $line = $_;
- my $pos = length $line;
- while (
- substr( $line, 0, $pos )
- =~ m/^(.*[^A-Za-z0-9.-])?(eth([-.:])([A-Za-z0-9-]+))([^A-Za-z0-9.-].*)?$/
- )
- {
- my $before = $1;
- my $match = $2;
- my $type = $3;
- my $vlan = $4;
- my $after = $5;
+if ( $HELP ) {
+ Do_help ();
+ exit 0;
+}
- my $lengthbefore = defined $before ? length $before : 0;
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
- my $vlan2 = $vlan;
- $vlan2 =~ s/POPNAME/$subst{'POPNAME'}/;
-
- my $eth = Get_If( $Z, $host, $vlan2 );
-
- if ( defined $eth ) {
- my $neweth = $eth;
- if ( $type eq '.' ) {
- $neweth =~ s/:.*$//;
- }
- elsif ( $type eq '-' ) {
- $neweth =~ s/[.:].*$//;
- }
-
- substr( $line, $lengthbefore, length $match ) = $neweth;
- $pos = $lengthbefore;
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
+ }
+ else {
+ ( $SITE ) = @{$site_list};
+ }
}
else {
- $pos = $lengthbefore;
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
}
- }
- print DST $line;
}
-close DST;
-close SRC;
+if ( $INPUT_FILE eq '' || $OUTPUT_FILE eq '' ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Source and/or destination file is(are) not defined on CLI" );
+}
+my $filtered_src = Search_and_replace ( $HOSTNAME, $SITE, $INPUT_FILE, 'iface', $PF_CONFIG, "", $GLOBAL_STRUCT );
+
+unless ( open ( OUTPUT, ">".$OUTPUT_FILE ) ) {
+ Abort ( $CODE->{'OPEN'},
+ "Unable to open destination file ".$OUTPUT_FILE." : $!" );
+}
+
+print OUTPUT join ( "", @{$filtered_src} );
+close ( OUTPUT );
+
+exit 0;
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=797&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Wed Aug 4 09:44:22 2010
@@ -285,13 +285,16 @@
'after_change' => 'undefined'
};
$DEF_SECTIONS->{'config'}->{'dpkg-purge'} = $DEF_SECTIONS->{'config'}->{'apt-get'};
-
+$DEF_SECTIONS->{'config'}->{'filter-model'} = {
+ 'MANDATORY_KEYS' => [ 'filter' ],
+ 'filter' => 'undefined'
+};
our @EXPORT_OK = qw();
my $DEBUG = 0 ;
# Global hash for substitution
-our %SUBST;
+# our %SUBST;
my $FAKEHOSTNAME;
my $FAKEDOMAINNAME;
@@ -362,7 +365,10 @@
'hostname' => $HOST_CONFIG_REGEX,
'hosttype' => $HOSTTYPE_CONFIG_REGEX
};
-
+$PF_CONFIG->{'location'} = {
+ 'site' => '',
+ 'zone' => ''
+};
sub Init_PF_CONFIG (;$) {
my ( $config_file ) = @_;
@@ -393,21 +399,22 @@
return $PF_CONFIG;
}
-sub Init_SUBST ($;$$$) {
- my ( $ref_subst, $pf_config, $fakehost, $fakedomain ) = @_ ;
- my $host_regex;
+sub Init_SUBST ($;$$) {
+ my ( $host, $pf_config, $domain ) = @_ ;
+ my $host_regex; my $ref_subst = {};
if ( ! defined $pf_config ) {
$pf_config = Init_PF_CONFIG ();
}
- if ( defined $fakehost && ! defined $fakedomain ) {
- warn "Unable to init substitution hash for hostname ".$fakehost."\n" ;
+ if ( ! defined $host ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to init substitution hash for hostname ".$host."\n" );
return ;
}
- elsif ( defined $fakehost ) {
- $ref_subst->{'HOSTNAME'} = $fakehost ;
- $ref_subst->{'DOMAINNAME'} = $fakedomain ;
+ elsif ( defined $host ) {
+ $ref_subst->{'HOSTNAME'} = $host ;
+ $ref_subst->{'DOMAINNAME'} = $domain || $pf_config->{'location'}->{'zone'} || "";
}
else {
chomp ( $ref_subst->{'HOSTNAME'} = `/bin/hostname -s 2>>/dev/null` ) ;
@@ -443,15 +450,14 @@
}
$ref_subst->{'HOSTMINUTE'} = $ref_subst->{'HOSTNUM'} % 60 ;
$ref_subst->{'HOSTHOUR'} = $ref_subst->{'HOSTNUM'} % 24 ;
-}
-
-Init_SUBST ( \%SUBST ) ;
-
-sub Get_source ($;$$) {
- my ( $source, $hash_subst, $pf_config ) = @_;
+ return $ref_subst;
+}
+
+sub Get_source ($$;$$) {
+ my ( $source, $hostname, $hash_subst, $pf_config ) = @_;
if ( ! defined $hash_subst ) {
- $hash_subst = \%SUBST;
+ $hash_subst = Init_SUBST ( $hostname, $pf_config ) ;
}
elsif ( ! defined $pf_config ) {
$pf_config = $PF_CONFIG;
@@ -473,9 +479,9 @@
sub __Get_config_path ($$$) {
my ( $hostvalue, $pf_config, $site ) = @_;
- my $site_conf_file = Get_source ( 'CONFSITE_'.$site.':/update-'.$hostvalue, {}, $pf_config );
+ my $site_conf_file = Get_source ( 'CONFSITE_'.$site.':/update-'.$hostvalue, $hostvalue, {}, $pf_config );
return $site_conf_file if ( -e $site_conf_file );
- my $default_conf_file = Get_source ( 'CONFIG:/update-'.$hostvalue, {}, $pf_config );
+ my $default_conf_file = Get_source ( 'CONFIG:/update-'.$hostvalue, $hostvalue, {}, $pf_config );
return $default_conf_file if ( -e $default_conf_file );
return undef;
}
@@ -791,7 +797,7 @@
$section =~ /^([^:]+)(::.+)?$/;
$sect_type = $1;
if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
- my $model_parsed = Load_conf ( Get_source ( $parsed->{$section}->{'model'}, $hash_subst, $pf_config ), $hash_subst, 'model', $pf_config );
+ my $model_parsed = Load_conf ( Get_source ( $parsed->{$section}->{'model'}, "", $hash_subst, $pf_config ), $hash_subst, 'model', $pf_config );
$parsed->{$section}->{'__model'} = $model_parsed;
}
}
@@ -803,7 +809,7 @@
$sect_type = $parsed->{$section}->{$select};
if ( $sect_type eq 'include' ) {
# We need to dive into deep ...
- my $inc_parsed = Load_conf ( Get_source ( $section, $hash_subst, $pf_config ), $hash_subst, $context, $pf_config );
+ my $inc_parsed = Load_conf ( Get_source ( $section, "", $hash_subst, $pf_config ), $hash_subst, $context, $pf_config );
$parsed->{$section}->{'__content'} = $inc_parsed;
}
}
@@ -891,7 +897,7 @@
foreach my $site ( @{$site_list} ) {
my $service_part = $GLOBAL->{'SITE'}->{'BY_NAME'}->{$site}->{'SERVICE'}->{'BY_NAME'};
foreach my $host ( @{$net_parsed->{$section}->{'@host'}} ) {
- my $hostfile = Get_source ( $host, $hash_subst, $pf_config );
+ my $hostfile = Get_source ( $host, "", $hash_subst, $pf_config );
my $host_parsed = Load_conf ( $hostfile, $hash_subst, 'host', $pf_config );
Add_host ( $hostfile, $host_parsed, $GLOBAL, $pf_config );
push ( @{$service_part->{$section}}, $host );
@@ -927,7 +933,7 @@
my ( $hostname, $site, $hash_subst, $global_config, $pf_config ) = @_;
# Common configuration file e.g. update-common
- my $global_host_conf = Load_conf ( Get_source ( 'COMMON:/'.$pf_config->{'path'}->{'common_config'}, $hash_subst, $pf_config ), $hash_subst, 'config', $pf_config );
+ my $global_host_conf = Load_conf ( Get_source ( 'COMMON:/'.$pf_config->{'path'}->{'common_config'}, $hostname, $hash_subst, $pf_config ), $hash_subst, 'config', $pf_config );
my $hosttype = Get_hosttype_from_hostname ( $hostname, $global_config, $site );
if ( ! defined $hosttype ) {
Abort ( $CODE->{'UNDEF_KEY'},
Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=797&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Wed Aug 4 09:44:22 2010
@@ -31,6 +31,7 @@
Get_host_config_from_CONFIG
Get_site_from_hostname
+ Get_zone_from_site_GLOBAL
Get_cmdline_from_hostprops
Mk_dhcp
@@ -40,6 +41,10 @@
Mk_resolvconf
Mk_zone_for_site
Change_kopt_for_hostname
+
+ Resolv_hostname_from_DNS
+ Resolv_hostname_from_GLOBAL
+ Search_and_replace
);
our @EXPORT_OK = qw();
@@ -159,6 +164,12 @@
}
}
return $site_list;
+}
+
+sub Get_zone_from_site_GLOBAL ($$) {
+ my ( $site, $global_config ) = @_;
+
+ return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
}
sub Get_cmdline_from_hostprops ($) {
@@ -460,30 +471,39 @@
}
}
- my $zone = Get_zone_from_hostname ( $hostname, $global_config, $site );
- $hostname =~ s/\.$zone$//;
- if ( ! defined $hosttype ) {
- $hosttype = Get_hosttype_from_hostname ( $hostname, $global_config, $site );
- return undef if ( ! defined $hosttype );
- }
- my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
- foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
- next if ( $entry !~ /^$hostname$/ );
- my @fields;
- if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
- @fields = @{$zone_part->{$hosttype}->{$entry}}
- }
- else {
- @fields = ( $zone_part->{$hosttype}->{$entry} );
- }
- foreach my $line ( @fields ) {
- my ( $type, $field ) = split ( /\s+/, $line );
- if ( $type eq 'A' ) {
- push ( @{$resolved}, $field );
- }
- elsif ( $type eq 'CNAME' ) {
- my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $hosttype );
- push ( @{$resolved}, @{$cname_resolved} );
+ my $zone = Get_zone_from_hostname ( $hostname, $global_config, $site );
+ $hostname =~ s/\.$zone$//;
+ $hostname =~ /^([^.]+)(\.([^.]+))?$/;
+ my ( $hostshort, $hostvlan ) = ( $1, $3 );
+ my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
+ if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ && defined $hostvlan ) {
+ return undef if ( ! defined $zone_part->{$hostvlan} );
+ my ( $type, $field ) = split ( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
+ push ( @{$resolved}, $field );
+ }
+ else {
+ if ( ! defined $hosttype ) {
+ $hosttype = Get_hosttype_from_hostname ( $hostshort, $global_config, $site );
+ return undef if ( ! defined $hosttype );
+ }
+ foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
+ next if ( $entry !~ /^$hostname$/ );
+ my @fields;
+ if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
+ @fields = @{$zone_part->{$hosttype}->{$entry}}
+ }
+ else {
+ @fields = ( $zone_part->{$hosttype}->{$entry} );
+ }
+ foreach my $line ( @fields ) {
+ my ( $type, $field ) = split ( /\s+/, $line );
+ if ( $type eq 'A' ) {
+ push ( @{$resolved}, $field );
+ }
+ elsif ( $type eq 'CNAME' ) {
+ my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $hosttype );
+ push ( @{$resolved}, @{$cname_resolved} );
+ }
}
}
}
@@ -508,6 +528,126 @@
return undef;
}
return $resolved;
+}
+
+sub __Search_and_resolve_IP ($$$$$$$) {
+ my ( $hostname, $site, $line, $separator, $type_resolve, $hash_subst, $global_config ) = @_;
+
+ my $zone = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
+ my $pos = length $line;
+ while (
+ substr( $line, 0, $pos ) =~ m/^(.*[^A-Za-z0-9.-])?([A-Za-z0-9.-]+)(\\?)(\.$zone)([^A-Za-z0-9.-].*)?$/
+ ) {
+ my $before = $1;
+ my $back = $3;
+ my $match = $2 . $3 . $4;
+ my $matchback = $2 . $4;
+ my $after = $5;
+ my $lengthbefore = defined $before ? length $before : 0;
+ if ( $back ne "\\\\" ) {
+ my $match2 = $match;
+ $match2 =~ s/HOSTNAME/$hostname/;
+ $match2 =~ s/POPNAME/$hash_subst->{'POPNAME'}/g;
+ my $resolved = ( $type_resolve eq 'cnf' )
+ ? Resolv_hostname_from_GLOBAL ( $match2, $global_config, $site )
+ : Resolv_hostname_from_DNS ( $match2 );
+ if ( scalar $resolved ) {
+ if ( $separator eq "DUPLICATE" ) {
+ my $templine = "";
+ my $templine2;
+ foreach my $res ( @{$resolved} ) {
+ $templine2 = $line;
+ substr ( $templine2, $lengthbefore, length $match ) = $res;
+ $templine .= $templine2;
+ }
+ $line = $templine;
+ }
+ else {
+ substr( $line, $lengthbefore, length $match ) = join( $separator, @{$resolved} );
+ }
+ $pos = $lengthbefore;
+ }
+ else {
+ $pos = $lengthbefore;
+ }
+ }
+ else {
+ substr( $line, $lengthbefore, length $match ) = $matchback;
+ $pos = $lengthbefore;
+ }
+ }
+ return $line;
+}
+
+sub __Search_and_resolve_IFACE ($$$) {
+ my ( $line, $host_props, $hash_subst ) = @_;
+
+ my $pos = length $line;
+ while (
+ substr( $line, 0, $pos )
+ =~ m/^(.*[^A-Za-z0-9.-])?(eth([-.:])([A-Za-z0-9-]+))([^A-Za-z0-9.-].*)?$/
+ ) {
+ my $before = $1;
+ my $match = $2;
+ my $type = $3;
+ my $vlan = $4;
+ my $after = $5;
+
+ my $lengthbefore = defined $before ? length $before : 0;
+
+ my $vlan2 = $vlan;
+ $vlan2 =~ s/POPNAME/$hash_subst->{'POPNAME'}/;
+
+ my $eth = Get_iface_vlan_from_hostname ( $vlan2, $host_props );
+
+ if ( defined $eth ) {
+ my $neweth = $eth;
+ if ( $type eq "." ) {
+ $neweth =~ s/:.*$//;
+ }
+ elsif ( $type eq "-" ) {
+ $neweth =~ s/[.:].*$//;
+ }
+ substr( $line, $lengthbefore, length $match ) = $neweth;
+ $pos = $lengthbefore;
+ }
+ else {
+ $pos = $lengthbefore;
+ }
+ }
+ return $line;
+}
+
+sub Search_and_replace ($$$$$$$;$) {
+ my ( $hostname, $site, $input_file, $type_replace, $pf_config, $separator, $global_config, $type_resolve ) = @_;
+ my $result = [];
+
+ if ( $type_resolve && $type_resolve eq 'cnf' && ! defined $global_config ) {
+ Warn ( $CODE->{'UNDEF_KEY'},
+ "Unable top resolve from configuration structure which is not defined" );
+ return undef;
+ }
+ my $subst = Init_SUBST ( $hostname, $pf_config );
+ my $host_props = Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
+
+ unless ( open ( SRC, $input_file ) ) {
+ Warn ( $CODE->{'OPEN'},
+ "Unable top open file ".$input_file." : $!" );
+ return 0;
+ }
+ my @src = <SRC>;
+ close ( SRC );
+
+ foreach my $line ( @src ) {
+ if ( $type_replace eq 'resolver' ) {
+ $line = __Search_and_resolve_IP ( $hostname, $site, $line, $separator, $type_resolve, $subst, $global_config );
+ }
+ elsif ( $type_replace eq 'iface' ) {
+ $line = __Search_and_resolve_IFACE ( $line, $host_props, $subst );
+ }
+ push ( @{$result}, $line );
+ }
+ return $result;
}
sub Mk_dhcp ($$) {
Modified: branches/next-gen/sbin/mk_grubopt
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_grubopt?rev=797&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_grubopt (original)
+++ branches/next-gen/sbin/mk_grubopt Wed Aug 4 09:44:22 2010
@@ -98,11 +98,29 @@
"Unable to modify grub options for an undefined hostname" );
}
-if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
- Abort ( $CODE->{'UNDEF_KEY'},
- "A site MUST BE defined for building DNS zone forward" );
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
+ }
+ else {
+ ( $SITE ) = @{$site_list};
+ }
+ }
+ else {
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
+ }
}
-elsif ( ! defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
+
+if ( ! defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
Abort ( $CODE->{'UNDEF_KEY'},
"Site ".$SITE." is not defined into global configuration" );
}
Modified: branches/next-gen/sbin/mk_interfaces
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_interfaces?rev=797&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_interfaces (original)
+++ branches/next-gen/sbin/mk_interfaces Wed Aug 4 09:44:22 2010
@@ -81,20 +81,25 @@
( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
-if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
- if ( ! defined $site_list ) {
- Abort ( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
- }
- elsif ( scalar @{$site_list} > 1 ) {
- Abort ( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
- .join ( ",", @{$site_list} ).".\n"
- ."Please relaunch this command with the right site" );
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
+ }
+ else {
+ ( $SITE ) = @{$site_list};
+ }
}
else {
- ( $SITE ) = @{$site_list};
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
}
}
Modified: branches/next-gen/sbin/mk_resolvconf
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_resolvconf?rev=797&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_resolvconf (original)
+++ branches/next-gen/sbin/mk_resolvconf Wed Aug 4 09:44:22 2010
@@ -81,20 +81,25 @@
( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
-if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
- if ( ! defined $site_list ) {
- Abort ( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
- }
- elsif ( scalar @{$site_list} > 1 ) {
- Abort ( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
- .join ( ",", @{$site_list} ).".\n"
- ."Please relaunch this command with the right site" );
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
+ }
+ else {
+ ( $SITE ) = @{$site_list};
+ }
}
else {
- ( $SITE ) = @{$site_list};
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
}
}
Modified: branches/next-gen/sbin/mk_sourceslist
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_sourceslist?rev=797&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_sourceslist (original)
+++ branches/next-gen/sbin/mk_sourceslist Wed Aug 4 09:44:22 2010
@@ -125,9 +125,26 @@
( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
-if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
- Abort ( $CODE->{'UNDEF_KEY'},
- "A site MUST BE defined for building DNS zone forward" );
+if ( $SITE eq '' ) {
+ if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Abort ( $CODE->{'DUPLICATE_VALUE'},
+ "Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ).".\n"
+ ."Please relaunch this command with the right site" );
+ }
+ else {
+ ( $SITE ) = @{$site_list};
+ }
+ }
+ else {
+ $SITE = $PF_CONFIG->{'location'}->{'site'}
+ }
}
$TO_ADD =~ s/,/ /g;
More information about the pf-tools-commits
mailing list