Changeset 582 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
01/04/13 17:19:57 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Begin adding DNS integration via RPC. See #1.
IPDB.pm

  • Add a global in IPDB.pm to identify the URL for RPC DNS changes. A blank URL means this capability is disabled. (also MyIPDB.pm)
  • Accept extra parameters in addMaster() for DNS changes (default rDNS pattern, DNS location/scope/view) and while we're at it, add space to handle VRF as an informational field
  • Drop maskbits from INSERTs in addMaster()
  • Make the RPC call to add a reverse zone when adding a new master block. To assist with export caching, we split the zone into /16 or /24 chunks and add each one separately.

main.cgi

  • Retrieve DNS locations for adding a master block
  • Pass the HTTP user in to addMaster() for logging in the DNS backend

Modify templates for add master
Remove long-obsolete function in widgets.js, add function for:
Add rDNS pattern reference page

Note the RPC calls require at least dnsadmin:trunk@r447 to work properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r579 r582  
    1717use Net::SMTP;
    1818use NetAddr::IP qw(:lower Compact );
     19use Frontier::Client;
    1920use POSIX;
    2021use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
     
    8788our $syslog_facility = 'local2';
    8889
     90our $rpc_url = '';
     91
    8992# Let's initialize the globals.
    9093## IPDB::initIPDBGlobals()
     
    214217  my $dbh = shift;
    215218  my $cidr = new NetAddr::IP shift;
     219  my %args = @_;
     220
     221  $args{vrf} = '' if !$args{vrf};
     222  $args{rdns} = '' if !$args{rdns};
     223  $args{defloc} = '' if !$args{defloc};
     224  $args{rwhois} = 'n' if !$args{rwhois};        # fail "safe", sort of.
     225  $args{rwhois} = 'n' if $args{rwhois} ne 'n' and $args{rwhois} ne 'y';
    216226
    217227  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    228238##fixme: rwhois should be globally-flagable somewhere, much like a number of other things
    229239## maybe a db table called "config"?
    230       $dbh->do("INSERT INTO masterblocks (cidr,rwhois) VALUES (?,?)", undef, ($cidr,'y') );
     240      $dbh->do("INSERT INTO masterblocks (cidr,rwhois,vrf,rdns) VALUES (?,?,?,?)", undef, ($cidr, 'y', $args{vrf}, $args{rdns}) );
    231241
    232242# Unrouted blocks aren't associated with a city (yet).  We don't rely on this
    233243# elsewhere though;  legacy data may have traps and pitfalls in it to break this.
    234244# Thus the "routed" flag.
    235       $dbh->do("INSERT INTO freeblocks (cidr,maskbits,city,routed,parent,rdepth) VALUES (?,?,?,?,?,?)", undef,
    236         ($cidr, $cidr->masklen, '<NULL>', 'm', $cidr, 1) );
     245      $dbh->do("INSERT INTO freeblocks (cidr,city,routed,parent,rdepth,vrf) VALUES (?,?,?,?,?,?)", undef,
     246        ($cidr, '<NULL>', 'm', $cidr, 1, $args{vrf}) );
    237247
    238248      # If we get here, everything is happy.  Commit changes.
     
    278288      # freeblocks
    279289      $sth = $dbh->prepare("DELETE FROM freeblocks WHERE cidr <<= ?");
    280       my $sth2 = $dbh->prepare("INSERT INTO freeblocks (cidr,maskbits,city,routed,parent,rdepth)".
    281         " VALUES (?,?,'<NULL>','m',?,1)");
     290      my $sth2 = $dbh->prepare("INSERT INTO freeblocks (cidr,city,routed,parent,rdepth,vrf)".
     291        " VALUES (?,'<NULL>','m',?,1,?)");
    282292      foreach my $newblock (@blocklist) {
    283293        $sth->execute($newblock);
    284         $sth2->execute($newblock, $newblock->masklen, $cidr);
     294        $sth2->execute($newblock, $cidr, $args{vrf});
    285295      }
    286296
     
    291301      # master
    292302      $dbh->do("DELETE FROM masterblocks WHERE cidr <<= ?", undef, ($cidr) );
    293       $dbh->do("INSERT INTO masterblocks (cidr,rwhois) VALUES (?,?)", undef, ($cidr, 'y') );
     303      $dbh->do("INSERT INTO masterblocks (cidr,rwhois,vrf,rdns) VALUES (?,?,?,?)", undef, ($cidr, 'y', $args{vrf}, $args{rdns}) );
    294304
    295305      # *whew*  If we got here, we likely suceeded.
     
    303313    return ('FAIL',$msg);
    304314  } else {
     315
     316    # Only attempt rDNS if the IPDB side succeeded
     317    if ($rpc_url) {
     318      # Make an object to represent the XML-RPC server.
     319      my $server = Frontier::Client->new(url => $rpc_url, debug => 0);
     320      my $result;
     321
     322# Note *not* splitting reverse zones negates any benefit from caching the exported data.
     323# IPv6 address space is far too large to split usefully, and in any case (also due to
     324# the large address space) doesn't support the iterated template records v4 zones do
     325# that causes the bulk of the slowdown that needs the cache anyway.
     326
     327      my @zonelist;
     328# allow splitting reverse zones to be disabled, maybe, someday
     329#if ($splitrevzones && !$cidr->{isv6}) {
     330      if (1 && !$cidr->{isv6}) {
     331        my $splitpoint = ($cidr->masklen <= 16 ? 16 : 24);      # hack pthui
     332        @zonelist = $cidr->split($splitpoint);
     333      } else {
     334        @zonelist = ($cidr);
     335      }
     336      my @fails;
     337      ##fixme:  remove hardcoding where possible
     338      foreach my $subzone (@zonelist) {
     339        my %rpcargs = (
     340          rpcuser => $args{user},
     341          rpcsystem => 'ipdb',
     342          revzone => "$subzone",
     343          revpatt => $args{rdns},
     344          defloc => $args{defloc},
     345          group => 1,   # not sure how these two could sanely be exposed, tbh...
     346          state => 1,   # could make them globally configurable maybe
     347        );
     348        eval {
     349          $result = $server->call('dnsdb.addRDNS', %rpcargs);
     350        };
     351        if ($@) {
     352          my $msg = $@;
     353          $msg =~ s/Fault returned from XML RPC Server, fault code 4: error executing RPC `dnsdb.addRDNS'\.\s//;
     354          push @fails, ("$subzone" => $msg);
     355        }
     356      }
     357      if (@fails) {
     358        return ('WARN',"Warning(s) adding $cidr to reverse DNS:\n".join("\n", @fails));
     359      }
     360    }
    305361    return ('OK','OK');
    306362  }
Note: See TracChangeset for help on using the changeset viewer.