API
1 month ago
Access
3 months ago
Application
1 month ago
Archive
1 month ago
ArchiveProcessor
1 month ago
Archiver
2 years ago
AssetManager
1 month ago
Auth
6 months ago
Category
6 months ago
Changes
1 month ago
CliMulti
1 year ago
Columns
1 month ago
Concurrency
1 month ago
Config
1 month ago
Container
1 month ago
CronArchive
3 months ago
DataAccess
1 month ago
DataFiles
2 years ago
DataTable
2 weeks ago
Db
2 weeks ago
DeviceDetector
1 year ago
Email
2 years ago
Exception
4 months ago
Http
4 months ago
Intl
3 months ago
Log
2 years ago
Mail
1 year ago
Measurable
6 months ago
Menu
1 month ago
Metrics
3 months ago
Notification
6 months ago
Period
1 month ago
Plugin
2 weeks ago
Policy
1 month ago
ProfessionalServices
1 year ago
Report
1 year ago
ReportRenderer
3 months ago
Request
3 months ago
Scheduler
1 month ago
Segment
1 month ago
Session
2 weeks ago
Settings
1 month ago
Tracker
2 weeks ago
Translation
1 month ago
Twig
1 year ago
UpdateCheck
3 months ago
Updater
1 month ago
Updates
2 days ago
Validators
1 year ago
View
1 month ago
ViewDataTable
2 weeks ago
Visualization
1 year ago
Widget
1 month ago
.htaccess
2 years ago
Access.php
1 month ago
Archive.php
1 month ago
ArchiveProcessor.php
1 month ago
AssetManager.php
1 month ago
Auth.php
6 months ago
AuthResult.php
6 months ago
BaseFactory.php
2 years ago
Cache.php
2 years ago
CacheId.php
4 months ago
CliMulti.php
1 month ago
Common.php
2 weeks ago
Config.php
1 month ago
Console.php
3 months ago
Context.php
2 years ago
Cookie.php
1 year ago
CronArchive.php
1 month ago
DI.php
3 months ago
DataArray.php
1 month ago
DataTable.php
1 month ago
Date.php
1 month ago
Db.php
1 month ago
DbHelper.php
1 month ago
Development.php
1 year ago
ErrorHandler.php
6 months ago
EventDispatcher.php
1 month ago
ExceptionHandler.php
4 months ago
FileIntegrity.php
1 month ago
Filechecks.php
1 year ago
Filesystem.php
1 month ago
FrontController.php
4 months ago
Http.php
1 month ago
IP.php
1 year ago
Log.php
3 months ago
LogDeleter.php
1 year ago
Mail.php
1 year ago
Metrics.php
1 month ago
NoAccessException.php
2 years ago
Nonce.php
6 months ago
Notification.php
1 month ago
NumberFormatter.php
5 months ago
Option.php
5 months ago
Period.php
1 month ago
Piwik.php
1 month ago
Plugin.php
1 month ago
Process.php
1 month ago
Profiler.php
6 months ago
ProxyHeaders.php
4 months ago
ProxyHttp.php
5 months ago
QuickForm2.php
3 months ago
RankingQuery.php
1 month ago
ReportRenderer.php
1 month ago
Request.php
1 month ago
Segment.php
1 month ago
Sequence.php
6 months ago
Session.php
2 weeks ago
SettingsPiwik.php
1 month ago
SettingsServer.php
1 year ago
Singleton.php
2 years ago
Site.php
1 month ago
SiteContentDetector.php
1 month ago
SupportedBrowser.php
2 years ago
TCPDF.php
1 year ago
Theme.php
1 year ago
Timer.php
1 month ago
Tracker.php
1 month ago
Twig.php
1 month ago
Unzip.php
1 year ago
UpdateCheck.php
1 month ago
Updater.php
1 month ago
UpdaterErrorException.php
2 years ago
Updates.php
3 months ago
Url.php
3 months ago
UrlHelper.php
1 month ago
Version.php
2 days ago
View.php
1 month ago
bootstrap.php
1 year ago
dispatch.php
2 years ago
testMinimumPhpVersion.php
6 months ago
testMinimumPhpVersion.php
160 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 | $piwik_errorMessage = ''; |
| 16 | // Minimum requirement: stream_resolve_include_path, working json_encode in 5.3.3, namespaces in 5.3 |
| 17 | // NOTE: when changing this variable, we also need to update |
| 18 | // 1) api.matomo.org |
| 19 | // 2) composer.json (in two places) |
| 20 | // 3) tests/PHPUnit/Integration/ReleaseCheckListTest.php |
| 21 | global $piwik_minimumPHPVersion; |
| 22 | $piwik_minimumPHPVersion = '7.2.5'; |
| 23 | $piwik_currentPHPVersion = \PHP_VERSION; |
| 24 | $minimumPhpInvalid = \version_compare($piwik_minimumPHPVersion, $piwik_currentPHPVersion) > 0; |
| 25 | if ($minimumPhpInvalid) { |
| 26 | $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>"; |
| 27 | } else { |
| 28 | if (!\extension_loaded('session')) { |
| 29 | $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>"; |
| 30 | } |
| 31 | if (!\function_exists('ini_set')) { |
| 32 | $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>"; |
| 33 | } |
| 34 | if (\ini_get('mbstring.func_overload')) { |
| 35 | $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>"; |
| 36 | } |
| 37 | if (!\function_exists('json_encode')) { |
| 38 | $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>"; |
| 39 | } |
| 40 | if (!\file_exists(\PIWIK_VENDOR_PATH . '/autoload.php')) { |
| 41 | $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> "; |
| 42 | if (\DIRECTORY_SEPARATOR === '\\') { |
| 43 | $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 "; |
| 44 | } |
| 45 | $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='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>"; |
| 46 | } |
| 47 | } |
| 48 | \define('PAGE_TITLE_WHEN_ERROR', 'Matomo › Error'); |
| 49 | if (!\function_exists('Piwik_GetErrorMessagePage')) { |
| 50 | /** |
| 51 | * Returns true if Piwik should print the backtrace with error messages. |
| 52 | * |
| 53 | * To make sure the backtrace is printed, define PIWIK_PRINT_ERROR_BACKTRACE. |
| 54 | * |
| 55 | * @return bool |
| 56 | */ |
| 57 | function Piwik_ShouldPrintBackTraceWithMessage() |
| 58 | { |
| 59 | if (!\class_exists(\Piwik\ExceptionHandler::class)) { |
| 60 | return \false; |
| 61 | } |
| 62 | return \Piwik\ExceptionHandler::shouldPrintBackTraceWithMessage(); |
| 63 | } |
| 64 | /** |
| 65 | * Displays info/warning/error message in a friendly UI and exits. |
| 66 | * |
| 67 | * Note: this method should not be called by anyone other than FrontController. |
| 68 | * |
| 69 | * @param string $message Main message, must be html encoded before calling |
| 70 | * @param bool|string $optionalTrace Backtrace; will be displayed in lighter color |
| 71 | * @param bool $optionalLinks If true, will show links to the Piwik website for help |
| 72 | * @param bool $optionalLinkBack If true, displays a link to go back |
| 73 | * @param bool|string $logoUrl The URL to the logo to use. |
| 74 | * @param bool|string $faviconUrl The URL to the favicon to use. |
| 75 | * @param string $errorLogPrefix String to prepend to the error in log file |
| 76 | * @param bool $writeErrorLog If true then a webserver error log will be written, defaults to true |
| 77 | * @return string |
| 78 | */ |
| 79 | function Piwik_GetErrorMessagePage($message, $optionalTrace = \false, $optionalLinks = \false, $optionalLinkBack = \false, $logoUrl = \false, $faviconUrl = \false, $isCli = null, $errorLogPrefix = '', $writeErrorLog = \true, $redirectUrl = null, $countdown = null) |
| 80 | { |
| 81 | $hasCountdownRedirect = !empty($redirectUrl) && !empty($countdown); |
| 82 | if ($writeErrorLog) { |
| 83 | \error_log(\sprintf("{$errorLogPrefix}Error in Matomo: %s", \str_replace("\n", " ", \strip_tags($message)))); |
| 84 | } |
| 85 | if (!\headers_sent()) { |
| 86 | \header('Content-Type: text/html; charset=utf-8'); |
| 87 | \header('Cache-Control: private, no-cache, no-store'); |
| 88 | $isInternalServerError = \preg_match('/(sql|database|mysql)/i', $message); |
| 89 | if ($isInternalServerError) { |
| 90 | \header('HTTP/1.1 500 Internal Server Error'); |
| 91 | } |
| 92 | } |
| 93 | // We return only an HTML fragment for AJAX requests |
| 94 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && \strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { |
| 95 | return "<div class='alert alert-danger'><strong>Error:</strong> {$message}</div>"; |
| 96 | } |
| 97 | if (empty($logoUrl)) { |
| 98 | $logoUrl = "plugins/Morpheus/images/logo.svg"; |
| 99 | } |
| 100 | if (empty($faviconUrl)) { |
| 101 | $faviconUrl = "plugins/CoreHome/images/favicon.png"; |
| 102 | } |
| 103 | if ($optionalTrace) { |
| 104 | $optionalTrace = '<h2>Stack trace</h2><pre>' . \htmlentities($optionalTrace, \ENT_COMPAT | \ENT_HTML401, 'UTF-8') . '</pre>'; |
| 105 | } |
| 106 | if ($isCli === null) { |
| 107 | $isCli = \PHP_SAPI == 'cli'; |
| 108 | } |
| 109 | if ($optionalLinks) { |
| 110 | $adjustUrl = function ($url) { |
| 111 | if (\class_exists(\Piwik\Url::class)) { |
| 112 | return \Piwik\Url::addCampaignParametersToMatomoLink($url); |
| 113 | } |
| 114 | return $url; |
| 115 | }; |
| 116 | $optionalLinks = '<ul> |
| 117 | <li><a rel="noreferrer noopener" target="_blank" href="' . $adjustUrl('https://matomo.org') . '">Matomo.org homepage</a></li> |
| 118 | <li><a rel="noreferrer noopener" target="_blank" href="' . $adjustUrl('https://matomo.org/faq/') . '">Frequently Asked Questions</a></li> |
| 119 | <li><a rel="noreferrer noopener" target="_blank" href="' . $adjustUrl('https://matomo.org/docs/') . '">User Guides</a></li> |
| 120 | <li><a rel="noreferrer noopener" target="_blank" href="' . $adjustUrl('https://forum.matomo.org/') . '">Matomo Forums</a></li> |
| 121 | <li><a rel="noreferrer noopener" target="_blank" href="' . $adjustUrl('https://matomo.org/support/') . '">Professional Support for Matomo</a></li> |
| 122 | </ul>'; |
| 123 | } |
| 124 | if ($optionalLinkBack) { |
| 125 | $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a>'; |
| 126 | } |
| 127 | $headerPage = \file_get_contents(\PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl'); |
| 128 | $headerPage = \str_replace('%logoUrl%', $logoUrl, $headerPage); |
| 129 | $headerPage = \str_replace('%faviconUrl%', $faviconUrl, $headerPage); |
| 130 | $footerPage = \file_get_contents(\PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl'); |
| 131 | $headerPage = \str_replace('{$HTML_TITLE}', \PAGE_TITLE_WHEN_ERROR, $headerPage); |
| 132 | $backLinks = '<p>' . $optionalLinkBack . ' | <a href="index.php">Go to Matomo</a>' . '</p>'; |
| 133 | $redirectSection = ''; |
| 134 | if ($hasCountdownRedirect) { |
| 135 | $redirectSection = '<p> |
| 136 | Please click below if you are not redirected in ' . $countdown . ' seconds</br></br> |
| 137 | Go to <a href="' . $redirectUrl . '">' . \htmlspecialchars($redirectUrl) . '</a> |
| 138 | </p> |
| 139 | <style>.header,.footer { display:none;}</style> |
| 140 | <script>setTimeout(function(){window.location.href="' . $redirectUrl . '"}, ' . $countdown * 1000 . ');</script>'; |
| 141 | $backLinks = ''; |
| 142 | $optionalLinks = ''; |
| 143 | } |
| 144 | $content = '<h2>' . $message . '</h2>' . $redirectSection . $backLinks . ' ' . (\Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '') . ' ' . $optionalLinks; |
| 145 | $message = \str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message); |
| 146 | $message = \str_replace("\t", "", $message); |
| 147 | $message = \strip_tags($message); |
| 148 | if (!$isCli) { |
| 149 | $message = $headerPage . $content . $footerPage; |
| 150 | } |
| 151 | $message .= "\n"; |
| 152 | return $message; |
| 153 | } |
| 154 | } |
| 155 | if (!empty($piwik_errorMessage)) { |
| 156 | echo \Piwik_GetErrorMessagePage($piwik_errorMessage, \false, \true); |
| 157 | exit(1); |
| 158 | } |
| 159 | } |
| 160 |