Changeset 680 for trunk/cgi-bin
- Timestamp:
- 01/19/15 18:17:21 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/extras/db2rwhois.pl
r453 r680 61 61 62 62 # Get the list of masters to export 63 my $msth = $dbh->prepare("select cidr,ctime,mtime from masterblocks where rwhois='y'"); 63 my $msth = $dbh->prepare(q( 64 SELECT cidr, createstamp, modifystamp, id 65 FROM allocations 66 WHERE type='mm' AND swip='y' 67 ) ); 64 68 $msth->execute; 65 69 … … 68 72 # no use or point in broadcasting our use of them. 69 73 # Also remove the details of our "reserved CORE/WAN" blocks; they're not critical. 70 my $ssth = $dbh->prepare("select cidr,custid,type,city,description,createstamp,modifystamp,swip ". 71 "from allocations where ". 72 "not (cidr <<= '192.168.0.0/16') and ". 73 "not (cidr <<= '172.16.0.0/12') and ". 74 "not (cidr <<= '10.0.0.0/8') and ". 75 "not (type = 'wr') and ". 76 "((masklen(cidr) <=30 and family(cidr)=4) or (masklen(cidr) <=56 and family(cidr)=6)) and ". 77 "cidr <<= ?"); 74 my $ssth = $dbh->prepare(q( 75 SELECT cidr, custid, type, city, description, createstamp, modifystamp, swip 76 FROM allocations 77 WHERE 78 NOT (cidr <<= '192.168.0.0/16') AND 79 NOT (cidr <<= '172.16.0.0/12') AND 80 NOT (cidr <<= '10.0.0.0/8') AND 81 NOT (type = 'wr' OR type = 'mm') AND 82 ((masklen(cidr) <=30 AND family(cidr)=4) OR (masklen(cidr) <=64 AND family(cidr)=6)) AND 83 master_id = ? AND 84 cidr <<= ? 85 ) ); 78 86 79 87 # Customer data, for those rare blocks we really need to delegate. 80 my $custsth = $dbh->prepare("select name,street,city,province,country,pocode,phone,tech_handle,special ". 81 "from customers where custid=?"); 88 my $custsth = $dbh->prepare(q( 89 SELECT name, street, city, province, country, pocode, phone, tech_handle, special 90 FROM customers 91 WHERE custid = ? 92 ) ); 82 93 83 94 # Fill in data about our master blocks as allocated from ARIN … … 86 97 # all data every time, this isn't so terrible as it might seem. 87 98 my $i=0; 88 while (my @data= $msth->fetchrow_array()) {89 90 $masterblocks[$i] = new NetAddr::IP $ data[0];91 my ($ctime,undef) = split /\s/, $ data[1];92 my ($mtime,undef) = split /\s/, $data[2];93 94 print "$masterblocks[$i] $ctime $m time\n";99 while (my ($master, $mcreate, $mmod, $mid) = $msth->fetchrow_array()) { 100 101 $masterblocks[$i] = new NetAddr::IP $master; 102 my ($ctime,undef) = split /\s/, $mcreate; 103 ($mmod,undef) = split /\s/, $mmod; 104 105 print "$masterblocks[$i] $ctime $mmod\n"; 95 106 96 107 my $date = strftime("%Y-%m-%d", localtime); … … 155 166 print " Creating org data...\n"; 156 167 open ORGDATAFILE, ">$netdatadir/data/org/ourorg.txt"; 157 print ORGDATAFILE qq(ID: NETBLK- ISP.$masterblocks[$i]168 print ORGDATAFILE qq(ID: NETBLK-$netnameprefix{mm}.$masterblocks[$i] 158 169 Auth-Area: $masterblocks[$i] 159 170 Org-Name: $IPDB::org_name … … 188 199 open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename"; 189 200 190 print MASTERFILE "ID: NETBLK- ISP.$masterblocks[$i]\n".201 print MASTERFILE "ID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n". 191 202 "Auth-Area: $masterblocks[$i]\n". 192 "Network-Name: ISP-".$masterblocks[$i]->network."\n".203 "Network-Name: $netnameprefix{mm}-".$masterblocks[$i]->network."\n". 193 204 "IP-Network: $masterblocks[$i]\n". 194 205 "IP-Network-Block: ".$masterblocks[$i]->range."\n". … … 201 212 "Tech-Contact: $IPDB::org_techhandle\n". 202 213 "Created: $ctime\n". 203 "Updated: $m time\n".214 "Updated: $mmod\n". 204 215 "Updated-By: $IPDB::org_email\n"; 205 216 206 217 # And now the subblocks 207 $ssth->execute( "$masterblocks[$i]");218 $ssth->execute($mid, $master) or die "nosubs: $!\n".$dbh->errstr."\n"; 208 219 while (my ($cidr, $custid, $type, $city, $desc, $ctime, $mtime, $swip) = $ssth->fetchrow_array) { 209 220 210 221 # We get master block info from @masterblocks. 211 # ID: NETBLK- ISP.10.0.0.0/8222 # ID: NETBLK-$netnameprefix{mm}.10.0.0.0/8 212 223 # Auth-Area: 10.0.0.0/8 213 # Network-Name: ISP-10.0.2.144224 # Network-Name: $netnameprefix{$type}-10.0.2.144 214 225 # IP-Network: 10.0.2.144.144/29 215 226 # IP-Network-Block: 10.0.2.144 - 10.0.2.151 … … 229 240 # cidr custid type city description notes maskbits 230 241 231 # Fill in a generic entry for nameless allocations232 if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }242 # Fill in a generic entry for nameless allocations 243 if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; } 233 244 234 245 # Fix up datestamps. We don't *really* need sub-microsecond resolution on our exports... … … 256 267 257 268 if ($swip eq 'n') { 258 print MASTERFILE "---\nID: NETBLK- ISP.$masterblocks[$i]\n".269 print MASTERFILE "---\nID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n". 259 270 "Auth-Area: $masterblocks[$i]\n". 260 271 "Network-Name: $netname-".$net->network."\n". … … 280 291 $netname .= "-".$net->network; 281 292 } 282 print MASTERFILE "---\nID: NETBLK- ISP.$masterblocks[$i]\n".293 print MASTERFILE "---\nID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n". 283 294 "Auth-Area: $masterblocks[$i]\n". 284 295 "Network-Name: $netname\n".
Note:
See TracChangeset
for help on using the changeset viewer.