Changeset 834


Ignore:
Timestamp:
04/19/22 16:34:34 (3 years ago)
Author:
Kris Deugau
Message:

/trunk

Accumulated tinkering on compact-recs.pl, part 1

  • Switch module-finding blob to latest theoretically-good form. See #80.
  • Fix broken handling of "n'th natural IP" on compaction, possibly also on export
  • Trim some development comments
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r833 r834  
    17981798  my $tmpl = shift;
    17991799  my $ip = shift;
    1800   my $subnet = shift;   # for %ngb and %c
     1800  my $subnet = shift;   # %ngb, %c, and %x
    18011801  my $ipindex = shift;  # for %c
    18021802
     
    18421842
    18431843    if ($cn) {
    1844       # "natural n'th IP in the block" pattern
    1845       $$tmpl =~ s/$cn/$ipindex+1/e;
     1844      # "n'th natural IP in the block" pattern.
     1845      my $iptmp = new NetAddr::IP $ip;
     1846      my $natdex = scalar($iptmp - $$subnet);
     1847      $natdex++;
     1848      $$tmpl =~ s/$cn/$natdex/;
    18461849    }
    18471850
  • trunk/compact-recs.pl

    r797 r834  
    44##
    55# $Id$
    6 # Copyright 2013,2014,2018,2020 Kris Deugau <kdeugau@deepnet.cx>
     6# Copyright 2013-2022 Kris Deugau <kdeugau@deepnet.cx>
    77#
    88#    This program is free software: you can redistribute it and/or modify
     
    2323use warnings;
    2424
    25 # push "the directory the script is in" into @INC
    26 use FindBin;
    27 use lib "$FindBin::RealBin/";
     25# Taint-safe (ish) voodoo to push "the directory the script is in" into @INC.
     26# See https://secure.deepnet.cx/trac/dnsadmin/ticket/80 for more gory details on how we got here.
     27use File::Spec ();
     28use File::Basename ();
     29my $path;
     30BEGIN {
     31    $path = File::Basename::dirname(File::Spec->rel2abs($0));
     32    if ($path =~ /(.*)/) {
     33        $path = $1;
     34    }
     35}
     36use lib $path;
    2837
    2938use DNSDB;
     
    8594  $dbh->{RaiseError} = 1;
    8695
    87   my ($zone,$ploc) = $dbh->selectrow_array("SELECT rdns_id,default_location FROM revzones WHERE revnet >>= ?",
     96  my ($zonecidr,$zone,$ploc) = $dbh->selectrow_array("SELECT revnet,rdns_id,default_location FROM revzones WHERE revnet >>= ?",
    8897        undef, ($cidr) );
    8998  if (!$zone) {
     
    106115
    107116  eval {
     117    # First, clean up the records that match the template.
    108118    my $getsth = $dbh->prepare("SELECT record_id,host,val FROM records ".
    109         "WHERE (type = 12 OR type > 65000) AND inetlazy(val) << ?");
     119        "WHERE (type = 12 OR type > 65000) AND inetlazy(val) << ? AND rdns_id = ?");
    110120    my $delsth = $dbh->prepare("DELETE FROM records WHERE record_id = ?");
    111     $getsth->execute($cidr);
     121    $getsth->execute($cidr, $zone);
    112122    my $i = 0;
    113123    while (my ($id,$host,$val) = $getsth->fetchrow_array) {
    114124      my $cmp = $patt;
    115       DNSDB::_template4_expand(\$cmp, $val);
     125      DNSDB::_template4_expand(\$cmp, $val, \$cidr);
    116126      $delsth->execute($id) if $cmp eq $host;
    117127      $delcnt++ if $cmp eq $host;
    118 #      print "got $id, '$host', '$val';  compare '$cmp'\t";
    119 #      print "  delete\n" if $cmp eq $host;
    120 #      print "  keep\n"  if $cmp ne $host;
    121 #      last if $i++ >8;
    122128    }
    123129
     
    129135        entry => "A+PTR and/or PTR records in $cidr matching $patt replaced by $typemap{$newtype} record for $cidr");
    130136
    131 #    $dbh->rollback;
    132137    $dbh->commit;
    133138  };
Note: See TracChangeset for help on using the changeset viewer.