Changeset 218 for trunk/cgi-bin


Ignore:
Timestamp:
04/06/05 17:06:28 (20 years ago)
Author:
Kris Deugau
Message:

/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.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

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

    r146 r218  
    1717use NetAddr::IP;
    1818use MyIPDB;
     19use Digest::MD5 qw(md5_hex);
    1920
    2021$ENV{"PATH"} = "/bin;/usr/bin";
     
    4142# Note that this ASS-U-MEs that we do not add master IP blocks-
    4243# there should probably be a separate system for doing that.
    43 my $sth = $dbh->prepare("select * from masterblocks;");
     44my $sth = $dbh->prepare("select cidr,ctime from masterblocks;");
    4445$sth->execute;
    4546my $i=0;
    4647GETMASTERS: while (my @data = $sth->fetchrow_array()) {
    4748
    48   if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
    49     next GETMASTERS;
    50   }
     49#  if ($data[0] =~ /^(192.168.0.0|172.16.0.0|10.0.0.0)/) {
     50#    next GETMASTERS;
     51#  }
    5152  $masterblocks[$i] = new NetAddr::IP $data[0];
    5253
     
    5556  my $date;
    5657  chomp ($date = `/bin/date +"%Y%m%d"`);
     58  my ($ctime,undef) = split /\s+/, $data[1];
    5759
    5860# Whew!  Ugly little varmint.
     
    7375        "Admin-Contact: ISP-ARIN-HANDLE\n".
    7476        "Abuse-Contact: abuse\@example.com\n".
    75         "Created: 20040308\n".
     77        "Created: $ctime\n".
    7678        "Updated: $date\n".
    7779        "Updated-By: noc\@example.com\n";
     
    8789# Make sure to remove the private netblocks from this.
    8890# No use or point in broadcasting our use of them.
    89 $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') and custid='6750400'");
     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");
    9095$sth->execute;
    9196
    92 while (my @data = $sth->fetchrow_array()) {
     97while (my ($cidr,$custid,$type,$city,$description,$ctime,$mtime) = $sth->fetchrow_array()) {
    9398
    9499# We get master block info from @masterblocks.
     
    105110 # Updated-By: noc@example.com
    106111
    107   # Get the "full" network number
    108   my $net = new NetAddr::IP $data[0];
     112  # Get the "full" network number - just in case.
     113  my $net = new NetAddr::IP $cidr;
    109114
    110115# Assumptions:  All data in ipdb is public
     
    121126        or print "File open error: '$!' on '$rwhoisDataPath/$masterfilename'\n";
    122127
    123 # cidr custid type city description notes maskbits
    124 
    125 # Creation date in record to eventually be "correct";  near-term will
    126 # be master's creation date;  immediate is today's date.
    127 my $date;
    128       chomp ($date = `/bin/date +"%Y%m%d"`);
    129128if ($data[4] =~ /^\s*$/) { $data[4] = 'Friendly ISP'; }
     129print "$type-type $net for $custid, created $ctime, modified $mtime\n";
    130130      print MASTERFILE "---\nID: NETBLK-ISP.$master\n".
    131131        "Auth-Area: $master\n".
     
    133133        "IP-Network: $net\n".
    134134        "IP-Network-Block: ".$net->range."\n".
    135         "Organization: $data[4]\n".
     135        "Organization: $description\n".
    136136#       "Tech-Contact: $data[9]\n".
    137137        "Tech-Contact: abuse\@example.com\n".
    138138        "Admin-Contact: ISP-ARIN-HANDLE\n".
    139         "Created: $date\n".
    140         "Updated: $date\n".
     139        "Created: $ctime\n".
     140        "Updated: $mtime\n".
    141141        "Updated-By: noc\@example.com\n";
    142142    }
     
    154154
    155155$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 };
  • trunk/cgi-bin/ipdb.psql

    r189 r218  
    7070        "circuitid" character varying(128) DEFAULT '' NOT NULL,
    7171        "newcustid" integer,
     72        "createstamp" timestamp DEFAULT now(),
     73        "modifystamp" timestamp DEFAULT now(),
    7274        CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar)))
    7375);
     
    8688        "maskbits" integer DEFAULT 128,
    8789        "circuitid" character varying(128) DEFAULT '',
     90        "createstamp" timestamp DEFAULT now(),
     91        "modifystamp" timestamp DEFAULT now(),
    8892        "newcustid" integer
    8993);
     
    182186pr      Dynamic-route DSL netblock      Dynamic-route DSL       203     
    183187\.
     188
     189--
     190-- Trigger and matching function to update modifystamp on allocations, poolips
     191--
     192CREATE FUNCTION up_modtime () RETURNS OPAQUE AS '
     193    BEGIN
     194        NEW.modifystamp := ''now'';
     195        RETURN NEW;
     196    END;
     197' LANGUAGE 'plpgsql';
     198
     199CREATE TRIGGER up_modtime BEFORE UPDATE ON allocations
     200    FOR EACH ROW EXECUTE PROCEDURE up_modtime();
     201
     202CREATE TRIGGER up_modtime BEFORE UPDATE ON poolips
     203    FOR EACH ROW EXECUTE PROCEDURE up_modtime();
Note: See TracChangeset for help on using the changeset viewer.