pf-tools commit: r778 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Net.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Jul 22 10:26:21 UTC 2010


Author: ccaillet-guest
Date: Thu Jul 22 10:26:20 2010
New Revision: 778

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=778
Log:
  - rewrite Mk_zoneheader to __Mk_zoneheader
  - rewrite Mk_zone to Mk_zone_for_site
* 

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Net.pm

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=778&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Jul 22 10:26:20 2010
@@ -35,12 +35,15 @@
     - Add_server : adding server (hosts defined into pf-tools only for IPs
     and name accessing by filters)
     - Add_host : adding pf-tools host configuration
+    - rewrite Mk_zoneheader to __Mk_zoneheader
+    - rewrite Mk_zone to Mk_zone_for_site
   * lib/PFTools/Packages.pm
     - using new packages Parser.pm et Logger.pm
   * lib/PFTools/Update.pm
     - using new packages Parser.pm et Logger.pm
-
- -- Christophe Caillet <quadchris at free.fr>  Mon, 19 Jul 2010 16:47:59 +0200
+  * 
+
+ -- Christophe Caillet <tof at sitadelle.com>  Thu, 22 Jul 2010 12:25:05 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=778&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Thu Jul 22 10:26:20 2010
@@ -60,6 +60,8 @@
     Add_server
     Add_host
     Get_site_list
+
+    Mk_zone_for_site
 );
 
 our @EXPORT_OK = qw();
@@ -181,17 +183,17 @@
     ( $ai cmp $bi ) || ( $an <=> $bn ) || ( $av <=> $bv ) || ( $aa <=> $ba );
 }
 
-sub Get_Host_Props ($$) {
-    my ( $Z, $host ) = @_ ;
-
-    $host =~ /^([^.]+)(\.([^.]+))?(\.$Z->{SOA}->{name})?$/ ;
-    my ( $hostshort, $hostvlan ) = ( $1, $3 ) ;
-    return undef if ( ! defined $hostshort ) ;
-
-    my $hostclass = Host_class( $hostshort, $Z ) ;
-
-    return $Z->{'SERVERS'}->{'BY_NAME'}->{$hostclass}->{'SRVLIST'}->{$hostshort} ;
-}
+# sub Get_Host_Props ($$) {
+#     my ( $Z, $host ) = @_ ;
+# 
+#     $host =~ /^([^.]+)(\.([^.]+))?(\.$Z->{SOA}->{name})?$/ ;
+#     my ( $hostshort, $hostvlan ) = ( $1, $3 ) ;
+#     return undef if ( ! defined $hostshort ) ;
+# 
+#     my $hostclass = Host_class( $hostshort, $Z ) ;
+# 
+#     return $Z->{'SERVERS'}->{'BY_NAME'}->{$hostclass}->{'SRVLIST'}->{$hostshort} ;
+# }
 
 # $interface Get_If ( $Zone, $host, $vlan )
 sub Get_If {
@@ -876,9 +878,10 @@
 	my ( $netfile, $net_name, $ref_net, $global_config, $pf_config ) = @_;
 	my ( $block, $block6, $site_list, $net_part, $dhcp_part, $net2add, $ip_gw, $ip6_gw );
 
-	my $site_part		= $global_config->{'SITE'};
-	$site_list			= Get_site_list ( $ref_net, $global_config );
-	$net2add->{'scope'}	= $ref_net->{'scope'};
+	my $site_part			= $global_config->{'SITE'};
+	$site_list				= Get_site_list ( $ref_net, $global_config );
+	$net2add->{'scope'}		= $ref_net->{'scope'};
+	$net2add->{'comment'}	= $ref_net->{'comment'} if ( $ref_net->{'comment'} );
 	# Check TAG
 	if ( $ref_net->{'tag'} && ( $ref_net->{'tag'} < 0 || $ref_net->{'tag'} > 4095 ) ) {
 		Abort ( $CODE->{'INVALID_VALUE'}, 
@@ -1008,6 +1011,11 @@
 			"Not enough places for indexing host number(s) according to hostname ".$hostname_model );
 	}
 	return ( $num_last, $node_last );
+}
+
+sub __Get_numbers_from_hostclass_CONFIG ($$$) {
+	my ( $hostclass, $site, $global_config ) = @_;
+	
 }
 
 sub __Get_hostname_from_model ($$$$) {
@@ -1549,7 +1557,7 @@
 	$hostname						=~ /^([^.]+)(\.([^.]+))?(\.$zone)?$/ ;
 	my ( $hostshort, $hostvlan )	= ( $1, $3 ) ;
 	my $hosttype					= Get_hosttype_from_hostname ( $hostname, $global_config );
-	return $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass}->{$hostshort} ;
+	return $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort} ;
 }
 
 #### BACKWARD Compatibility
@@ -1559,47 +1567,41 @@
 	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};
-	unless ( open ( ZONE, ">".$zone_file ) ) {
-		Abort( $CODE->{'OPEN'}, 
-			"Unable to open file ".$zone_file." for building zone header " );
-	}
-
-	my $old_STDOUT = select ( ZONE );
+
+###############################################################
+### Building zone file for IPv4 entries
+
+sub __Mk_zoneheader ($$$) {
+	my ( $zone_name, $zone_site, $zone_part ) = @_;
+	my $zone_result = [];
+
 	# SOA
-	print ";;\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'};
-	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", '', ')';
+	push ( @{$zone_result}, ";;" );
+	push ( @{$zone_result}, ";; BIND configuration file for zone : ".$zone_name );
+	push ( @{$zone_result}, ";; Site : ".$zone_site );
+	push ( @{$zone_result}, ";;" );
+	push ( @{$zone_result}, ";; ", $zone_part->{'SOA'}->{'comment'} );
+	push ( @{$zone_result}, "\n;;============================================================================\n" );
+	push ( @{$zone_result}, "\$TTL ".$zone_part->{'SOA'}->{'ttl'} );
+	push ( @{$zone_result}, "\@\t\tIN SOA ".$zone_part->{'SOA'}->{'soa'}." ".$zone_part->{'SOA'}->{'mail'}." (" );
+	my $serial =  ( $zone_part->{'SOA'}->{'serial'} eq 'AUTO' ) ? time."\t; Serial" : $zone_part->{'SOA'}->{'serial'};
+	push ( @{$zone_result}, "\t\t\t".$serial );
+	foreach my $spec ( 'refresh', 'retry', 'expire', 'negttl' ) {
+		push ( @{$zone_result}, "\t\t\t".$zone_part->{'SOA'}->{$spec} );
+	}
+	push ( @{$zone_result}, "\t\t)" );
+	push ( @{$zone_result}, "\n" );
 	# NS fields
-	foreach my $namserver ( @{ $Z->{'@ns'} } ) {
-			printf "%-29s IN NS\t%s\n", '', $namerver;
-	}
-	print "\n";
+	foreach my $nameserver ( @{ $zone_part->{'SOA'}->{'@ns'} } ) {
+		push ( @{$zone_result}, "\t\tIN NS\t".$nameserver );
+	}
+	push ( @{$zone_result}, "\n" );
 	# MX fields
-	foreach my $mx ( @{ $Z->{'@mx'} } ) {
-			printf "%-29s IN MX\t%s\n", '', $mx;
-	}
-	print "\n";
-	$| = 1;
-	select ( $old_STDOUT );
-	close ( ZONE );
+	foreach my $mx ( @{ $zone_part->{'SOA'}->{'@mx'} } ) {
+		push ( @{$zone_result}, "\t\tIN MX\t".$mx );
+	}
+	push ( @{$zone_result}, "\n" );
+	return $zone_result;
 }
 
 #
@@ -1608,97 +1610,55 @@
 #	Construit un le fichier $fic_zone pour la zone DNS decrite par la structure $Z
 #
 #==============================================================================================
-sub Mk_zone {
-    my ( $fic_zone, $Z ) = @_;
-
-    Mk_zoneheader( $fic_zone, $Z );
-
-    # Ouverture du fichier de destination
-    open( FIC_ZONE, ">> " . $fic_zone )
-	|| Abort( $ERR_OPEN, "Impossible d'ouvrir " . $fic_zone );
-    my $old_STDOUT = select(FIC_ZONE);
-
-    my $s;
-    my $n;
-    my $m;
-    my $j;
-
-    ### Reseaux
-    print "\n\n;;\n";
-    print ";; Networks\n";
-    print
-	";;============================================================================\n\n";
-
-    foreach $n ( sort ( keys %{ $Z->{'NETWORK'}->{'BY_ADDR'} } ) ) {
-	my $N = $Z->{'NETWORK'}->{'BY_ADDR'}->{$n};
-	print "; ", $N->{'comment'}, "\n";
-	print
-	    ";----------------------------------------------------------------------------\n";
-	printf(
-	    "%-29s IN A\t%s\n",
-	    "network." . $N->{'name'},
-	    $N->{'network'}
-	);
-	printf(
-	    "%-29s IN A\t%s\n",
-	    "netmask." . $N->{'name'},
-	    $N->{'netmask'}
-	);
-	printf( "%-29s IN A\t%s\n", "prefix." . $N->{'name'},
-	    $N->{'prefix'} );
-	printf(
-	    "%-29s IN A\t%s\n",
-	    "broadcast." . $N->{'name'},
-	    $N->{'broadcast'}
-	);
-	print "\n";
-    }
-
-    ### Servers
-    print "\n\n;;\n";
-    print ";; Servers\n";
-    print
-	";;============================================================================\n\n";
-
-    foreach $s ( sort ( keys %{ $Z->{'SERVERS'}->{'BY_ADDR'} } ) ) {
-    	foreach my $host ( @{$Z->{'SERVERS'}->{'BY_ADDR'}->{$s}} ) {
-	    print "; ",         $host->{'comment'}, "\n";
-	    print "; number: ", $host->{'number'},  "\n";
-	    print "; nodes:  ", $host->{'nodes'},   "\n" if ( defined( $host->{'nodes'} ) && $host->{'nodes'} > 1 );
-	    print ";----------------------------------------------------------------------------\n";
-
-	    foreach $m ( sort ( keys %{ $host->{'SRVLIST'} } ) ) {
-		my $M = $host->{'SRVLIST'}->{$m};
-		my $nam;
-
-		foreach $nam ( sort ( keys %{ $M->{'zone'} } ) ) {
-		    printf ( "%-29s IN %s\t%s\n", $nam, $M->{'zone'}->{$nam}->{'TYPE'}, $M->{'zone'}->{$nam}->{'FIELD'} );
-		}
-		print "\n";
-	    }
-    	}
-	
-    }
-
-    ### Alias
-    print "\n\n;;\n";
-    print ";; Alias (round robin)\n";
-    print
-	";;============================================================================\n\n";
-
-    foreach $j ( sort ( keys %{ $Z->{'ALIAS'} } ) ) {
-	my $i;
-
-	foreach $i ( sort ( @{ $Z->{'ALIAS'}->{$j} } ) ) {
-	    printf( "%-29s IN A\t%s\n", $j, $i );
-	}
-    }
-
-    # Fermeture du fichier de destination
-    $| = 1;
-    select($old_STDOUT);
-    close(FIC_ZONE);
-
+sub Mk_zone_for_site ($$$) {
+    my ( $zone_name, $zone_site, $global_config ) = @_;
+	my $zone_result	= [];
+
+	# Building Header (SOA, NS an MX fileds)
+	$zone_result	= __Mk_zoneheader( $zone_name, $zone_site, $global_config->{'ZONE'}->{'BY_NAME'}->{$zone_name} );
+	my $zone_part	= $global_config->{'ZONE'}->{'BY_NAME'}->{$zone_name}->{'BY_SITE'}->{$zone_site};
+
+	### Building Networks part
+	push ( @{$zone_result}, "\n\n;;" );
+	push ( @{$zone_result}, ";; Networks" );
+	push ( @{$zone_result}, ";;============================================================================\n" );
+
+	foreach my $network ( @{$global_config->{'ZONE'}->{'BY_NAME'}->{$zone_name}->{'__network_order'}->{$zone_site}} ) {
+		my $head	= $network;
+		$head		.= " : ".$zone_part->{$network}->{'comment'} if ( $zone_part->{$network}->{'comment'} );
+		push ( @{$zone_result}, "; ".$head );
+		push ( @{$zone_result}, ";----------------------------------------------------------------------------" );
+		foreach my $spec ( 'network', 'netmask', 'broadcast', 'gateway' ) {
+			next if ( ! defined $zone_part->{$network}->{$spec} );
+			push ( @{$zone_result}, $spec.".".$network."\t\t".$zone_part->{$network}->{$spec} );
+		}
+		push ( @{$zone_result}, "" );
+	}
+
+	### Servers
+	push ( @{$zone_result}, "\n\n;;" );
+	push ( @{$zone_result}, ";; Servers" );
+	push ( @{$zone_result}, ";;============================================================================\n" );
+
+	foreach my $server ( @{$global_config->{'ZONE'}->{'BY_NAME'}->{$zone_name}->{'__hostclass_order'}->{$zone_site}} ) {
+		my $head	= $server;
+		$head		.= " : ".$zone_part->{$server}->{'comment'} if ( $zone_part->{$server}->{'comment'} );
+		push ( @{$zone_result}, "; ".$head );
+		push ( @{$zone_result}, ";----------------------------------------------------------------------------" );
+		foreach my $field ( sort keys %{$zone_part->{$server}} ) {
+			next if ( $field eq 'comment' );
+			if ( ref $zone_part->{$server}->{$field} eq 'ARRAY' ) {
+				foreach my $elt ( @{$zone_part->{$server}->{$field}} ) {
+					push ( @{$zone_result}, $field."\t\t".$elt );
+				}
+			}
+			else {
+				push ( @{$zone_result}, $field."\t".$zone_part->{$server}->{$field} );
+			}
+		}
+		push ( @{$zone_result}, "" );
+	}
+	return $zone_result;
 }
 
 #




More information about the pf-tools-commits mailing list