API
5 years ago
Access
5 years ago
Application
5 years ago
Archive
5 years ago
ArchiveProcessor
5 years ago
Archiver
5 years ago
AssetManager
5 years ago
Auth
5 years ago
Category
5 years ago
CliMulti
5 years ago
Columns
5 years ago
Composer
5 years ago
Concurrency
5 years ago
Config
5 years ago
Container
5 years ago
CronArchive
5 years ago
DataAccess
5 years ago
DataFiles
5 years ago
DataTable
5 years ago
Db
5 years ago
DeviceDetector
5 years ago
Email
5 years ago
Exception
5 years ago
Http
5 years ago
Intl
5 years ago
Mail
5 years ago
Measurable
5 years ago
Menu
5 years ago
Metrics
5 years ago
Notification
5 years ago
Period
5 years ago
Plugin
5 years ago
ProfessionalServices
5 years ago
Report
5 years ago
ReportRenderer
5 years ago
Scheduler
5 years ago
Segment
5 years ago
Session
5 years ago
Settings
5 years ago
Tracker
5 years ago
Translation
5 years ago
UpdateCheck
5 years ago
Updater
5 years ago
Updates
5 years ago
Validators
5 years ago
View
5 years ago
ViewDataTable
5 years ago
Visualization
5 years ago
Widget
5 years ago
.htaccess
6 years ago
Access.php
5 years ago
Archive.php
5 years ago
ArchiveProcessor.php
5 years ago
AssetManager.php
5 years ago
Auth.php
5 years ago
AuthResult.php
5 years ago
BaseFactory.php
5 years ago
Cache.php
5 years ago
CacheId.php
5 years ago
CliMulti.php
5 years ago
Common.php
5 years ago
Config.php
5 years ago
Console.php
5 years ago
Context.php
5 years ago
Cookie.php
5 years ago
CronArchive.php
5 years ago
DataArray.php
5 years ago
DataTable.php
5 years ago
Date.php
5 years ago
Db.php
5 years ago
DbHelper.php
5 years ago
Development.php
5 years ago
ErrorHandler.php
5 years ago
EventDispatcher.php
5 years ago
ExceptionHandler.php
5 years ago
FileIntegrity.php
5 years ago
Filechecks.php
5 years ago
Filesystem.php
5 years ago
FrontController.php
5 years ago
Http.php
5 years ago
IP.php
5 years ago
Log.php
5 years ago
LogDeleter.php
5 years ago
Mail.php
5 years ago
Metrics.php
5 years ago
NoAccessException.php
5 years ago
Nonce.php
5 years ago
Notification.php
5 years ago
NumberFormatter.php
5 years ago
Option.php
5 years ago
Period.php
5 years ago
Piwik.php
5 years ago
Plugin.php
5 years ago
Profiler.php
5 years ago
ProxyHeaders.php
5 years ago
ProxyHttp.php
5 years ago
QuickForm2.php
5 years ago
RankingQuery.php
5 years ago
ReportRenderer.php
5 years ago
Segment.php
5 years ago
Sequence.php
5 years ago
Session.php
5 years ago
SettingsPiwik.php
5 years ago
SettingsServer.php
5 years ago
Singleton.php
5 years ago
Site.php
5 years ago
SupportedBrowser.php
5 years ago
TCPDF.php
5 years ago
Theme.php
5 years ago
Timer.php
5 years ago
Tracker.php
5 years ago
Twig.php
5 years ago
Unzip.php
5 years ago
UpdateCheck.php
5 years ago
Updater.php
5 years ago
UpdaterErrorException.php
5 years ago
Updates.php
5 years ago
Url.php
5 years ago
UrlHelper.php
5 years ago
Version.php
5 years ago
View.php
5 years ago
bootstrap.php
5 years ago
dispatch.php
5 years ago
testMinimumPhpVersion.php
5 years ago
testMinimumPhpVersion.php
200 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 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 PHP4. |
| 14 | */ |
| 15 | |
| 16 | $piwik_errorMessage = ''; |
| 17 | |
| 18 | // Minimum requirement: stream_resolve_include_path, working json_encode in 5.3.3, namespaces in 5.3 |
| 19 | // NOTE: when changing this variable, we also need to update |
| 20 | // 1) api.matomo.org |
| 21 | // 2) tests/travis/generator/Generator.php |
| 22 | // 3) composer.json (in two places) |
| 23 | // 4) tests/PHPUnit/Integration/ReleaseCheckListTest.php |
| 24 | $piwik_minimumPHPVersion = '7.2.5'; |
| 25 | $piwik_currentPHPVersion = PHP_VERSION; |
| 26 | $minimumPhpInvalid = version_compare($piwik_minimumPHPVersion, $piwik_currentPHPVersion) > 0; |
| 27 | if ($minimumPhpInvalid) { |
| 28 | $piwik_errorMessage .= "<p><strong>To run Matomo you need at least PHP version $piwik_minimumPHPVersion</strong></p> |
| 29 | <p>Unfortunately it seems your webserver is using PHP version $piwik_currentPHPVersion. </p> |
| 30 | <p>Please try to update your PHP version, Matomo is really worth it! Nowadays most web hosts |
| 31 | support PHP $piwik_minimumPHPVersion.</p>"; |
| 32 | } else { |
| 33 | if (!extension_loaded('session')) { |
| 34 | $piwik_errorMessage .= "<p><strong>Matomo and Zend_Session require the session extension</strong></p> |
| 35 | <p>It appears your PHP was compiled with <pre>--disable-session</pre>. |
| 36 | To enjoy Matomo, you need PHP compiled without that configure option.</p>"; |
| 37 | } |
| 38 | |
| 39 | if (!function_exists('ini_set')) { |
| 40 | $piwik_errorMessage .= "<p><strong>Matomo and Zend_Session require the <code>ini_set()</code> function</strong></p> |
| 41 | <p>It appears your PHP has disabled this function. |
| 42 | To enjoy Matomo, you need remove <pre>ini_set</pre> from your <pre>disable_functions</pre> directive in php.ini, and restart your webserver.</p>"; |
| 43 | } |
| 44 | |
| 45 | if (ini_get('mbstring.func_overload')) { |
| 46 | $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> |
| 47 | <p>It appears your mbstring extension in PHP is configured to override string functions. |
| 48 | To enjoy Matomo, you need to modify php.ini <pre>mbstring.func_overload = 0</pre>, and restart your webserver.</p>"; |
| 49 | } |
| 50 | |
| 51 | if (!function_exists('json_encode')) { |
| 52 | $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> |
| 53 | <p>It appears your PHP has not yet installed the php-json extension. |
| 54 | To 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>"; |
| 55 | } |
| 56 | |
| 57 | if (!file_exists(PIWIK_VENDOR_PATH . '/autoload.php')) { |
| 58 | $composerInstall = "In the matomo directory, run in the command line the following (eg. via ssh): \n\n" |
| 59 | . "<pre> curl -sS https://getcomposer.org/installer | php \n\n php composer.phar install\n\n</pre> "; |
| 60 | if (DIRECTORY_SEPARATOR === '\\' /* ::isWindows() */) { |
| 61 | $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. " |
| 62 | . " <br>Then run this command in a terminal in the matomo directory: <br> $ php composer.phar install "; |
| 63 | } |
| 64 | $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". |
| 65 | "<br/>" . $composerInstall. |
| 66 | " This will initialize composer for Matomo and download libraries we use in vendor/* directory.". |
| 67 | "\n\n<br/><br/>Then reload this page to access your analytics reports." . |
| 68 | "\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>." . |
| 69 | "\n\n<br/><br/>Note: if for some reasons you cannot install composer, instead install the latest Matomo release from ". |
| 70 | "<a href='https://builds.matomo.org/piwik.zip' rel='noreferrer noopener'>builds.matomo.org</a>.</p>"; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | define('PAGE_TITLE_WHEN_ERROR', 'Matomo › Error'); |
| 75 | |
| 76 | if (!function_exists('Piwik_GetErrorMessagePage')) { |
| 77 | /** |
| 78 | * Returns true if Piwik should print the backtrace with error messages. |
| 79 | * |
| 80 | * To make sure the backtrace is printed, define PIWIK_PRINT_ERROR_BACKTRACE. |
| 81 | * |
| 82 | * @return bool |
| 83 | */ |
| 84 | function Piwik_ShouldPrintBackTraceWithMessage() |
| 85 | { |
| 86 | if (class_exists('\Piwik\SettingsServer') |
| 87 | && class_exists('\Piwik\Common') |
| 88 | && \Piwik\SettingsServer::isArchivePhpTriggered() |
| 89 | && \Piwik\Common::isPhpCliMode() |
| 90 | ) { |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | $bool = (defined('PIWIK_PRINT_ERROR_BACKTRACE') && PIWIK_PRINT_ERROR_BACKTRACE) |
| 95 | || !empty($GLOBALS['PIWIK_PRINT_ERROR_BACKTRACE']) |
| 96 | || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']); |
| 97 | |
| 98 | return $bool; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Displays info/warning/error message in a friendly UI and exits. |
| 103 | * |
| 104 | * Note: this method should not be called by anyone other than FrontController. |
| 105 | * |
| 106 | * @param string $message Main message, must be html encoded before calling |
| 107 | * @param bool|string $optionalTrace Backtrace; will be displayed in lighter color |
| 108 | * @param bool $optionalLinks If true, will show links to the Piwik website for help |
| 109 | * @param bool $optionalLinkBack If true, displays a link to go back |
| 110 | * @param bool|string $logoUrl The URL to the logo to use. |
| 111 | * @param bool|string $faviconUrl The URL to the favicon to use. |
| 112 | * @return string |
| 113 | */ |
| 114 | function Piwik_GetErrorMessagePage($message, $optionalTrace = false, $optionalLinks = false, $optionalLinkBack = false, |
| 115 | $logoUrl = false, $faviconUrl = false, $isCli = null) |
| 116 | { |
| 117 | error_log(sprintf("Error in Matomo: %s", str_replace("\n", " ", strip_tags($message)))); |
| 118 | |
| 119 | if (!headers_sent()) { |
| 120 | header('Content-Type: text/html; charset=utf-8'); |
| 121 | header('Cache-Control: private, no-cache, no-store'); |
| 122 | |
| 123 | $isInternalServerError = preg_match('/(sql|database|mysql)/i', $message); |
| 124 | if ($isInternalServerError) { |
| 125 | header('HTTP/1.1 500 Internal Server Error'); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // We return only an HTML fragment for AJAX requests |
| 130 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) |
| 131 | && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') |
| 132 | ) { |
| 133 | return "<div class='alert alert-danger'><strong>Error:</strong> $message</div>"; |
| 134 | } |
| 135 | |
| 136 | if (empty($logoUrl)) { |
| 137 | $logoUrl = "plugins/Morpheus/images/logo.svg"; |
| 138 | } |
| 139 | |
| 140 | if (empty($faviconUrl)) { |
| 141 | $faviconUrl = "plugins/CoreHome/images/favicon.png"; |
| 142 | } |
| 143 | |
| 144 | if ($optionalTrace) { |
| 145 | $optionalTrace = '<h2>Stack trace</h2><pre>' . htmlentities($optionalTrace, ENT_COMPAT | ENT_HTML401, 'UTF-8') . '</pre>'; |
| 146 | } |
| 147 | |
| 148 | if ($isCli === null) { |
| 149 | $isCli = PHP_SAPI == 'cli'; |
| 150 | } |
| 151 | |
| 152 | if ($optionalLinks) { |
| 153 | $optionalLinks = '<ul> |
| 154 | <li><a rel="noreferrer noopener" target="_blank" href="https://matomo.org">Matomo.org homepage</a></li> |
| 155 | <li><a rel="noreferrer noopener" target="_blank" href="https://matomo.org/faq/">Frequently Asked Questions</a></li> |
| 156 | <li><a rel="noreferrer noopener" target="_blank" href="https://matomo.org/docs/">User Guides</a></li> |
| 157 | <li><a rel="noreferrer noopener" target="_blank" href="https://forum.matomo.org/">Matomo Forums</a></li> |
| 158 | <li><a rel="noreferrer noopener" target="_blank" href="https://matomo.org/support/?pk_campaign=App_AnErrorOccured&pk_source=Matomo_App&pk_medium=ProfessionalServicesLink">Professional Support for Matomo</a></li> |
| 159 | </ul>'; |
| 160 | } |
| 161 | if ($optionalLinkBack) { |
| 162 | $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a>'; |
| 163 | } |
| 164 | |
| 165 | $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl'); |
| 166 | $headerPage = str_replace('%logoUrl%', $logoUrl, $headerPage); |
| 167 | $headerPage = str_replace('%faviconUrl%', $faviconUrl, $headerPage); |
| 168 | |
| 169 | $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl'); |
| 170 | |
| 171 | $headerPage = str_replace('{$HTML_TITLE}', PAGE_TITLE_WHEN_ERROR, $headerPage); |
| 172 | |
| 173 | $content = '<h2>' . $message . '</h2> |
| 174 | <p>' |
| 175 | . $optionalLinkBack |
| 176 | . ' | <a href="index.php">Go to Matomo</a>' |
| 177 | . '</p>' |
| 178 | . ' ' . (Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '') |
| 179 | . ' ' . $optionalLinks; |
| 180 | |
| 181 | |
| 182 | $message = str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message); |
| 183 | $message = str_replace("\t", "", $message); |
| 184 | $message = strip_tags($message); |
| 185 | |
| 186 | if (!$isCli) { |
| 187 | $message = $headerPage . $content . $footerPage; |
| 188 | } |
| 189 | |
| 190 | $message .= "\n"; |
| 191 | |
| 192 | return $message; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (!empty($piwik_errorMessage)) { |
| 197 | echo Piwik_GetErrorMessagePage($piwik_errorMessage, false, true); |
| 198 | exit(1); |
| 199 | } |
| 200 |