source: branches/stable/cgi-bin/extras/db2rwhois.pl@ 314

Last change on this file since 314 was 308, checked in by Kris Deugau, 19 years ago

/branches/stable

Fixups and cleanups for rWHOIS export script.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 5.0 KB
RevLine 
[15]1#!/usr/bin/perl
2# -T
3# ipdb/cgi-bin/extras/db2rwhois.pl
[2]4# Pull data from ipdb and mangle it into RWHOIS
[15]5# Initial version 03/26/2004 kdeugau against IPDB v1
6###
7# Revision info
8# $Date: 2006-02-28 22:45:43 +0000 (Tue, 28 Feb 2006) $
9# SVN revision $Rev: 308 $
10# Last update by $Author: kdeugau $
11###
[158]12# Copyright (C) 2004,2005 - Kris Deugau
[2]13
[15]14use strict;
15use warnings;
[2]16use DBI;
17use NetAddr::IP;
[158]18use MyIPDB;
[2]19
20$ENV{"PATH"} = "/bin;/usr/bin";
21
[15]22my $rwhoisDataPath = "/etc/rwhoisd";
23
[158]24my ($dbh,$msg) = connectDB_My;
[2]25
[158]26# For WHOIS purposes this may not be very useful. YMMV, we'll see.
27#initIPDBGlobals($dbh);
28
[15]29my @masterblocks;
30
[2]31# Fill in data about our master blocks as allocated from ARIN
32# We open separate files for each of these as appropriate.
33# Note that this ASS-U-MEs that we do not add master IP blocks-
34# there should probably be a separate system for doing that.
[253]35my $sth = $dbh->prepare("select cidr,ctime from masterblocks;");
[2]36$sth->execute;
[15]37my $i=0;
38GETMASTERS: while (my @data = $sth->fetchrow_array()) {
[2]39
[253]40# Techically, we only need to exclude 204.138.172.0/24, as we "own" all of the other blocks.
[308]41# However, 205.207.184.0/23 and 206.130.64.0/24 are, um, awkward.
[253]42 if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0|20[456])/) {
[15]43 next GETMASTERS;
44 }
45 $masterblocks[$i] = new NetAddr::IP $data[0];
[253]46 my ($ctime,undef) = split /\s/, $data[1];
[2]47
[253]48print "$masterblocks[$i] $data[1]\n";
[15]49
50 my $date;
[253]51 chomp ($date = `/bin/date +"%Y-%m-%d"`);
[2]52
53# Whew! Ugly little varmint.
[15]54 my $masterfilename = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.
[2]55 "/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
56
[15]57# Need check here to create tree for netblock?
[2]58
[15]59 open MASTERFILE,">$rwhoisDataPath/$masterfilename";
60
[2]61 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
62 "Auth-Area: $masterblocks[$i]\n".
63 "Network-Name: ISP-".$masterblocks[$i]->network."\n".
64 "IP-Network: $masterblocks[$i]\n".
65 "IP-Network-Block: ".$masterblocks[$i]->range."\n".
[15]66 "Organization: Friendly ISP\n".
67 "Tech-Contact: noc\@example.com\n".
[2]68 "Admin-Contact: ISP-ARIN-HANDLE\n".
[15]69 "Abuse-Contact: abuse\@example.com\n".
[253]70 "Created: $ctime\n".
[2]71 "Updated: $date\n".
72 "Updated-By: noc\@example.com\n";
73
74 close MASTERFILE;
75 $i++;
76}
77
78# Now read out the data in the "main" delegation list, and check it
79# with the master blocks. We need to do this to decide which rWHOIS
80# "net-xxx.xxx.xxx.xxx-mask" tree the data belongs in.
81
[15]82# Make sure to remove the private netblocks from this.
83# No use or point in broadcasting our use of them.
[308]84# Also remove the details of our "reserved CORE/WAN" blocks; they're not critical.
[253]85$sth = $dbh->prepare("select cidr,custid,type,city,description,createstamp,modifystamp ".
86 "from allocations where ".
87 "not (cidr <<= '192.168.0.0/16') and ".
88 "not (cidr <<= '172.16.0.0/12') and ".
89 "not (cidr <<= '10.0.0.0/8') and ".
[308]90 "not (type = 'wr') and ".
[253]91 "masklen(cidr) <=30");
92#" and (custid='6750400' or custid like '%-RES' or custid like '%-BUS')");
[2]93$sth->execute;
94
[253]95$i=0;
96while (my ($cidr, $custid, $type, $city, $desc, $ctime, $mtime) = $sth->fetchrow_array) {
[2]97
98# We get master block info from @masterblocks.
99 # ID: NETBLK-ISP.10.0.0.0/8
100 # Auth-Area: 10.0.0.0/8
101 # Network-Name: ISP-10.0.2.144
102 # IP-Network: 10.0.2.144.144/29
103 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
104 # Organization: WidgetCorp
105 # Tech-Contact: bob@widgetcorp.com
106 # Admin-Contact: ISP-ARIN-HANDLE
107 # Created: 20040314
108 # Updated: 20040314
109 # Updated-By: noc@example.com
110
111 # Get the "full" network number
[253]112 my $net = new NetAddr::IP $cidr;
[2]113
114# Assumptions: All data in ipdb is public
115# If not, we need another field to indicate "public/private".
116
[15]117 foreach my $master (@masterblocks) {
[2]118 if ($master->contains($net)) {
119
120# Whew! Ugly little varmint.
[15]121 my $masterfilename = "net-".$master->addr."-".$master->masklen.
[2]122 "/data/network/".$master->addr."-".$master->masklen.".txt";
123
[15]124 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
125 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
[2]126
[15]127# cidr custid type city description notes maskbits
128
[308]129# Fill in a generic entry for nameless allocations
[253]130if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }
131
[308]132 # Fix up datestamps. We don't *really* need sub-microsecond resolution on our exports...
133 ($ctime) = ($ctime =~ /^(\d+-\d+-\d+)\s+/);
134 ($mtime) = ($mtime =~ /^(\d+-\d+-\d+)\s+/);
135
[2]136 print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
137 "Auth-Area: $master\n".
138 "Network-Name: ISP-".$net->network."\n".
139 "IP-Network: $net\n".
140 "IP-Network-Block: ".$net->range."\n".
[253]141 "Organization: $desc\n".
[2]142# "Tech-Contact: $data[9]\n".
143 "Tech-Contact: abuse\@example.com\n".
144 "Admin-Contact: ISP-ARIN-HANDLE\n".
[253]145 "Created: $ctime\n".
146 "Updated: $mtime\n".
[2]147 "Updated-By: noc\@example.com\n";
148 }
149 }
150
151
152
153 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
154 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\t| $data[9]\n";
155 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
156 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
[253]157 $i++;
[2]158} # while fetchrow_array()
159
160
161$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.