/** * send email to Piwik team and display nice thanks */ function sendFeedback() { $email = Piwik_Common::getRequestVar('email', '', 'string'); $body = Piwik_Common::getRequestVar('body', '', 'string'); $category = Piwik_Common::getRequestVar('category', '', 'string'); $nonce = Piwik_Common::getRequestVar('nonce', '', 'string'); $view = Piwik_View::factory('sent'); $view->feedbackEmailAddress = Zend_Registry::get('config')->General->feedback_email_address; try { $minimumBodyLength = 35; if (strlen($body) < $minimumBodyLength) { throw new Exception(Piwik_TranslateException('Feedback_ExceptionBodyLength', array($minimumBodyLength))); } if (!Piwik::isValidEmailString($email)) { throw new Exception(Piwik_TranslateException('UsersManager_ExceptionInvalidEmail')); } if (preg_match('/https?:/i', $body)) { throw new Exception(Piwik_TranslateException('Feedback_ExceptionNoUrls')); } if (!Piwik_Nonce::verifyNonce('Piwik_Feedback.sendFeedback', $nonce)) { throw new Exception(Piwik_TranslateException('General_ExceptionNonceMismatch')); } Piwik_Nonce::discardNonce('Piwik_Feedback.sendFeedback'); $mail = new Piwik_Mail(); $mail->setFrom(Piwik_Common::unsanitizeInputValue($email)); $mail->addTo($view->feedbackEmailAddress, 'Piwik Team'); $mail->setSubject('[ Feedback form - Piwik ] ' . $category); $mail->setBodyText(Piwik_Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Piwik_Version::VERSION . "\n" . 'IP: ' . Piwik_Common::getIpString() . "\n" . 'URL: ' . Piwik_Url::getReferer() . "\n"); @$mail->send(); } catch (Exception $e) { $view->ErrorString = $e->getMessage(); $view->message = $body; } echo $view->render(); }
/** * @dataProvider getAcceptableOriginsTestData * @group Core * @group Nonce */ public function test_getAcceptableOrigins($host, $expected) { Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 0; $_SERVER['HTTP_HOST'] = $host; Piwik_Config::getInstance()->General['trusted_hosts'] = array('example.com'); $this->assertEquals($expected, Piwik_Nonce::getAcceptableOrigins(), $host); }
public function test_getAcceptableOrigins() { Piwik::createConfigObject(); Piwik_Config::getInstance()->setTestEnvironment(); $tests = array('example.com' => array('http://example.com', 'https://example.com'), 'example.com:80' => array('http://example.com', 'https://example.com'), 'example.com:443' => array('http://example.com', 'https://example.com'), 'example.com:8080' => array('http://example.com', 'https://example.com', 'http://example.com:8080', 'https://example.com:8080')); foreach ($tests as $host => $expected) { $_SERVER['HTTP_HOST'] = $host; $this->assertEqual(Piwik_Nonce::getAcceptableOrigins(), $expected, $host); } }
public function generate() { Piwik::checkUserIsSuperUser(); $nonce = Piwik_Common::getRequestVar('form_nonce', '', 'string', $_POST); if(Piwik_Common::getRequestVar('choice', 'no') != 'yes' || !Piwik_Nonce::verifyNonce('Piwik_VisitorGenerator.generate', $nonce)) { Piwik::redirectToModule('VisitorGenerator', 'index'); } Piwik_Nonce::discardNonce('Piwik_VisitorGenerator.generate'); $daysToCompute = Piwik_Common::getRequestVar('daysToCompute', 1, 'int'); // get idSite from POST with fallback to GET $idSite = Piwik_Common::getRequestVar('idSite', false, 'int', $_GET); $idSite = Piwik_Common::getRequestVar('idSite', $idSite, 'int', $_POST); Piwik::setMaxExecutionTime(0); $timer = new Piwik_Timer; $time = time() - ($daysToCompute-1)*86400; // Update site.ts_created if we generate visits on days before the website was created $site = new Piwik_Site($idSite); $minGeneratedDate = Piwik_Date::factory($time); if($minGeneratedDate->isEarlier($site->getCreationDate())) { // direct access to the website table (bad practise but this is a debug / dev plugin) Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"), array('ts_created' => $minGeneratedDate->getDatetime()), "idsite = $idSite"); } $nbActionsTotal = 0; while($time <= time()) { $nbActionsTotalThisDay = $this->generateVisits($time, $idSite); $time += 86400; $nbActionsTotal += $nbActionsTotalThisDay; } // Init view $view = Piwik_View::factory('generate'); $this->setBasicVariablesView($view); $view->menu = Piwik_GetAdminMenu(); $view->assign('timer', $timer); $view->assign('days', $daysToCompute); $view->assign('nbActionsTotal', $nbActionsTotal); $view->assign('nbRequestsPerSec', round($nbActionsTotal / $timer->getTime(),0)); echo $view->render(); }
/** * Shows the "Track Visits" checkbox. */ public function optOut() { $trackVisits = !Piwik_Tracker_IgnoreCookie::isIgnoreCookieFound(); $nonce = Piwik_Common::getRequestVar('nonce', false); $language = Piwik_Common::getRequestVar('language', ''); if ($nonce !== false && Piwik_Nonce::verifyNonce('Piwik_OptOut', $nonce)) { Piwik_Nonce::discardNonce('Piwik_OptOut'); Piwik_Tracker_IgnoreCookie::setIgnoreCookie(); $trackVisits = !$trackVisits; } $view = Piwik_View::factory('optOut'); $view->trackVisits = $trackVisits; $view->nonce = Piwik_Nonce::getNonce('Piwik_OptOut', 3600); $view->language = Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($language) ? $language : Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); echo $view->render(); }
/** * @dataProvider getAcceptableOriginsTestData * @group Core * @group Nonce */ public function test_getAcceptableOrigins($host, $expected) { $_SERVER['HTTP_HOST'] = $host; $this->assertEquals($expected, Piwik_Nonce::getAcceptableOrigins(), $host); }
public function generate() { // Only admin is allowed to do this! Piwik::checkUserIsSuperUser(); $GET = $_GET; $POST = $_POST; $COOKIE = $_COOKIE; $REQUEST = $_REQUEST; $nonce = Piwik_Common::getRequestVar('form_nonce', '', 'string', $_POST); if (Piwik_Common::getRequestVar('choice', 'no') != 'yes' || !Piwik_Nonce::verifyNonce('Piwik_VisitorGenerator.generate', $nonce)) { Piwik::redirectToModule('VisitorGenerator', 'index'); } Piwik_Nonce::discardNonce('Piwik_VisitorGenerator.generate'); $minVisitors = Piwik_Common::getRequestVar('minVisitors', 20, 'int'); $maxVisitors = Piwik_Common::getRequestVar('maxVisitors', 100, 'int'); $nbActions = Piwik_Common::getRequestVar('nbActions', 10, 'int'); $daysToCompute = Piwik_Common::getRequestVar('daysToCompute', 1, 'int'); // get idSite from POST with fallback to GET $idSite = Piwik_Common::getRequestVar('idSite', false, 'int', $_GET); $idSite = Piwik_Common::getRequestVar('idSite', $idSite, 'int', $_POST); Piwik::setMaxExecutionTime(0); $loadedPlugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); $loadedPlugins = array_keys($loadedPlugins); // we have to unload the Provider plugin otherwise it tries to lookup the IP for a hostname, and there is no dns server here if (Piwik_PluginsManager::getInstance()->isPluginActivated('Provider')) { Piwik_PluginsManager::getInstance()->unloadPlugin('Provider'); } // we set the DO NOT load plugins so that the Tracker generator doesn't load the plugins we've just disabled. // if for some reasons you want to load the plugins, comment this line, and disable the plugin Provider in the plugins interface Piwik_PluginsManager::getInstance()->doNotLoadPlugins(); $generator = new Piwik_VisitorGenerator_Generator(); $generator->setMaximumUrlDepth(3); //$generator->disableProfiler(); $generator->setIdSite($idSite); $nbActionsTotal = 0; //$generator->emptyAllLogTables(); $generator->init(); $timer = new Piwik_Timer(); $startTime = time() - ($daysToCompute - 1) * 86400; // Update site.ts_created if we generate visits on days before the website was created $site = new Piwik_Site($idSite); $minGeneratedDate = Piwik_Date::factory($startTime); if ($minGeneratedDate->isEarlier($site->getCreationDate())) { // direct access to the website table (bad practise but this is a debug / dev plugin) Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"), array('ts_created' => $minGeneratedDate->getDatetime()), "idsite = {$idSite}"); } $dates = array(); while ($startTime <= time()) { $visitors = rand($minVisitors, $maxVisitors); $actions = $nbActions; $generator->setTimestampToUse($startTime); $nbActionsTotalThisDay = $generator->generate($visitors, $actions); $actionsPerVisit = round($nbActionsTotalThisDay / $visitors); $date = array(); $date['visitors'] = $visitors; $date['actionsPerVisit'] = $actionsPerVisit; $date['startTime'] = $startTime; $dates[] = $date; $startTime += 86400; $nbActionsTotal += $nbActionsTotalThisDay; //sleep(1); } $generator->end(); // Recover all super globals $_GET = $GET; $_POST = $POST; $_COOKIE = $COOKIE; $_REQUEST = $REQUEST; // Reload plugins Piwik_PluginsManager::getInstance()->loadPlugins($loadedPlugins); // Init view $view = Piwik_View::factory('generate'); $this->setBasicVariablesView($view); $view->menu = Piwik_GetAdminMenu(); $view->assign('dates', $dates); $view->assign('timer', $timer); $view->assign('nbActionsTotal', $nbActionsTotal); $view->assign('nbRequestsPerSec', round($nbActionsTotal / $timer->getTime(), 0)); echo $view->render(); }
/** * Reset password form. Enter new password here. * * @param none * @return void */ function resetPassword() { self::checkForceSslLogin(); $messageNoAccess = null; $form = new Piwik_Login_FormResetPassword(); if ($form->validate()) { $nonce = $form->getSubmitValue('form_nonce'); if (Piwik_Nonce::verifyNonce('Piwik_Login.login', $nonce)) { $loginMail = $form->getSubmitValue('form_login'); $token = $form->getSubmitValue('form_token'); $password = $form->getSubmitValue('form_password'); $messageNoAccess = $this->resetPasswordFormValidated($loginMail, $token, $password); } else { $messageNoAccess = $this->getMessageExceptionNoAccess(); } } $view = Piwik_View::factory('resetPassword'); $view->AccessErrorString = $messageNoAccess; $view->forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login; $view->addForm($form); $this->configureView($view); echo $view->render(); }
/** * Reset password action. Stores new password as hash and sends email * to confirm use. * * @param none * @return void */ function resetPassword() { self::checkForceSslLogin(); $infoMessage = null; $formErrors = null; $form = new Piwik_Login_FormResetPassword(); if ($form->validate()) { $nonce = $form->getSubmitValue('form_nonce'); if (Piwik_Nonce::verifyNonce('Piwik_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 = Piwik_View::factory('message'); $view->infoMessage = $infoMessage; $view->formErrors = $formErrors; echo $view->render(); }