[or-cvs] r14852: (ticket:81) Adding auto-updating (in torstatus/trunk: . web)

kasimir at seul.org kasimir at seul.org
Sat May 31 05:55:16 UTC 2008


Author: kasimir
Date: 2008-05-31 01:55:16 -0400 (Sat, 31 May 2008)
New Revision: 14852

Modified:
   torstatus/trunk/tns_update.pl
   torstatus/trunk/web/config_template.php
Log:
(ticket:81) Adding auto-updating

Modified: torstatus/trunk/tns_update.pl
===================================================================
--- torstatus/trunk/tns_update.pl	2008-05-31 02:11:56 UTC (rev 14851)
+++ torstatus/trunk/tns_update.pl	2008-05-31 05:55:16 UTC (rev 14852)
@@ -29,6 +29,7 @@
 #  * Date::Parse from CPAN
 #  * Geo::IP   ** Geo::IP::PurePerl should be used for those without
 #                 access to the C version of GeoIP.
+#  * Compress::Zlib from CPAN required to decompress GeoIP files after updating
 #
 # Included Perl packages
 #  * serialize.pm
@@ -45,6 +46,7 @@
 use LWP::Simple;
 use Date::Parse;
 use RRDs;
+use Compress::Zlib;
 
 # Temporary Debugging
 $| = 1;
@@ -114,6 +116,52 @@
 my $dbresponse;
 my $record;
 
+# Determine if the GeoIP database should be automatically updated
+if ($config{'AutomaticallyUpdateGeoIPDatbase'} eq "yes")
+{
+	# Query the last set date from the database
+	$query = "SElECT geoip FROM Status LIMIT 1;";
+	$dbresponse = $dbh->prepare($query);
+	$dbresponse->execute();
+	$record = $dbresponse->fetchrow();
+	
+	# Extract the month from the record
+	my @time = localtime(time());
+	my $month = $time[4]+1;
+	my $day = $time[3];
+	my $oldmonth;
+	if ($record =~ m/.*?\-(.*?)\-/)
+	{
+		$oldmonth = $1;
+	}
+	if ($oldmonth != $month && $day > 2) # Give extra time
+	{
+		# The GeoIP database should be updated
+		my $getresponse = getstore('http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz','/tmp/GeoIP.dat.gz');
+		unless (is_success($getresponse))
+		{
+			print "Error retrieving GeoIP file.  Please contact Kasimir <kasimir\@kgprog.com>. \n(not dying)\n";
+		}
+		else
+		{
+			# Convert and save the new GeoIP file
+			my $gz = gzopen ("/tmp/GeoIP.dat.gz","rb");
+			open (my $output, ">" . $config{'GEOIP_Database_Path'} . "GeoIP.dat");
+			my $buffer;
+			while ($gz->gzread($buffer))
+			{
+				print $output $buffer;	
+			}
+			$gz->gzclose;
+			close ($output);
+			# The update has completed - save
+			$query = "UPDATE Status SET geoip=NOW();";
+			$dbresponse = $dbh->prepare($query);
+			$dbresponse->execute();
+		}
+	}
+}
+
 # Determine whether or not the mirror list needs to be updated
 if ($updateCounter % 20 == 0)
 {

Modified: torstatus/trunk/web/config_template.php
===================================================================
--- torstatus/trunk/web/config_template.php	2008-05-31 02:11:56 UTC (rev 14851)
+++ torstatus/trunk/web/config_template.php	2008-05-31 05:55:16 UTC (rev 14852)
@@ -47,6 +47,8 @@
 $JPGraph_Path = "jpgraph/";
 $GEOIP_Path = "geoip/";
 $GEOIP_Database_Path = "geoip/";
+$AutomaticallyUpdateGeoIPDatbase = "yes"; // Change to stop auto updating
+
 $PHP_Path = "/usr/bin/";
 $TNS_Path = "/home/torstatus-kgprog-com/project/trunk/";
 



More information about the tor-commits mailing list