File size: 27,461 Bytes
58ce155 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Installation;
use Exception;
use Piwik\Access;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\AssetManager;
use Piwik\Common;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Date;
use Piwik\Db;
use Piwik\DbHelper;
use Piwik\Filesystem;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugin\ControllerAdmin;
use Piwik\Plugin\Manager;
use Piwik\Plugins\CoreVue\CoreVue;
use Piwik\Plugins\Diagnostics\DiagnosticReport;
use Piwik\Plugins\Diagnostics\DiagnosticService;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Plugins\SitesManager\SitesManager;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\Plugins\UsersManager\NewsletterSignup;
use Piwik\Plugins\UsersManager\UserUpdater;
use Piwik\ProxyHeaders;
use Piwik\SettingsPiwik;
use Piwik\Tracker\TrackerCodeGenerator;
use Piwik\Translation\Translator;
use Piwik\Updater;
use Piwik\Url;
use Piwik\Version;
use Zend_Db_Adapter_Exception;
/**
* Installation controller
*/
class Controller extends ControllerAdmin
{
public $steps = array(
'welcome' => 'Installation_Welcome',
'systemCheck' => 'Installation_SystemCheck',
'databaseSetup' => 'Installation_DatabaseSetup',
'tablesCreation' => 'Installation_Tables',
'setupSuperUser' => 'Installation_SuperUser',
'firstWebsiteSetup' => 'Installation_SetupWebsite',
'trackingCode' => 'General_JsTrackingTag',
'finished' => 'Installation_Congratulations',
);
/**
* Get installation steps
*
* @return array installation steps
*/
public function getInstallationSteps()
{
return $this->steps;
}
/**
* Get default action (first installation step)
*
* @return string function name
*/
public function getDefaultAction()
{
$steps = array_keys($this->steps);
return $steps[0];
}
/**
* Installation Step 1: Welcome
*
* Can also display an error message when there is a failure early (eg. DB connection failed)
*
* @param string $possibleErrorMessage Possible error message which may be set in the frontcontroller when event. Config.badConfigurationFile was triggered
*/
public function welcome($possibleErrorMessage = null)
{
// Delete merged js/css files to force regenerations based on updated activated plugin list
Filesystem::deleteAllCacheOnUpdate();
$this->checkPiwikIsNotInstalled($possibleErrorMessage);
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/welcome',
$this->getInstallationSteps(),
__FUNCTION__
);
$view->showNextStep = true;
return $view->render();
}
/**
* Installation Step 2: System Check
*/
public function systemCheck()
{
$this->checkPiwikIsNotInstalled();
$this->deleteConfigFileIfNeeded();
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/systemCheck',
$this->getInstallationSteps(),
__FUNCTION__
);
// Do not use dependency injection because this service requires a lot of sub-services across plugins
/** @var DiagnosticService $diagnosticService */
$diagnosticService = StaticContainer::get('Piwik\Plugins\Diagnostics\DiagnosticService');
$view->diagnosticReport = $diagnosticService->runDiagnostics();
$view->isInstallation = true;
$view->systemCheckInfo = $this->getSystemCheckTextareaValue($view->diagnosticReport);
$view->showNextStep = !$view->diagnosticReport->hasErrors();
// On the system check page, if all is green, display Next link at the top
$view->showNextStepAtTop = $view->showNextStep && !$view->diagnosticReport->hasWarnings();
return $view->render();
}
/**
* Installation Step 3: Database Set-up
* @throws Exception|Zend_Db_Adapter_Exception
*/
public function databaseSetup()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/databaseSetup',
$this->getInstallationSteps(),
__FUNCTION__
);
$view->showNextStep = false;
$form = new FormDatabaseSetup();
if ($form->validate()) {
try {
$dbInfos = $form->createDatabaseObject();
$this->createConfigFile($dbInfos);
DbHelper::checkDatabaseVersion();
Db::get()->checkClientVersion();
$this->redirectToNextStep(__FUNCTION__);
} catch (Exception $e) {
$view->errorMessage = Common::sanitizeInputValue($e->getMessage());
}
}
$view->addForm($form);
return $view->render();
}
/**
* Installation Step 4: Table Creation
*/
public function tablesCreation()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/tablesCreation',
$this->getInstallationSteps(),
__FUNCTION__
);
if ($this->getParam('deleteTables')) {
Manager::getInstance()->clearPluginsInstalledConfig();
Db::dropAllTables();
$view->existingTablesDeleted = true;
}
$tablesInstalled = DbHelper::getTablesInstalled();
$view->tablesInstalled = '';
if (count($tablesInstalled) > 0) {
// we have existing tables
$view->tablesInstalled = implode(', ', $tablesInstalled);
$view->someTablesInstalled = true;
$self = $this;
Access::doAsSuperUser(function () use ($self, $tablesInstalled, $view) {
Access::getInstance();
if (
$self->hasEnoughTablesToReuseDb($tablesInstalled) &&
count(APISitesManager::getInstance()->getAllSitesId()) > 0 &&
count(APIUsersManager::getInstance()->getUsers()) > 0
) {
$view->showReuseExistingTables = true;
}
});
} else {
DbHelper::createTables();
DbHelper::createAnonymousUser();
DbHelper::recordInstallVersion();
$this->updateComponents();
Updater::recordComponentSuccessfullyUpdated('core', Version::VERSION);
$view->tablesCreated = true;
$view->showNextStep = true;
}
return $view->render();
}
public function reuseTables()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$steps = $this->getInstallationSteps();
$steps['tablesCreation'] = 'Installation_ReusingTables';
$view = new View(
'@Installation/reuseTables',
$steps,
'tablesCreation'
);
$oldVersion = Option::get('version_core');
$result = $this->updateComponents();
if ($result === false) {
$this->redirectToNextStep('tablesCreation');
}
$view->coreError = $result['coreError'];
$view->warningMessages = $result['warnings'];
$view->errorMessages = $result['errors'];
$view->deactivatedPlugins = $result['deactivatedPlugins'];
$view->currentVersion = Version::VERSION;
$view->oldVersion = $oldVersion;
$view->showNextStep = true;
return $view->render();
}
/**
* Installation Step 5: General Set-up (superuser login/password/email and subscriptions)
*/
public function setupSuperUser()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$superUserAlreadyExists = Access::doAsSuperUser(function () {
return count(APIUsersManager::getInstance()->getUsersHavingSuperUserAccess()) > 0;
});
if ($superUserAlreadyExists) {
$this->redirectToNextStep('setupSuperUser');
}
$view = new View(
'@Installation/setupSuperUser',
$this->getInstallationSteps(),
__FUNCTION__
);
$form = new FormSuperUser();
if ($form->validate()) {
try {
$loginName = $form->getSubmitValue('login');
$email = $form->getSubmitValue('email');
$this->createSuperUser(
$loginName,
$form->getSubmitValue('password'),
$email
);
$newsletterPiwikORG = $form->getSubmitValue('subscribe_newsletter_piwikorg');
$newsletterProfessionalServices = $form->getSubmitValue('subscribe_newsletter_professionalservices');
NewsletterSignup::signupForNewsletter(
$loginName,
$email,
$newsletterPiwikORG,
$newsletterProfessionalServices
);
Onboarding::sendSysAdminMail($email);
$this->redirectToNextStep(__FUNCTION__);
} catch (Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
$view->addForm($form);
return $view->render();
}
/**
* Installation Step 6: Configure first web-site
*/
public function firstWebsiteSetup()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
ServerFilesGenerator::createFilesForSecurity();
$siteIdsCount = Access::doAsSuperUser(function () {
return count(APISitesManager::getInstance()->getAllSitesId());
});
if ($siteIdsCount > 0) {
// if there is a already a website, skip this step and trackingCode step
$this->redirectToNextStep('trackingCode');
}
$view = new View(
'@Installation/firstWebsiteSetup',
$this->getInstallationSteps(),
__FUNCTION__
);
$form = new FormFirstWebsiteSetup();
if ($form->validate()) {
$name = Common::sanitizeInputValue($form->getSubmitValue('siteName'));
$url = Common::unsanitizeInputValue($form->getSubmitValue('url'));
$ecommerce = (int)$form->getSubmitValue('ecommerce');
try {
$result = Access::doAsSuperUser(function () use ($name, $url, $ecommerce) {
return APISitesManager::getInstance()->addSite($name, $url, $ecommerce);
});
$params = array(
'site_idSite' => $result,
'site_name' => urlencode($name),
);
$this->redirectToNextStep(__FUNCTION__, $params);
} catch (Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
// Display previous step success message, when current step form was not submitted yet
if (count($form->getErrorMessages()) == 0) {
$view->displayGeneralSetupSuccess = true;
}
$view->addForm($form);
return $view->render();
}
/**
* Installation Step 7: Display JavaScript tracking code
*/
public function trackingCode()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/trackingCode',
$this->getInstallationSteps(),
__FUNCTION__
);
$siteName = Common::unsanitizeInputValue($this->getParam('site_name'));
$idSite = $this->getParam('site_idSite');
$javascriptGenerator = new TrackerCodeGenerator();
$jsTag = $javascriptGenerator->generate($idSite, Url::getCurrentUrlWithoutFileName());
// Needs to be generated as super user, as API requests would otherwise fail
$emailBody = Access::doAsSuperUser(
function () use ($idSite) {
return SitesManager::renderTrackingCodeEmail($idSite);
}
);
// Load the Tracking code and help text from the SitesManager
$viewTrackingHelp = new \Piwik\View('@SitesManager/_displayJavascriptCode');
$viewTrackingHelp->displaySiteName = $siteName;
$viewTrackingHelp->jsTag = $jsTag;
$viewTrackingHelp->emailBody = $emailBody;
$viewTrackingHelp->idSite = $idSite;
$viewTrackingHelp->piwikUrl = Url::getCurrentUrlWithoutFileName();
$viewTrackingHelp->isInstall = true;
$view->trackingHelp = $viewTrackingHelp->render();
$view->displaySiteName = $siteName;
$view->displayfirstWebsiteSetupSuccess = true;
$view->showNextStep = true;
return $view->render();
}
/**
* Installation Step 8: Finished!
*/
public function finished()
{
$this->checkPiwikIsNotInstalled();
$this->checkInstallationIsNotExpired();
$view = new View(
'@Installation/finished',
$this->getInstallationSteps(),
__FUNCTION__
);
$form = new FormDefaultSettings();
/**
* Triggered on initialization of the form to customize default Matomo settings (at the end of the installation process).
*
* @param \Piwik\Plugins\Installation\FormDefaultSettings $form
*/
Piwik::postEvent('Installation.defaultSettingsForm.init', array($form));
$form->addElement('submit', 'submit', array('value' => Piwik::translate('General_ContinueToPiwik') . ' »', 'class' => 'btn'));
if ($form->validate()) {
try {
/**
* Triggered on submission of the form to customize default Matomo settings (at the end of the installation process).
*
* @param \Piwik\Plugins\Installation\FormDefaultSettings $form
*/
Piwik::postEvent('Installation.defaultSettingsForm.submit', array($form));
$this->markInstallationAsCompleted();
Url::redirectToUrl('index.php');
} catch (Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
$view->addForm($form);
$view->showNextStep = false;
$output = $view->render();
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!';
}
/**
* This controller action renders an admin tab that runs the installation
* system check, so people can see if there are any issues w/ their running
* Matomo installation.
*
* This admin tab is only viewable by the Super User.
*/
public function systemCheckPage()
{
Piwik::checkUserHasSuperUserAccess();
$view = new View(
'@Installation/systemCheckPage',
$this->getInstallationSteps(),
__FUNCTION__
);
$this->setBasicVariablesView($view);
/** @var DiagnosticService $diagnosticService */
$diagnosticService = StaticContainer::get('Piwik\Plugins\Diagnostics\DiagnosticService');
$view->diagnosticReport = $diagnosticService->runDiagnostics();
$view->systemCheckInfo = $this->getSystemCheckTextareaValue($view->diagnosticReport);
return $view->render();
}
/**
* Save language selection in session-store
*/
public function saveLanguage()
{
if (DbHelper::isInstalled()) {
$this->checkTokenInUrl();
}
$language = $this->getParam('language');
LanguagesManager::setLanguageForSession($language);
Url::redirectToReferrer();
}
/**
* Return the base.less compiled to css
*
* @return string
*/
public function getInstallationCss()
{
Common::sendHeader('Content-Type: text/css');
Common::sendHeader('Cache-Control: max-age=' . (60 * 60));
$files = array(
'plugins/Morpheus/stylesheets/base/bootstrap.css',
'plugins/Morpheus/stylesheets/base/icons.css',
"node_modules/jquery-ui-dist/jquery-ui.theme.min.css",
'node_modules/@materializecss/materialize/dist/css/materialize.min.css',
'plugins/Morpheus/stylesheets/base.less',
'plugins/Morpheus/stylesheets/general/_forms.less',
'plugins/Installation/stylesheets/installation.css',
);
return AssetManager::compileCustomStylesheets($files);
}
/**
* Return the compiled JavaScript for the installation screen.
*
* @return string
*/
public function getInstallationJs()
{
Common::sendHeader('Content-Type: application/javascript; charset=UTF-8');
Common::sendHeader('Cache-Control: max-age=' . (60 * 60));
$files = array(
"node_modules/jquery/dist/jquery.min.js",
"node_modules/jquery-ui-dist/jquery-ui.min.js",
'node_modules/@materializecss/materialize/dist/js/materialize.min.js',
"plugins/CoreHome/javascripts/materialize-bc.js",
'plugins/Installation/javascripts/installation.js',
'plugins/Morpheus/javascripts/piwikHelper.js',
"plugins/CoreHome/javascripts/broadcast.js",
);
CoreVue::addJsFilesTo($files);
$files[] = AssetManager\UIAssetFetcher\PluginUmdAssetFetcher::getUmdFileToUseForPlugin('CoreHome');
$files[] = AssetManager\UIAssetFetcher\PluginUmdAssetFetcher::getUmdFileToUseForPlugin('Installation');
if (
defined('PIWIK_TEST_MODE') && PIWIK_TEST_MODE
&& file_exists(PIWIK_DOCUMENT_ROOT . '/tests/resources/screenshot-override/override.js')
) {
$files[] = 'tests/resources/screenshot-override/override.js';
}
return AssetManager::compileCustomJs($files);
}
private function getParam($name)
{
return Common::getRequestVar($name, false, 'string');
}
/**
* Write configuration file from session-store
*/
private function createConfigFile($dbInfos)
{
$config = Config::getInstance();
// make sure DB sessions are used if the filesystem is NFS
if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
$config->General['proxy_client_headers'] = $headers;
}
if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
$config->General['proxy_host_headers'] = $headers;
}
if (count($headers = ProxyHeaders::getProxySchemeHeaders()) > 0) {
$config->General['proxy_scheme_headers'] = $headers;
}
if (Common::getRequestVar('clientProtocol', 'http', 'string') == 'https') {
$protocol = 'https';
} else {
$protocol = ProxyHeaders::getProtocolInformation();
}
if (
!empty($protocol)
&& !\Piwik\ProxyHttp::isHttps()
) {
$config->General['assume_secure_protocol'] = '1';
}
$config->General['salt'] = Common::generateUniqId();
$config->General['installation_in_progress'] = 1;
$this->setTrustedHost($config);
$config->database = $dbInfos;
$config->database['charset'] = DbHelper::getDefaultCharset();
$config->database['collation'] = DbHelper::getDefaultCollationForCharset($config->database['charset']);
$config->forceSave();
// re-save the currently viewed language (since we saved the config file, there is now a salt which makes the
// existing session cookie invalid)
$this->resetLanguageCookie();
}
private function resetLanguageCookie()
{
/** @var Translator $translator */
$translator = StaticContainer::get('Piwik\Translation\Translator');
LanguagesManager::setLanguageForSession($translator->getCurrentLanguage());
}
private function checkPiwikIsNotInstalled($possibleErrorMessage = null)
{
if (!SettingsPiwik::isMatomoInstalled()) {
return;
}
$possibleErrorMessage = $possibleErrorMessage ? sprintf('<br/><br/>Original error was "%s".<br/>', $possibleErrorMessage) : '';
\Piwik\Plugins\Login\Controller::clearSession();
$message = Piwik::translate(
'Installation_InvalidStateError',
array($possibleErrorMessage . '<br /><strong>',
// piwik-is-already-installed is checked against in checkPiwikServerWorking
'</strong><a id="piwik-is-already-installed" href=\'' . Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()) . '\'>',
'</a>')
);
Piwik::exitWithErrorMessage($message);
}
/**
* Write configuration file from session-store
*/
private function markInstallationAsCompleted()
{
$config = Config::getInstance();
unset($config->General['installation_in_progress']);
unset($config->General['installation_first_accessed']);
$config->forceSave();
}
/**
* Redirect to next step
*
* @param string $currentStep Current step
* @return void
*/
private function redirectToNextStep($currentStep, $parameters = array())
{
$steps = array_keys($this->steps);
$nextStep = $steps[1 + array_search($currentStep, $steps)];
Piwik::redirectToModule('Installation', $nextStep, $parameters);
}
/**
* Extract host from URL
*
* @param string $url URL
*
* @return string|false
*/
private function extractHostAndPort($url)
{
$host = parse_url($url, PHP_URL_HOST) ?? false;
if (empty($host)) {
return false;
}
$port = (int) parse_url($url, PHP_URL_PORT) ?? 0;
if (!empty($port) && $port !== 80 && $port !== 443) {
return $host . ':' . $port;
}
return $host;
}
/**
* Sets trusted hosts in config
*/
private function setTrustedHost(Config $config): void
{
$host = Url::getHost(false);
// check hostname in server variables is correctly parsable
if ($host === $this->extractHostAndPort('http://' . $host)) {
$config->General['trusted_hosts'] = [$host];
}
}
private function createSuperUser(
$login,
#[\SensitiveParameter]
$password,
$email
) {
Access::doAsSuperUser(function () use ($login, $password, $email) {
$api = APIUsersManager::getInstance();
$api->addUser($login, $password, $email);
$userUpdater = new UserUpdater();
$userUpdater->setSuperUserAccessWithoutCurrentPassword($login, true);
});
}
// should be private but there's a bug in php 5.3.6
public function hasEnoughTablesToReuseDb($tablesInstalled)
{
if (empty($tablesInstalled) || !is_array($tablesInstalled)) {
return false;
}
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
$baseTablesInstalled = count($tablesInstalled) - count($archiveTables);
$minimumCountPiwikTables = 12;
return $baseTablesInstalled >= $minimumCountPiwikTables;
}
private function deleteConfigFileIfNeeded()
{
$config = Config::getInstance();
if ($config->existsLocalConfig()) {
$firstInstallationAccess = $config->General['installation_first_accessed'];
$settingsProvider = StaticContainer::get(GlobalSettingsProvider::class);
$config->deleteLocalConfig();
$settingsProvider->reload();
$this->setUpInstallationExpiration($config, $firstInstallationAccess);
// deleting the config file removes the salt, which in turns invalidates existing cookies (including the
// one for selected language), so we re-save that cookie now
$this->resetLanguageCookie();
}
}
/**
* @return array|bool
*/
protected function updateComponents()
{
Access::getInstance();
return Access::doAsSuperUser(function () {
$updater = new Updater();
$componentsWithUpdateFile = $updater->getComponentUpdates();
if (empty($componentsWithUpdateFile)) {
return false;
}
$result = $updater->updateComponents($componentsWithUpdateFile);
return $result;
});
}
private function getSystemCheckTextareaValue(DiagnosticReport $diagnosticReport)
{
$view = new \Piwik\View('@Installation/_systemCheckSection');
$view->diagnosticReport = $diagnosticReport;
return $view->render();
}
private function checkInstallationIsNotExpired(): void
{
$config = Config::getInstance();
if (
empty($config->General['installation_first_accessed'])
|| !is_numeric($config->General['installation_first_accessed'])
) {
$this->setUpInstallationExpiration($config, Date::getNowTimestamp());
return;
}
$firstAccess = (int) $config->General['installation_first_accessed'];
$threeDaysAgo = Date::getNowTimestamp() - (3 * 24 * 60 * 60);
if ($firstAccess < $threeDaysAgo) {
Piwik::exitWithErrorMessage(
Piwik::translate('Installation_ErrorExpired1') .
"\n<br/>" .
Piwik::translate('Installation_ErrorExpired2') .
"\n<ul>" .
"\n<li>" . Piwik::translate('Installation_ErrorExpired3', ['<strong>', '</strong>']) . '</li>' .
"\n<li>" . Piwik::translate('Installation_ErrorExpired4', ['<strong>', '</strong>']) . '</li>' .
"\n<li>" . Piwik::translate('Installation_ErrorExpired5') . '</li>' .
"\n</ul>" .
Piwik::translate('Installation_ErrorExpired6') .
"\n<br/>" .
Piwik::translate('Installation_ErrorExpired7', [
Url::getExternalLinkTag('https://matomo.org/faq/how-to-install/manage-secure-access-to-the-matomo-installer/'),
'</a>',
])
);
}
}
private function setUpInstallationExpiration(Config $config, int $timestamp): void
{
if (
!empty($config->General['installation_first_accessed'])
&& is_numeric($config->General['installation_first_accessed'])
) {
return;
}
$config->General['installation_first_accessed'] = $timestamp;
$config->forceSave();
}
}
|