Beispiel #1
0
	function initAuthenticationObject($notification)
	{
		$auth = new Piwik_Login_Auth();
		Zend_Registry::set('auth', $auth);

		$action = Piwik::getAction();
		if(Piwik::getModule() === 'API'
			&& (empty($action) || $action == 'index'))
		{
			return;
		}

		$authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
		$authCookieExpiry = time() + Zend_Registry::get('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);
	}
Beispiel #2
0
 function recordGoals($visitorInformation, $action)
 {
     $location_country = isset($visitorInformation['location_country']) ? $visitorInformation['location_country'] : Piwik_Common::getCountry(Piwik_Common::getBrowserLanguage(), $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess']);
     $location_continent = isset($visitorInformation['location_continent']) ? $visitorInformation['location_continent'] : Piwik_Common::getContinent($location_country);
     $goal = array('idvisit' => $visitorInformation['idvisit'], 'idsite' => $visitorInformation['idsite'], 'visitor_idcookie' => $visitorInformation['visitor_idcookie'], 'server_time' => Piwik_Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']), 'visit_server_date' => $visitorInformation['visit_server_date'], 'location_country' => $location_country, 'location_continent' => $location_continent, 'visitor_returning' => $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_VISITOR_RETURNING));
     $referer_idvisit = $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_ID_VISIT);
     if ($referer_idvisit !== false) {
         $goal += array('referer_idvisit' => $referer_idvisit, 'referer_visit_server_date' => date("Y-m-d", $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TIMESTAMP)), 'referer_type' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE)), 'referer_name' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_NAME)), 'referer_keyword' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_KEYWORD)));
     }
     foreach ($this->convertedGoals as $convertedGoal) {
         printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $newGoal = $goal;
         $newGoal['idgoal'] = $convertedGoal['idgoal'];
         $newGoal['url'] = $convertedGoal['url'];
         $newGoal['revenue'] = $convertedGoal['revenue'];
         if (!is_null($action)) {
             $newGoal['idaction'] = $action->getIdAction();
             $newGoal['idlink_va'] = $action->getIdLinkVisitAction();
         }
         printDebug($newGoal);
         $fields = implode(", ", array_keys($newGoal));
         $bindFields = substr(str_repeat("?,", count($newGoal)), 0, -1);
         try {
             Piwik_Tracker::getDatabase()->query("INSERT INTO " . Piwik_Common::prefixTable('log_conversion') . "\t({$fields}) \n\t\t\t\t\tVALUES ({$bindFields}) ", array_values($newGoal));
         } catch (Exception $e) {
             if (strpos($e->getMessage(), '1062') !== false) {
                 // integrity violation when same visit converts to the same goal twice
                 printDebug("--> Goal already recorded for this (idvisit, idgoal)");
             } else {
                 throw $e;
             }
         }
         //$idlog_goal = Piwik_Tracker::getDatabase()->lastInsertId();
     }
 }
Beispiel #3
0
 /**
  * Update the cookie information.
  */
 protected function updateCookie()
 {
     printDebug("We manage the cookie...");
     if (isset($this->visitorInfo['referer_type']) && $this->visitorInfo['referer_type'] != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) {
         // if the setting is set to use only the first referer,
         // we don't update the cookie referer values if they are already set
         if (!Piwik_Tracker_Config::getInstance()->Tracker['use_first_referer_to_determine_goal_referer'] || $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE) == false) {
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE, $this->visitorInfo['referer_type']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_NAME, $this->visitorInfo['referer_name']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_KEYWORD, $this->visitorInfo['referer_keyword']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_ID_VISIT, $this->visitorInfo['idvisit']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_TIMESTAMP, $this->getCurrentTimestamp());
         }
     }
     // idcookie has been generated in handleNewVisit or we simply propagate the old value
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_IDVISITOR, $this->visitorInfo['visitor_idcookie']);
     // the last action timestamp is the current timestamp
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_TIMESTAMP_LAST_ACTION, $this->visitorInfo['visit_last_action_time']);
     // the first action timestamp is the timestamp of the first action of the current visit
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION, $this->visitorInfo['visit_first_action_time']);
     // the idvisit has been generated by mysql in handleNewVisit or simply propagated here
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_ID_VISIT, $this->visitorInfo['idvisit']);
     // the last action ID is the current exit idaction
     if (isset($this->visitorInfo['visit_exit_idaction'])) {
         $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_ID_LAST_ACTION, $this->visitorInfo['visit_exit_idaction']);
     }
     // for a new visit, we flag the visit with visitor_returning
     if (isset($this->visitorInfo['visitor_returning'])) {
         $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_VISITOR_RETURNING, $this->visitorInfo['visitor_returning']);
     }
     $this->cookie->save();
 }
Beispiel #4
0
 /**
  * Update the cookie information.
  */
 protected function setThirdPartyCookie()
 {
     if (!$this->shouldUseThirdPartyCookie()) {
         return;
     }
     printDebug("We manage the cookie...");
     // idcookie has been generated in handleNewVisit or we simply propagate the old value
     $this->cookie->set(0, bin2hex($this->visitorInfo['idvisitor']));
     $this->cookie->save();
 }
Beispiel #5
0
 /**
  * Authenticate user and initializes the session.
  * Listens to Login.initSession hook.
  *
  * @param Piwik_Event_Notification $notification  notification object
  * @throws Exception
  */
 function initSession($notification)
 {
     $info = $notification->getNotificationObject();
     $login = $info['login'];
     $md5Password = $info['md5Password'];
     $rememberMe = $info['rememberMe'];
     $tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
     $authCookieExpiry = $rememberMe ? time() + Piwik_Config::getInstance()->General['login_cookie_expire'] : 0;
     $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path'];
     $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     if (!$authResult->isValid()) {
         $cookie->delete();
         throw new Exception(Piwik_Translate('Login_LoginPasswordNotCorrect'));
     }
     $cookie->set('login', $login);
     $cookie->set('token_auth', $auth->getHashTokenAuth($login, $authResult->getTokenAuth()));
     $cookie->setSecure(Piwik::isHttps());
     $cookie->setHttpOnly(true);
     $cookie->save();
     @Piwik_Session::regenerateId();
     // remove password reset entry if it exists
     self::removePasswordResetInfo($login);
 }
 /**
  * Set the language for the session
  *
  * @param string $languageCode ISO language code
  */
 public static function setLanguageForSession($languageCode)
 {
     if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($languageCode)) {
         return false;
     }
     $cookieName = Zend_Registry::get('config')->General->language_cookie_name;
     $cookie = new Piwik_Cookie($cookieName, 0);
     $cookie->set('language', $languageCode);
     $cookie->save();
 }
Beispiel #7
0
 /**
  * Clear session information
  *
  * @param none
  * @return void
  */
 public static function clearSession()
 {
     $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
     $cookie = new Piwik_Cookie($authCookieName);
     $cookie->delete();
     Zend_Session::expireSessionCookie();
 }
Beispiel #8
0
 /**
  * Clear session information
  *
  * @param none
  * @return void
  */
 public static function clearSession()
 {
     $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
     $cookie = new Piwik_Cookie($authCookieName);
     $cookie->delete();
     Piwik_Session::expireSessionCookie();
 }