Changeset 585
- Timestamp:
- 01/16/13 17:16:46 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 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') { -
trunk/templates/assign.tmpl
r575 r585 71 71 72 72 <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>"> 73 78 <td>Customer ID:</td> 74 79 <td><input type="text" name="custid" size="15" maxlength="15"> (Only required for Customer allocations)</td> 75 80 </tr> 76 81 77 <tr class="<TMPL_VAR NAME=row b>">82 <tr class="<TMPL_VAR NAME=rowa>"> 78 83 <td>Wifi tower/Fibre demarc</td> 79 84 <td> … … 88 93 89 94 <TMPL_UNLESS allocfrom> 90 <tr class="<TMPL_VAR NAME=row a>">95 <tr class="<TMPL_VAR NAME=rowb>"> 91 96 <td>Route from/through:</td> 92 97 <td> … … 99 104 </tr> 100 105 101 <tr class="<TMPL_VAR NAME=row b>">106 <tr class="<TMPL_VAR NAME=rowa>"> 102 107 <td>Route/allocate from this master: </td> 103 108 <td> … … 111 116 </TMPL_UNLESS> 112 117 113 <tr class="<TMPL_VAR NAME=row a>">118 <tr class="<TMPL_VAR NAME=rowb>"> 114 119 <td>Circuit ID:</td> 115 120 <td><input name="circid" size="40"></td> 116 121 </tr> 117 122 118 <tr class="<TMPL_VAR NAME=row b>">123 <tr class="<TMPL_VAR NAME=rowa>"> 119 124 <td>Description/Name:</td> 120 125 <td><input name="desc" size="40"></td> 121 126 </tr> 122 127 123 <tr class="<TMPL_VAR NAME=row a>">128 <tr class="<TMPL_VAR NAME=rowb>"> 124 129 <td>Notes: </td> 125 130 <td><textarea name="notes" rows="3" cols="40"></textarea></td> … … 127 132 128 133 <TMPL_IF privdata> 129 <tr class="<TMPL_VAR NAME=row b>">134 <tr class="<TMPL_VAR NAME=rowa>"> 130 135 <td>Restricted data:</td> 131 136 <td><textarea rows="3" cols="64" name="privdata" class="regular"></textarea></td> … … 133 138 </TMPL_IF> 134 139 135 <tr class="<TMPL_IF privdata><TMPL_VAR NAME=row a><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>"> 136 141 <td class="center" colspan="2"><input type="submit" value=" Assign "></td> 137 142 </tr> -
trunk/templates/confirm.tmpl
r575 r585 32 32 33 33 <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"> 34 41 <td>City:</td> 35 42 <td><TMPL_VAR NAME=city></td> 36 43 </tr> 37 44 38 <tr class="row 1">45 <tr class="row0"> 39 46 <td>Demarc switch/wifi tower:</td> 40 47 <td><TMPL_VAR NAME=nodename></td> 41 48 </tr> 42 49 43 <tr class="row 0">50 <tr class="row1"> 44 51 <td>Allocation type:</td> 45 52 <td><TMPL_VAR NAME=typefull></td> 46 53 </tr> 47 54 48 <tr class="row 1">55 <tr class="row0"> 49 56 <td>Customer ID:</td> 50 57 <td><TMPL_VAR NAME=custid></td> 51 58 </tr> 52 59 53 <tr class="row 0">60 <tr class="row1"> 54 61 <td valign="top">Circuit ID:</td> 55 62 <td><TMPL_VAR NAME=circid></td> 56 63 </tr> 57 64 58 <tr class="row 1">65 <tr class="row0"> 59 66 <td valign="top">Description/name:</td> 60 67 <td><TMPL_VAR NAME=desc></td> 61 68 </tr> 62 69 63 <tr class="row 0">70 <tr class="row1"> 64 71 <td valign="top">Notes:</td> 65 72 <td><TMPL_VAR NAME=notes></td> … … 67 74 68 75 <TMPL_IF privdata> 69 <tr class="row 1">76 <tr class="row0"> 70 77 <td>Restricted data:</td> 71 78 <td><TMPL_VAR NAME=privdata></td> … … 74 81 75 82 <!-- warn --> 76 <tr class="<TMPL_IF privdata>row 0<TMPL_ELSE>row1</TMPL_IF>">83 <tr class="<TMPL_IF privdata>row1<TMPL_ELSE>row0</TMPL_IF>"> 77 84 <td class="center" colspan="2"> 78 85 <TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS> 79 86 <input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>"> 80 87 <input type="hidden" name="fullcidr" value="<TMPL_VAR NAME=cidr>"> 88 <input type="hidden" name="rdns" value="<TMPL_VAR NAME=rdns>"> 81 89 <input type="hidden" name="city" value="<TMPL_VAR NAME=city>"> 82 90 <input type="hidden" name="node" value="<TMPL_VAR NAME=nodeid>">
Note:
See TracChangeset
for help on using the changeset viewer.