source: branches/rpc/cgi-bin/extras/db2rwhois.pl@ 382

Last change on this file since 382 was 218, checked in by Kris Deugau, 20 years ago

/trunk

Updated SQL tabledefs with timestamps for master block, routed

block, allocation, and static IP "creation" times; also
allocation and static IP modification times.

Updated db2rwhois.pl with timestamp support and a little code cleanup.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 4.9 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-04-06 21:06:28 +0000 (Wed, 06 Apr 2005) $
9# SVN revision $Rev: 218 $
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;
19use Digest::MD5 qw(md5_hex);
20
21$ENV{"PATH"} = "/bin;/usr/bin";
22
23my $rwhoisDataPath = "/etc/rwhoisd";
24
25# We'll pull this out of the database instead. Just make sure our
26# master blocks are actually listed.... <g>
27#@masterblocks = (
28# (new NetAddr::IP "209.91.128.0/18"),
29# (new NetAddr::IP "66.186.64.0/19"),
30# (new NetAddr::IP "192.168.99.0/24")
31# );
32
33my ($dbh,$msg) = connectDB_My;
34
35# For WHOIS purposes this may not be very useful. YMMV, we'll see.
36#initIPDBGlobals($dbh);
37
38my @masterblocks;
39
40# Fill in data about our master blocks as allocated from ARIN
41# We open separate files for each of these as appropriate.
42# Note that this ASS-U-MEs that we do not add master IP blocks-
43# there should probably be a separate system for doing that.
44my $sth = $dbh->prepare("select cidr,ctime from masterblocks;");
45$sth->execute;
46my $i=0;
47GETMASTERS: while (my @data = $sth->fetchrow_array()) {
48
49# if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
50# next GETMASTERS;
51# }
52 $masterblocks[$i] = new NetAddr::IP $data[0];
53
54print "$masterblocks[$i]\n";
55
56 my $date;
57 chomp ($date = `/bin/date +"%Y%m%d"`);
58 my ($ctime,undef) = split /\s+/, $data[1];
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 * from allocations where not (cidr <<= '192.168.0.0/16') and not (cidr <<= '172.16.0.0/12') and not (cidr <<= '10.0.0.0/8')");
92# cidr,custid,type,city,description,notes,maskbits,circuitid,createstamp,modifystamp,newcustid
93
94$sth = $dbh->prepare("select cidr,custid,type,city,description,createstamp,modifystamp from allocations");
95$sth->execute;
96
97while (my ($cidr,$custid,$type,$city,$description,$ctime,$mtime) = $sth->fetchrow_array()) {
98
99# We get master block info from @masterblocks.
100 # ID: NETBLK-ISP.10.0.0.0/8
101 # Auth-Area: 10.0.0.0/8
102 # Network-Name: ISP-10.0.2.144
103 # IP-Network: 10.0.2.144.144/29
104 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
105 # Organization: WidgetCorp
106 # Tech-Contact: bob@widgetcorp.com
107 # Admin-Contact: ISP-ARIN-HANDLE
108 # Created: 20040314
109 # Updated: 20040314
110 # Updated-By: noc@example.com
111
112 # Get the "full" network number - just in case.
113 my $net = new NetAddr::IP $cidr;
114
115# Assumptions: All data in ipdb is public
116# If not, we need another field to indicate "public/private".
117
118 foreach my $master (@masterblocks) {
119 if ($master->contains($net)) {
120
121# Whew! Ugly little varmint.
122 my $masterfilename = "net-".$master->addr."-".$master->masklen.
123 "/data/network/".$master->addr."-".$master->masklen.".txt";
124
125 open MASTERFILE,">>$rwhoisDataPath/$masterfilename"
126 or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
127
128if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
129print "$type-type $net for $custid, created $ctime, modified $mtime\n";
130 print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
131 "Auth-Area: $master\n".
132 "Network-Name: ISP-".$net->network."\n".
133 "IP-Network: $net\n".
134 "IP-Network-Block: ".$net->range."\n".
135 "Organization: $description\n".
136# "Tech-Contact: $data[9]\n".
137 "Tech-Contact: abuse\@example.com\n".
138 "Admin-Contact: ISP-ARIN-HANDLE\n".
139 "Created: $ctime\n".
140 "Updated: $mtime\n".
141 "Updated-By: noc\@example.com\n";
142 }
143 }
144
145
146
147 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
148 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\t| $data[9]\n";
149 # print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
150 # "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
151
152} # while fetchrow_array()
153
154
155$dbh->disconnect;
156
157# This doesn't work, with a vengeance.
158#print qx{ /usr/bin/rwhois_indexer -c /etc/rwhoisd/rwhoisd.conf -i -v -s txt };
Note: See TracBrowser for help on using the repository browser.