--- geoip.admin.inc	2010-05-20 23:05:28.000000000 +0200
+++ geoip.admin.inc	2010-10-19 16:47:35.375000000 +0200
@@ -17,13 +17,18 @@ function geoip_admin_settings() {
     '#default_value' => variable_get('geoip_data_file', 'sites/all/libraries/geoip/GeoIP.dat'),
     '#after_build' => array('geoip_data_file_validate'),
   );
+  $form['geoip_data_url'] = array(
+    '#type' => 'textfield',
+    '#title' => t('GeoIP data file url'),
+    '#description' => t('The URL to the GeoIP database file.'),
+    '#default_value' => variable_get('geoip_data_url', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'),
+  );
   $form['geoip_debug'] = array(
     '#type' => 'checkbox',
     '#title' => t('GeoIP debug mode'),
     '#description' => t('With this setting enabled, an IP may be passed in through the query string using the <kbd>geoip_debug</kbd> parameter. This should not be used on production sites.'),
     '#default_value' => variable_get('geoip_debug', FALSE),
   );
-
   return system_settings_form($form);
 }
 
--- geoip.module	2010-05-05 17:09:49.000000000 +0200
+++ geoip.module	2010-10-21 11:15:24.296875000 +0200
@@ -212,5 +212,68 @@ function geoip_country_values() {
 }
 
 /**
+ * Implementation of hook_cron.
+ */
+function geoip_cron() {
+  $file = variable_get('geoip_data_file', 'sites/all/libraries/geoip/GeoIP.dat');
+  $url = variable_get('geoip_data_url', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz');
+
+  if (@$file_modified = filemtime($file)) {
+    $info = geoip_headers($url);
+    if (isset($info['code'], $info['modified'], $info['length']) && !$info['timed_out']
+     && ($info['code'] == '200') && ($info['length'] > 0) && ($info['modified'] > $file_modified + 86400)) {
+      $tmp = tempnam(realpath(file_directory_temp()), 'file');
+      if (($src = fopen($url, 'rb')) && ($dst = fopen($tmp, 'wb'))) {
+        stream_set_timeout($src, 1);
+        while (!feof($src)) {
+          if ($data = fread($src, 1024)) {
+            fwrite($dst, $data);
+          }
+        }
+        fclose($src);
+        fclose($dst);
+      }
+      if ((@filesize($tmp) == $info['length']) && ($src = gzopen($tmp, 'rb')) && ($dst = fopen($file, 'wb'))) {
+        while ($data = gzread($src, 1024)) {
+          fwrite($dst, $data);
+        }
+        gzclose($src);
+        fclose($dst);
+        unlink($tmp);
+        watchdog('geoip', 'The %file file was updated.', array('%file' => 'GeoIP.dat'), WATCHDOG_INFO);
+      }
+    }
+  }
+}
+
+function geoip_headers($url) {
+  $info = parse_url($url);
+  if ($info && isset($info['host'], $info['scheme'], $info['path']) && ($info['scheme'] == 'http')) {
+    $f = @fsockopen($info['host'], 80, $errno, $errstr, 1);
+    if ($f) {
+      $req = 'HEAD '. $info['path']. " HTTP/1.1\r\nHost: ". $info['host'] ."\r\n\r\n";
+      stream_set_timeout($f, 1);
+      fwrite($f, $req);
+      while (!feof($f)) {
+        $header = fgets($f);
+        if (!isset($data['code']) && preg_match('`^HTTP/1\.1 (\d{3}) `', $header, $matches)) {
+          $data['code'] = intval($matches[1]);
+        }
+        elseif (substr($header, 0, 15) == 'Last-Modified: ') {
+          $data['modified'] = strtotime(substr($header, 15));
+        }
+        elseif (substr($header, 0, 16) == 'Content-Length: ') {
+          $data['length'] = intval(substr($header, 16));
+        }
+      }
+      $md = stream_get_meta_data($f);
+      fclose($f);
+    }
+  }
+  $data['timed_out'] = @$md['timed_out'];
+  return $data;
+}
+
+/**
  * @} End of "defgroup geoip".
  */
