Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenakamoorthi <benaka.moorthi@gmail.com>2012-12-06 08:52:20 +0400
committerbenakamoorthi <benaka.moorthi@gmail.com>2012-12-06 08:52:20 +0400
commit0e3080e015d3c939770edc335bf47056acca3d0d (patch)
tree7a0cc992998fde471df2b84ccbc65e3c2322c824 /plugins/UserCountry
parent2b3ecb8cc9cc075f2c5cd7647280087ebd832370 (diff)
Refs #3456, remove downloaded files on all exceptions, even sanity check.
git-svn-id: http://dev.piwik.org/svn/trunk@7578 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/UserCountry')
-rwxr-xr-xplugins/UserCountry/GeoIPAutoUpdater.php96
1 files changed, 53 insertions, 43 deletions
diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php
index aac72ec5bd..d1b74eec74 100755
--- a/plugins/UserCountry/GeoIPAutoUpdater.php
+++ b/plugins/UserCountry/GeoIPAutoUpdater.php
@@ -196,63 +196,73 @@ class Piwik_UserCountry_GeoIPAutoUpdater
throw new Exception(Piwik_Translate('UserCountry_UnsupportedArchiveType', "'$ext'"));
}
- // test that the new archive is a valid GeoIP database
- $dbType = Piwik_UserCountry_LocationProvider_GeoIp::getGeoIPDatabaseTypeFromFilename($dbFilename);
- if ($dbType === false) // sanity check
+ try
{
- throw new Exception("Unexpected GeoIP archive file name '$path'.");
- }
+ // test that the new archive is a valid GeoIP database
+ $dbType = Piwik_UserCountry_LocationProvider_GeoIp::getGeoIPDatabaseTypeFromFilename($dbFilename);
+ if ($dbType === false) // sanity check
+ {
+ throw new Exception("Unexpected GeoIP archive file name '$path'.");
+ }
- $customDbNames = array(
- 'loc' => array(),
- 'isp' => array(),
- 'org' => array()
- );
- $customDbNames[$dbType] = array($tempFilename);
+ $customDbNames = array(
+ 'loc' => array(),
+ 'isp' => array(),
+ 'org' => array()
+ );
+ $customDbNames[$dbType] = array($tempFilename);
- $phpProvider = new Piwik_UserCountry_LocationProvider_GeoIp_Php($customDbNames);
+ $phpProvider = new Piwik_UserCountry_LocationProvider_GeoIp_Php($customDbNames);
- // note: in most cases where this will fail, the error will usually be a PHP fatal error/notice.
- // in order to delete the files in such a case (which can be caused by a man-in-the-middle attack)
- // we need to catch them, so we set a new error handler.
- self::$unzipPhpError = null;
- set_error_handler(array('Piwik_UserCountry_GeoIPAutoUpdater', 'catchGeoIPError'));
+ // note: in most cases where this will fail, the error will usually be a PHP fatal error/notice.
+ // in order to delete the files in such a case (which can be caused by a man-in-the-middle attack)
+ // we need to catch them, so we set a new error handler.
+ self::$unzipPhpError = null;
+ set_error_handler(array('Piwik_UserCountry_GeoIPAutoUpdater', 'catchGeoIPError'));
- $location = $phpProvider->getLocation(array('ip' => Piwik_UserCountry_LocationProvider_GeoIp::TEST_IP));
+ $location = $phpProvider->getLocation(array('ip' => Piwik_UserCountry_LocationProvider_GeoIp::TEST_IP));
- restore_error_handler();
+ restore_error_handler();
- if (empty($location)
- || self::$unzipPhpError !== null)
- {
- if (self::$unzipPhpError !== null)
+ if (empty($location)
+ || self::$unzipPhpError !== null)
{
- list($errno, $errstr, $errfile, $errline) = self::$unzipPhpError;
- Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: Encountered PHP error when testing newly downloaded".
- " GeoIP database: $errno: $errstr on line $errline of $errfile.");
- }
-
- // remove downloaded files in this case
- unlink($outputPath);
- unlink($path);
+ if (self::$unzipPhpError !== null)
+ {
+ list($errno, $errstr, $errfile, $errline) = self::$unzipPhpError;
+ Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: Encountered PHP error when testing newly downloaded".
+ " GeoIP database: $errno: $errstr on line $errline of $errfile.");
+ }
- throw new Exception(Piwik_Translate('UserCountry_ThisUrlIsNotAValidGeoIPDB'));
- }
+ throw new Exception(Piwik_Translate('UserCountry_ThisUrlIsNotAValidGeoIPDB'));
+ }
- // delete the existing GeoIP database (if any) and rename the downloaded file
- $oldDbFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($dbFilename);
- if (file_exists($oldDbFile))
- {
- unlink($oldDbFile);
- }
+ // delete the existing GeoIP database (if any) and rename the downloaded file
+ $oldDbFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($dbFilename);
+ if (file_exists($oldDbFile))
+ {
+ unlink($oldDbFile);
+ }
- $tempFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($tempFilename);
- rename($existing = $tempFile, $newName = $oldDbFile);
+ $tempFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($tempFilename);
+ rename($existing = $tempFile, $newName = $oldDbFile);
- // delete original archive
- if ($unlink)
+ // delete original archive
+ if ($unlink)
+ {
+ unlink($path);
+ }
+ }
+ catch (Exception $ex)
{
+ // remove downloaded files
+ if (file_exists($outputPath))
+ {
+ unlink($outputPath);
+ }
unlink($path);
+
+ throw $ex;
}
}