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

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

/branches/stable

Cleanup commit for db2rwhois.pl; looks like I forgot. :/
Changes are all of the "make it work (better)" variety.
Further significant changes require new billing system to
be completed for crosslinking.

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