Ignore:
Timestamp:
06/13/17 13:58:57 (7 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge /trunk through r749 for 1.4.0

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/mergerecs

    r690 r756  
    33##
    44# $Id$
    5 # Copyright 2014 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2014,2016 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    3636sub usage {
    3737  die qq(usage:  mergerecs zone [domain] [--detail]
    38     zone  The zone to walk for PTR records to try to merge.
    39   domain  Optionally restrict record merges to a specified domain as well.
     38    zone  The primary zone to walk for records to try to merge.  May be either
     39          a reverse zone or a domain.
     40  domain  Optionally restrict record merges in a reverse zone to a specific
     41          domain.
    4042 --detail Optional argument to add one log entry for each A+PTR pair merged
    4143          instead of a single generic entry.
     
    8284  }
    8385  die "$pzone is not a valid reverse zone specification\n" if !$npzone;
    84   $zid = $dnsdb->revID($npzone);
     86  $zid = $dnsdb->revID($npzone, '');
    8587} else {
    8688  $rev = 'n';
    87   $zid = $dnsdb->domainID($pzone);
    88 }
    89 die "$pzone is not a zone in the database\n" if !$zid;
     89  $zid = $dnsdb->domainID($pzone, '');
     90}
     91die "$pzone is not a zone in the database (".$dnsdb->errstr.")\n" if !$zid;
    9092
    9193# check the second arg.
    92 my $fzid = $dnsdb->domainID($matchdom);
     94my $fzid = $dnsdb->domainID($matchdom, '');
    9395die "$matchdom is not a domain in the database\n" if $matchdom && !$fzid;
    9496
     
    116118    $reclist->execute($zid);
    117119    my $nrecs = 0;
     120    my @cloglist;
    118121    while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) {
    119122      my $etype = 12;
     
    134137        $delsth->execute($erid);
    135138        if ($logdetail) {
    136           $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
     139          my $lid = $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
     140          push @cloglist, $lid;
    137141          print "$logentry\n";
    138142        }
     
    140144      }
    141145    } # while
    142     if (!$logdetail) {
    143       $dnsdb->_log(group_id => $group, domain_id => $zid,
     146    my $lpid = $dnsdb->_log(group_id => $group, domain_id => $zid,
    144147        entry => "Merged $nrecs A and AAAA records in $pzone with matching PTRs");
     148    # since unlike in most other operations, we only "know" the parent log entry *after*
     149    # we're done entering all the child entries, we have to update the children with the parent ID
     150    my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?");
     151    for my $lcid (@cloglist) {
     152      $assoc->execute($lpid, $lcid);
    145153    }
    146154    print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n";
     
    157165    $reclist->execute($zid);
    158166    my $nrecs = 0;
     167    my @cloglist;
    159168    while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) {
    160169      if ($matchdom) {
     
    178187        $delsth->execute($erid);
    179188        if ($logdetail) {
    180           $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
    181           print "$logentry\n";
     189          my $lid = $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
     190          push @cloglist, $lid;
     191          print "$lid: $logentry\n";
    182192        }
    183193        $nrecs++;
     
    185195    } # while
    186196    my $entry = "Merged $nrecs PTR records in $pzone with matching A or AAAA records".($fzid ? " in $matchdom" : '');
    187     if (!$logdetail) {
    188       if ($fzid) {
    189         $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry);
    190       } else {
    191         $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry);
    192       }
     197    my $lpid;
     198    if ($fzid) {
     199      $lpid = $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry);
     200    } else {
     201      $lpid = $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry);
     202    }
     203    # since unlike in most other operations, we only "know" the parent log entry *after*
     204    # we're done entering all the child entries, we have to update the children with the parent ID
     205    my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?");
     206    for my $lcid (@cloglist) {
     207      $assoc->execute($lpid, $lcid);
    193208    }
    194209    print "$entry\n";
    195   } # else
     210  }
     211
    196212  $dbh->commit;
    197213};
Note: See TracChangeset for help on using the changeset viewer.