Skip to content

Commit

Permalink
Fixes matomo-org#5081 Warn in system check when Pagespeed module is e…
Browse files Browse the repository at this point in the history
…nabled
  • Loading branch information
mattab committed Nov 28, 2014
1 parent f0311f6 commit d89ba25
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
11 changes: 11 additions & 0 deletions plugins/Installation/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ public function finished()
return $output;
}

/**
* System check will call this page which should load quickly,
* in order to look at Response headers (eg. to detect if pagespeed is running)
*
* @return string
*/
public function getEmptyPageForSystemCheck()
{
return 'Hello, world!';
}

/**
* Get system information
*/
Expand Down
41 changes: 40 additions & 1 deletion plugins/Installation/SystemCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\SettingsServer;
use Piwik\Url;

class SystemCheck
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public static function getSystemInformation()
$infos['adapters'] = Adapter::getAdapters();

$infos['needed_functions'] = self::getRequiredFunctions();
$infos['missing_functions'] = self::getRequiredFunctionsMissing();;
$infos['missing_functions'] = self::getRequiredFunctionsMissing();

// warnings
$infos['desired_extensions'] = self::getRecommendedExtensions();
Expand All @@ -61,6 +62,8 @@ public static function getSystemInformation()
$infos['needed_settings'] = self::getRequiredPhpSettings();
$infos['missing_settings'] = self::getMissingPhpSettings();

$infos['pagespeed_module_disabled_ok'] = self::isPageSpeedDisabled();

$infos['openurl'] = Http::getTransportMethod();
$infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
$infos['serverVersion'] = addslashes(isset($_SERVER['SERVER_SOFTWARE']) ?: '');
Expand Down Expand Up @@ -468,4 +471,40 @@ protected static function getMissingPhpSettings()
}
return $missingPhpSettings;
}

protected static function isPageSpeedDisabled()
{
$url = Url::getCurrentUrlWithoutQueryString() . '?module=Installation&action=getEmptyPageForSystemCheck';

try {
$page = Http::sendHttpRequest($url,
$timeout = 1,
$userAgent = null,
$destinationPath = null,
$followDepth = 0,
$acceptLanguage = false,
$byteRange = false,

// Return headers
$getExtendedInfo = true
);
} catch(\Exception $e) {

// If the test failed, we assume Page speed is not enabled
return true;
}

$headers = $page['headers'];

return !self::isPageSpeedHeaderFound($headers);
}

/**
* @param $headers
* @return bool
*/
protected static function isPageSpeedHeaderFound($headers)
{
return isset($headers['X-Mod-Pagespeed']) || isset($headers['X-Page-Speed']);
}
}
2 changes: 2 additions & 0 deletions plugins/Installation/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
"SystemCheckOpenURLHelp": "Newsletter subscriptions, update notifications, and one-click updates requires the \"curl\" extension, allow_url_fopen=On, or fsockopen() enabled.",
"SystemCheckOtherExtensions": "Other extensions",
"SystemCheckOtherFunctions": "Other functions",
"SystemCheckPageSpeedDisabled": "PageSpeed disabled",
"SystemCheckPageSpeedWarn": "We recommend to disable the PageSpeed Module in your web server %s: PageSpeed was reported to cause several issues with Piwik.",
"SystemCheckPackHelp": "The pack() function is required to track visitors in Piwik.",
"SystemCheckParseIniFileHelp": "This built-in function has been disabled on your host. Piwik will attempt to emulate this function but may encounter further security restrictions. Tracker performance will also be impacted.",
"SystemCheckPdoAndMysqliHelp": "On a GNU\/Linux server you can compile php with the following options: %1$s In your php.ini, add the following lines: %2$s",
Expand Down
10 changes: 10 additions & 0 deletions plugins/Installation/templates/_systemCheckSection.twig
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@
{% endif %}
</td>
</tr>
<tr>
<td class="label">{{ 'Installation_SystemCheckPageSpeedDisabled'|translate }}</td>
<td>
{% if infos.pagespeed_module_disabled_ok %}
{{ ok }}
{% else %}
{{ warning }} <span class="warn">{{ 'Installation_SystemCheckPageSpeedWarn'|translate('(eg. Apache, Nginx or IIS)') }}</span>
{% endif %}
</td>
</tr>
<tr>
<td class="label">{{ 'Installation_SystemCheckGDFreeType'|translate }}</td>
<td>
Expand Down

0 comments on commit d89ba25

Please sign in to comment.