From 11f54ee6389bd8ac408385b0d1760936c496470c Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 2 Sep 2020 19:02:12 +1200 Subject: Provide more debug information in system check (#16350) * Provide more debug information in system check * hide some info in screenshots * try overriding some columns * hide tr instead of only the content * trying to get tests to work * try different way * try fix tests * make sure cookie exists * add overridejs to install * more tweaks * fix test * more tweaks * move things to DI * minor tweaks * minor tweaks * fix test * also anonymise DB username * Update Twig.php * Improve query performance * Fix ClientTest keywords Co-authored-by: diosmosis --- core/Twig.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'core/Twig.php') diff --git a/core/Twig.php b/core/Twig.php index 1ff38003ab..a4fe82be08 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -176,6 +176,7 @@ class Twig $this->addFilter_prettyDate(); $this->addFilter_safeDecodeRaw(); $this->addFilter_number(); + $this->addFilter_anonymiseSystemInfo(); $this->addFilter_nonce(); $this->addFilter_md5(); $this->addFilter_onlyDomain(); @@ -434,6 +435,39 @@ class Twig $this->twig->addFilter($formatter); } + protected function addFilter_anonymiseSystemInfo() + { + $formatter = new TwigFilter('anonymiseSystemInfo', function ($string) { + if ($string === null) { + return ''; + } + if ($string === false || $string === true) { + return (int) $string; + } + $string = str_replace([PIWIK_DOCUMENT_ROOT, str_replace( '/', '\/', PIWIK_DOCUMENT_ROOT )], '$DOC_ROOT', $string); + $string = str_replace([PIWIK_USER_PATH, str_replace( '/', '\/', PIWIK_USER_PATH ) ], '$USER_PATH', $string); + $string = str_replace([PIWIK_INCLUDE_PATH, str_replace( '/', '\/', PIWIK_INCLUDE_PATH ) ], '$INCLUDE_PATH', $string); + + // replace anything token like + $string = preg_replace('/[[:xdigit:]]{31,80}/', 'TOKEN_REPLACED', $string); + + // just in case it was somehow show in a text + if (SettingsPiwik::isMatomoInstalled()) { + $string = str_replace(SettingsPiwik::getPiwikUrl(), '$MATOMO_URL', $string); + $string = str_replace(SettingsPiwik::getSalt(), '$MATOMO_SALT', $string); + + $config = Config::getInstance(); + $db = $config->database; + $string = str_replace($db['username'], '$DB_USERNAME', $string); + $string = str_replace($db['password'], '$DB_PASSWORD', $string); + $string = str_replace($db['host'], '$DB_HOST', $string); + $string = str_replace($db['dbname'], '$DB_NAME', $string); + } + return $string; + }); + $this->twig->addFilter($formatter); + } + protected function addFilter_nonce() { $nonce = new TwigFilter('nonce', array('Piwik\\Nonce', 'getNonce')); -- cgit v1.2.3