示例#1
0
 /**
  * Create user via AJAX
  * @param type $userParams
  */
 public function createUser()
 {
     $error = false;
     $errorMessage = '';
     if ($this->__isAjax()) {
         //check the parameters
         if (Nonce::verifyNonce($this->__LOGIN_FORM_NONCE_ID, Common::getRequestVar($this->__LOGIN_FORM_NONCE_FIELD_NAME))) {
             $userLogin = Common::getRequestVar('form_login');
             $userPassword = Common::getRequestVar('form_password');
             $userEmail = Common::getRequestVar('form_email');
             //check if the user already exists
             if (!$this->__checkUserExists($userLogin, $userEmail)) {
                 BKLoginAPI::getInstance()->createUser($userLogin, $userPassword, $userEmail);
                 //if there has been some error in API call, get the errors as well
                 $errorMessages = BKLoginAPI::getInstance()->getErrors();
                 if (!empty($errorMessages)) {
                     $error = true;
                     $errorMessage = implode(' ', $errorMessages);
                 }
             }
             //create the SSO login record for the user
             $this->model = new Model();
             $this->model->createSSOUserRecord(Common::getRequestVar('form_provider_name'), Common::getRequestVar('form_provider_user_id'));
         } else {
             $error = true;
             $errorMessage = 'The NONCE value is invalid';
         }
     }
     if (!$error) {
         $response = array('success' => true, 'code' => '200', 'reason' => null, 'data' => array());
     } else {
         $response = array('success' => false, 'code' => '403', 'reason' => $errorMessage, 'data' => array());
     }
     //return the response
     $this->__sendJSON($response);
 }
示例#2
0
 /**
  * Reset password action. Stores new password as hash and sends email
  * to confirm use.
  *
  * @param none
  */
 function resetPassword()
 {
     $infoMessage = null;
     $formErrors = null;
     $form = new FormResetPassword();
     if ($form->validate()) {
         $nonce = $form->getSubmitValue('form_nonce');
         if (Nonce::verifyNonce('Login.login', $nonce)) {
             $formErrors = $this->resetPasswordFirstStep($form);
             if (empty($formErrors)) {
                 $infoMessage = Piwik::translate('Login_ConfirmationLinkSent');
             }
         } else {
             $formErrors = array($this->getMessageExceptionNoAccess());
         }
     } else {
         // if invalid, display error
         $formData = $form->getFormData();
         $formErrors = $formData['errors'];
     }
     $view = new View('@Login/resetPassword');
     $view->infoMessage = $infoMessage;
     $view->formErrors = $formErrors;
     return $view->render();
 }
示例#3
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $view = new View('@CoreAdminHome/optOut');
     $view->trackVisits = $trackVisits;
     $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $view->language = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     return $view->render();
 }
示例#4
0
 protected function initPluginModification($nonceName)
 {
     Piwik::checkUserHasSuperUserAccess();
     $nonce = Common::getRequestVar('nonce', null, 'string');
     if (!Nonce::verifyNonce($nonceName, $nonce)) {
         throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch'));
     }
     Nonce::discardNonce($nonceName);
     $pluginName = Common::getRequestVar('pluginName', null, 'string');
     return $pluginName;
 }
示例#5
0
 public function setPluginSettings()
 {
     Piwik::checkUserIsNotAnonymous();
     Json::sendHeaderJSON();
     $nonce = Common::getRequestVar('nonce', null, 'string');
     if (!Nonce::verifyNonce(static::SET_PLUGIN_SETTINGS_NONCE, $nonce)) {
         return json_encode(array('result' => 'error', 'message' => $this->translator->translate('General_ExceptionNonceMismatch')));
     }
     $pluginsSettings = SettingsManager::getPluginSettingsForCurrentUser();
     try {
         foreach ($pluginsSettings as $pluginName => $pluginSetting) {
             foreach ($pluginSetting->getSettingsForCurrentUser() as $setting) {
                 $value = $this->findSettingValueFromRequest($pluginName, $setting->getKey());
                 if (!is_null($value)) {
                     $setting->setValue($value);
                 }
             }
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
         if (!empty($setting)) {
             $message = $setting->title . ': ' . $message;
         }
         $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
         return json_encode(array('result' => 'error', 'message' => $message));
     }
     try {
         foreach ($pluginsSettings as $pluginSetting) {
             $pluginSetting->save();
         }
     } catch (Exception $e) {
         return json_encode(array('result' => 'error', 'message' => $this->translator->translate('CoreAdminHome_PluginSettingsSaveFailed')));
     }
     Nonce::discardNonce(static::SET_PLUGIN_SETTINGS_NONCE);
     return json_encode(array('result' => 'success'));
 }
示例#6
0
 /**
  * @return View
  * @throws \Exception
  */
 public function getOptOutView()
 {
     if ($this->view) {
         return $this->view;
     }
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $dntFound = $this->getDoNotTrackHeaderChecker()->isDoNotTrackFound();
     $setCookieInNewWindow = Common::getRequestVar('setCookieInNewWindow', false, 'int');
     if ($setCookieInNewWindow) {
         $reloadUrl = Url::getCurrentQueryStringWithParametersModified(array('showConfirmOnly' => 1, 'setCookieInNewWindow' => 0));
     } else {
         $reloadUrl = false;
         $nonce = Common::getRequestVar('nonce', false);
         if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
             Nonce::discardNonce('Piwik_OptOut');
             IgnoreCookie::setIgnoreCookie();
             $trackVisits = !$trackVisits;
         }
     }
     $language = Common::getRequestVar('language', '');
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     $this->addQueryParameters(array('module' => 'CoreAdminHome', 'action' => 'optOut', 'language' => $lang, 'setCookieInNewWindow' => 1), false);
     $this->view = new View("@CoreAdminHome/optOut");
     $this->view->setXFrameOptions('allow');
     $this->view->dntFound = $dntFound;
     $this->view->trackVisits = $trackVisits;
     $this->view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $this->view->language = $lang;
     $this->view->showConfirmOnly = Common::getRequestVar('showConfirmOnly', false, 'int');
     $this->view->reloadUrl = $reloadUrl;
     $this->view->javascripts = $this->getJavascripts();
     $this->view->stylesheets = $this->getStylesheets();
     $this->view->title = $this->getTitle();
     $this->view->queryParameters = $this->getQueryParameters();
     return $this->view;
 }
 /**
  * Action to generate a new Google Authenticator secret for the current user
  *
  * @return string
  * @throws \Exception
  * @throws \Piwik\NoAccessException
  */
 public function regenerate()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = new View('@GoogleAuthenticator/regenerate');
     $this->setGeneralVariablesView($view);
     $googleAuth = new PHPGangsta\GoogleAuthenticator();
     $storage = new Storage(Piwik::getCurrentUserLogin());
     $secret = Common::getRequestVar('gasecret', '', 'string');
     $authCode = Common::getRequestVar('gaauthcode', '', 'string');
     $authCodeNonce = Common::getRequestVar('authCodeNonce', '', 'string');
     $title = Common::getRequestVar('gatitle', $storage->getTitle(), 'string');
     $description = Common::getRequestVar('gadescription', $storage->getDescription(), 'string');
     if (!empty($secret) && !empty($authCode) && Nonce::verifyNonce(self::AUTH_CODE_NONCE, $authCodeNonce) && $googleAuth->verifyCode($secret, $authCode, 2)) {
         $storage->setSecret($secret);
         $storage->setDescription($description);
         $storage->setTitle($title);
         $this->auth->setAuthCode($authCode);
         $this->auth->validateAuthCode();
         Url::redirectToUrl(Url::getCurrentUrlWithoutQueryString() . Url::getCurrentQueryStringWithParametersModified(array('action' => 'settings', 'activate' => '1')));
     }
     if (empty($secret)) {
         $secret = $googleAuth->createSecret(32);
     }
     $view->title = $title;
     $view->description = $description;
     $view->authCodeNonce = Nonce::getNonce(self::AUTH_CODE_NONCE);
     $view->newSecret = $secret;
     $view->googleAuthImage = $googleAuth->getQRCodeGoogleUrl($description, $secret, $title);
     return $view->render();
 }
示例#8
0
 private function getPluginNameIfNonceValid($nonceName)
 {
     $nonce = Common::getRequestVar('nonce', null, 'string');
     if (!Nonce::verifyNonce($nonceName, $nonce)) {
         throw new \Exception(Piwik::translate('General_ExceptionNonceMismatch'));
     }
     Nonce::discardNonce($nonceName);
     $pluginName = Common::getRequestVar('pluginName', null, 'string');
     if (!$this->pluginManager->isValidPluginName($pluginName)) {
         throw new Exception('Invalid plugin name');
     }
     return $pluginName;
 }
示例#9
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     // should not use self::renderTemplate since that uses setBasicVariablesView. this will cause
     // an error when setBasicVariablesAdminView is called, and MenuTop is requested (the idSite query
     // parameter is required)
     $view = new View("@CoreAdminHome/optOut");
     $view->setXFrameOptions('allow');
     $view->trackVisits = $trackVisits;
     $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $view->language = $lang;
     return $view->render();
 }
示例#10
0
    /**
     * Shows the "Track Visits" checkbox.
     */
    public function optOut()
    {
        $trackVisits = !IgnoreCookie::isIgnoreCookieFound();

        $dntChecker = new DoNotTrackHeaderChecker();
        $dntFound = $dntChecker->isDoNotTrackFound();

        $setCookieInNewWindow = Common::getRequestVar('setCookieInNewWindow', false, 'int');
        if ($setCookieInNewWindow) {
            $reloadUrl = Url::getCurrentQueryStringWithParametersModified(array(
                'showConfirmOnly' => 1,
                'setCookieInNewWindow' => 0,
            ));
        } else {
            $reloadUrl = false;

            $nonce = Common::getRequestVar('nonce', false);
            if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
                Nonce::discardNonce('Piwik_OptOut');
                IgnoreCookie::setIgnoreCookie();
                $trackVisits = !$trackVisits;
            }
        }

        $language = Common::getRequestVar('language', '');
        $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language)
            ? $language
            : LanguagesManager::getLanguageCodeForCurrentUser();

        // should not use self::renderTemplate since that uses setBasicVariablesView. this will cause
        // an error when setBasicVariablesAdminView is called, and MenuTop is requested (the idSite query
        // parameter is required)
        $view = new View("@CoreAdminHome/optOut");
        $view->setXFrameOptions('allow');
        $view->dntFound = $dntFound;
        $view->trackVisits = $trackVisits;
        $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
        $view->language = $lang;
        $view->isSafari = $this->isUserAgentSafari();
        $view->showConfirmOnly = Common::getRequestVar('showConfirmOnly', false, 'int');
        $view->reloadUrl = $reloadUrl;
        return $view->render();
    }
示例#11
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     return $this->renderTemplate('optOut', array('trackVisits' => $trackVisits, 'nonce' => Nonce::getNonce('Piwik_OptOut', 3600), 'language' => $lang));
 }
示例#12
-1
 /**
  * send email to Piwik team and display nice thanks
  * @throws Exception
  */
 function sendFeedback()
 {
     $email = Common::getRequestVar('email', '', 'string');
     $body = Common::getRequestVar('body', '', 'string');
     $category = Common::getRequestVar('category', '', 'string');
     $nonce = Common::getRequestVar('nonce', '', 'string');
     $view = new View('@Feedback/sendFeedback');
     $view->feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     try {
         $minimumBodyLength = 40;
         if (strlen($body) < $minimumBodyLength || strpos($email, 'probe@') !== false || strpos($body, '&lt;probe') !== false) {
             throw new Exception(Piwik::translate('Feedback_ExceptionBodyLength', array($minimumBodyLength)));
         }
         if (!Piwik::isValidEmailString($email)) {
             throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidEmail'));
         }
         if (preg_match('/https?:/i', $body)) {
             throw new Exception(Piwik::translate('Feedback_ExceptionNoUrls'));
         }
         if (!Nonce::verifyNonce('Feedback.sendFeedback', $nonce)) {
             throw new Exception(Piwik::translate('General_ExceptionNonceMismatch'));
         }
         Nonce::discardNonce('Feedback.sendFeedback');
         $mail = new Mail();
         $mail->setFrom(Common::unsanitizeInputValue($email));
         $mail->addTo($view->feedbackEmailAddress, 'Piwik Team');
         $mail->setSubject('[ Feedback form - Piwik ] ' . $category);
         $mail->setBodyText(Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n");
         @$mail->send();
     } catch (Exception $e) {
         $view->errorString = $e->getMessage();
         $view->message = $body;
     }
     return $view->render();
 }