public function index() { Piwik::checkUserIsNotAnonymous(); $view = new View('@MobileMessaging/index'); $view->isSuperUser = Piwik::hasUserSuperUserAccess(); $mobileMessagingAPI = API::getInstance(); $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement(); $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided(); $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement; $view->strHelpAddPhone = Piwik::translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik::translate('General_Settings'), Piwik::translate('MobileMessaging_SettingsMenu'))); if ($view->credentialSupplied && $view->accountManagedByCurrentUser) { $view->provider = $mobileMessagingAPI->getSMSProvider(); $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } $view->smsProviders = SMSProvider::$availableSMSProviders; // construct the list of countries from the lang files $countries = array(); foreach (Common::getCountriesList() as $countryCode => $continentCode) { if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { $countries[$countryCode] = array('countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode]); } } $view->countries = $countries; $view->defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader()); $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); $this->setBasicVariablesView($view); return $view->render(); }
/** * Mobile Messaging Settings tab : * - set delegated management * - provide & validate SMS API credential * - add & activate phone numbers * - check remaining credits */ public function index() { Piwik::checkUserIsNotAnonymous(); $view = new View('@MobileMessaging/index'); $this->setManageVariables($view); return $view->render(); }
/** * Sends feedback for a specific feature to the Piwik team or alternatively to the email address configured in the * config: "feedback_email_address". * * @param string $featureName The name of a feature you want to give feedback to. * @param bool|int $like Whether you like the feature or not * @param string|bool $message A message containing the actual feedback */ public function sendFeedbackForFeature($featureName, $like, $message = false) { Piwik::checkUserIsNotAnonymous(); Piwik::checkUserHasSomeViewAccess(); $featureName = $this->getEnglishTranslationForFeatureName($featureName); $likeText = 'Yes'; if (empty($like)) { $likeText = 'No'; } $body = sprintf("Feature: %s\nLike: %s\n", $featureName, $likeText, $message); $feedbackMessage = ""; if (!empty($message) && $message != 'undefined') { $feedbackMessage = sprintf("Feedback:\n%s\n", trim($message)); } $body .= $feedbackMessage ? $feedbackMessage : " \n"; $subject = sprintf("%s for %s %s", empty($like) ? "-1" : "+1", $featureName, empty($feedbackMessage) ? "" : "(w/ feedback)"); $this->sendMail($subject, $body); }
/** * 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(); }
/** * Sets the language for the user * * @param string $login * @param string $languageCode * @return bool */ public function setLanguageForUser($login, $languageCode) { Piwik::checkUserHasSuperUserAccessOrIsTheUser($login); Piwik::checkUserIsNotAnonymous(); if (!$this->isLanguageAvailable($languageCode)) { return false; } $this->getModel()->setLanguageForUser($login, $languageCode); return true; }
/** * @internal * @return array * @throws \Piwik\NoAccessException */ public function getUserSettings() { Piwik::checkUserIsNotAnonymous(); $userSettings = $this->settingsProvider->getAllUserSettings(); return $this->settingsMetadata->formatSettings($userSettings); }
public function setIgnoreCookie() { Piwik::checkUserHasSomeViewAccess(); Piwik::checkUserIsNotAnonymous(); $this->checkTokenInUrl(); IgnoreCookie::setIgnoreCookie(); Piwik::redirectToModule('UsersManager', 'userSettings', array('token_auth' => false)); }
private function checkCredentialManagementRights() { $this->getDelegatedManagement() ? Piwik::checkUserIsNotAnonymous() : Piwik::checkUserHasSuperUserAccess(); }
public function setIgnoreCookie() { Piwik::checkUserHasSomeViewAccess(); Piwik::checkUserIsNotAnonymous(); $salt = Common::getRequestVar('ignoreSalt', false, 'string'); if ($salt !== $this->getIgnoreCookieSalt()) { throw new Exception("Not authorized"); } IgnoreCookie::setIgnoreCookie(); Piwik::redirectToModule('UsersManager', 'userSettings', array('token_auth' => false)); }
public function sendReport($idReport, $period = false, $date = false) { Piwik::checkUserIsNotAnonymous(); $reports = $this->getReports($idSite = false, false, $idReport); $report = reset($reports); if ($report['period'] == 'never') { $report['period'] = 'day'; } if (!empty($period)) { $report['period'] = $period; } if (empty($date)) { $date = Date::now()->subPeriod(1, $report['period'])->toString(); } $language = \Piwik\Plugins\LanguagesManager\API::getInstance()->getLanguageForUser($report['login']); // generate report list($outputFilename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles) = $this->generateReport($idReport, $date, $language, self::OUTPUT_SAVE_ON_DISK, $report['period']); if (!file_exists($outputFilename)) { throw new Exception("The report file wasn't found in {$outputFilename}"); } $filename = basename($outputFilename); $handle = fopen($outputFilename, "r"); $contents = fread($handle, filesize($outputFilename)); fclose($handle); /** * Triggered when sending scheduled reports. * * Plugins that provide new scheduled report transport mediums should use this event to * send the scheduled report. * * @param string $reportType A string ID describing how the report is sent, eg, * `'sms'` or `'email'`. * @param array $report An array describing the scheduled report that is being * generated. * @param string $contents The contents of the scheduled report that was generated * and now should be sent. * @param string $filename The path to the file where the scheduled report has * been saved. * @param string $prettyDate A prettified date string for the data within the * scheduled report. * @param string $reportSubject A string describing what's in the scheduled * report. * @param string $reportTitle The scheduled report's given title (given by a Piwik user). * @param array $additionalFiles The list of additional files that should be * sent with this report. */ Piwik::postEvent(self::SEND_REPORT_EVENT, array($report['type'], $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles)); // Update flag in DB Db::get()->update(Common::prefixTable('report'), array('ts_last_sent' => Date::now()->getDatetime()), "idreport = " . $report['idreport']); // If running from piwik.php with debug, do not delete the PDF after sending the email if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) { @chmod($outputFilename, 0600); } }
/** * Returns true if user with given email (userEmail) is known in the database, or the Super User * * @param string $userEmail * @return bool true if the user is known */ public function userEmailExists($userEmail) { Piwik::checkUserIsNotAnonymous(); return $this->model->userEmailExists($userEmail); }
/** * Returns the first login name of an existing user that has the given email address. If no user can be found for * this user an error will be returned. * * @param string $userEmail * @return bool true if the user is known */ public function getUserLoginFromUserEmail($userEmail) { Piwik::checkUserIsNotAnonymous(); Piwik::checkUserHasSomeAdminAccess(); $this->checkUserEmailExists($userEmail); $user = $this->model->getUserByEmail($userEmail); // any user with some admin access is allowed to find any user by email, no need to filter by access here return $user['login']; }
private function checkPermission() { Piwik::checkUserIsNotAnonymous(); }
public function sendReport($idReport, $period = false, $date = false, $force = false) { Piwik::checkUserIsNotAnonymous(); $reports = $this->getReports($idSite = false, false, $idReport); $report = reset($reports); if ($report['period'] == 'never') { $report['period'] = 'day'; } if (!empty($period)) { $report['period'] = $period; } if (empty($date)) { $date = Date::now()->subPeriod(1, $report['period'])->toString(); } $language = \Piwik\Plugins\LanguagesManager\API::getInstance()->getLanguageForUser($report['login']); // generate report list($outputFilename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles) = $this->generateReport($idReport, $date, $language, self::OUTPUT_SAVE_ON_DISK, $report['period']); if (!file_exists($outputFilename)) { throw new Exception("The report file wasn't found in {$outputFilename}"); } $contents = file_get_contents($outputFilename); if (empty($contents)) { Log::warning("Scheduled report file '%s' exists but is empty!", $outputFilename); } /** * Triggered when sending scheduled reports. * * Plugins that provide new scheduled report transport mediums should use this event to * send the scheduled report. * * @param string $reportType A string ID describing how the report is sent, eg, * `'sms'` or `'email'`. * @param array $report An array describing the scheduled report that is being * generated. * @param string $contents The contents of the scheduled report that was generated * and now should be sent. * @param string $filename The path to the file where the scheduled report has * been saved. * @param string $prettyDate A prettified date string for the data within the * scheduled report. * @param string $reportSubject A string describing what's in the scheduled * report. * @param string $reportTitle The scheduled report's given title (given by a Piwik user). * @param array $additionalFiles The list of additional files that should be * sent with this report. * @param \Piwik\Period $period The period for which the report has been generated. * @param boolean $force A report can only be sent once per period. Setting this to true * will force to send the report even if it has already been sent. */ Piwik::postEvent(self::SEND_REPORT_EVENT, array($report['type'], $report, $contents, $filename = basename($outputFilename), $prettyDate, $reportSubject, $reportTitle, $additionalFiles, \Piwik\Period\Factory::build($report['period'], $date), $force)); // Update flag in DB $now = Date::now()->getDatetime(); $this->getModel()->updateReport($report['idreport'], array('ts_last_sent' => $now)); // If running from piwik.php with debug, do not delete the PDF after sending the email $tracker = new Tracker(); if (!$tracker->isDebugModeEnabled()) { @chmod($outputFilename, 0600); } }
/** * Sets the language for the user * * @param string $login * @param string $languageCode * @return bool */ public function setLanguageForUser($login, $languageCode) { Piwik::checkUserHasSuperUserAccessOrIsTheUser($login); Piwik::checkUserIsNotAnonymous(); if (!$this->isLanguageAvailable($languageCode)) { return false; } $paramsBind = array($login, $languageCode, $languageCode); Db::query('INSERT INTO ' . Common::prefixTable('user_language') . ' (login, language) VALUES (?,?) ON DUPLICATE KEY UPDATE language=?', $paramsBind); return true; }
protected function configureView($template) { Piwik::checkUserIsNotAnonymous(); $view = new View($template); $this->setBasicVariablesView($view); $this->displayWarningIfConfigFileNotWritable(); $view->errorMessage = ''; return $view; }
/** * Returns true if user with given email (userEmail) is known in the database, or the super user * * @param string $userEmail * @return bool true if the user is known */ public function userEmailExists($userEmail) { Piwik::checkUserIsNotAnonymous(); $count = Db::fetchOne("SELECT count(*)\n\t\t\t\t\t\t\t\tFROM " . Common::prefixTable("user") . "\n\t\t\t\t\t\t\t\tWHERE email = ?", $userEmail); return $count != 0 || Config::getInstance()->superuser['email'] == $userEmail; }
protected function configureView($template) { Piwik::checkUserIsNotAnonymous(); $view = new View($template); $this->setBasicVariablesView($view); // If user can manage plugins+themes, display a warning if config not writable if (CorePluginsAdmin::isPluginsAdminEnabled()) { $this->displayWarningIfConfigFileNotWritable(); } $view->errorMessage = ''; return $view; }
public function saveViewDataTableParameters() { Piwik::checkUserIsNotAnonymous(); $this->checkTokenInUrl(); $reportId = Common::getRequestVar('report_id', null, 'string'); $parameters = (array) Common::getRequestVar('parameters', null, 'json'); $login = Piwik::getCurrentUserLogin(); ViewDataTableManager::saveViewDataTableParameters($login, $reportId, $parameters); }
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' => Piwik::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); } } } foreach ($pluginsSettings as $pluginSetting) { $pluginSetting->save(); } } catch (Exception $e) { $message = html_entity_decode($e->getMessage(), ENT_QUOTES, 'UTF-8'); return json_encode(array('result' => 'error', 'message' => $message)); } Nonce::discardNonce(static::SET_PLUGIN_SETTINGS_NONCE); return json_encode(array('result' => 'success')); }
/** * Get Piwik version * @return string */ public function getPiwikVersion() { Piwik::checkUserHasSomeViewAccess(); Piwik::checkUserIsNotAnonymous(); return Version::VERSION; }