public function safemode($lastError = array()) { if (empty($lastError)) { $lastError = array('message' => Common::getRequestVar('error_message', null, 'string'), 'file' => Common::getRequestVar('error_file', null, 'string'), 'line' => Common::getRequestVar('error_line', null, 'integer')); } $outputFormat = Common::getRequestVar('format', 'html', 'string'); $outputFormat = strtolower($outputFormat); if (!empty($outputFormat) && 'html' !== $outputFormat) { $errorMessage = $lastError['message']; if (Piwik::isUserIsAnonymous()) { $errorMessage = 'A fatal error occurred.'; } $response = new \Piwik\API\ResponseBuilder($outputFormat); $message = $response->getResponseException(new Exception($errorMessage)); return $message; } $view = new View('@CorePluginsAdmin/safemode'); $view->lastError = $lastError; $view->isSuperUser = Piwik::isUserIsSuperUser(); $view->isAnonymousUser = Piwik::isUserIsAnonymous(); $view->plugins = Plugin\Manager::getInstance()->returnLoadedPluginsInfo(); $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE); $view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE); $view->emailSuperUser = Piwik::getSuperUserEmail(); $view->piwikVersion = Version::VERSION; $view->showVersion = !Common::getRequestVar('tests_hide_piwik_version', 0); $view->pluginCausesIssue = ''; if (!empty($lastError['file'])) { preg_match('/piwik\\/plugins\\/(.*)\\//', $lastError['file'], $matches); if (!empty($matches[1])) { $view->pluginCausesIssue = $matches[1]; } } return $view->render(); }
/** * Get user information * * @param string $loginMail user login or email address * @return array ("login" => '...', "email" => '...', "password" => '...') or null, if user not found */ protected function getUserInformation($loginMail) { Piwik::setUserIsSuperUser(); $user = null; if ($loginMail == Piwik::getSuperUserEmail() || $loginMail == Config::getInstance()->superuser['login']) { $user = array('login' => Config::getInstance()->superuser['login'], 'email' => Piwik::getSuperUserEmail(), 'password' => Config::getInstance()->superuser['password']); } else { if (API::getInstance()->userExists($loginMail)) { $user = API::getInstance()->getUser($loginMail); } else { if (API::getInstance()->userEmailExists($loginMail)) { $user = API::getInstance()->getUserByEmail($loginMail); } } } return $user; }
/** * Helper method used to redirect the current HTTP request to another module/action. * * This function will exit immediately after executing. * * @param string $moduleToRedirect The plugin to redirect to, eg. `"MultiSites"`. * @param string $actionToRedirect Action, eg. `"index"`. * @param int|null $websiteId The new idSite query parameter, eg, `1`. * @param string|null $defaultPeriod The new period query parameter, eg, `'day'`. * @param string|null $defaultDate The new date query parameter, eg, `'today'`. * @param array $parameters Other query parameters to append to the URL. * @api */ public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array()) { if (empty($websiteId)) { $websiteId = $this->getDefaultWebsiteId(); } if (empty($defaultDate)) { $defaultDate = $this->getDefaultDate(); } if (empty($defaultPeriod)) { $defaultPeriod = $this->getDefaultPeriod(); } $parametersString = ''; if (!empty($parameters)) { $parametersString = '&' . Url::getQueryStringFromParameters($parameters); } if ($websiteId) { $url = "Location: index.php?module=" . $moduleToRedirect . "&action=" . $actionToRedirect . "&idSite=" . $websiteId . "&period=" . $defaultPeriod . "&date=" . $defaultDate . $parametersString; header($url); exit; } if (Piwik::isUserIsSuperUser()) { Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.\n\t\t\t<br />Check the table '" . Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true); } $currentLogin = Piwik::getCurrentUserLogin(); if (!empty($currentLogin) && $currentLogin != 'anonymous') { $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>"); $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik::translate('General_Logout') . "</a></b><br />"; Piwik_ExitWithMessage($errorMessage, false, true); } echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false); exit; }
public function sendReport($reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles) { if (self::manageEvent($reportType)) { $periods = self::getPeriodToFrequencyAsAdjective(); $message = Piwik::translate('ScheduledReports_EmailHello'); $subject = Piwik::translate('General_Report') . ' ' . $reportTitle . " - " . $prettyDate; $mail = new Mail(); $mail->setSubject($subject); $fromEmailName = Config::getInstance()->branding['use_custom_logo'] ? Piwik::translate('CoreHome_WebAnalyticsReports') : Piwik::translate('ScheduledReports_PiwikReports'); $fromEmailAddress = Config::getInstance()->General['noreply_email_address']; $attachmentName = $subject; $mail->setFrom($fromEmailAddress, $fromEmailName); $displaySegmentInfo = false; $segmentInfo = null; $segment = API::getSegment($report['idsegment']); if ($segment != null) { $displaySegmentInfo = true; $segmentInfo = Piwik::translate('ScheduledReports_SegmentAppliedToReports', $segment['name']); } switch ($report['format']) { case 'html': // Needed when using images as attachment with cid $mail->setType(Zend_Mime::MULTIPART_RELATED); $message .= "<br/>" . Piwik::translate('ScheduledReports_PleaseFindBelow', array($periods[$report['period']], $reportTitle)); if ($displaySegmentInfo) { $message .= " " . $segmentInfo; } $mail->setBodyHtml($message . "<br/><br/>" . $contents); break; default: case 'pdf': $message .= "\n" . Piwik::translate('ScheduledReports_PleaseFindAttachedFile', array($periods[$report['period']], $reportTitle)); if ($displaySegmentInfo) { $message .= " " . $segmentInfo; } $mail->setBodyText($message); $mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf'); break; } foreach ($additionalFiles as $additionalFile) { $fileContent = $additionalFile['content']; $at = $mail->createAttachment($fileContent, $additionalFile['mimeType'], Zend_Mime::DISPOSITION_INLINE, $additionalFile['encoding'], $additionalFile['filename']); $at->id = $additionalFile['cid']; unset($fileContent); } // Get user emails and languages $reportParameters = $report['parameters']; $emails = array(); if (isset($reportParameters[self::ADDITIONAL_EMAILS_PARAMETER])) { $emails = $reportParameters[self::ADDITIONAL_EMAILS_PARAMETER]; } if ($reportParameters[self::EMAIL_ME_PARAMETER] == 1) { if (Piwik::getCurrentUserLogin() == $report['login']) { $emails[] = Piwik::getCurrentUserEmail(); } elseif ($report['login'] == Piwik::getSuperUserLogin()) { $emails[] = Piwik::getSuperUserEmail(); } else { try { $user = APIUsersManager::getInstance()->getUser($report['login']); } catch (Exception $e) { return; } $emails[] = $user['email']; } } foreach ($emails as $email) { if (empty($email)) { continue; } $mail->addTo($email); try { $mail->send(); } catch (Exception $e) { // If running from piwik.php with debug, we ignore the 'email not sent' error if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) { throw new Exception("An error occured while sending '{$filename}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'"); } } $mail->clearRecipients(); } } }
/** * The "User Settings" admin UI screen view */ public function userSettings() { Piwik::checkUserIsNotAnonymous(); $view = new View('@UsersManager/userSettings'); $userLogin = Piwik::getCurrentUserLogin(); if (Piwik::isUserIsSuperUser()) { $view->userAlias = $userLogin; $view->userEmail = Piwik::getSuperUserEmail(); $this->displayWarningIfConfigFileNotWritable(); } else { $user = APIUsersManager::getInstance()->getUser($userLogin); $view->userAlias = $user['alias']; $view->userEmail = $user['email']; } $defaultReport = APIUsersManager::getInstance()->getUserPreference($userLogin, APIUsersManager::PREFERENCE_DEFAULT_REPORT); if ($defaultReport === false) { $defaultReport = $this->getDefaultWebsiteId(); } $view->defaultReport = $defaultReport; if ($defaultReport == 'MultiSites') { $view->defaultReportSiteName = Site::getNameFor($this->getDefaultWebsiteId()); } else { $view->defaultReportSiteName = Site::getNameFor($defaultReport); } $view->defaultDate = $this->getDefaultDateForUser($userLogin); $view->availableDefaultDates = array('today' => Piwik::translate('General_Today'), 'yesterday' => Piwik::translate('General_Yesterday'), 'previous7' => Piwik::translate('General_PreviousDays', 7), 'previous30' => Piwik::translate('General_PreviousDays', 30), 'last7' => Piwik::translate('General_LastDays', 7), 'last30' => Piwik::translate('General_LastDays', 30), 'week' => Piwik::translate('General_CurrentWeek'), 'month' => Piwik::translate('General_CurrentMonth'), 'year' => Piwik::translate('General_CurrentYear')); $view->ignoreCookieSet = IgnoreCookie::isIgnoreCookieFound(); $this->initViewAnonymousUserSettings($view); $view->piwikHost = Url::getCurrentHost(); $this->setBasicVariablesView($view); return $view->render(); }