Changeset 585 for trunk/cgi-bin
- Timestamp:
- 01/16/13 17:16:46 (12 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r582 r585 25 25 @EXPORT_OK = qw( 26 26 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist 27 %IPDBacl %aclmsg 27 %IPDBacl %aclmsg $errstr 28 28 &initIPDBGlobals &connectDB &finish &checkDBSanity 29 29 &addMaster &touchMaster … … 31 31 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 32 32 &ipParent &subParent &blockParent &getRoutedCity 33 &allocateBlock &updateBlock &deleteBlock &getBlockData 33 &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS 34 34 &getNodeList &getNodeName &getNodeInfo 35 35 &mailNotify … … 39 39 %EXPORT_TAGS = ( ALL => [qw( 40 40 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist 41 %IPDBacl %aclmsg 41 %IPDBacl %aclmsg $errstr 42 42 &initIPDBGlobals &connectDB &finish &checkDBSanity 43 43 &addMaster &touchMaster … … 45 45 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 46 46 &ipParent &subParent &blockParent &getRoutedCity 47 &allocateBlock &updateBlock &deleteBlock &getBlockData 47 &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS 48 48 &getNodeList &getNodeName &getNodeInfo 49 49 &mailNotify … … 68 68 delblock => 'delete an allocation', 69 69 ); 70 71 # error reporting 72 our $errstr = ''; 70 73 71 74 our $org_name = 'Example Corp'; … … 89 92 90 93 our $rpc_url = ''; 94 our $revgroup = 1; # should probably be configurable somewhere 95 our $rpccount = 0; 96 97 ## 98 ## Internal utility functions 99 ## 100 101 ## IPDB::_rpc 102 # Make an RPC call for DNS changes 103 sub _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//; 123 print "error! $errstr\n"; 124 } 125 $rpccount++; 126 127 return $result if $result; 128 } # end _rpc() 129 91 130 92 131 # Let's initialize the globals. … … 316 355 # Only attempt rDNS if the IPDB side succeeded 317 356 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 357 322 358 # Note *not* splitting reverse zones negates any benefit from caching the exported data. … … 339 375 my %rpcargs = ( 340 376 rpcuser => $args{user}, 341 rpcsystem => 'ipdb',342 377 revzone => "$subzone", 343 378 revpatt => $args{rdns}, 344 379 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... 346 381 state => 1, # could make them globally configurable maybe 347 382 ); 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); 355 385 } 356 386 } … … 815 845 $args{privdata} = '' if !$args{privdata}; 816 846 $args{vrf} = '' if !$args{vrf}; 847 $args{rdns} = '' if !$args{rdns}; 817 848 818 849 my $sth; … … 843 874 undef, ($args{alloc_from}) ); 844 875 } 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=? ". 846 877 "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}) ); 848 879 849 880 # node hack … … 860 891 return ('FAIL', $msg); 861 892 } else { 893 _rpc('addOrUpdateRevRec', cidr => "$args{cidr}", name => $args{rdns}, rpcuser => $args{user}); 862 894 return ('OK', $args{cidr}); 863 895 } … … 891 923 # Insert the allocations entry 892 924 $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, 895 927 ($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}) ); 897 929 898 930 # And initialize the pool, if necessary … … 921 953 eval { $dbh->rollback; }; 922 954 return ('FAIL',$msg); 923 } else {924 return ('OK',"OK");925 955 } 926 956 … … 969 999 # Insert the allocations entry 970 1000 $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, 973 1003 ($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}) ); 975 1005 976 1006 # And initialize the pool, if necessary … … 999 1029 eval { $dbh->rollback; }; 1000 1030 return ('FAIL',$msg); 1001 } else {1002 return ('OK',"OK");1003 1031 } 1004 1032 1005 1033 } # 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'); 1006 1040 1007 1041 } # end static-IP vs netblock allocation … … 1442 1476 1443 1477 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. 1483 sub 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 1444 1526 ## IPDB::getNodeList() 1445 1527 # Gets a list of node ID+name pairs as an arrayref to a list of hashrefs -
trunk/cgi-bin/main.cgi
r584 r585 318 318 $page->param(rdepth => $webvar{rdepth}); 319 319 320 my $rdns = getBlockRDNS($ip_dbh, $webvar{block}, $webvar{rdepth}, vrf => $webvar{vrf}, user => $authuser); 321 $page->param(rdns => $rdns) if $rdns; 322 320 323 $webvar{fbtype} = '' if !$webvar{fbtype}; 321 324 if ($webvar{fbtype} eq 'i') { … … 468 471 $page->param(rdepth => $webvar{rdepth}); 469 472 $page->param(cidr => $cidr); 473 $page->param(rdns => $webvar{rdns}); 470 474 $page->param(city => $q->escapeHTML($webvar{city})); 471 475 $page->param(custid => $webvar{custid}); … … 518 522 rdepth => $webvar{rdepth}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city}, 519 523 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); 521 525 522 526 if ($code eq 'OK') {
Note:
See TracChangeset
for help on using the changeset viewer.