| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Config; |
|
|
| use Matomo\Cache\Backend\File; |
| use Piwik\Common; |
| use Piwik\Piwik; |
| use Piwik\Url; |
|
|
| |
| |
| |
| |
| class Cache extends File |
| { |
| private $host = ''; |
|
|
| public function __construct() |
| { |
| $this->host = $this->getHost(); |
|
|
| |
| |
| $dir = $this->makeCacheDir($this->host); |
|
|
| parent::__construct($dir); |
| } |
|
|
| private function makeCacheDir($host) |
| { |
| return PIWIK_INCLUDE_PATH . '/tmp/' . $host . '/cache/tracker'; |
| } |
|
|
| public static function hasHostConfig($mergedConfigSettings) |
| { |
| return isset($mergedConfigSettings['General']['trusted_hosts']) && is_array($mergedConfigSettings['General']['trusted_hosts']); |
| } |
|
|
| public function isValidHost($mergedConfigSettings) |
| { |
| if (!self::hasHostConfig($mergedConfigSettings)) { |
| return false; |
| } |
| |
| return in_array($this->host, $mergedConfigSettings['General']['trusted_hosts'], true); |
| } |
|
|
| private function getHost() |
| { |
| $host = Url::getHost($checkIfTrusted = false); |
| $host = Url::getHostSanitized($host); |
| $host = Common::sanitizeInputValue($host); |
|
|
| if ( |
| empty($host) |
| || strpos($host, '..') !== false |
| || strpos($host, '\\') !== false |
| || strpos($host, '/') !== false |
| ) { |
| throw new \Exception('Unsupported host'); |
| } |
|
|
| $this->host = $host; |
|
|
| return $host; |
| } |
|
|
| public function doDelete($id) |
| { |
| |
| |
| $hosts = Url::getTrustedHosts(); |
| $initialDir = $this->directory; |
|
|
| foreach ($hosts as $host) { |
| $dir = $this->makeCacheDir($host); |
| if (@is_dir($dir)) { |
| $this->directory = $dir; |
| $success = parent::doDelete($id); |
| if ($success) { |
| Piwik::postEvent('Core.configFileDeleted', [$this->getFilename($id)]); |
| } |
| } |
| } |
|
|
| $this->directory = $initialDir; |
|
|
| return true; |
| } |
| } |
|
|