예제 #1
0
 function activate()
 {
     Piwik::checkUserIsSuperUser();
     $pluginName = Piwik_Common::getRequestVar('pluginName', null, 'string');
     Piwik_PluginsManager::getInstance()->activatePlugin($pluginName);
     Piwik_Url::redirectToUrl('index.php?module=CorePluginsAdmin');
 }
예제 #2
0
 protected function authenticateAndRedirect($login, $md5Password, $urlToRedirect)
 {
     $tokenAuth = Piwik_UsersManager_API::getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     if ($authResult->isValid()) {
         $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
         $authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
         $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
         $cookie->set('login', $login);
         $cookie->set('token_auth', $authResult->getTokenAuth());
         $cookie->save();
         $urlToRedirect = htmlspecialchars_decode($urlToRedirect);
         Piwik_Url::redirectToUrl($urlToRedirect);
     }
     return false;
 }
예제 #3
0
 /**
  * returns false if the URL to redirect to is already this URL
  */
 public static function redirectToModule($newModule, $newAction = '')
 {
     $currentModule = self::getModule();
     $currentAction = self::getAction();
     if ($currentModule != $newModule || $currentAction != $newAction) {
         $newUrl = 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => $newModule, 'action' => $newAction));
         Piwik_Url::redirectToUrl($newUrl);
     }
     return false;
 }
예제 #4
0
 /**
  * Redirect to module (and action)
  *
  * @param string $newModule Target module
  * @param string $newAction Target action
  * @param array $parameters Parameters to modify in the URL
  * @return bool false if the URL to redirect to is already this URL
  */
 public static function redirectToModule($newModule, $newAction = '', $parameters = array())
 {
     $newUrl = 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => $newModule, 'action' => $newAction) + $parameters);
     Piwik_Url::redirectToUrl($newUrl);
 }
예제 #5
0
 /**
  * Authenticate user and password.  Redirect if successful.
  *
  * @param string $login (user name)
  * @param string $md5Password (md5 hash of password)
  * @param string $urlToRedirect (URL to redirect to, if successfully authenticated)
  * @return string (failure message if unable to authenticate)
  */
 protected function authenticateAndRedirect($login, $md5Password, $urlToRedirect)
 {
     $tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     if (!$authResult->isValid()) {
         return Piwik_Translate('Login_LoginPasswordNotCorrect');
     }
     $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
     $authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
     $authCookiePath = Zend_Registry::get('config')->General->login_cookie_path;
     $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     $cookie->set('login', $login);
     $cookie->set('token_auth', $authResult->getTokenAuth());
     $cookie->save();
     Zend_Session::regenerateId();
     Piwik_Url::redirectToUrl($urlToRedirect);
 }
예제 #6
0
 /**
  * Check force_ssl_login and redirect if connection isn't secure and not using a reverse proxy
  *
  * @param none
  * @return void
  */
 protected function checkForceSslLogin()
 {
     $forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login;
     if ($forceSslLogin) {
         if (!Piwik::isHttps()) {
             $url = 'https://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryString();
             Piwik_Url::redirectToUrl($url);
         }
     }
 }
예제 #7
0
 /**
  * Check force_ssl_login and redirect if connection isn't secure and not using a reverse proxy
  *
  * @param none
  * @return void
  */
 protected function checkForceSslLogin()
 {
     $forceSslLogin = Piwik_Config::getInstance()->General['force_ssl_login'];
     if ($forceSslLogin && !Piwik::isHttps()) {
         $url = 'https://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryString();
         Piwik_Url::redirectToUrl($url);
     }
 }
 /**
  * Must be called before dispatch()
  * - checks that directories are writable,
  * - loads the configuration file,
  * - loads the plugin, 
  * - inits the DB connection,
  * - etc.
  */
 function init()
 {
     static $initialized = false;
     if ($initialized) {
         return;
     }
     $initialized = true;
     try {
         Zend_Registry::set('timer', new Piwik_Timer());
         $directoriesToCheck = array('/tmp/', '/tmp/templates_c/', '/tmp/cache/', '/tmp/assets/', '/tmp/tcpdf/');
         Piwik::checkDirectoriesWritableOrDie($directoriesToCheck);
         Piwik_Common::assignCliParametersToRequest();
         Piwik_Translate::getInstance()->loadEnglishTranslation();
         $exceptionToThrow = false;
         try {
             Piwik::createConfigObject();
         } catch (Exception $e) {
             Piwik_PostEvent('FrontController.NoConfigurationFile', $e, $info = array(), $pending = true);
             $exceptionToThrow = $e;
         }
         if (Piwik_Session::isFileBasedSessions()) {
             Piwik_Session::start();
         }
         if (Piwik_Config::getInstance()->General['maintenance_mode'] == 1 && !Piwik_Common::isPhpCliMode()) {
             $format = Piwik_Common::getRequestVar('format', '');
             $exception = new Exception("Piwik is in scheduled maintenance. Please come back later.");
             if (empty($format)) {
                 throw $exception;
             }
             $response = new Piwik_API_ResponseBuilder($format);
             echo $response->getResponseException($exception);
             exit;
         }
         if (!Piwik_Common::isPhpCliMode() && Piwik_Config::getInstance()->General['force_ssl'] == 1 && !Piwik::isHttps()) {
             $url = Piwik_Url::getCurrentUrl();
             $url = str_replace("http://", "https://", $url);
             Piwik_Url::redirectToUrl($url);
         }
         $pluginsManager = Piwik_PluginsManager::getInstance();
         $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
         $pluginsManager->loadPlugins($pluginsToLoad);
         if ($exceptionToThrow) {
             throw $exceptionToThrow;
         }
         try {
             Piwik::createDatabaseObject();
         } catch (Exception $e) {
             if (self::shouldRethrowException()) {
                 throw $e;
             }
             Piwik_PostEvent('FrontController.badConfigurationFile', $e, $info = array(), $pending = true);
             throw $e;
         }
         Piwik::createLogObject();
         // creating the access object, so that core/Updates/* can enforce Super User and use some APIs
         Piwik::createAccessObject();
         Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen');
         Piwik_PluginsManager::getInstance()->installLoadedPlugins();
         Piwik::install();
         // ensure the current Piwik URL is known for later use
         if (method_exists('Piwik', 'getPiwikUrl')) {
             $host = Piwik::getPiwikUrl();
         }
         Piwik_PostEvent('FrontController.initAuthenticationObject');
         try {
             $authAdapter = Zend_Registry::get('auth');
         } catch (Exception $e) {
             throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?\n\t\t\t\t\t\t\t\t\t<br />You can activate the plugin by adding:<br />\n\t\t\t\t\t\t\t\t\t<code>Plugins[] = Login</code><br />\n\t\t\t\t\t\t\t\t\tunder the <code>[Plugins]</code> section in your config/config.ini.php");
         }
         Zend_Registry::get('access')->reloadAccess($authAdapter);
         Piwik::raiseMemoryLimitIfNecessary();
         Piwik_Translate::getInstance()->reloadLanguage();
         $pluginsManager->postLoadPlugins();
         Piwik_PostEvent('FrontController.checkForUpdates');
     } catch (Exception $e) {
         if (self::shouldRethrowException()) {
             throw $e;
         }
         Piwik_ExitWithMessage($e->getMessage(), false, true);
     }
     //		Piwik::log('End FrontController->init() - Request: '. var_export($_REQUEST, true));
 }
예제 #9
0
 protected function handleSSLRedirection()
 {
     if (!Piwik_Common::isPhpCliMode() && Piwik_Config::getInstance()->General['force_ssl'] == 1 && !Piwik::isHttps() && !(Piwik_Common::getRequestVar('module', '') == 'CoreAdminHome' && Piwik_Common::getRequestVar('action', '') == 'optOut')) {
         $url = Piwik_Url::getCurrentUrl();
         $url = str_replace("http://", "https://", $url);
         Piwik_Url::redirectToUrl($url);
     }
 }