Changeset 311


Ignore:
Timestamp:
03/28/06 15:27:06 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

Copy db2rwhois.pl from /branches/stable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/extras/db2rwhois.pl

    r218 r311  
    1717use NetAddr::IP;
    1818use MyIPDB;
    19 use Digest::MD5 qw(md5_hex);
    2019
    2120$ENV{"PATH"} = "/bin;/usr/bin";
    2221
    2322my $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 #               );
    3223
    3324my ($dbh,$msg) = connectDB_My;
     
    4738GETMASTERS: while (my @data = $sth->fetchrow_array()) {
    4839
    49 #  if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
    50 #    next GETMASTERS;
    51 #  }
     40# Techically, we only need to exclude 204.138.172.0/24, as we "own" all of the other blocks.
     41# However, 205.207.184.0/23 and 206.130.64.0/24 are, um, awkward.
     42  if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0|20[456])/) {
     43    next GETMASTERS;
     44  }
    5245  $masterblocks[$i] = new NetAddr::IP $data[0];
     46  my ($ctime,undef) = split /\s/, $data[1];
    5347
    54 print "$masterblocks[$i]\n";
     48print "$masterblocks[$i] $data[1]\n";
    5549
    5650  my $date;
    57   chomp ($date = `/bin/date +"%Y%m%d"`);
    58   my ($ctime,undef) = split /\s+/, $data[1];
     51  chomp ($date = `/bin/date +"%Y-%m-%d"`);
    5952
    6053# Whew!  Ugly little varmint.
     
    8982# Make sure to remove the private netblocks from this.
    9083# 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");
     84# Also remove the details of our "reserved CORE/WAN" blocks;  they're not critical.
     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 ".
     90        "not (type = 'wr') and ".
     91        "masklen(cidr) <=30");
     92#" and (custid='6750400' or custid like '%-RES' or custid like '%-BUS')");
    9593$sth->execute;
    9694
    97 while (my ($cidr,$custid,$type,$city,$description,$ctime,$mtime) = $sth->fetchrow_array()) {
     95$i=0;
     96while (my ($cidr, $custid, $type, $city, $desc, $ctime, $mtime) = $sth->fetchrow_array) {
    9897
    9998# We get master block info from @masterblocks.
     
    110109 # Updated-By: noc@example.com
    111110
    112   # Get the "full" network number - just in case.
     111  # Get the "full" network number
    113112  my $net = new NetAddr::IP $cidr;
    114113
     
    126125        or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
    127126
    128 if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
    129 print "$type-type $net for $custid, created $ctime, modified $mtime\n";
     127# cidr custid type city description notes maskbits
     128
     129# Fill in a generic entry for nameless allocations
     130if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }
     131
     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
    130136      print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
    131137        "Auth-Area: $master\n".
     
    133139        "IP-Network: $net\n".
    134140        "IP-Network-Block: ".$net->range."\n".
    135         "Organization: $description\n".
     141        "Organization: $desc\n".
    136142#       "Tech-Contact: $data[9]\n".
    137143        "Tech-Contact: abuse\@example.com\n".
     
    149155  #  print "$data[0]\t| $data[1]\t| $data[2]\t| $data[3]\t| $data[4]\t| ".
    150156  #     "$data[5]\t| $data[6]\t| $data[7]\t| $data[8]\n";
    151 
     157  $i++;
    152158} # while fetchrow_array()
    153159
    154160
    155161$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 TracChangeset for help on using the changeset viewer.