diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/AssetManager.php | 8 | ||||
-rw-r--r-- | core/CacheFile.php | 4 | ||||
-rw-r--r-- | core/Config.php | 32 | ||||
-rw-r--r-- | core/Db/BatchInsert.php | 2 | ||||
-rw-r--r-- | core/ExceptionHandler.php | 8 | ||||
-rw-r--r-- | core/Filechecks.php | 3 | ||||
-rw-r--r-- | core/Filesystem.php | 2 | ||||
-rw-r--r-- | core/Log.php | 3 | ||||
-rw-r--r-- | core/Piwik.php | 2 | ||||
-rw-r--r-- | core/ProxyHttp.php | 3 | ||||
-rw-r--r-- | core/ReportRenderer.php | 2 | ||||
-rw-r--r-- | core/Session.php | 5 | ||||
-rw-r--r-- | core/SettingsPiwik.php | 26 | ||||
-rw-r--r-- | core/Twig.php | 5 | ||||
-rw-r--r-- | core/functions.php | 3 |
15 files changed, 90 insertions, 18 deletions
diff --git a/core/AssetManager.php b/core/AssetManager.php index b5ae6a6a5f..c3c3101762 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -46,6 +46,8 @@ class AssetManager const CSS_IMPORT_EVENT = "AssetManager.getStylesheetFiles"; const JS_IMPORT_EVENT = "AssetManager.getJsFiles"; const MERGED_FILE_DIR = "tmp/assets/"; + const COMPRESSED_FILE_LOCATION = "/tmp/assets/"; + const CSS_IMPORT_DIRECTIVE = "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n"; const JS_IMPORT_DIRECTIVE = "<script type=\"text/javascript\" src=\"%s\"></script>\n"; const GET_CSS_MODULE_ACTION = "index.php?module=Proxy&action=getCss"; @@ -500,8 +502,9 @@ class AssetManager } // Tries to remove compressed version of the merged file. - // See Piwik::serverStaticFile() for more info on static file compression - $compressedFileLocation = PIWIK_USER_PATH . Piwik::COMPRESSED_FILE_LOCATION . $filename; + // See ProxyHttp::serverStaticFile() for more info on static file compression + $compressedFileLocation = PIWIK_USER_PATH . self::COMPRESSED_FILE_LOCATION . $filename; + $compressedFileLocation = SettingsPiwik::rewriteTmpPathWithHostname($compressedFileLocation); @unlink($compressedFileLocation . ".deflate"); @unlink($compressedFileLocation . ".gz"); @@ -538,6 +541,7 @@ class AssetManager private static function getMergedFileDirectory() { $mergedFileDirectory = PIWIK_USER_PATH . '/' . self::MERGED_FILE_DIR; + $mergedFileDirectory = SettingsPiwik::rewriteTmpPathWithHostname($mergedFileDirectory); if (!is_dir($mergedFileDirectory)) { Filesystem::mkdir($mergedFileDirectory); diff --git a/core/CacheFile.php b/core/CacheFile.php index 139beeaffc..9ee78168f5 100644 --- a/core/CacheFile.php +++ b/core/CacheFile.php @@ -48,7 +48,9 @@ class CacheFile */ public function __construct($directory, $timeToLiveInSeconds = 300) { - $this->cachePath = PIWIK_USER_PATH . '/tmp/cache/' . $directory . '/'; + $cachePath = PIWIK_USER_PATH . '/tmp/cache/' . $directory . '/'; + $this->cachePath = SettingsPiwik::rewriteTmpPathWithHostname($cachePath); + if ($timeToLiveInSeconds < self::MINIMUM_TTL) { $timeToLiveInSeconds = self::MINIMUM_TTL; } diff --git a/core/Config.php b/core/Config.php index d88709379a..c7536ac338 100644 --- a/core/Config.php +++ b/core/Config.php @@ -155,9 +155,41 @@ class Config */ public static function getLocalConfigPath() { + $path = self::getByDomainConfigPath(); + if($path) { + return $path; + } + return PIWIK_USER_PATH . '/config/config.ini.php'; } + public function getConfigHostnameIfSet() + { + if($this->getByDomainConfigPath() === false) { + return false; + } + return $this->getHostname(); + } + + protected static function getByDomainConfigPath() + { + $host = self::getHostname(); + $perHostFilename = $host . '.config.ini.php'; + $pathDomainConfig = PIWIK_USER_PATH . '/config/' . $perHostFilename; + if (Filesystem::isValidFilename($perHostFilename) + && file_exists($pathDomainConfig) + ) { + return $pathDomainConfig; + } + return false; + } + + protected static function getHostname() + { + $host = Url::getHost($checkIfTrusted = false); // Check trusted requires config file which is not ready yet + return $host; + } + /** * Is local configuration file writable? * diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php index 019cd4d51c..cd339e215e 100644 --- a/core/Db/BatchInsert.php +++ b/core/Db/BatchInsert.php @@ -17,6 +17,7 @@ use Piwik\Config; use Piwik\Db; use Piwik\DbHelper; use Piwik\Piwik; +use Piwik\SettingsPiwik; use Piwik\SettingsServer; class BatchInsert @@ -60,6 +61,7 @@ class BatchInsert public static function tableInsertBatch($tableName, $fields, $values, $throwException = false) { $filePath = PIWIK_USER_PATH . '/' . AssetManager::MERGED_FILE_DIR . $tableName . '-' . Common::generateUniqId() . '.csv'; + $filePath = SettingsPiwik::rewriteTmpPathWithHostname($filePath); if (Db::get()->hasBulkLoader()) { try { diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 081e4601a8..26ecef6a00 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -10,12 +10,8 @@ */ namespace Piwik; -use Piwik\Common; -use Piwik\Piwik; -use Piwik\Plugin; -use Piwik\Log; -use Piwik\FrontController; use Piwik\API\ResponseBuilder; +use Piwik\Plugin; /** * Contains Piwik's uncaught exception handler and log file formatting for exception @@ -62,7 +58,7 @@ class ExceptionHandler } } - public static function exceptionHandler(Exception $exception) + public static function exceptionHandler(\Exception $exception) { Log::error($exception); } diff --git a/core/Filechecks.php b/core/Filechecks.php index 1c15cc5ea8..893e158d62 100644 --- a/core/Filechecks.php +++ b/core/Filechecks.php @@ -40,10 +40,13 @@ class Filechecks { $resultCheck = array(); foreach ($directoriesToCheck as $directoryToCheck) { + if (!preg_match('/^' . preg_quote(PIWIK_USER_PATH, '/') . '/', $directoryToCheck)) { $directoryToCheck = PIWIK_USER_PATH . $directoryToCheck; } + $directoryToCheck = SettingsPiwik::rewriteTmpPathWithHostname($directoryToCheck); + // Create an empty directory $isFile = strpos($directoryToCheck, '.') !== false; if (!$isFile && !file_exists($directoryToCheck)) { diff --git a/core/Filesystem.php b/core/Filesystem.php index 51bdc5fee8..5c7ea6d868 100644 --- a/core/Filesystem.php +++ b/core/Filesystem.php @@ -194,7 +194,7 @@ class Filesystem * @param boolean $deleteRootToo Delete specified top-level directory as well * @param Closure|false $beforeUnlink A closure to execute before unlinking. */ - public static function unlinkRecursive($dir, $deleteRootToo, $beforeUnlink = false) + public static function unlinkRecursive($dir, $deleteRootToo, \Closure $beforeUnlink = null) { if (!$dh = @opendir($dir)) { return; diff --git a/core/Log.php b/core/Log.php index 06755e41de..f3e566c12d 100644 --- a/core/Log.php +++ b/core/Log.php @@ -290,7 +290,8 @@ class Log if (is_dir($logPath)) { $logPath .= '/piwik.log'; } - $this->logToFilePath = $logPath; + + $this->logToFilePath = SettingsPiwik::rewriteTmpPathWithHostname($logPath); } private function createWriterByName($writerName) diff --git a/core/Piwik.php b/core/Piwik.php index 0d33e42a06..4977cb1dad 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -34,8 +34,6 @@ require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; */ class Piwik { - const COMPRESSED_FILE_LOCATION = '/tmp/assets/'; - /** * Piwik periods * @var array diff --git a/core/ProxyHttp.php b/core/ProxyHttp.php index 5bcde43de1..030443d801 100644 --- a/core/ProxyHttp.php +++ b/core/ProxyHttp.php @@ -91,7 +91,8 @@ class ProxyHttp // optional compression $compressed = false; $encoding = ''; - $compressedFileLocation = PIWIK_USER_PATH . Piwik::COMPRESSED_FILE_LOCATION . basename($file); + $compressedFileLocation = PIWIK_USER_PATH . AssetManager::COMPRESSED_FILE_LOCATION . basename($file); + $compressedFileLocation = SettingsPiwik::rewriteTmpPathWithHostname($compressedFileLocation); $phpOutputCompressionEnabled = ProxyHttp::isPhpOutputCompressed(); if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !$phpOutputCompressionEnabled) { diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 3287a6e97e..18ac8f9c51 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -147,6 +147,8 @@ abstract class ReportRenderer protected static function getOutputPath($filename) { $outputFilename = PIWIK_USER_PATH . '/tmp/assets/' . $filename; + $outputFilename = SettingsPiwik::rewriteTmpPathWithHostname($outputFilename); + @chmod($outputFilename, 0600); @unlink($outputFilename); return $outputFilename; diff --git a/core/Session.php b/core/Session.php index 221c62bac2..5f3c765a7a 100644 --- a/core/Session.php +++ b/core/Session.php @@ -128,9 +128,11 @@ class Session extends Zend_Session we recommend that you <a href='http://piwik.org/faq/how-to-install/#faq_133' target='_blank'>enable database session storage</a>."; } + $pathToSessions = Filechecks::getErrorMessageMissingPermissions(Filesystem::getPathToPiwikRoot() . '/tmp/sessions/'); + $pathToSessions = SettingsPiwik::rewriteTmpPathWithHostname($pathToSessions); $message = sprintf("Error: %s %s %s\n<pre>Debug: the original error was \n%s</pre>", Piwik_Translate('General_ExceptionUnableToStartSession'), - Filechecks::getErrorMessageMissingPermissions(Filesystem::getPathToPiwikRoot() . '/tmp/sessions/'), + $pathToSessions, $enableDbSessions, $e->getMessage() ); @@ -146,6 +148,7 @@ class Session extends Zend_Session */ public static function getSessionsDirectory() { + //tmp return PIWIK_USER_PATH . '/tmp/sessions'; } } diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php index 19e9233891..51e7c006a8 100644 --- a/core/SettingsPiwik.php +++ b/core/SettingsPiwik.php @@ -166,4 +166,30 @@ class SettingsPiwik return $result; } + + /** + * If Piwik uses per-domain config file, also make tmp/ folder per-domain + * @param $path + * @return string + * @throws \Exception + */ + public static function rewriteTmpPathWithHostname($path) + { + $configByHost = Config::getInstance()->getConfigHostnameIfSet(); + if(empty($configByHost)) { + return $path; + } + + $tmp = '/tmp/'; + if(($posTmp = strrpos($path, $tmp)) === false) { + throw new Exception("The path $path was expected to contain the string /tmp/ "); + } + + $tmpToReplace = $tmp . $configByHost . '/'; + + // replace only the latest occurrence (in case path contains twice /tmp) + $path = substr_replace($path, $tmpToReplace, $posTmp, strlen($tmp)); + + return $path; + } } diff --git a/core/Twig.php b/core/Twig.php index 59fabb8a2e..0520d242d7 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -46,11 +46,14 @@ class Twig $chainLoader = new Twig_Loader_Chain(array($loader)); // Create new Twig Environment and set cache dir + $templatesCompiledPath = PIWIK_USER_PATH . '/tmp/templates_c'; + $templatesCompiledPath = SettingsPiwik::rewriteTmpPathWithHostname($templatesCompiledPath); + $this->twig = new Twig_Environment($chainLoader, array( 'debug' => true, // to use {{ dump(var) }} in twig templates 'strict_variables' => true, // throw an exception if variables are invalid - 'cache' => PIWIK_USER_PATH . '/tmp/templates_c', + 'cache' => $templatesCompiledPath, ) ); $this->twig->addExtension(new Twig_Extension_Debug()); diff --git a/core/functions.php b/core/functions.php index c706a17b6a..a34fdca893 100644 --- a/core/functions.php +++ b/core/functions.php @@ -262,8 +262,7 @@ namespace { // Bridge between pre Piwik2 serialized format and namespaced classes // Do not need to define these classes in tracker or archive - if(empty($GLOBALS['PIWIK_TRACKER_MODE']) - && !defined('PIWIK_MODE_ARCHIVE')) { + if(class_exists('\\Piwik\\DataTable\\Row\\DataTableSummaryRow')) { class Piwik_DataTable_Row_DataTableSummary extends \Piwik\DataTable\Row\DataTableSummaryRow { } |