Newer
Older
<?php
/**
* Piwik - Open source web analytics
robocoder
a validé
*
* @link http://piwik.org
robocoder
a validé
*
mattab
a validé
namespace Piwik\Plugins\Installation;
use Exception;
use Piwik\API\Request;
use Piwik\AssetManager;
use Piwik\Common;
use Piwik\Config;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Db\Adapter;
mattab
a validé
use Piwik\Db;
Thomas Steur
a validé
use Piwik\Option;
Thomas Steur
a validé
use Piwik\Plugins\CoreUpdater\CoreUpdater;
mattab
a validé
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\ProxyHeaders;
use Piwik\Session\SessionNamespace;
use Piwik\SettingsServer;
Thomas Steur
a validé
use Piwik\UpdaterErrorException;
mattab
a validé
use Zend_Db_Adapter_Exception;
robocoder
a validé
* Installation controller
robocoder
a validé
*
class Controller extends \Piwik\Plugin\ControllerAdmin
// public so plugins can add/delete installation steps
public $steps = array(
mattab
a validé
'welcome' => 'Installation_Welcome',
'systemCheck' => 'Installation_SystemCheck',
'databaseSetup' => 'Installation_DatabaseSetup',
'databaseCheck' => 'Installation_DatabaseCheck',
'tablesCreation' => 'Installation_Tables',
'generalSetup' => 'Installation_SuperUser',
'firstWebsiteSetup' => 'Installation_SetupWebsite',
'trackingCode' => 'General_JsTrackingTag',
mattab
a validé
'finished' => 'Installation_Congratulations',
);
protected $session;
public function __construct()
{
mattab
a validé
$this->session = new SessionNamespace('Installation');
if (!isset($this->session->currentStepDone)) {
$this->session->currentStepDone = '';
$this->session->skipThisStep = array();
}
}
protected static function initServerFilesForSecurity()
{
if (SettingsServer::isIIS()) {
ServerFilesGenerator::createWebConfigFiles();
} else {
ServerFilesGenerator::createHtAccessFiles();
}
ServerFilesGenerator::createWebRootFiles();
}
/**
* Get installation steps
*
* @return array installation steps
*/
public function getInstallationSteps()
{
return $this->steps;
}
/**
* Get default action (first installation step)
*
* @return string function name
*/
function getDefaultAction()
{
$steps = array_keys($this->steps);
return $steps[0];
}
/**
* Installation Step 1: Welcome
*/
function welcome($message = false)
{
// Delete merged js/css files to force regenerations based on updated activated plugin list
Filesystem::deleteAllCacheOnUpdate();
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
Thomas Steur
a validé
$view->newInstall = !$this->isFinishedInstallation();
$view->errorMessage = $message;
$this->skipThisStep(__FUNCTION__);
$view->showNextStep = $view->newInstall;
$this->session->currentStepDone = __FUNCTION__;
}
/**
* Installation Step 2: System Check
*/
function systemCheck()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
$view->duringInstall = true;
$this->setupSystemCheckView($view);
$this->session->general_infos = $view->infos['general_infos'];
$this->session->general_infos['salt'] = Common::generateUniqId();
// make sure DB sessions are used if the filesystem is NFS
if ($view->infos['is_nfs']) {
$this->session->general_infos['session_save_handler'] = 'dbtable';
}
$view->showNextStep = !$view->problemWithSomeDirectories
&& $view->infos['phpVersion_ok']
&& count($view->infos['adapters'])
&& !count($view->infos['missing_extensions'])
&& !count($view->infos['missing_functions']);
// On the system check page, if all is green, display Next link at the top
$view->showNextStepAtTop = $view->showNextStep;
$this->session->currentStepDone = __FUNCTION__;
}
/**
* Installation Step 3: Database Set-up
* @throws Exception|Zend_Db_Adapter_Exception
*/
function databaseSetup()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
// case the user hits the back button
$this->session->skipThisStep = array(
mattab
a validé
'firstWebsiteSetup' => false,
'trackingCode' => false,
);
Thomas Steur
a validé
$this->skipThisStep(__FUNCTION__);
if (Config::getInstance()->existsLocalConfig()) {
try {
$database = Config::getInstance()->database;
if ($database) {
$db = Db::get();
DbHelper::checkDatabaseVersion();
$db->checkClientVersion();
}
$tmp = $this->session->skipThisStep;
$tmp[__FUNCTION__] = true;
$tmp['databaseCheck'] = true;
$tmp['tablesCreation'] = false;
$this->session->skipThisStep = $tmp;
$this->redirectToNextStep(__FUNCTION__ );
} catch (Exception $e) {
// existing database info in config is not complete or not valid, user has to reconfigure
}
}
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$view->showNextStep = false;
mattab
a validé
$form = new FormDatabaseSetup();
if ($form->validate()) {
try {
$dbInfos = $form->createDatabaseObject();
$this->session->databaseCreated = true;
$this->session->databaseVersionOk = true;
Thomas Steur
a validé
$this->createConfigFileIfNeeded($dbInfos);
$this->redirectToNextStep(__FUNCTION__);
} catch (Exception $e) {
$view->errorMessage = Common::sanitizeInputValue($e->getMessage());
}
}
$view->addForm($form);
}
/**
* Installation Step 4: Database Check
*/
function databaseCheck()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$error = false;
$this->skipThisStep(__FUNCTION__);
if (isset($this->session->databaseVersionOk)
&& $this->session->databaseVersionOk === true
) {
$view->databaseVersionOk = true;
} else {
$error = true;
}
if (isset($this->session->databaseCreated)
&& $this->session->databaseCreated === true
) {
Thomas Steur
a validé
$view->databaseName = Config::getInstance()->database['dbname'];
$view->databaseCreated = true;
} else {
$error = true;
}
try {
$db->checkClientVersion();
} catch (Exception $e) {
$view->clientVersionWarning = $e->getMessage();
$error = true;
}
if (!DbHelper::isDatabaseConnectionUTF8()) {
Thomas Steur
a validé
Config::getInstance()->database['charset'] = 'utf8';
Config::getInstance()->forceSave();
}
$view->showNextStep = true;
$this->session->currentStepDone = __FUNCTION__;
if ($error === false) {
$this->redirectToNextStep(__FUNCTION__);
}
}
/**
* Installation Step 5: Table Creation
*/
function tablesCreation()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
if (Common::getRequestVar('deleteTables', 0, 'int') == 1) {
$view->existingTablesDeleted = true;
// when the user decides to drop the tables then we dont skip the next steps anymore
// workaround ZF-1743
$tmp = $this->session->skipThisStep;
$tmp['firstWebsiteSetup'] = false;
$tmp['trackingCode'] = false;
$this->session->skipThisStep = $tmp;
}
$tablesInstalled = DbHelper::getTablesInstalled();
$view->tablesInstalled = '';
Thomas Steur
a validé
if (count($tablesInstalled) > 0) {
Thomas Steur
a validé
// we have existing tables
$view->tablesInstalled = implode(', ', $tablesInstalled);
$view->someTablesInstalled = true;
// remove monthly archive tables
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
$baseTablesInstalled = count($tablesInstalled) - count($archiveTables);
$minimumCountPiwikTables = 12;
Piwik::setUserHasSuperUserAccess();
if ($baseTablesInstalled >= $minimumCountPiwikTables &&
count(APISitesManager::getInstance()->getAllSitesId()) > 0 &&
count(APIUsersManager::getInstance()->getUsers()) > 0
) {
$view->showReuseExistingTables = true;
// when the user reuses the same tables we skip the website creation step
// workaround ZF-1743
$tmp = $this->session->skipThisStep;
$tmp['firstWebsiteSetup'] = true;
$tmp['trackingCode'] = true;
$this->session->skipThisStep = $tmp;
}
} else {
Updater::recordComponentSuccessfullyUpdated('core', Version::VERSION);
$view->tablesCreated = true;
$view->showNextStep = true;
}
$this->session->currentStepDone = __FUNCTION__;
Thomas Steur
a validé
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
function reuseTables()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
$view = new View(
'@Installation/reuseTables',
$this->getInstallationSteps(),
'tablesCreation'
);
Access::getInstance();
Piwik::setUserHasSuperUserAccess();
$updater = new Updater();
$componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
if (empty($componentsWithUpdateFile)) {
$this->session->currentStepDone = 'tablesCreation';
$this->redirectToNextStep('tablesCreation');
return '';
}
$oldVersion = Option::get('version_core');
$result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile);
$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;
$this->session->currentStepDone = 'tablesCreation';
return $view->render();
}
/**
* Installation Step 6: General Set-up (superuser login/password/email and subscriptions)
*/
function generalSetup()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
mattab
a validé
$form = new FormGeneralSetup();
if ($form->validate()) {
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
try {
$this->createSuperUser($form->getSubmitValue('login'),
$form->getSubmitValue('password'),
$form->getSubmitValue('email'));
$url = Config::getInstance()->General['api_service_url'];
$url .= '/1.0/subscribeNewsletter/';
$params = array(
'email' => $form->getSubmitValue('email'),
'security' => $form->getSubmitValue('subscribe_newsletter_security'),
'community' => $form->getSubmitValue('subscribe_newsletter_community'),
'url' => Url::getCurrentUrlWithoutQueryString(),
);
if ($params['security'] == '1'
|| $params['community'] == '1'
) {
if (!isset($params['security'])) {
$params['security'] = '0';
}
if (!isset($params['community'])) {
$params['community'] = '0';
}
$url .= '?' . http_build_query($params, '', '&');
try {
Http::sendHttpRequest($url, $timeout = 2);
} catch (Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
}
$this->redirectToNextStep(__FUNCTION__);
} catch (Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
$view->addForm($form);
}
/**
* Installation Step 7: Configure first web-site
*/
public function firstWebsiteSetup()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
mattab
a validé
$form = new FormFirstWebsiteSetup();
if (!isset($this->session->generalSetupSuccessMessage)) {
$view->displayGeneralSetupSuccess = true;
$this->session->generalSetupSuccessMessage = true;
}
$this->initObjectsToCallAPI();
if ($form->validate()) {
$name = Common::unsanitizeInputValue($form->getSubmitValue('siteName'));
$url = Common::unsanitizeInputValue($form->getSubmitValue('url'));
$ecommerce = (int)$form->getSubmitValue('ecommerce');
try {
Thomas Steur
a validé
$result = APISitesManager::getInstance()->addSite($name, $url, $ecommerce);
$this->session->site_idSite = $result;
$this->session->site_name = $name;
$this->session->site_url = $url;
$this->redirectToNextStep(__FUNCTION__);
} catch (Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
$view->addForm($form);
}
/**
* Installation Step 8: Display JavaScript tracking code
*/
public function trackingCode()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
'@Installation/trackingCode',
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
if (!isset($this->session->firstWebsiteSetupSuccessMessage)) {
$view->displayfirstWebsiteSetupSuccess = true;
$this->session->firstWebsiteSetupSuccessMessage = true;
}
$siteName = $this->session->site_name;
$idSite = $this->session->site_idSite;
// Load the Tracking code and help text from the SitesManager
$viewTrackingHelp = new \Piwik\View('@SitesManager/_displayJavascriptCode');
$viewTrackingHelp->displaySiteName = $siteName;
$viewTrackingHelp->jsTag = Piwik::getJavascriptCode($idSite, Url::getCurrentUrlWithoutFileName());
$viewTrackingHelp->idSite = $idSite;
$viewTrackingHelp->piwikUrl = Url::getCurrentUrlWithoutFileName();
$view->trackingHelp = $viewTrackingHelp->render();
$view->displaySiteName = $siteName;
$view->showNextStep = true;
$this->session->currentStepDone = __FUNCTION__;
}
/**
* Installation Step 9: Finished!
*/
public function finished()
{
$this->checkPreviousStepIsValid(__FUNCTION__);
mattab
a validé
$view = new View(
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep(__FUNCTION__);
Thomas Steur
a validé
if (!$this->isFinishedInstallation()) {
Thomas Steur
a validé
$this->markInstallationAsCompleted();
}
$view->showNextStep = false;
$this->session->currentStepDone = __FUNCTION__;
$this->session->unsetAll();
}
/**
* 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
* Piwik installation.
*
* This admin tab is only viewable by the Super User.
*/
public function systemCheckPage()
{
Thomas Steur
a validé
Piwik::checkUserHasSuperUserAccess();
$view = new View(
'@Installation/systemCheckPage',
$this->getInstallationSteps(),
__FUNCTION__
);
$this->setBasicVariablesView($view);
$view->duringInstall = false;
$this->setupSystemCheckView($view);
$infos = $view->infos;
$infos['extra'] = self::performAdminPageOnlySystemCheck();
$view->infos = $infos;
}
/**
* Instantiate access and log objects
*/
protected function initObjectsToCallAPI()
{
Piwik::setUserHasSuperUserAccess();
}
/**
* Write configuration file from session-store
*/
Thomas Steur
a validé
protected function createConfigFileIfNeeded($dbInfos)
$config = Config::getInstance();
Thomas Steur
a validé
try {
// expect exception since config.ini.php doesn't exist yet
Thomas Steur
a validé
} catch (Exception $e) {
if (!empty($this->session->general_infos)) {
$config->General = $this->session->general_infos;
}
}
Thomas Steur
a validé
$config->General['install_in_progress'] = 1;
$config->database = $dbInfos;
$config->forceSave();
unset($this->session->general_infos);
}
Thomas Steur
a validé
/**
* Write configuration file from session-store
*/
protected function markInstallationAsCompleted()
{
$config = Config::getInstance();
Thomas Steur
a validé
unset($config->General['install_in_progress']);
Thomas Steur
a validé
$config->forceSave();
}
/**
* Save language selection in session-store
*/
public function saveLanguage()
{
$language = Common::getRequestVar('language');
mattab
a validé
LanguagesManager::setLanguageForSession($language);
Url::redirectToReferrer();
/**
* Prints out the CSS for installer/updater
*
* During installation and update process, we load a minimal Less file.
* At this point Piwik may not be setup yet to write files in tmp/assets/
* so in this case we compile and return the string on every request.
*/
public function getBaseCss()
{
Benaka Moorthi
a validé
@header('Content-Type: text/css');
return AssetManager::getInstance()->getCompiledBaseCss()->getContent();
}
/**
* The previous step is valid if it is either
* - any step before (OK to go back)
* - the current step (case when validating a form)
* If step is invalid, then exit.
*
* @param string $currentStep Current step
*/
protected function checkPreviousStepIsValid($currentStep)
{
$error = false;
if (empty($this->session->currentStepDone)) {
$error = true;
} else if ($currentStep == 'finished' && $this->session->currentStepDone == 'finished') {
// ok to refresh this page or use language selector
Thomas Steur
a validé
} else if ($currentStep == 'reuseTables' && in_array($this->session->currentStepDone, array('tablesCreation', 'reuseTables'))) {
// this is ok, we cannot add 'reuseTables' to steps as it would appear in the menu otherwise
} else {
Thomas Steur
a validé
if ($this->isFinishedInstallation()) {
$error = true;
}
$steps = array_keys($this->steps);
// the currentStep
$currentStepId = array_search($currentStep, $steps);
// the step before
$previousStepId = array_search($this->session->currentStepDone, $steps);
// not OK if currentStepId > previous+1
if ($currentStepId > $previousStepId + 1) {
$error = true;
}
}
if ($error) {
mattab
a validé
\Piwik\Plugins\Login\Controller::clearSession();
$message = Piwik::translate('Installation_ErrorInvalidState',
'<a href=\'' . Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()) . '\'>',
'</a>')
);
Piwik::exitWithErrorMessage($message);
}
}
/**
* Redirect to next step
*
* @param string $currentStep Current step
* @return void
*/
protected function redirectToNextStep($currentStep)
{
$steps = array_keys($this->steps);
$this->session->currentStepDone = $currentStep;
$nextStep = $steps[1 + array_search($currentStep, $steps)];
Piwik::redirectToModule('Installation', $nextStep);
}
/**
* Skip this step (typically to mark the current function as completed)
*
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
*/
protected function skipThisStep($step)
{
$skipThisStep = $this->session->skipThisStep;
if (isset($skipThisStep[$step]) && $skipThisStep[$step]) {
$this->redirectToNextStep($step);
}
}
/**
* Extract host from URL
*
* @param string $url URL
*
* @return string|false
*/
protected function extractHost($url)
{
$urlParts = parse_url($url);
if (isset($urlParts['host']) && strlen($host = $urlParts['host'])) {
return $host;
}
return false;
}
/**
* Add trusted hosts
*/
protected function addTrustedHosts()
{
$trustedHosts = array();
// extract host from the request header
if (($host = $this->extractHost('http://' . Url::getHost())) !== false) {
$trustedHosts[] = $host;
}
// extract host from first web site
if (($host = $this->extractHost(urldecode($this->session->site_url))) !== false) {
$trustedHosts[] = $host;
}
$trustedHosts = array_unique($trustedHosts);
if (count($trustedHosts)) {
Thomas Steur
a validé
$general = Config::getInstance()->General;
$general['trusted_hosts'] = $trustedHosts;
Config::getInstance()->General = $general;
Config::getInstance()->forceSave();
}
}
/**
* Get system information
*/
public static function getSystemInformation()
{
global $piwik_minimumPHPVersion;
$minimumMemoryLimit = Config::getInstance()->General['minimum_memory_limit'];
$infos = array();
$infos['general_infos'] = array();
$directoriesToCheck = array();
// at install, need /config to be writable (so we can create config.ini.php)
$directoriesToCheck[] = '/config/';
}
$directoriesToCheck = array_merge($directoriesToCheck, array(
mattab
a validé
'/tmp/',
'/tmp/assets/',
'/tmp/cache/',
mattab
a validé
'/tmp/latest/',
'/tmp/logs/',
mattab
a validé
'/tmp/sessions/',
'/tmp/tcpdf/',
'/tmp/templates_c/',
mattab
a validé
));
$infos['directories'] = Filechecks::checkDirectoriesWritable($directoriesToCheck);
$infos['can_auto_update'] = Filechecks::canAutoUpdate();
self::initServerFilesForSecurity();
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
$infos['phpVersion_minimum'] = $piwik_minimumPHPVersion;
$infos['phpVersion'] = PHP_VERSION;
$infos['phpVersion_ok'] = version_compare($piwik_minimumPHPVersion, $infos['phpVersion']) === -1;
// critical errors
$extensions = @get_loaded_extensions();
$needed_extensions = array(
'zlib',
'SPL',
'iconv',
'Reflection',
);
$infos['needed_extensions'] = $needed_extensions;
$infos['missing_extensions'] = array();
foreach ($needed_extensions as $needed_extension) {
if (!in_array($needed_extension, $extensions)) {
$infos['missing_extensions'][] = $needed_extension;
}
}
$infos['pdo_ok'] = false;
if (in_array('PDO', $extensions)) {
$infos['pdo_ok'] = true;
}
$infos['adapters'] = Adapter::getAdapters();
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
$needed_functions = array(
'debug_backtrace',
'create_function',
'eval',
'gzcompress',
'gzuncompress',
'pack',
);
$infos['needed_functions'] = $needed_functions;
$infos['missing_functions'] = array();
foreach ($needed_functions as $needed_function) {
if (!self::functionExists($needed_function)) {
$infos['missing_functions'][] = $needed_function;
}
}
// warnings
$desired_extensions = array(
'json',
'libxml',
'dom',
'SimpleXML',
);
$infos['desired_extensions'] = $desired_extensions;
$infos['missing_desired_extensions'] = array();
foreach ($desired_extensions as $desired_extension) {
if (!in_array($desired_extension, $extensions)) {
$infos['missing_desired_extensions'][] = $desired_extension;
}
}
$desired_functions = array(
'set_time_limit',
'mail',
'parse_ini_file',
'glob',
);
$infos['desired_functions'] = $desired_functions;
$infos['missing_desired_functions'] = array();
foreach ($desired_functions as $desired_function) {
if (!self::functionExists($desired_function)) {
$infos['missing_desired_functions'][] = $desired_function;
}
}
$infos['openurl'] = Http::getTransportMethod();
$infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
$infos['hasMbstring'] = false;
$infos['multibyte_ok'] = true;
if (function_exists('mb_internal_encoding')) {
$infos['hasMbstring'] = true;
if (((int)ini_get('mbstring.func_overload')) != 0) {
$infos['multibyte_ok'] = false;
}
}
$serverSoftware = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
$infos['serverVersion'] = addslashes($serverSoftware);
$infos['serverOs'] = @php_uname();
$infos['serverTime'] = date('H:i:s');
$infos['registerGlobals_ok'] = ini_get('register_globals') == 0;
$infos['memoryMinimum'] = $minimumMemoryLimit;
$infos['memory_ok'] = true;
$infos['memoryCurrent'] = '';
$raised = SettingsServer::raiseMemoryLimitIfNecessary();
if (($memoryValue = SettingsServer::getMemoryLimitValue()) > 0) {
$infos['memoryCurrent'] = $memoryValue . 'M';
$infos['memory_ok'] = $memoryValue >= $minimumMemoryLimit;
}
$infos['isWindows'] = SettingsServer::isWindows();
$integrityInfo = Filechecks::getFileIntegrityInformation();
$infos['integrity'] = $integrityInfo[0];
$infos['integrityErrorMessages'] = array();
if (isset($integrityInfo[1])) {
if ($infos['integrity'] == false) {
$infos['integrityErrorMessages'][] = Piwik::translate('General_FileIntegrityWarningExplanation');
}
$infos['integrityErrorMessages'] = array_merge($infos['integrityErrorMessages'], array_slice($integrityInfo, 1));
}
$infos['timezone'] = SettingsServer::isTimezoneSupportEnabled();
$infos['tracker_status'] = Common::getRequestVar('trackerStatus', 0, 'int');
$infos['protocol'] = ProxyHeaders::getProtocolInformation();
if (!\Piwik\ProxyHttp::isHttps() && $infos['protocol'] !== null) {
$infos['general_infos']['assume_secure_protocol'] = '1';
}
if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
$infos['general_infos']['proxy_client_headers'] = $headers;
}
if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
$infos['general_infos']['proxy_host_headers'] = $headers;
}
// check if filesystem is NFS, if it is file based sessions won't work properly
$infos['is_nfs'] = Filesystem::checkIfFileSystemIsNFS();
return $infos;
}
/**
* @param $infos
* @return mixed
*/
public static function enrichSystemChecks($infos)
{
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// determine whether there are any errors/warnings from the checks done above
$infos['has_errors'] = false;
$infos['has_warnings'] = false;
if (in_array(0, $infos['directories']) // if a directory is not writable
|| !$infos['phpVersion_ok']
|| !empty($infos['missing_extensions'])
|| empty($infos['adapters'])
|| !empty($infos['missing_functions'])
) {
$infos['has_errors'] = true;
}
if (!$infos['can_auto_update']
|| !empty($infos['missing_desired_extensions'])
|| !$infos['gd_ok']
|| !$infos['multibyte_ok']
|| !$infos['registerGlobals_ok']
|| !$infos['memory_ok']
|| !empty($infos['integrityErrorMessages'])
|| !$infos['timezone'] // if timezone support isn't available
|| $infos['tracker_status'] != 0
|| $infos['is_nfs']
) {
$infos['has_warnings'] = true;
}
return $infos;
}
/**
* Test if function exists. Also handles case where function is disabled via Suhosin.
*
* @param string $functionName Function name
* @return bool True if function exists (not disabled); False otherwise.
*/
public static function functionExists($functionName)
{
// eval() is a language construct
if ($functionName == 'eval') {
// does not check suhosin.executor.eval.whitelist (or blacklist)
if (extension_loaded('suhosin')) {
return @ini_get("suhosin.executor.disable_eval") != "1";
}
return true;
}
$exists = function_exists($functionName);
if (extension_loaded('suhosin')) {
$blacklist = @ini_get("suhosin.executor.func.blacklist");
if (!empty($blacklist)) {
$blacklistFunctions = array_map('strtolower', array_map('trim', explode(',', $blacklist)));
return $exists && !in_array($functionName, $blacklistFunctions);
}
}