API
1 year ago
Access
1 year ago
Application
1 year ago
Archive
1 year ago
ArchiveProcessor
1 year ago
Archiver
2 years ago
AssetManager
1 year ago
Auth
1 year ago
Category
2 years ago
Changes
1 year ago
CliMulti
1 year ago
Columns
1 year ago
Concurrency
1 year ago
Config
1 year ago
Container
1 year ago
CronArchive
1 year ago
DataAccess
1 year ago
DataFiles
2 years ago
DataTable
1 year ago
Db
1 year ago
DeviceDetector
1 year ago
Email
2 years ago
Exception
1 year ago
Http
1 year ago
Intl
1 year ago
Log
2 years ago
Mail
1 year ago
Measurable
1 year ago
Menu
1 year ago
Metrics
1 year ago
Notification
1 year ago
Period
1 year ago
Plugin
1 year ago
ProfessionalServices
1 year ago
Report
1 year ago
ReportRenderer
1 year ago
Scheduler
1 year ago
Segment
1 year ago
Session
1 year ago
Settings
1 year ago
Tracker
1 year ago
Translation
1 year ago
Twig
1 year ago
UpdateCheck
1 year ago
Updater
1 year ago
Updates
1 year ago
Validators
1 year ago
View
1 year ago
ViewDataTable
1 year ago
Visualization
1 year ago
Widget
1 year ago
.htaccess
2 years ago
Access.php
1 year ago
Archive.php
1 year ago
ArchiveProcessor.php
1 year ago
AssetManager.php
1 year ago
Auth.php
2 years ago
AuthResult.php
2 years ago
BaseFactory.php
2 years ago
Cache.php
2 years ago
CacheId.php
1 year ago
CliMulti.php
1 year ago
Common.php
1 year ago
Config.php
1 year ago
Console.php
1 year ago
Context.php
2 years ago
Cookie.php
1 year ago
CronArchive.php
1 year ago
DI.php
1 year ago
DataArray.php
1 year ago
DataTable.php
1 year ago
Date.php
1 year ago
Db.php
1 year ago
DbHelper.php
1 year ago
Development.php
1 year ago
ErrorHandler.php
1 year ago
EventDispatcher.php
1 year ago
ExceptionHandler.php
1 year ago
FileIntegrity.php
1 year ago
Filechecks.php
1 year ago
Filesystem.php
1 year ago
FrontController.php
1 year ago
Http.php
1 year ago
IP.php
1 year ago
Log.php
2 years ago
LogDeleter.php
1 year ago
Mail.php
1 year ago
Metrics.php
1 year ago
NoAccessException.php
2 years ago
Nonce.php
1 year ago
Notification.php
1 year ago
NumberFormatter.php
1 year ago
Option.php
1 year ago
Period.php
1 year ago
Piwik.php
1 year ago
Plugin.php
1 year ago
Process.php
1 year ago
Profiler.php
1 year ago
ProxyHeaders.php
2 years ago
ProxyHttp.php
1 year ago
QuickForm2.php
1 year ago
RankingQuery.php
1 year ago
ReportRenderer.php
1 year ago
Request.php
1 year ago
Segment.php
1 year ago
Sequence.php
2 years ago
Session.php
1 year ago
SettingsPiwik.php
1 year ago
SettingsServer.php
1 year ago
Singleton.php
2 years ago
Site.php
1 year ago
SiteContentDetector.php
1 year ago
SupportedBrowser.php
2 years ago
TCPDF.php
1 year ago
Theme.php
1 year ago
Timer.php
2 years ago
Tracker.php
1 year ago
Twig.php
1 year ago
Unzip.php
1 year ago
UpdateCheck.php
1 year ago
Updater.php
1 year ago
UpdaterErrorException.php
2 years ago
Updates.php
1 year ago
Url.php
1 year ago
UrlHelper.php
1 year ago
Version.php
1 year ago
View.php
1 year ago
bootstrap.php
1 year ago
dispatch.php
2 years ago
testMinimumPhpVersion.php
2 years ago
testMinimumPhpVersion.php
156 lines
| 1 | <?php |
| 2 | |
| 3 | namespace { |
| 4 | /** |
| 5 | * Matomo - free/libre analytics platform |
| 6 | * |
| 7 | * @link https://matomo.org |
| 8 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 9 | */ |
| 10 | /** |
| 11 | * This file is executed before anything else. |
| 12 | * It checks the minimum PHP version required to run Matomo. |
| 13 | * This file must be compatible with PHP 5.3. |
| 14 | */ |
| 15 | use Piwik\Url; |
| 16 | $piwik_errorMessage = ''; |
| 17 | // Minimum requirement: stream_resolve_include_path, working json_encode in 5.3.3, namespaces in 5.3 |
| 18 | // NOTE: when changing this variable, we also need to update |
| 19 | // 1) api.matomo.org |
| 20 | // 2) composer.json (in two places) |
| 21 | // 3) tests/PHPUnit/Integration/ReleaseCheckListTest.php |
| 22 | global $piwik_minimumPHPVersion; |
| 23 | $piwik_minimumPHPVersion = '7.2.5'; |
| 24 | $piwik_currentPHPVersion = \PHP_VERSION; |
| 25 | $minimumPhpInvalid = \version_compare($piwik_minimumPHPVersion, $piwik_currentPHPVersion) > 0; |
| 26 | if ($minimumPhpInvalid) { |
| 27 | $piwik_errorMessage .= "<p><strong>To run Matomo you need at least PHP version {$piwik_minimumPHPVersion}</strong></p>\n\t\t\t\t<p>Unfortunately it seems your webserver is using PHP version {$piwik_currentPHPVersion}. </p>\n\t\t\t\t<p>Please try to update your PHP version, Matomo is really worth it! Nowadays most web hosts\n\t\t\t\tsupport PHP {$piwik_minimumPHPVersion}.</p>"; |
| 28 | } else { |
| 29 | if (!\extension_loaded('session')) { |
| 30 | $piwik_errorMessage .= "<p><strong>Matomo and Zend_Session require the session extension</strong></p>\n\t\t\t\t\t<p>It appears your PHP was compiled with <pre>--disable-session</pre>.\n\t\t\t\t\tTo enjoy Matomo, you need PHP compiled without that configure option.</p>"; |
| 31 | } |
| 32 | if (!\function_exists('ini_set')) { |
| 33 | $piwik_errorMessage .= "<p><strong>Matomo and Zend_Session require the <code>ini_set()</code> function</strong></p>\n\t\t\t\t\t<p>It appears your PHP has disabled this function.\n\t\t\t\t\tTo enjoy Matomo, you need remove <pre>ini_set</pre> from your <pre>disable_functions</pre> directive in php.ini, and restart your webserver.</p>"; |
| 34 | } |
| 35 | if (\ini_get('mbstring.func_overload')) { |
| 36 | $piwik_errorMessage .= "<p><strong>Matomo does not work when PHP is configured with <pre>mbstring.func_overload = " . \ini_get('mbstring.func_overload') . "</pre></strong></p>\n\t\t\t\t\t<p>It appears your mbstring extension in PHP is configured to override string functions.\n\t\t\t\t\tTo enjoy Matomo, you need to modify php.ini <pre>mbstring.func_overload = 0</pre>, and restart your webserver.</p>"; |
| 37 | } |
| 38 | if (!\function_exists('json_encode')) { |
| 39 | $piwik_errorMessage .= "<p><strong>Matomo requires the php-json extension which provides the functions <code>json_encode()</code> and <code>json_decode()</code></strong></p>\n\t\t\t\t\t<p>It appears your PHP has not yet installed the php-json extension.\n\t\t\t\t\tTo use Matomo, please ask your web host to install php-json or install it yourself, for example on debian system: <code>sudo apt-get install php-json</code>. <br/>Then restart your webserver and refresh this page.</p>"; |
| 40 | } |
| 41 | if (!\file_exists(\PIWIK_VENDOR_PATH . '/autoload.php')) { |
| 42 | $composerInstall = "In the matomo directory, run in the command line the following (eg. via ssh): \n\n" . "<pre> curl -sS https://getcomposer.org/installer | php \n\n php composer.phar install\n\n</pre> "; |
| 43 | if (\DIRECTORY_SEPARATOR === '\\') { |
| 44 | $composerInstall = "Download and run <a href=\"https://getcomposer.org/Composer-Setup.exe\"><b>Composer-Setup.exe</b></a>, it will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line. " . " <br>Then run this command in a terminal in the matomo directory: <br> \$ php composer.phar install "; |
| 45 | } |
| 46 | $piwik_errorMessage .= "<p>It appears the <a href='https://getcomposer.org/' rel='noreferrer noopener' target='_blank'>composer</a> tool is not yet installed. You can install Composer in a few easy steps:\n\n" . "<br/>" . $composerInstall . " This will initialize composer for Matomo and download libraries we use in vendor/* directory." . "\n\n<br/><br/>Then reload this page to access your analytics reports." . "\n\n<br/><br/>For more information check out this FAQ: <a href='" . Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/how-to-install/faq_18271/') . "' rel='noreferrer noopener' target='_blank'>How do I use Matomo from the Git repository?</a>." . "\n\n<br/><br/>Note: if for some reasons you cannot install composer, instead install the latest Matomo release from " . "<a href='https://builds.matomo.org/piwik.zip' rel='noreferrer noopener'>builds.matomo.org</a>.</p>"; |
| 47 | } |
| 48 | } |
| 49 | \define('PAGE_TITLE_WHEN_ERROR', 'Matomo › Error'); |
| 50 | if (!\function_exists('Piwik_GetErrorMessagePage')) { |
| 51 | /** |
| 52 | * Returns true if Piwik should print the backtrace with error messages. |
| 53 | * |
| 54 | * To make sure the backtrace is printed, define PIWIK_PRINT_ERROR_BACKTRACE. |
| 55 | * |
| 56 | * @return bool |
| 57 | */ |
| 58 | function Piwik_ShouldPrintBackTraceWithMessage() |
| 59 | { |
| 60 | if (\class_exists('\\Piwik\\SettingsServer') && \class_exists('\\Piwik\\Common') && \Piwik\SettingsServer::isArchivePhpTriggered() && \Piwik\Common::isPhpCliMode()) { |
| 61 | return \true; |
| 62 | } |
| 63 | $bool = \defined('PIWIK_PRINT_ERROR_BACKTRACE') && \PIWIK_PRINT_ERROR_BACKTRACE || !empty($GLOBALS['PIWIK_PRINT_ERROR_BACKTRACE']) || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']); |
| 64 | return $bool; |
| 65 | } |
| 66 | /** |
| 67 | * Displays info/warning/error message in a friendly UI and exits. |
| 68 | * |
| 69 | * Note: this method should not be called by anyone other than FrontController. |
| 70 | * |
| 71 | * @param string $message Main message, must be html encoded before calling |
| 72 | * @param bool|string $optionalTrace Backtrace; will be displayed in lighter color |
| 73 | * @param bool $optionalLinks If true, will show links to the Piwik website for help |
| 74 | * @param bool $optionalLinkBack If true, displays a link to go back |
| 75 | * @param bool|string $logoUrl The URL to the logo to use. |
| 76 | * @param bool|string $faviconUrl The URL to the favicon to use. |
| 77 | * @param string $errorLogPrefix String to prepend to the error in log file |
| 78 | * @param bool $writeErrorLog If true then a webserver error log will be written, defaults to true |
| 79 | * @return string |
| 80 | */ |
| 81 | function Piwik_GetErrorMessagePage($message, $optionalTrace = \false, $optionalLinks = \false, $optionalLinkBack = \false, $logoUrl = \false, $faviconUrl = \false, $isCli = null, $errorLogPrefix = '', $writeErrorLog = \true, $redirectUrl = null, $countdown = null) |
| 82 | { |
| 83 | $hasCountdownRedirect = !empty($redirectUrl) && !empty($countdown); |
| 84 | if ($writeErrorLog) { |
| 85 | \error_log(\sprintf("{$errorLogPrefix}Error in Matomo: %s", \str_replace("\n", " ", \strip_tags($message)))); |
| 86 | } |
| 87 | if (!\headers_sent()) { |
| 88 | \header('Content-Type: text/html; charset=utf-8'); |
| 89 | \header('Cache-Control: private, no-cache, no-store'); |
| 90 | $isInternalServerError = \preg_match('/(sql|database|mysql)/i', $message); |
| 91 | if ($isInternalServerError) { |
| 92 | \header('HTTP/1.1 500 Internal Server Error'); |
| 93 | } |
| 94 | } |
| 95 | // We return only an HTML fragment for AJAX requests |
| 96 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && \strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { |
| 97 | return "<div class='alert alert-danger'><strong>Error:</strong> {$message}</div>"; |
| 98 | } |
| 99 | if (empty($logoUrl)) { |
| 100 | $logoUrl = "plugins/Morpheus/images/logo.svg"; |
| 101 | } |
| 102 | if (empty($faviconUrl)) { |
| 103 | $faviconUrl = "plugins/CoreHome/images/favicon.png"; |
| 104 | } |
| 105 | if ($optionalTrace) { |
| 106 | $optionalTrace = '<h2>Stack trace</h2><pre>' . \htmlentities($optionalTrace, \ENT_COMPAT | \ENT_HTML401, 'UTF-8') . '</pre>'; |
| 107 | } |
| 108 | if ($isCli === null) { |
| 109 | $isCli = \PHP_SAPI == 'cli'; |
| 110 | } |
| 111 | if ($optionalLinks) { |
| 112 | $optionalLinks = '<ul> |
| 113 | <li><a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org') . '">Matomo.org homepage</a></li> |
| 114 | <li><a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/') . '">Frequently Asked Questions</a></li> |
| 115 | <li><a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org/docs/') . '">User Guides</a></li> |
| 116 | <li><a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://forum.matomo.org/') . '">Matomo Forums</a></li> |
| 117 | <li><a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org/support/') . '">Professional Support for Matomo</a></li> |
| 118 | </ul>'; |
| 119 | } |
| 120 | if ($optionalLinkBack) { |
| 121 | $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a>'; |
| 122 | } |
| 123 | $headerPage = \file_get_contents(\PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl'); |
| 124 | $headerPage = \str_replace('%logoUrl%', $logoUrl, $headerPage); |
| 125 | $headerPage = \str_replace('%faviconUrl%', $faviconUrl, $headerPage); |
| 126 | $footerPage = \file_get_contents(\PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl'); |
| 127 | $headerPage = \str_replace('{$HTML_TITLE}', \PAGE_TITLE_WHEN_ERROR, $headerPage); |
| 128 | $backLinks = '<p>' . $optionalLinkBack . ' | <a href="index.php">Go to Matomo</a>' . '</p>'; |
| 129 | $redirectSection = ''; |
| 130 | if ($hasCountdownRedirect) { |
| 131 | $redirectSection = '<p> |
| 132 | Please click below if you are not redirected in ' . $countdown . ' seconds</br></br> |
| 133 | Go to <a href="' . $redirectUrl . '">' . \htmlspecialchars($redirectUrl) . '</a> |
| 134 | </p> |
| 135 | <style>.header,.footer { display:none;}</style> |
| 136 | <script>setTimeout(function(){window.location.href="' . $redirectUrl . '"}, ' . $countdown * 1000 . ');</script>'; |
| 137 | $backLinks = ''; |
| 138 | $optionalLinks = ''; |
| 139 | } |
| 140 | $content = '<h2>' . $message . '</h2>' . $redirectSection . $backLinks . ' ' . (\Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '') . ' ' . $optionalLinks; |
| 141 | $message = \str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message); |
| 142 | $message = \str_replace("\t", "", $message); |
| 143 | $message = \strip_tags($message); |
| 144 | if (!$isCli) { |
| 145 | $message = $headerPage . $content . $footerPage; |
| 146 | } |
| 147 | $message .= "\n"; |
| 148 | return $message; |
| 149 | } |
| 150 | } |
| 151 | if (!empty($piwik_errorMessage)) { |
| 152 | echo \Piwik_GetErrorMessagePage($piwik_errorMessage, \false, \true); |
| 153 | exit(1); |
| 154 | } |
| 155 | } |
| 156 |