Changeset 585 for trunk/cgi-bin


Ignore:
Timestamp:
01/16/13 17:16:46 (11 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/cgi-bin
Files:
2 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') {
Note: See TracChangeset for help on using the changeset viewer.