Changeset 445 for branches/stable/cgi-bin/extras
- Timestamp:
- 07/26/10 17:00:00 (14 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
- Property svn:ignore
-
old new 1 1 local.css 2 *.tar.gz
-
- Property svn:mergeinfo changed
/trunk merged: 415-420,422-443
- Property svn:ignore
-
branches/stable/cgi-bin/extras/db2rwhois.pl
r375 r445 10 10 # Last update by $Author$ 11 11 ### 12 # Copyright (C) 2004-20 07- Kris Deugau12 # Copyright (C) 2004-2010 - Kris Deugau 13 13 14 14 use strict; … … 16 16 use DBI; 17 17 use NetAddr::IP; 18 use File::Path 'rmtree'; 19 use POSIX qw(strftime); 20 21 # don't remove! required for GNU/FHS-ish install from tarball 22 ##uselib## 23 18 24 use 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"; 24 27 25 28 my @autharea; 26 29 my $authrw; 27 30 # Use the template file to allow us to keep persistent nodes aside from netblock data 28 open AUTHTEMPLATE, "<$ rwhoisDataPath/rwhoisd.auth_template";31 open AUTHTEMPLATE, "<$IPDB::rwhoisDataPath/rwhoisd.auth_template"; 29 32 my $template_persist; 30 33 while (<AUTHTEMPLATE>) { … … 43 46 44 47 # Get the list of live directories for potential deletion 45 opendir RWHOISROOT, $ rwhoisDataPath;48 opendir RWHOISROOT, $IPDB::rwhoisDataPath; 46 49 my %rwhoisdirs; 47 50 foreach (readdir RWHOISROOT) { … … 91 94 print "$masterblocks[$i] $ctime $mtime\n"; 92 95 93 my $date; 94 chomp ($date = `/bin/date +"%Y-%m-%d"`); 96 my $date = strftime("%Y-%m-%d", localtime); 95 97 96 98 my $rwnet = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen; … … 100 102 101 103 # 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"; 103 105 if (! -e $netdatadir) { 104 106 print " New master $masterblocks[$i]!\n"; … … 111 113 mkdir "$netdatadir/data/referral"; 112 114 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 :( 116 118 print " Creating SOA...\n"; 117 119 open SOAFILE, ">$netdatadir/soa"; … … 121 123 Retry-Interval: 1800 122 124 Time-To-Live: 86400 123 Primary-Server: rwhois. example.com:4321124 Hostmaster: dns\@example.com125 Primary-Server: rwhois.$IPDB::domain:4321 126 Hostmaster: $IPDB::hostmaster 125 127 ); 126 128 close SOAFILE; … … 147 149 148 150 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... 151 155 print " Creating org data...\n"; 152 open ORGDATAFILE, ">$netdatadir/data/org/ friendlyisp.txt";156 open ORGDATAFILE, ">$netdatadir/data/org/ourorg.txt"; 153 157 print ORGDATAFILE qq(ID: NETBLK-ISP.$masterblocks[$i] 154 158 Auth-Area: $masterblocks[$i] 155 Org-Name: Friendly ISP156 Street-Address: 123 4th Street157 City: Anytown158 State: ON159 Postal-Code: H0H 0H0160 Country-Code: CA161 Phone: 000-555-1234159 Org-Name: $IPDB::org_name 160 Street-Address: $IPDB::org_street 161 City: $IPDB::org_city 162 State: $IPDB::org_prov_state 163 Postal-Code: $IPDB::org_pocode 164 Country-Code: $IPDB::org_country 165 Phone: $IPDB::org_phone 162 166 Created: 20040308 163 167 Updated: 20040308 … … 182 186 my $masterfilename = "$rwnet/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt"; 183 187 184 open MASTERFILE,">$ rwhoisDataPath/$masterfilename";188 open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename"; 185 189 186 190 print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n". … … 189 193 "IP-Network: $masterblocks[$i]\n". 190 194 "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". 198 202 "Created: $ctime\n". 199 203 "Updated: $mtime\n". 200 "Updated-By: noc\@example.com\n";204 "Updated-By: $IPDB::org_email\n"; 201 205 202 206 # And now the subblocks … … 226 230 227 231 # Fill in a generic entry for nameless allocations 228 if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }232 if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; } 229 233 230 234 # Fix up datestamps. We don't *really* need sub-microsecond resolution on our exports... … … 257 261 "IP-Network: $net\n". 258 262 "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". 266 270 "Created: $ctime\n". 267 271 "Updated: $mtime\n". 268 "Updated-By: noc\@example.com\n";272 "Updated-By: $IPDB::org_email\n"; 269 273 } else { 270 274 $custsth->execute($custid); … … 281 285 "IP-Network: $net\n". 282 286 "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". 290 294 "Created: $ctime\n". 291 295 "Updated: $mtime\n". 292 "Updated-By: noc\@example.com\n";296 "Updated-By: $IPDB::org_email\n"; 293 297 } # swip 294 298 … … 304 308 foreach my $netdir (keys %rwhoisdirs) { 305 309 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 } ); 307 311 for my $diag (@$errlist) { 308 312 my ($file, $message) = each %$diag; … … 317 321 if ($authrw) { 318 322 print "Regenerating auth_area\n"; 319 open RWHOISDAUTH, ">$ rwhoisDataPath/rwhoisd.auth_area";323 open RWHOISDAUTH, ">$IPDB::rwhoisDataPath/rwhoisd.auth_area"; 320 324 print RWHOISDAUTH "# WARNING: This file is autogenerated! Any static nodes should\n". 321 325 "# be entered in /etc/rwhoisd/rwhoisd.auth_template\n"; … … 333 337 334 338 # restart/reload rwhoisd 335 if (-e "$ rwhoisDataPath/rwhoisd.pid") { # no pidfile, no restart.339 if (-e "$IPDB::rwhoisDataPath/rwhoisd.pid") { # no pidfile, no restart. 336 340 print "Restarting rwhoisd\n"; 337 open PIDFILE, "<$ rwhoisDataPath/rwhoisd.pid";341 open PIDFILE, "<$IPDB::rwhoisDataPath/rwhoisd.pid"; 338 342 my ($rwpid) = (<PIDFILE> =~ /^(\d+)/); 339 343 close PIDFILE;
Note:
See TracChangeset
for help on using the changeset viewer.