Changeset 582


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.

Location:
trunk
Files:
1 added
6 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  }
  • trunk/cgi-bin/MyIPDB.pm

    r517 r582  
    5151#$IPDB::syslog_facility = 'daemon';
    5252
     53# RPC URL for pushing DNS changes out.  Blank by default;  disables RPC calls for DNS changes when blank.
     54#$IPDB::rpc_url = 'http://dnsadmin.example.com/dns-rpc.cgi';
    5355
    5456## connectDB_My()
  • trunk/cgi-bin/main.cgi

    r577 r582  
    1717use POSIX qw(ceil);
    1818use NetAddr::IP;
     19use Frontier::Client;
    1920
    2021use Sys::Syslog;
     
    100101    $aclerr = 'addmaster';
    101102  }
     103
     104  # Retrieve the list of DNS locations if we've got a place to grab them from
     105  if ($IPDB::rpc_url) {
     106    # Make an object to represent the XML-RPC server.
     107    my $server = Frontier::Client->new(url => $IPDB::rpc_url, debug => 0);
     108    my $result;
     109
     110    my %rpcargs = (
     111        rpcuser => $authuser,
     112        rpcsystem => 'ipdb',
     113        group => 1,     # bleh
     114        defloc => '',
     115        );
     116    $result = $server->call('dnsdb.getLocDropdown', %rpcargs);
     117    $page->param(loclist => $result);
     118  }
     119
    102120} elsif ($webvar{action} eq 'newmaster') {
    103121
     
    108126    $page->param(cidr => "$cidr");
    109127
    110     my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr});
     128    my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr}, (vrf => $webvar{vrf}, rdns => $webvar{rdns},
     129        rwhois => $webvar{rwhois}, defloc => $webvar{loc}, user => $authuser) );
    111130
    112131    if ($code eq 'FAIL') {
     
    114133      $page->param(err => $msg);
    115134    } else {
     135      if ($code eq 'WARN') {
     136        $msg =~ s/\n\n/<br>\n/g;
     137        $msg =~ s/:\n/:<br>\n/g;
     138        $page->param(warn => $msg);
     139      }
    116140      syslog "info", "$authuser added master block $webvar{cidr}";
    117141    }
  • trunk/templates/addmaster.tmpl

    r517 r582  
    99</tr>
    1010<tr class="row1">
     11<td>Default VRF:</td>
     12<td><input type="text" name="vrf"></td>
     13</tr>
     14<tr class="row0">
     15<td>Default rDNS pattern:</td>
     16<td><input type="text" name="rdns"><input type="button" value=" ? " onclick="helpRDNS()" class="regular"></td>
     17</tr>
     18<tr class="row1">
     19<TMPL_IF loclist>
     20<td>Default DNS scope:</td>
     21<td>
     22<select name="loc">
     23<TMPL_LOOP loclist>
     24<option value="<TMPL_VAR NAME=loc>"<TMPL_IF selected> selected</TMPL_IF>><TMPL_VAR NAME=locname></option>
     25</TMPL_LOOP>
     26</select>
     27</td>
     28</tr>
     29<tr class="row0">
     30<TMPL_ELSE>
     31</TMPL_IF>
    1132<td class="center" colspan="2"><input type="submit" value="  Assign  "></td>
    1233</tr>
  • trunk/templates/newmaster.tmpl

    r517 r582  
    66<TMPL_ELSE>
    77<div class="heading">Success!</div>
     8<TMPL_IF warn>
     9<div class="warning"><TMPL_VAR NAME=warn></div>
     10</TMPL_IF>
    811</TMPL_IF>
    912</div>
  • trunk/templates/widgets.js

    r517 r582  
    1414        window.open(webPath() + "help.html", "help_window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=400")
    1515}
    16 function openTables() {
    17         window.open(webPath() + "tables.html", "subnet_tables", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=250") 
    18 }
    1916function helpAllocTypes() {
    2017        window.open(webPath() + "alloctypes.html", "alloc_window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=750,height=550")
     18}
     19function helpRDNS() {
     20        window.open(webPath() + "rDNS.html", "rdns_window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=850,height=450")
    2121}
    2222function popNotes(page) {
Note: See TracChangeset for help on using the changeset viewer.