pf-tools commit: r776 [ccaillet-guest] - /branches/next-gen/lib/PFTools/Net.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Jul 21 13:29:26 UTC 2010
Author: ccaillet-guest
Date: Wed Jul 21 13:29:24 2010
New Revision: 776
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=776
Log:
UPD: rewrite Mk_zoneheader according to new global structure and need to add site parameter
Modified:
branches/next-gen/lib/PFTools/Net.pm
Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=776&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Wed Jul 21 13:29:24 2010
@@ -1526,48 +1526,83 @@
}
}
-
-sub Mk_zoneheader {
- my ( $fic_zone, $Z ) = @_;
- my $m;
- my $n;
-
+sub Get_host_config_from_CONFIG ($$;$) {
+ my ( $hostname, $global_config, $site ) = @_ ;
+
+ if ( ! defined $site ) {
+ my $site_list = Get_site_from_hostname ( $hostname, $global_config );
+ if ( ! defined $site_list ) {
+ Warn ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$hostname." : hostname not defined" );
+ }
+ elsif ( scalar @{$site_list} > 1 ) {
+ Warn ( $CODE->{'UNDEF_KEY'},
+ "Unable to retrieve site for hostname ".$hostname." : hostname appeared in multiple sites : "
+ .join ( ",", @{$site_list} ) );
+ }
+ else {
+ ( $site ) = @{$site_list};
+ }
+ }
+ my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
+ my $zone = __Get_site_zone ( $site, $global_config->{'SITE'}->{'BY_NAME'}->{$site} );
+ $hostname =~ /^([^.]+)(\.([^.]+))?(\.$zone)?$/ ;
+ my ( $hostshort, $hostvlan ) = ( $1, $3 ) ;
+ my $hosttype = Get_hosttype_from_hostname ( $hostname, $global_config );
+ return $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass}->{$hostshort} ;
+}
+
+#### BACKWARD Compatibility
+sub Get_Host_Props ($$;$) {
+ my ( $hostname, $global_config, $site ) = @_ ;
+
+ return Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
+}
+
+sub Mk_zoneheader ($$$$) {
+ my ( $zone_file, $zone_name, $zone_site, $global_config ) = @_;
+
+ my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone_name};
# Ouverture du fichier de destination
- open( FIC_ZONE, "> " . $fic_zone )
- || Abort( $ERR_OPEN, "Impossible d'ouvrir " . $fic_zone );
- my $old_STDOUT = select(FIC_ZONE);
+ unless ( open ( ZONE, ">".$zone_file ) ) {
+ Abort( $CODE->{'OPEN'},
+ "Unable to open file ".$zone_file." for building zone header " );
+ }
+
+ my $old_STDOUT = select ( ZONE );
### Zone
print ";;\n";
- print ";; Fichier de configuration BIND\n";
+ print ";; BIND configuration file for zone : ".$zone_name."\n";
+ print ";; Site : ".$zone_site."\n";
print ";;\n";
print ";; ", $Z->{'SOA'}->{'comment'}, "\n";
print
";;============================================================================\n\n";
print "\n";
printf "\$TTL %s\n", $Z->{'SOA'}->{'ttl'};
- printf "%-29s IN SOA\t%s %s (\n", '@', $Z->{'SOA'}->{'soa'},
- $Z->{'SOA'}->{'mail'};
- printf "%-30s%s\n", '', $Z->{'SOA'}->{'serial'};
+ printf "%-29s IN SOA\t%s %s (\n", '@', $Z->{'SOA'}->{'soa'}, $Z->{'SOA'}->{'mail'};
+ my $serial = ( $Z->{'SOA'}->{'serial'} eq 'AUTO' ) ? time : $Z->{'SOA'}->{'serial'};
+ printf "%-30s%s\n", '', $serial;
printf "%-30s%s\n", '', $Z->{'SOA'}->{'refresh'};
printf "%-30s%s\n", '', $Z->{'SOA'}->{'retry'};
printf "%-30s%s\n", '', $Z->{'SOA'}->{'expire'};
printf "%-30s%s\n", '', $Z->{'SOA'}->{'negttl'};
printf "%-30s%s\n\n", '', ')';
- foreach $n ( @{ $Z->{'NS'} } ) {
- printf "%-29s IN NS\t%s\n", '', $n;
+ foreach my $namserver ( @{ $Z->{'@ns'} } ) {
+ printf "%-29s IN NS\t%s\n", '', $namerver;
}
print "\n";
- foreach $m ( @{ $Z->{'MX'} } ) {
- printf "%-29s IN MX\t%s\n", '', $m;
+ foreach my $mx ( @{ $Z->{'@mx'} } ) {
+ printf "%-29s IN MX\t%s\n", '', $mx;
}
print "\n";
$| = 1;
- select($old_STDOUT);
- close(FIC_ZONE);
+ select ( $old_STDOUT );
+ close ( ZONE );
}
#
More information about the pf-tools-commits
mailing list