diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-12-27 12:12:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-27 12:12:10 +0300 |
commit | cd8c762a3df4440e69c8fce1d407ef62f6f185a7 (patch) | |
tree | 7a269aa6c7f47dfe0288ea73778cd0a9418638bb /plugins/CorePluginsAdmin/Controller.php | |
parent | 3ce6d87aa1e8d772fb727413346f8e7426c38706 (diff) |
When safe mode is displayed, and Super User was not logged in already, let Super User display the full safe mode to troubleshoot further (#11082)
* When safe mode is displayed, and Super User was not logged in already, let Super User display the full safe mode to troubleshoot further
* meant for a different PR
* Catch exceptions during CSS/Less compiling
* when there's an error during Twig template processing, or during LESS css compiling, display the safe mode
* Deactivate plugin as super user when authenticated with i_am_super_user
* when user is not logged as Super User, Make deactivate plugin work by forwarding the i_am_super_user URL parameter
* Display plugin version in safe mode fixes https://github.com/piwik/piwik/issues/11043
* Added a text to indicate users to first disable third party plugins
* Updated UI test
* clarify that salt is a secret
* reuse helper method
* minor
* Catching PHP7 errors and making it work on php5
Diffstat (limited to 'plugins/CorePluginsAdmin/Controller.php')
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index 860cee7404..6d6006fdce 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\CorePluginsAdmin; use Exception; use Piwik\API\Request; use Piwik\Common; +use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Exception\MissingFilePermissionException; use Piwik\Filechecks; @@ -22,6 +23,7 @@ use Piwik\Plugin; use Piwik\Plugins\Marketplace\Marketplace; use Piwik\Plugins\Marketplace\Controller as MarketplaceController; use Piwik\Plugins\Marketplace\Plugins; +use Piwik\SettingsPiwik; use Piwik\Translation\Translator; use Piwik\Url; use Piwik\Version; @@ -296,22 +298,27 @@ class Controller extends Plugin\ControllerAdmin return $message; } - if (Common::isPhpCliMode()) { // TODO: I can't find how this will ever get called / safeMode is never set for Console + if (Common::isPhpCliMode()) { throw new Exception("Error: " . var_export($lastError, true)); } - $view = new View('@CorePluginsAdmin/safemode'); $view->lastError = $lastError; + $view->isAllowedToTroubleshootAsSuperUser = $this->isAllowedToTroubleshootAsSuperUser(); $view->isSuperUser = Piwik::hasUserSuperUserAccess(); $view->isAnonymousUser = Piwik::isUserIsAnonymous(); $view->plugins = $this->pluginManager->loadAllPluginsAndGetTheirInfo(); $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE); + $view->deactivateIAmSuperUserSalt = Common::getRequestVar('i_am_super_user', '', 'string'); $view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE); $view->emailSuperUser = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); $view->piwikVersion = Version::VERSION; $view->showVersion = !Common::getRequestVar('tests_hide_piwik_version', 0); $view->pluginCausesIssue = ''; + // When the CSS merger in StylesheetUIAssetMerger throws an exception, safe mode is displayed. + // This flag prevents an infinite loop where safemode would try to re-generate the cache buster which requires CSS merger.. + $view->disableCacheBuster(); + if (!empty($lastError['file'])) { preg_match('/piwik\/plugins\/(.*)\//', $lastError['file'], $matches); @@ -367,11 +374,13 @@ class Controller extends Plugin\ControllerAdmin public function deactivate($redirectAfter = true) { - $pluginName = $this->initPluginModification(static::DEACTIVATE_NONCE); - $this->dieIfPluginsAdminIsDisabled(); - - $this->pluginManager->deactivatePlugin($pluginName); - $this->redirectAfterModification($redirectAfter); + if($this->isAllowedToTroubleshootAsSuperUser()) { + Piwik::doAsSuperUser(function() use ($redirectAfter) { + $this->doDeactivatePlugin($redirectAfter); + }); + } else { + $this->doDeactivatePlugin($redirectAfter); + } } public function uninstall($redirectAfter = true) @@ -455,4 +464,34 @@ class Controller extends Plugin\ControllerAdmin } catch (Exception $e) {} } + /** + * Let Super User troubleshoot in safe mode, even when Login is broken, with this special trick + * + * @return bool + * @throws Exception + */ + protected function isAllowedToTroubleshootAsSuperUser() + { + $isAllowedToTroubleshootAsSuperUser = false; + $salt = SettingsPiwik::getSalt(); + if (!empty($salt)) { + $saltFromRequest = Common::getRequestVar('i_am_super_user', '', 'string'); + $isAllowedToTroubleshootAsSuperUser = ($salt == $saltFromRequest); + } + return $isAllowedToTroubleshootAsSuperUser; + } + + /** + * @param $redirectAfter + * @throws Exception + */ + protected function doDeactivatePlugin($redirectAfter) + { + $pluginName = $this->initPluginModification(static::DEACTIVATE_NONCE); + $this->dieIfPluginsAdminIsDisabled(); + + $this->pluginManager->deactivatePlugin($pluginName); + $this->redirectAfterModification($redirectAfter); + } + } |