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