Ignore:
Timestamp:
07/26/10 17:00:00 (14 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Bring /branches/stable up to date with /trunk. See #13.

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

    • Property svn:ignore
      •  

        old new  
        11local.css
         2*.tar.gz
    • Property svn:mergeinfo changed
      /trunkmerged: 415-420,​422-443
  • branches/stable/cgi-bin/extras/db2rwhois.pl

    r375 r445  
    1010# Last update by $Author$
    1111###
    12 # Copyright (C) 2004-2007 - Kris Deugau
     12# Copyright (C) 2004-2010 - Kris Deugau
    1313
    1414use strict;
     
    1616use DBI;
    1717use NetAddr::IP;
     18use File::Path 'rmtree';
     19use POSIX qw(strftime);
     20
     21# don't remove!  required for GNU/FHS-ish install from tarball
     22##uselib##
     23
    1824use MyIPDB;
    19 use File::Path 'rmtree';
    20 
    21 $ENV{"PATH"} = "/bin;/usr/bin";
    22 
    23 my $rwhoisDataPath = "/etc/rwhoisd";
     25
     26#$ENV{"PATH"} = "/bin;/usr/bin";
    2427
    2528my @autharea;
    2629my $authrw;
    2730# Use the template file to allow us to keep persistent nodes aside from netblock data
    28 open AUTHTEMPLATE, "<$rwhoisDataPath/rwhoisd.auth_template";
     31open AUTHTEMPLATE, "<$IPDB::rwhoisDataPath/rwhoisd.auth_template";
    2932my $template_persist;
    3033while (<AUTHTEMPLATE>) {
     
    4346
    4447# Get the list of live directories for potential deletion
    45 opendir RWHOISROOT, $rwhoisDataPath;
     48opendir RWHOISROOT, $IPDB::rwhoisDataPath;
    4649my %rwhoisdirs;
    4750foreach (readdir RWHOISROOT) {
     
    9194  print "$masterblocks[$i] $ctime $mtime\n";
    9295
    93   my $date;
    94   chomp ($date = `/bin/date +"%Y-%m-%d"`);
     96  my $date = strftime("%Y-%m-%d", localtime);
    9597
    9698  my $rwnet = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen;
     
    100102
    101103# Hokay.  Gonna do checks *here* to see if we need to create new master trees
    102   my $netdatadir = "$rwhoisDataPath/$rwnet";
     104  my $netdatadir = "$IPDB::rwhoisDataPath/$rwnet";
    103105  if (! -e $netdatadir) {
    104106    print " New master $masterblocks[$i]!\n";
     
    111113    mkdir "$netdatadir/data/referral";
    112114
    113     my $serial;
    114     chomp ($serial = `/bin/date '+%Y%m%d'000000000`);
    115 
     115    my $serial = strftime("%Y%m%d%H%M%S000", localtime);
     116
     117##fixme: SOA should be different every time data changes, therefore need to rewrite this ~~ every export :(
    116118    print "  Creating SOA...\n";
    117119    open SOAFILE, ">$netdatadir/soa";
     
    121123Retry-Interval: 1800
    122124Time-To-Live: 86400
    123 Primary-Server: rwhois.example.com:4321
    124 Hostmaster: dns\@example.com
     125Primary-Server: rwhois.$IPDB::domain:4321
     126Hostmaster: $IPDB::hostmaster
    125127);
    126128    close SOAFILE;
     
    147149
    148150    print "  Copying template files...\n";
    149     qx { /bin/cp $rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
    150 
     151##fixme: find a way to do this without a shell (or functional equivalent)
     152    qx { /bin/cp $IPDB::rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
     153
     154##fixme: not sure if this is even necessary, since it's not referenced anywhere I can recall...
    151155    print "  Creating org data...\n";
    152     open ORGDATAFILE, ">$netdatadir/data/org/friendlyisp.txt";
     156    open ORGDATAFILE, ">$netdatadir/data/org/ourorg.txt";
    153157    print ORGDATAFILE qq(ID: NETBLK-ISP.$masterblocks[$i]
    154158Auth-Area: $masterblocks[$i]
    155 Org-Name: Friendly ISP
    156 Street-Address: 123 4th Street
    157 City: Anytown
    158 State: ON
    159 Postal-Code: H0H 0H0
    160 Country-Code: CA
    161 Phone: 000-555-1234
     159Org-Name: $IPDB::org_name
     160Street-Address: $IPDB::org_street
     161City: $IPDB::org_city
     162State: $IPDB::org_prov_state
     163Postal-Code: $IPDB::org_pocode
     164Country-Code: $IPDB::org_country
     165Phone: $IPDB::org_phone
    162166Created: 20040308
    163167Updated: 20040308
     
    182186  my $masterfilename = "$rwnet/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
    183187
    184   open MASTERFILE,">$rwhoisDataPath/$masterfilename";
     188  open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename";
    185189
    186190  print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
     
    189193        "IP-Network: $masterblocks[$i]\n".
    190194        "IP-Network-Block: ".$masterblocks[$i]->range."\n".
    191         "Org-Name: Friendly ISP\n".
    192         "Street-Address: 123 4th Street\n".
    193         "City: Anytown\n".
    194         "StateProv: Ontario\n".
    195         "Postal-Code: H0H 0H0\n".
    196         "Country-Code: CA\n".
    197         "Tech-Contact: ISP-ARIN-HANDLE\n".
     195        "Org-Name: $IPDB::org_name\n".
     196        "Street-Address: $IPDB::org_street\n".
     197        "City: $IPDB::org_city\n".
     198        "StateProv: $IPDB::org_prov_state\n".
     199        "Postal-Code: $IPDB::org_pocode\n".
     200        "Country-Code: $IPDB::org_country\n".
     201        "Tech-Contact: $IPDB::org_techhandle\n".
    198202        "Created: $ctime\n".
    199203        "Updated: $mtime\n".
    200         "Updated-By: noc\@example.com\n";
     204        "Updated-By: $IPDB::org_email\n";
    201205
    202206  # And now the subblocks
     
    226230
    227231# Fill in a generic entry for nameless allocations
    228 if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }
     232if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }
    229233
    230234    # Fix up datestamps.  We don't *really* need sub-microsecond resolution on our exports...
     
    257261        "IP-Network: $net\n".
    258262        "IP-Network-Block: ".$net->range."\n".
    259         "Org-Name: Friendly ISP\n".
    260         "Street-Address: 123 4th Street\n".
    261         "City: Anytown\n".
    262         "StateProv: Ontario\n".
    263         "Postal-Code: H0H 0H0\n".
    264         "Country-Code: CA\n".
    265         "Tech-Contact: ISP-ARIN-HANDLE\n".
     263        "Org-Name: $IPDB::org_name\n".
     264        "Street-Address: $IPDB::org_street\n".
     265        "City: $IPDB::org_city\n".
     266        "StateProv: $IPDB::org_prov_state\n".
     267        "Postal-Code: $IPDB::org_pocode\n".
     268        "Country-Code: $IPDB::org_country\n".
     269        "Tech-Contact: $IPDB::org_techhandle\n".
    266270        "Created: $ctime\n".
    267271        "Updated: $mtime\n".
    268         "Updated-By: noc\@example.com\n";
     272        "Updated-By: $IPDB::org_email\n";
    269273    } else {
    270274      $custsth->execute($custid);
     
    281285        "IP-Network: $net\n".
    282286        "IP-Network-Block: ".$net->range."\n".
    283         "Org-Name: ".($name ? $name : 'Friendly ISP')."\n".
    284         "Street-Address: ".($street ? $street : '123 4th Street')."\n".
    285         "City: ".($city ? $city : 'Anytown')."\n".
    286         "StateProv: ".($prov ? $prov : 'Ontario')."\n".
    287         "Postal-Code: ".($pocode ? $pocode : 'H0H 0H0')."\n".
    288         "Country-Code: ".($country ? $country : 'CA')."\n".
    289         "Tech-Contact: ".($tech ? $tech : 'ISP-ARIN-HANDLE')."\n".
     287        "Org-Name: ".($name ? $name : $IPDB::org_name)."\n".
     288        "Street-Address: ".($street ? $street : $IPDB::org_street)."\n".
     289        "City: ".($city ? $city : $IPDB::org_city)."\n".
     290        "StateProv: ".($prov ? $prov : $IPDB::org_prov_state)."\n".
     291        "Postal-Code: ".($pocode ? $pocode : $IPDB::org_pocode)."\n".
     292        "Country-Code: ".($country ? $country : $IPDB::org_country)."\n".
     293        "Tech-Contact: ".($tech ? $tech : $IPDB::org_techhandle)."\n".
    290294        "Created: $ctime\n".
    291295        "Updated: $mtime\n".
    292         "Updated-By: noc\@example.com\n";
     296        "Updated-By: $IPDB::org_email\n";
    293297    } # swip
    294298
     
    304308foreach my $netdir (keys %rwhoisdirs) {
    305309  print "deleting obsolete directory $netdir...\n";
    306   rmtree ( "$rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
     310  rmtree ( "$IPDB::rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
    307311  for my $diag (@$errlist) {
    308312    my ($file, $message) = each %$diag;
     
    317321if ($authrw) {
    318322  print "Regenerating auth_area\n";
    319   open RWHOISDAUTH, ">$rwhoisDataPath/rwhoisd.auth_area";
     323  open RWHOISDAUTH, ">$IPDB::rwhoisDataPath/rwhoisd.auth_area";
    320324  print RWHOISDAUTH "# WARNING: This file is autogenerated!  Any static nodes should\n".
    321325                "# be entered in /etc/rwhoisd/rwhoisd.auth_template\n";
     
    333337
    334338  # restart/reload rwhoisd
    335   if (-e "$rwhoisDataPath/rwhoisd.pid") {       # no pidfile, no restart.
     339  if (-e "$IPDB::rwhoisDataPath/rwhoisd.pid") { # no pidfile, no restart.
    336340    print "Restarting rwhoisd\n";
    337     open PIDFILE, "<$rwhoisDataPath/rwhoisd.pid";
     341    open PIDFILE, "<$IPDB::rwhoisDataPath/rwhoisd.pid";
    338342    my ($rwpid) = (<PIDFILE> =~ /^(\d+)/);
    339343    close PIDFILE;
Note: See TracChangeset for help on using the changeset viewer.