예제 #1
0
 /**
  * Returns the current AdminMenu name
  *
  * @return boolean
  */
 public function getCurrentAdminMenuName()
 {
     $menu = MenuAdmin::getInstance()->getMenu();
     $currentModule = Piwik::getModule();
     $currentAction = Piwik::getAction();
     foreach ($menu as $submenu) {
         foreach ($submenu as $subMenuName => $parameters) {
             if (strpos($subMenuName, '_') !== 0 && $parameters['_url']['module'] == $currentModule && $parameters['_url']['action'] == $currentAction) {
                 return $subMenuName;
             }
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Initializes the authentication object.
  * Listens to Request.initAuthenticationObject hook.
  */
 function initAuthenticationObject($allowCookieAuthentication = false)
 {
     $auth = new Auth();
     \Piwik\Registry::set('auth', $auth);
     $action = Piwik::getAction();
     if (Piwik::getModule() === 'API' && (empty($action) || $action == 'index') && $allowCookieAuthentication !== true) {
         return;
     }
     $authCookieName = Config::getInstance()->General['login_cookie_name'];
     $authCookieExpiry = 0;
     $authCookiePath = Config::getInstance()->General['login_cookie_path'];
     $authCookie = new Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     $defaultLogin = '******';
     $defaultTokenAuth = 'anonymous';
     if ($authCookie->isCookieFound()) {
         $defaultLogin = $authCookie->get('login');
         $defaultTokenAuth = $authCookie->get('token_auth');
     }
     $auth->setLogin($defaultLogin);
     $auth->setTokenAuth($defaultTokenAuth);
 }
예제 #3
0
 public function runUpdaterAndExit($doDryRun = null)
 {
     $updater = new Updater();
     $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
     if (empty($componentsWithUpdateFile)) {
         throw new NoUpdatesFoundException("Everything is already up to date.");
     }
     SettingsServer::setMaxExecutionTime(0);
     $cli = Common::isPhpCliMode() ? '_cli' : '';
     $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli;
     $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli;
     $viewWelcome = new View($welcomeTemplate);
     $this->addCustomLogoInfo($viewWelcome);
     $viewDone = new View($doneTemplate);
     $this->addCustomLogoInfo($viewDone);
     $doExecuteUpdates = Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1;
     if (is_null($doDryRun)) {
         $doDryRun = !$doExecuteUpdates;
     }
     if ($doDryRun) {
         $viewWelcome->queries = $updater->getSqlQueriesToExecute();
         $viewWelcome->isMajor = $updater->hasMajorDbUpdate();
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         return $viewWelcome->render();
     }
     // CLI
     if (Common::isPhpCliMode()) {
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         $output = $viewWelcome->render();
         // Proceed with upgrade in CLI only if user specifically asked for it, or if running console command
         $isUpdateRequested = Common::isRunningConsoleCommand() || Piwik::getModule() == 'CoreUpdater';
         if (!$this->coreError && $isUpdateRequested) {
             $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
             $output .= $viewDone->render();
         }
         return $output;
     }
     // Web
     if ($doExecuteUpdates) {
         $this->warningMessages = array();
         $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
         $this->redirectToDashboardWhenNoError($updater);
         return $viewDone->render();
     }
     exit;
 }
 protected function handleSSLRedirection()
 {
     // Specifically disable for the opt out iframe
     if (Piwik::getModule() == 'CoreAdminHome' && Piwik::getAction() == 'optOut') {
         return;
     }
     // Disable Https for VisitorGenerator
     if (Piwik::getModule() == 'VisitorGenerator') {
         return;
     }
     if (Common::isPhpCliMode()) {
         return;
     }
     // Only enable this feature after Piwik is already installed
     if (!SettingsPiwik::isPiwikInstalled()) {
         return;
     }
     // proceed only when force_ssl = 1
     if (!SettingsPiwik::isHttpsForced()) {
         return;
     }
     Url::redirectToHttps();
 }
예제 #5
0
파일: View.php 프로젝트: diosmosis/piwik
 /**
  * Renders the current view. Also sends the stored 'Content-Type' HTML header.
  * See {@link setContentType()}.
  *
  * @return string Generated template.
  */
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentAction = Piwik::getAction();
         $this->url = Common::sanitizeInputValue(Url::getCurrentUrl());
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsAnonymous = Piwik::isUserIsAnonymous();
         $this->userIsSuperUser = Piwik::hasUserSuperUserAccess();
         $this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
         $this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
         $this->isWidget = Common::getRequestVar('widget', 0, 'int');
         $piwikAds = StaticContainer::get('Piwik\\ProfessionalServices\\Advertising');
         $this->areAdsForProfessionalServicesEnabled = $piwikAds->areAdsForProfessionalServicesEnabled();
         if (Development::isEnabled()) {
             $cacheBuster = rand(0, 10000);
         } else {
             $cacheBuster = UIAssetCacheBuster::getInstance()->piwikVersionBasedCacheBuster();
         }
         $this->cacheBuster = $cacheBuster;
         $this->loginModule = Piwik::getLoginPluginName();
         $user = APIUsersManager::getInstance()->getUser($this->userLogin);
         $this->userAlias = $user['alias'];
     } catch (Exception $e) {
         Log::debug($e);
         // can fail, for example at installation (no plugin loaded yet)
     }
     ProxyHttp::overrideCacheControlHeaders('no-store');
     Common::sendHeader('Content-Type: ' . $this->contentType);
     // always sending this header, sometimes empty, to ensure that Dashboard embed loads
     // - when calling sendHeader() multiple times, the last one prevails
     Common::sendHeader('X-Frame-Options: ' . (string) $this->xFrameOptions);
     return $this->renderTwigTemplate();
 }
예제 #6
0
 protected function runUpdaterAndExit()
 {
     $updater = new Updater();
     $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
     if (empty($componentsWithUpdateFile)) {
         Piwik::redirectToModule('CoreHome');
     }
     SettingsServer::setMaxExecutionTime(0);
     $cli = Common::isPhpCliMode() ? '_cli' : '';
     $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli;
     $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli;
     $viewWelcome = new View($welcomeTemplate);
     $viewDone = new View($doneTemplate);
     if (Common::isPhpCliMode()) {
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         $output = $viewWelcome->render();
         if (!$this->coreError && Piwik::getModule() == 'CoreUpdater') {
             $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
             $output .= $viewDone->render();
         }
         return $output;
     } else {
         if (Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1) {
             $this->warningMessages = array();
             $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
             $this->redirectToDashboardWhenNoError($updater);
             return $viewDone->render();
         } else {
             $viewWelcome->queries = $updater->getSqlQueriesToExecute();
             $viewWelcome->isMajor = $updater->hasMajorDbUpdate();
             $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
             return $viewWelcome->render();
         }
     }
     exit;
 }
예제 #7
0
파일: Piwik.php 프로젝트: GovanifY/piwik
 /**
  * Returns the plugin currently being used to display the page
  *
  * @return Plugin
  */
 public static function getCurrentPlugin()
 {
     return \Piwik\Plugin\Manager::getInstance()->getLoadedPlugin(Piwik::getModule());
 }
예제 #8
0
파일: Login.php 프로젝트: hichnik/piwik
 protected static function isModuleIsAPI()
 {
     return Piwik::getModule() === 'API' && (Piwik::getAction() == '' || Piwik::getAction() == 'index');
 }
예제 #9
0
파일: View.php 프로젝트: brienomatty/elmsln
 /**
  * Renders the current view. Also sends the stored 'Content-Type' HTML header.
  * See {@link setContentType()}.
  *
  * @return string Generated template.
  */
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentAction = Piwik::getAction();
         $this->url = Common::sanitizeInputValue(Url::getCurrentUrl());
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsSuperUser = Piwik::hasUserSuperUserAccess();
         $this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
         $this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
         $this->isWidget = Common::getRequestVar('widget', 0, 'int');
         $this->cacheBuster = UIAssetCacheBuster::getInstance()->piwikVersionBasedCacheBuster();
         $this->loginModule = Piwik::getLoginPluginName();
         $user = APIUsersManager::getInstance()->getUser($this->userLogin);
         $this->userAlias = $user['alias'];
     } catch (Exception $e) {
         // can fail, for example at installation (no plugin loaded yet)
     }
     try {
         $this->totalTimeGeneration = Registry::get('timer')->getTime();
         $this->totalNumberOfQueries = Profiler::getQueryCount();
     } catch (Exception $e) {
         $this->totalNumberOfQueries = 0;
     }
     ProxyHttp::overrideCacheControlHeaders('no-store');
     @header('Content-Type: ' . $this->contentType);
     // always sending this header, sometimes empty, to ensure that Dashboard embed loads (which could call this header() multiple times, the last one will prevail)
     @header('X-Frame-Options: ' . (string) $this->xFrameOptions);
     return $this->renderTwigTemplate();
 }
예제 #10
0
 /**
  * Renders the current view. Also sends the stored 'Content-Type' HTML header.
  * See {@link setContentType()}.
  *
  * @return string Generated template.
  */
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentAction = Piwik::getAction();
         $userLogin = Piwik::getCurrentUserLogin();
         $this->userLogin = $userLogin;
         $count = SettingsPiwik::getWebsitesCountToDisplay();
         $sites = APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($count);
         usort($sites, function ($site1, $site2) {
             return strcasecmp($site1["name"], $site2["name"]);
         });
         $this->sites = $sites;
         $this->url = Common::sanitizeInputValue(Url::getCurrentUrl());
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsSuperUser = Piwik::isUserIsSuperUser();
         $this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
         $this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
         $this->isWidget = Common::getRequestVar('widget', 0, 'int');
         if (Config::getInstance()->General['autocomplete_min_sites'] <= count($sites)) {
             $this->show_autocompleter = true;
         } else {
             $this->show_autocompleter = false;
         }
         $this->loginModule = Piwik::getLoginPluginName();
         $user = APIUsersManager::getInstance()->getUser($userLogin);
         $this->userAlias = $user['alias'];
     } catch (Exception $e) {
         // can fail, for example at installation (no plugin loaded yet)
     }
     try {
         $this->totalTimeGeneration = Registry::get('timer')->getTime();
         $this->totalNumberOfQueries = Profiler::getQueryCount();
     } catch (Exception $e) {
         $this->totalNumberOfQueries = 0;
     }
     ProxyHttp::overrideCacheControlHeaders('no-store');
     @header('Content-Type: ' . $this->contentType);
     // always sending this header, sometimes empty, to ensure that Dashboard embed loads (which could call this header() multiple times, the last one will prevail)
     @header('X-Frame-Options: ' . (string) $this->xFrameOptions);
     return $this->renderTwigTemplate();
 }
 /**
  * init the authentification object
  *
  * @return	void
  */
 function initAuthenticationObject()
 {
     $config = \Piwik\Config::getInstance();
     $auth = new \Piwik\Plugins\TYPO3Login\Auth();
     StaticContainer::getContainer()->set('Piwik\\Auth', $auth);
     $action = \Piwik\Piwik::getAction();
     if (\Piwik\Piwik::getModule() === 'API' && (empty($action) || $action == 'index')) {
         return;
     }
     $authCookieName = $config->General['login_cookie_name'];
     $authCookieExpiry = time() + $config->General['login_cookie_expire'];
     $authCookie = new \Piwik\Cookie($authCookieName, $authCookieExpiry);
     $defaultLogin = '******';
     $defaultTokenAuth = 'anonymous';
     if ($authCookie->isCookieFound()) {
         $defaultLogin = $authCookie->get('login');
         $defaultTokenAuth = $authCookie->get('token_auth');
     }
     $auth->setLogin($defaultLogin);
     $auth->setTokenAuth($defaultTokenAuth);
 }