Index: branches/stable/cgi-bin/extras/db2rwhois.pl
===================================================================
--- branches/stable/cgi-bin/extras/db2rwhois.pl	(revision 375)
+++ branches/stable/cgi-bin/extras/db2rwhois.pl	(revision 445)
@@ -10,5 +10,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2007 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;
@@ -16,15 +16,18 @@
 use DBI;
 use NetAddr::IP;
+use File::Path 'rmtree';
+use POSIX qw(strftime);
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
 use MyIPDB;
-use File::Path 'rmtree';
-
-$ENV{"PATH"} = "/bin;/usr/bin";
-
-my $rwhoisDataPath = "/etc/rwhoisd";
+
+#$ENV{"PATH"} = "/bin;/usr/bin";
 
 my @autharea;
 my $authrw;
 # Use the template file to allow us to keep persistent nodes aside from netblock data
-open AUTHTEMPLATE, "<$rwhoisDataPath/rwhoisd.auth_template";
+open AUTHTEMPLATE, "<$IPDB::rwhoisDataPath/rwhoisd.auth_template";
 my $template_persist;
 while (<AUTHTEMPLATE>) {
@@ -43,5 +46,5 @@
 
 # Get the list of live directories for potential deletion
-opendir RWHOISROOT, $rwhoisDataPath;
+opendir RWHOISROOT, $IPDB::rwhoisDataPath;
 my %rwhoisdirs;
 foreach (readdir RWHOISROOT) {
@@ -91,6 +94,5 @@
   print "$masterblocks[$i] $ctime $mtime\n";
 
-  my $date;
-  chomp ($date = `/bin/date +"%Y-%m-%d"`);
+  my $date = strftime("%Y-%m-%d", localtime);
 
   my $rwnet = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen;
@@ -100,5 +102,5 @@
 
 # Hokay.  Gonna do checks *here* to see if we need to create new master trees
-  my $netdatadir = "$rwhoisDataPath/$rwnet";
+  my $netdatadir = "$IPDB::rwhoisDataPath/$rwnet";
   if (! -e $netdatadir) {
     print " New master $masterblocks[$i]!\n";
@@ -111,7 +113,7 @@
     mkdir "$netdatadir/data/referral";
 
-    my $serial;
-    chomp ($serial = `/bin/date '+%Y%m%d'000000000`);
-
+    my $serial = strftime("%Y%m%d%H%M%S000", localtime);
+
+##fixme: SOA should be different every time data changes, therefore need to rewrite this ~~ every export :(
     print "  Creating SOA...\n";
     open SOAFILE, ">$netdatadir/soa";
@@ -121,6 +123,6 @@
 Retry-Interval: 1800
 Time-To-Live: 86400
-Primary-Server: rwhois.example.com:4321
-Hostmaster: dns\@example.com
+Primary-Server: rwhois.$IPDB::domain:4321
+Hostmaster: $IPDB::hostmaster
 );
     close SOAFILE;
@@ -147,17 +149,19 @@
 
     print "  Copying template files...\n";
-    qx { /bin/cp $rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
-
+##fixme: find a way to do this without a shell (or functional equivalent)
+    qx { /bin/cp $IPDB::rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
+
+##fixme: not sure if this is even necessary, since it's not referenced anywhere I can recall...
     print "  Creating org data...\n";
-    open ORGDATAFILE, ">$netdatadir/data/org/friendlyisp.txt";
+    open ORGDATAFILE, ">$netdatadir/data/org/ourorg.txt";
     print ORGDATAFILE qq(ID: NETBLK-ISP.$masterblocks[$i]
 Auth-Area: $masterblocks[$i]
-Org-Name: Friendly ISP
-Street-Address: 123 4th Street
-City: Anytown
-State: ON
-Postal-Code: H0H 0H0
-Country-Code: CA
-Phone: 000-555-1234
+Org-Name: $IPDB::org_name
+Street-Address: $IPDB::org_street
+City: $IPDB::org_city
+State: $IPDB::org_prov_state
+Postal-Code: $IPDB::org_pocode
+Country-Code: $IPDB::org_country
+Phone: $IPDB::org_phone
 Created: 20040308
 Updated: 20040308
@@ -182,5 +186,5 @@
   my $masterfilename = "$rwnet/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
 
-  open MASTERFILE,">$rwhoisDataPath/$masterfilename";
+  open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename";
 
   print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
@@ -189,14 +193,14 @@
 	"IP-Network: $masterblocks[$i]\n".
 	"IP-Network-Block: ".$masterblocks[$i]->range."\n".
-	"Org-Name: Friendly ISP\n".
-	"Street-Address: 123 4th Street\n".
-	"City: Anytown\n".
-	"StateProv: Ontario\n".
-	"Postal-Code: H0H 0H0\n".
-	"Country-Code: CA\n".
-	"Tech-Contact: ISP-ARIN-HANDLE\n".
+	"Org-Name: $IPDB::org_name\n".
+	"Street-Address: $IPDB::org_street\n".
+	"City: $IPDB::org_city\n".
+	"StateProv: $IPDB::org_prov_state\n".
+	"Postal-Code: $IPDB::org_pocode\n".
+	"Country-Code: $IPDB::org_country\n".
+	"Tech-Contact: $IPDB::org_techhandle\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
 
   # And now the subblocks
@@ -226,5 +230,5 @@
 
 # Fill in a generic entry for nameless allocations
-if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }
+if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }
 
     # Fix up datestamps.  We don't *really* need sub-microsecond resolution on our exports...
@@ -257,14 +261,14 @@
 	"IP-Network: $net\n".
 	"IP-Network-Block: ".$net->range."\n".
-	"Org-Name: Friendly ISP\n".
-	"Street-Address: 123 4th Street\n".
-	"City: Anytown\n".
-	"StateProv: Ontario\n".
-	"Postal-Code: H0H 0H0\n".
-	"Country-Code: CA\n".
-	"Tech-Contact: ISP-ARIN-HANDLE\n".
+	"Org-Name: $IPDB::org_name\n".
+	"Street-Address: $IPDB::org_street\n".
+	"City: $IPDB::org_city\n".
+	"StateProv: $IPDB::org_prov_state\n".
+	"Postal-Code: $IPDB::org_pocode\n".
+	"Country-Code: $IPDB::org_country\n".
+	"Tech-Contact: $IPDB::org_techhandle\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
     } else {
       $custsth->execute($custid);
@@ -281,14 +285,14 @@
 	"IP-Network: $net\n".
 	"IP-Network-Block: ".$net->range."\n".
-	"Org-Name: ".($name ? $name : 'Friendly ISP')."\n".
-	"Street-Address: ".($street ? $street : '123 4th Street')."\n".
-	"City: ".($city ? $city : 'Anytown')."\n".
-	"StateProv: ".($prov ? $prov : 'Ontario')."\n".
-	"Postal-Code: ".($pocode ? $pocode : 'H0H 0H0')."\n".
-	"Country-Code: ".($country ? $country : 'CA')."\n".
-	"Tech-Contact: ".($tech ? $tech : 'ISP-ARIN-HANDLE')."\n".
+	"Org-Name: ".($name ? $name : $IPDB::org_name)."\n".
+	"Street-Address: ".($street ? $street : $IPDB::org_street)."\n".
+	"City: ".($city ? $city : $IPDB::org_city)."\n".
+	"StateProv: ".($prov ? $prov : $IPDB::org_prov_state)."\n".
+	"Postal-Code: ".($pocode ? $pocode : $IPDB::org_pocode)."\n".
+	"Country-Code: ".($country ? $country : $IPDB::org_country)."\n".
+	"Tech-Contact: ".($tech ? $tech : $IPDB::org_techhandle)."\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
     } # swip
 
@@ -304,5 +308,5 @@
 foreach my $netdir (keys %rwhoisdirs) {
   print "deleting obsolete directory $netdir...\n";
-  rmtree ( "$rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
+  rmtree ( "$IPDB::rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
   for my $diag (@$errlist) {
     my ($file, $message) = each %$diag;
@@ -317,5 +321,5 @@
 if ($authrw) {
   print "Regenerating auth_area\n";
-  open RWHOISDAUTH, ">$rwhoisDataPath/rwhoisd.auth_area";
+  open RWHOISDAUTH, ">$IPDB::rwhoisDataPath/rwhoisd.auth_area";
   print RWHOISDAUTH "# WARNING: This file is autogenerated!  Any static nodes should\n".
 		"# be entered in /etc/rwhoisd/rwhoisd.auth_template\n";
@@ -333,7 +337,7 @@
 
   # restart/reload rwhoisd
-  if (-e "$rwhoisDataPath/rwhoisd.pid") {	# no pidfile, no restart.
+  if (-e "$IPDB::rwhoisDataPath/rwhoisd.pid") {	# no pidfile, no restart.
     print "Restarting rwhoisd\n";
-    open PIDFILE, "<$rwhoisDataPath/rwhoisd.pid";
+    open PIDFILE, "<$IPDB::rwhoisDataPath/rwhoisd.pid";
     my ($rwpid) = (<PIDFILE> =~ /^(\d+)/);
     close PIDFILE;
