Changeset 318


Ignore:
Timestamp:
Jul 19, 2018, 11:40:43 PM (6 years ago)
Author:
g7moreau
Message:
  • Begin rework on gen dns file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r317 r318  
    2121use strict;
    2222#use warnings;
    23 use version; our $VERSION = version->declare('0.9.8');
     23use version; our $VERSION = version->declare('0.10.0');
    2424
    2525use Getopt::Long qw(GetOptions);
     
    24862486
    24872487sub cmd_generate_dns_file {
    2488    my $buffer;
     2488   my $buffer_fwd;
    24892489   my $buffer_rev;
    24902490   my $pool_domain;
     
    25002500
    25012501      if ($domainset_current eq 'pool') {
    2502          #next;
    2503          for my $value (@{$computer_db->{$domainset_current}}) {
    2504             for my $pool_name (keys %{$value}) {
    2505                $pool_domain = $value->{$pool_name}->{'domain'}."\n";
    2506                #print $value->{$pool_name}->{'file'};
     2502         LOOP_ON_COMPUTER:
     2503         for my $computer (@{$computer_db->{$domainset_current}}) {
     2504            for my $pool_name (keys %{$computer}) {
     2505               $pool_domain = $computer->{$pool_name}->{'domain'}."\n";
     2506               #print $computer->{$pool_name}->{'file'};
    25072507               chomp $pool_domain;
    25082508               open FILE_FORWARD_DNS, '>>', "$FOLDER_GEN_DNS/db.$pool_domain.fwd";
    25092509               open FILE_REVERSE_DNS, '>>', "$FOLDER_GEN_DNS/db.$pool_domain.rev";
    2510                my @T_pool_ip = @{$value->{$pool_name}->{'ip'}};
     2510               my @T_pool_ip = @{$computer->{$pool_name}->{'ip'}};
    25112511               for my $pool_ip (@T_pool_ip) {
    25122512                  my @T_split = split(/\./ , $pool_ip);
    2513                   $buffer    = sprintf "%-24s IN  A  %-15s ;\n", "$pool_name$T_split[3]", $pool_ip;
     2513                  $buffer_fwd = sprintf "%-24s IN  A  %-15s ;\n", "$pool_name$T_split[3]", $pool_ip;
    25142514                  $buffer_rev = "$T_split[3]   IN PTR   $pool_name$T_split[3].$pool_domain.\n";
    2515                   print FILE_FORWARD_DNS $buffer;
     2515                  print FILE_FORWARD_DNS $buffer_fwd;
    25162516                  print FILE_REVERSE_DNS $buffer_rev;
    25172517                  }
     
    25242524      else {
    25252525         #--- Création du fichier non-reverse ---#
    2526          open ( FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.fwd");
    2527          open ( FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.rev");
     2526         open FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.fwd";
     2527         open FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.rev";
     2528
    25282529         my @domainsetdb = @{$computer_db->{$domainset_current}};
    2529          for my $value (@domainsetdb) {
    2530             for my $id (keys %{$value}) {
    2531                #host pcdavoust {  deny-unknown-clients;
    2532                #hardware ethernet 0:6:5b:b8:13:d1;
    2533                #fixed-address 194.254.66.72;
    2534                #}
    2535                my $hostname = $value->{$id}->{'hostname'};
    2536                my $ip       = $value->{$id}->{'ip'};
    2537                my $comment  = $value->{$id}->{'comment'};
    2538                my $address_type = $value->{$id}->{'address_type'};
    2539                my $enabled      = $value->{$id}->{'enabled'};
    2540 
    2541                my $dns_domain = $domainset_current;
    2542                if (exists $computer_db->{'dset'}{$domainset_current}) {
    2543                   $dns_domain = $computer_db->{'dset'}{$domainset_current}{'dns_extension'};
     2530
     2531         LOOP_ON_COMPUTER:
     2532         for my $computer (@domainsetdb) {
     2533            my ($mac_address, $attribute) = %{$computer};
     2534
     2535            #host pcdavoust {  deny-unknown-clients;
     2536            #hardware ethernet 0:6:5b:b8:13:d1;
     2537            #fixed-address 194.254.66.72;
     2538            #}
     2539
     2540            my $hostname     = $attribute->{'hostname'};
     2541            my $ip           = $attribute->{'ip'};
     2542            my $comment      = $attribute->{'comment'};
     2543            my $address_type = $attribute->{'address_type'};
     2544            my $enabled      = $attribute->{'enabled'};
     2545
     2546            next LOOP_ON_COMPUTER if not (($address_type eq 'dhcp') or ($address_type eq 'static'));
     2547
     2548            my $dns_domain = $domainset_current;
     2549            if (exists $computer_db->{'dset'}{$domainset_current}) {
     2550               $dns_domain = $computer_db->{'dset'}{$domainset_current}{'dns_extension'};
     2551               }
     2552
     2553            my @ip_split = split /\./, $ip;
     2554            if ($enabled eq 'yes') {
     2555               if (exists $attribute->{'dns_extension'}
     2556                     and "$attribute->{'dns_extension'}" != "$dns_domain") {
     2557                  print "A FAIRE\n";
    25442558                  }
    2545                my @T_split = split(/\./ , $ip);
    2546                if  (($address_type eq 'dhcp') or ($address_type eq 'static')) {
    2547                   if ($enabled eq 'yes') {
    2548                      $buffer = sprintf "%-24s IN A %-15s ; %s\n", $hostname, $ip, $comment;
    2549                      if (exists $value->{$id}->{'dns_extension'}
    2550                            and "$value->{$id}->{'dns_extension'}" != "$dns_domain") {
    2551                         print "A FAIRE\n";
    2552                         }
    2553                      $buffer_rev = $T_split[3]."     IN PTR   $hostname.$dns_domain.\n";
    2554                      }
    2555 
    2556                   else {
    2557                      $buffer = sprintf "%-24s IN A %-15s ; %s\n", $hostname, $ip, $comment;
    2558                      $buffer_rev = ";".$T_split[3]."    IN PTR   $hostname.$dns_domain.\n";
    2559                      }
    2560                   print FILE_REVERSE_DNS $buffer_rev;
    2561                   print FILE_FORWARD_DNS $buffer;
    2562                   }
     2559               $buffer_fwd = sprintf "%-24s  IN A   %-15s ; %s\n", $hostname, $ip, $comment;
     2560               $buffer_rev = sprintf "%3i    IN PTR %-15s\n", $ip_split[3], "$hostname.$dns_domain.";
    25632561               }
    2564             #$cpt=$cpt+1;
     2562
     2563            else {
     2564               $buffer_fwd = sprintf ";%-24s IN A   %-15s ; %s\n", $hostname, $ip, $comment;
     2565               $buffer_rev = sprintf ";%3i   IN PTR %-15s\n", $ip_split[3], "$hostname.$dns_domain.";
     2566               }
     2567            print FILE_REVERSE_DNS $buffer_rev;
     2568            print FILE_FORWARD_DNS $buffer_fwd;
    25652569            }
    25662570         print "- DNS: db.$domainset_current.fwd db.$domainset_current.rev [CREATE].\n";
Note: See TracChangeset for help on using the changeset viewer.