Changeset 680


Ignore:
Timestamp:
01/19/15 18:17:21 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Update db2rwhois for new database structure:

  • new location for master blocks
  • recheck ARIN policies for inclusion of netblock assignments in rWHOIS (v6 /64 should be included; was /56 at one point waaay back)
  • file off another site-specific-ism that's built from the database and configuration
File:
1 edited

Legend:

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

    r453 r680  
    6161
    6262# Get the list of masters to export
    63 my $msth = $dbh->prepare("select cidr,ctime,mtime from masterblocks where rwhois='y'");
     63my $msth = $dbh->prepare(q(
     64        SELECT cidr, createstamp, modifystamp, id
     65        FROM allocations
     66        WHERE type='mm' AND swip='y'
     67        ) );
    6468$msth->execute;
    6569
     
    6872# no use or point in broadcasting our use of them.
    6973# 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 <<= ?");
     74my $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        ) );
    7886
    7987# 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=?");
     88my $custsth = $dbh->prepare(q(
     89        SELECT name, street, city, province, country, pocode, phone, tech_handle, special
     90        FROM customers
     91        WHERE custid = ?
     92        ) );
    8293
    8394# Fill in data about our master blocks as allocated from ARIN
     
    8697# all data every time, this isn't so terrible as it might seem.
    8798my $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 $mtime\n";
     99while (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";
    95106
    96107  my $date = strftime("%Y-%m-%d", localtime);
     
    155166    print "  Creating org data...\n";
    156167    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]
    158169Auth-Area: $masterblocks[$i]
    159170Org-Name: $IPDB::org_name
     
    188199  open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename";
    189200
    190   print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
     201  print MASTERFILE "ID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n".
    191202        "Auth-Area: $masterblocks[$i]\n".
    192         "Network-Name: ISP-".$masterblocks[$i]->network."\n".
     203        "Network-Name: $netnameprefix{mm}-".$masterblocks[$i]->network."\n".
    193204        "IP-Network: $masterblocks[$i]\n".
    194205        "IP-Network-Block: ".$masterblocks[$i]->range."\n".
     
    201212        "Tech-Contact: $IPDB::org_techhandle\n".
    202213        "Created: $ctime\n".
    203         "Updated: $mtime\n".
     214        "Updated: $mmod\n".
    204215        "Updated-By: $IPDB::org_email\n";
    205216
    206217  # And now the subblocks
    207   $ssth->execute("$masterblocks[$i]");
     218  $ssth->execute($mid, $master) or die "nosubs: $!\n".$dbh->errstr."\n";
    208219  while (my ($cidr, $custid, $type, $city, $desc, $ctime, $mtime, $swip) = $ssth->fetchrow_array) {
    209220
    210221# We get master block info from @masterblocks.
    211  # ID: NETBLK-ISP.10.0.0.0/8
     222 # ID: NETBLK-$netnameprefix{mm}.10.0.0.0/8
    212223 # Auth-Area: 10.0.0.0/8
    213  # Network-Name: ISP-10.0.2.144
     224 # Network-Name: $netnameprefix{$type}-10.0.2.144
    214225 # IP-Network: 10.0.2.144.144/29
    215226 # IP-Network-Block: 10.0.2.144 - 10.0.2.151
     
    229240# cidr custid type city description notes maskbits
    230241
    231 # Fill in a generic entry for nameless allocations
    232 if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }
     242    # Fill in a generic entry for nameless allocations
     243    if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }
    233244
    234245    # Fix up datestamps.  We don't *really* need sub-microsecond resolution on our exports...
     
    256267
    257268    if ($swip eq 'n') {
    258       print MASTERFILE "---\nID: NETBLK-ISP.$masterblocks[$i]\n".
     269      print MASTERFILE "---\nID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n".
    259270        "Auth-Area: $masterblocks[$i]\n".
    260271        "Network-Name: $netname-".$net->network."\n".
     
    280291        $netname .= "-".$net->network;
    281292      }
    282       print MASTERFILE "---\nID: NETBLK-ISP.$masterblocks[$i]\n".
     293      print MASTERFILE "---\nID: NETBLK-$netnameprefix{mm}.$masterblocks[$i]\n".
    283294        "Auth-Area: $masterblocks[$i]\n".
    284295        "Network-Name: $netname\n".
Note: See TracChangeset for help on using the changeset viewer.