Changeset 585


Ignore:
Timestamp:
01/16/13 17:16:46 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Reverse DNS RPCing should now be complete for all add operations.
See #1.

Some fine-tuning may still be needed, eg for static IPs, convert
template placeholders before doing the RPC call; this could also
be done entirely on the DNS side at export instead.

Location:
trunk
Files:
4 edited

Legend:

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

    r582 r585  
    2525@EXPORT_OK    = qw(
    2626        %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    27         %IPDBacl %aclmsg
     27        %IPDBacl %aclmsg $errstr
    2828        &initIPDBGlobals &connectDB &finish &checkDBSanity
    2929        &addMaster &touchMaster
     
    3131        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    3232        &ipParent &subParent &blockParent &getRoutedCity
    33         &allocateBlock &updateBlock &deleteBlock &getBlockData
     33        &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS
    3434        &getNodeList &getNodeName &getNodeInfo
    3535        &mailNotify
     
    3939%EXPORT_TAGS    = ( ALL => [qw(
    4040                %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    41                 %IPDBacl %aclmsg
     41                %IPDBacl %aclmsg $errstr
    4242                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4343                &addMaster &touchMaster
     
    4545                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    4646                &ipParent &subParent &blockParent &getRoutedCity
    47                 &allocateBlock &updateBlock &deleteBlock &getBlockData
     47                &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS
    4848                &getNodeList &getNodeName &getNodeInfo
    4949                &mailNotify
     
    6868        delblock        => 'delete an allocation',
    6969        );
     70
     71# error reporting
     72our $errstr = '';
    7073
    7174our $org_name = 'Example Corp';
     
    8992
    9093our $rpc_url = '';
     94our $revgroup = 1;      # should probably be configurable somewhere
     95our $rpccount = 0;
     96
     97##
     98## Internal utility functions
     99##
     100
     101## IPDB::_rpc
     102# Make an RPC call for DNS changes
     103sub _rpc {
     104  return if !$rpc_url;  # Just In Case
     105  my $rpcsub = shift;
     106  my %args = @_;
     107
     108  # Make an object to represent the XML-RPC server.
     109  my $server = Frontier::Client->new(url => $rpc_url, debug => 0);
     110  my $result;
     111
     112  my %rpcargs = (
     113        rpcsystem => 'ipdb',
     114        rpcuser => $args{user},
     115        );
     116
     117  eval {
     118    $result = $server->call("dnsdb.$rpcsub", %rpcargs, %args);
     119  };
     120  if ($@) {
     121    $errstr = $@;
     122    $errstr =~ s/Fault returned from XML RPC Server, fault code 4: error executing RPC `dnsdb.$rpcsub'\.\s//;
     123print "error!  $errstr\n";
     124  }
     125  $rpccount++;
     126
     127  return $result if $result;
     128} # end _rpc()
     129
    91130
    92131# Let's initialize the globals.
     
    316355    # Only attempt rDNS if the IPDB side succeeded
    317356    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;
    321357
    322358# Note *not* splitting reverse zones negates any benefit from caching the exported data.
     
    339375        my %rpcargs = (
    340376          rpcuser => $args{user},
    341           rpcsystem => 'ipdb',
    342377          revzone => "$subzone",
    343378          revpatt => $args{rdns},
    344379          defloc => $args{defloc},
    345           group => 1,   # not sure how these two could sanely be exposed, tbh...
     380          group => $revgroup,   # not sure how these two could sanely be exposed, tbh...
    346381          state => 1,   # could make them globally configurable maybe
    347382        );
    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);
     383        if (!_rpc('addRDNS', %rpcargs)) {
     384          push @fails, ("$subzone" => $errstr);
    355385        }
    356386      }
     
    815845  $args{privdata} = '' if !$args{privdata};
    816846  $args{vrf} = '' if !$args{vrf};
     847  $args{rdns} = '' if !$args{rdns};
    817848
    818849  my $sth;
     
    843874                undef, ($args{alloc_from}) );
    844875      }
    845       $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=?,vrf=? ".
     876      $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=?,vrf=?,rdns=? ".
    846877        "WHERE ip=?", undef, ($args{custid}, $args{city}, $args{desc}, $args{notes}, $args{circid},
    847                 $args{privdata}, $args{vrf}, $args{cidr}) );
     878                $args{privdata}, $args{vrf}, $args{rdns}, $args{cidr}) );
    848879
    849880# node hack
     
    860891      return ('FAIL', $msg);
    861892    } else {
     893      _rpc('addOrUpdateRevRec', cidr => "$args{cidr}", name => $args{rdns}, rpcuser => $args{user});
    862894      return ('OK', $args{cidr});
    863895    }
     
    891923        # Insert the allocations entry
    892924        $dbh->do("INSERT INTO allocations ".
    893                 "(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata)".
    894                 " VALUES (?,?,?,?,?,?,?,?,?,?,?)", undef,
     925                "(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata,rdns)".
     926                " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
    895927                ($args{cidr}, $fparent, $args{vrf}, $args{rdepth}, $args{custid}, $args{type}, $args{city},
    896                 $args{desc}, $args{notes}, $args{circid}, $args{privdata}) );
     928                $args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
    897929
    898930        # And initialize the pool, if necessary
     
    921953        eval { $dbh->rollback; };
    922954        return ('FAIL',$msg);
    923       } else {
    924         return ('OK',"OK");
    925955      }
    926956
     
    969999        # Insert the allocations entry
    9701000        $dbh->do("INSERT INTO allocations ".
    971                 "(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata)".
    972                 " VALUES (?,?,?,?,?,?,?,?,?,?,?)", undef,
     1001                "(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata,rdns)".
     1002                " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
    9731003                ($args{cidr}, $fparent, $args{vrf}, $args{rdepth}, $args{custid}, $args{type}, $args{city},
    974                 $args{desc}, $args{notes}, $args{circid}, $args{privdata}) );
     1004                $args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
    9751005
    9761006        # And initialize the pool, if necessary
     
    9991029        eval { $dbh->rollback; };
    10001030        return ('FAIL',$msg);
    1001       } else {
    1002         return ('OK',"OK");
    10031031      }
    10041032
    10051033    } # end fullcidr != alloc_from
     1034
     1035    # now we do the DNS dance for netblocks, if we have an RPC server to do it with.
     1036    _rpc('addOrUpdateRevRec', cidr => "$args{cidr}", name => $args{rdns}, rpcuser => $args{user})
     1037      if $rpc_url;
     1038
     1039    return ('OK', 'OK');
    10061040
    10071041  } # end static-IP vs netblock allocation
     
    14421476
    14431477
     1478## IPDB::getBlockRDNS()
     1479# Gets reverse DNS pattern for a block or IP.  Note that this will also
     1480# retrieve any default pattern following the parent chain up, and check via
     1481# RPC (if available) to see what the narrowest pattern for the requested block is
     1482# Returns the current pattern for the block or IP.
     1483sub getBlockRDNS {
     1484  my $dbh = shift;
     1485  my $block = shift;
     1486  my $rdepth = shift;   # do we really need this?
     1487  my %args = @_;
     1488
     1489  $args{vrf} = '' if !$args{vrf};
     1490
     1491  my $cidr = new NetAddr::IP $block;
     1492
     1493  my ($rdns,$rfrom) = $dbh->selectrow_array("SELECT rdns,cidr FROM allocations WHERE cidr >>= ? UNION ".
     1494        "SELECT rdns,cidr FROM masterblocks WHERE cidr >>= ? ORDER BY cidr", undef, ($cidr,$cidr) );
     1495
     1496  if ($rpc_url) {
     1497    # Make an object to represent the XML-RPC server.
     1498    my $server = Frontier::Client->new(url => $rpc_url, debug => 0);
     1499    my $result;
     1500
     1501    # Use the first /16 or /24, rather than dithering over which sub-/14 /16
     1502    # or sub-/19 /24 to retrieve - it's the least-wrong way to do things.
     1503
     1504    my ($rpcblock) = $cidr->split( ($cidr->masklen <= 16 ? 16 : 24) );
     1505    my %rpcargs = (
     1506        rpcuser => $args{user},
     1507        rpcsystem => 'ipdb',
     1508        group => $revgroup,     # not sure how this could sanely be exposed, tbh...
     1509        cidr => "$rpcblock",
     1510        );
     1511
     1512    eval {
     1513      $result = $server->call('dnsdb.getRevPattern', %rpcargs);
     1514    };
     1515    if ($@) {
     1516      my $msg = $@;
     1517      $msg =~ s/Fault returned from XML RPC Server, fault code 4: error executing RPC `dnsdb.addRDNS'\.\s//;
     1518    }
     1519  }
     1520
     1521  # hmm.  do we care about where it actually came from?
     1522  return $rdns;
     1523} # end getBlockRDNS()
     1524
     1525
    14441526## IPDB::getNodeList()
    14451527# Gets a list of node ID+name pairs as an arrayref to a list of hashrefs
  • trunk/cgi-bin/main.cgi

    r584 r585  
    318318    $page->param(rdepth => $webvar{rdepth});
    319319
     320    my $rdns = getBlockRDNS($ip_dbh, $webvar{block}, $webvar{rdepth}, vrf => $webvar{vrf}, user => $authuser);
     321    $page->param(rdns => $rdns) if $rdns;
     322
    320323    $webvar{fbtype} = '' if !$webvar{fbtype};
    321324    if ($webvar{fbtype} eq 'i') {
     
    468471  $page->param(rdepth => $webvar{rdepth});
    469472  $page->param(cidr => $cidr);
     473  $page->param(rdns => $webvar{rdns});
    470474  $page->param(city => $q->escapeHTML($webvar{city}));
    471475  $page->param(custid => $webvar{custid});
     
    518522        rdepth => $webvar{rdepth}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city},
    519523        desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
    520         privdata => $webvar{privdata}, nodeid => $webvar{node});
     524        privdata => $webvar{privdata}, nodeid => $webvar{node}, rdns => $webvar{rdns}, user => $authuser);
    521525
    522526  if ($code eq 'OK') {
  • trunk/templates/assign.tmpl

    r575 r585  
    7171
    7272<tr class="<TMPL_VAR NAME=rowa>">
     73<td>Reverse DNS pattern:</td>
     74<td><input type="text" name="rdns" value="<TMPL_VAR NAME=rdns>" size="40"><input type="button" value=" ? " onclick="helpRDNS()" class="regular"></td>
     75</tr>
     76
     77<tr class="<TMPL_VAR NAME=rowb>">
    7378<td>Customer ID:</td>
    7479<td><input type="text" name="custid" size="15" maxlength="15"> (Only required for Customer allocations)</td>
    7580</tr>
    7681
    77 <tr class="<TMPL_VAR NAME=rowb>">
     82<tr class="<TMPL_VAR NAME=rowa>">
    7883<td>Wifi tower/Fibre demarc</td>
    7984<td>
     
    8893
    8994<TMPL_UNLESS allocfrom>
    90 <tr class="<TMPL_VAR NAME=rowa>">
     95<tr class="<TMPL_VAR NAME=rowb>">
    9196<td>Route from/through:</td>
    9297<td>
     
    99104</tr>
    100105
    101 <tr class="<TMPL_VAR NAME=rowb>">
     106<tr class="<TMPL_VAR NAME=rowa>">
    102107<td>Route/allocate from this master:&nbsp;</td>
    103108<td>
     
    111116</TMPL_UNLESS>
    112117
    113 <tr class="<TMPL_VAR NAME=rowa>">
     118<tr class="<TMPL_VAR NAME=rowb>">
    114119<td>Circuit ID:</td>
    115120<td><input name="circid" size="40"></td>
    116121</tr>
    117122
    118 <tr class="<TMPL_VAR NAME=rowb>">
     123<tr class="<TMPL_VAR NAME=rowa>">
    119124<td>Description/Name:</td>
    120125<td><input name="desc" size="40"></td>
    121126</tr>
    122127
    123 <tr class="<TMPL_VAR NAME=rowa>">
     128<tr class="<TMPL_VAR NAME=rowb>">
    124129<td>Notes:&nbsp;</td>
    125130<td><textarea name="notes" rows="3" cols="40"></textarea></td>
     
    127132
    128133<TMPL_IF privdata>
    129 <tr class="<TMPL_VAR NAME=rowb>">
     134<tr class="<TMPL_VAR NAME=rowa>">
    130135<td>Restricted data:</td>
    131136<td><textarea rows="3" cols="64" name="privdata" class="regular"></textarea></td>
     
    133138</TMPL_IF>
    134139
    135 <tr class="<TMPL_IF privdata><TMPL_VAR NAME=rowa><TMPL_ELSE><TMPL_VAR NAME=rowb></TMPL_IF>">
     140<tr class="<TMPL_IF privdata><TMPL_VAR NAME=rowb><TMPL_ELSE><TMPL_VAR NAME=rowa></TMPL_IF>">
    136141<td class="center" colspan="2"><input type="submit" value="  Assign  "></td>
    137142</tr>
  • trunk/templates/confirm.tmpl

    r575 r585  
    3232
    3333<tr class="row0">
     34<td>Reverse DNS pattern:</td>
     35<td><TMPL_IF rdns><TMPL_VAR NAME=rdns><TMPL_ELSE>[ Keep default ]</TMPL_IF>
     36<input type="button" value=" ? " onclick="helpRDNS()" class="regular">
     37</td>
     38</tr>
     39
     40<tr class="row1">
    3441<td>City:</td>
    3542<td><TMPL_VAR NAME=city></td>
    3643</tr>
    3744
    38 <tr class="row1">
     45<tr class="row0">
    3946<td>Demarc switch/wifi tower:</td>
    4047<td><TMPL_VAR NAME=nodename></td>
    4148</tr>
    4249
    43 <tr class="row0">
     50<tr class="row1">
    4451<td>Allocation type:</td>
    4552<td><TMPL_VAR NAME=typefull></td>
    4653</tr>
    4754
    48 <tr class="row1">
     55<tr class="row0">
    4956<td>Customer ID:</td>
    5057<td><TMPL_VAR NAME=custid></td>
    5158</tr>
    5259
    53 <tr class="row0">
     60<tr class="row1">
    5461<td valign="top">Circuit ID:</td>
    5562<td><TMPL_VAR NAME=circid></td>
    5663</tr>
    5764
    58 <tr class="row1">
     65<tr class="row0">
    5966<td valign="top">Description/name:</td>
    6067<td><TMPL_VAR NAME=desc></td>
    6168</tr>
    6269
    63 <tr class="row0">
     70<tr class="row1">
    6471<td valign="top">Notes:</td>
    6572<td><TMPL_VAR NAME=notes></td>
     
    6774
    6875<TMPL_IF privdata>
    69 <tr class="row1">
     76<tr class="row0">
    7077<td>Restricted data:</td>
    7178<td><TMPL_VAR NAME=privdata></td>
     
    7481
    7582<!-- warn -->
    76 <tr class="<TMPL_IF privdata>row0<TMPL_ELSE>row1</TMPL_IF>">
     83<tr class="<TMPL_IF privdata>row1<TMPL_ELSE>row0</TMPL_IF>">
    7784<td class="center" colspan="2">
    7885<TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS>
    7986<input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
    8087<input type="hidden" name="fullcidr" value="<TMPL_VAR NAME=cidr>">
     88<input type="hidden" name="rdns" value="<TMPL_VAR NAME=rdns>">
    8189<input type="hidden" name="city" value="<TMPL_VAR NAME=city>">
    8290<input type="hidden" name="node" value="<TMPL_VAR NAME=nodeid>">
Note: See TracChangeset for help on using the changeset viewer.