コード例 #1
0
ファイル: Mail.php プロジェクト: BackupTheBerlios/oos-svn
	private function initSmtpTransport()
	{
		$config = Zend_Registry::get('config')->mail;
		if ( empty($config->host) 
			 || $config->transport != 'smtp')
		{
			return;
		}
		$smtpConfig = array();
		if ( !empty($config->type)
			 || !empty($config->username)
			 || !empty($config->password)
			 || !empty($config->encryption)
		)
		{
			$smtpConfig = array(
				'auth' => strtolower($config->type),
				'username' => $config->username,
				'password' => $config->password,
				'ssl' => $config->encryption,
			);
		}
		
		$tr = new Zend_Mail_Transport_Smtp($config->host, $smtpConfig);
		Piwik_Mail::setDefaultTransport($tr);
		ini_set("smtp_port", $config->port);
	}
コード例 #2
0
ファイル: Controller.php プロジェクト: Gninety/Microweber
 /**
  * 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();
 }
コード例 #3
0
 /**
  * send email to Piwik team and display nice thanks
  */
 function sendFeedback()
 {
     $body = Piwik_Common::getRequestVar('body', '', 'string');
     $email = Piwik_Common::getRequestVar('email', '', 'string');
     $view = new Piwik_View('Feedback/templates/sent.tpl');
     try {
         $minimumBodyLength = 35;
         if (strlen($body) < $minimumBodyLength) {
             throw new Exception(sprintf("Message must be at least %s characters long.", $minimumBodyLength));
         }
         if (!Piwik::isValidEmailString($email)) {
             throw new Exception(Piwik_Translate('UsersManager_ExceptionInvalidEmail'));
         }
         if (strpos($body, 'http://') !== false) {
             throw new Exception("The message cannot contain a URL, to avoid spams messages.");
         }
         $mail = new Piwik_Mail();
         $mail->setFrom($email);
         $mail->addTo('*****@*****.**', 'Piwik Team');
         $mail->setSubject('[ Feedback form - Piwik ]');
         $mail->setBodyText($body);
         @$mail->send();
     } catch (Exception $e) {
         $view->ErrorString = $e->getMessage();
         $view->message = $body;
     }
     echo $view->render();
 }
コード例 #4
0
ファイル: Mail.php プロジェクト: nnnnathann/piwik
 /**
  * @return void
  */
 private function initSmtpTransport()
 {
     $mailConfig = Piwik_Config::getInstance()->mail;
     if (empty($mailConfig['host']) || $mailConfig['transport'] != 'smtp') {
         return;
     }
     $smtpConfig = array();
     if (!empty($mailConfig['type'])) {
         $smtpConfig['auth'] = strtolower($mailConfig['type']);
     }
     if (!empty($mailConfig['username'])) {
         $smtpConfig['username'] = $mailConfig['username'];
     }
     if (!empty($mailConfig['password'])) {
         $smtpConfig['password'] = $mailConfig['password'];
     }
     if (!empty($mailConfig['encryption'])) {
         $smtpConfig['ssl'] = $mailConfig['encryption'];
     }
     $tr = new Zend_Mail_Transport_Smtp($mailConfig['host'], $smtpConfig);
     Piwik_Mail::setDefaultTransport($tr);
     ini_set("smtp_port", $mailConfig['port']);
 }
コード例 #5
0
 protected function sendReportEmail($emails, $outputFilename, $prettyDate, $websiteName, $report, $reportFormat, $additionalFiles)
 {
     $periods = self::getPeriodToFrequency();
     $message = Piwik_Translate('PDFReports_EmailHello');
     $subject = Piwik_Translate('General_Report') . ' ' . $websiteName . " - " . $prettyDate;
     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);
     $mail = new Piwik_Mail();
     $mail->setSubject($subject);
     $fromEmailName = Piwik_Config::getInstance()->branding['use_custom_logo'] ? Piwik_Translate('CoreHome_WebAnalyticsReports') : Piwik_Translate('PDFReports_PiwikReports');
     $fromEmailAddress = Piwik_Config::getInstance()->General['noreply_email_address'];
     $attachmentName = $subject;
     $mail->setFrom($fromEmailAddress, $fromEmailName);
     switch ($reportFormat) {
         case 'html':
             // Needed when using images as attachment with cid
             $mail->setType(Zend_Mime::MULTIPART_RELATED);
             $message .= "<br/>" . Piwik_Translate('PDFReports_PleaseFindBelow', array($periods[$report['period']], $websiteName));
             $mail->setBodyHtml($message . "<br/><br/>" . $contents);
             break;
         default:
         case 'pdf':
             $message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $websiteName));
             $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);
     }
     foreach ($emails as $email) {
         $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();
     }
     // Update flag in DB
     Zend_Registry::get('db')->update(Piwik_Common::prefixTable('pdf'), array('ts_last_sent' => Piwik_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);
         @unlink($outputFilename);
     }
 }
コード例 #6
0
ファイル: PDFReports.php プロジェクト: nnnnathann/piwik
 /**
  * @param Piwik_Event_Notification $notification notification object
  */
 function sendReport($notification)
 {
     if (self::manageEvent($notification)) {
         $notificationInfo = $notification->getNotificationInfo();
         $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY];
         $websiteName = $notificationInfo[Piwik_PDFReports_API::WEBSITE_NAME_KEY];
         $prettyDate = $notificationInfo[Piwik_PDFReports_API::PRETTY_DATE_KEY];
         $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY];
         $filename = $notificationInfo[Piwik_PDFReports_API::FILENAME_KEY];
         $additionalFiles = $notificationInfo[Piwik_PDFReports_API::ADDITIONAL_FILES_KEY];
         $periods = self::getPeriodToFrequency();
         $message = Piwik_Translate('PDFReports_EmailHello');
         $subject = Piwik_Translate('General_Report') . ' ' . $websiteName . " - " . $prettyDate;
         $mail = new Piwik_Mail();
         $mail->setSubject($subject);
         $fromEmailName = Piwik_Config::getInstance()->branding['use_custom_logo'] ? Piwik_Translate('CoreHome_WebAnalyticsReports') : Piwik_Translate('PDFReports_PiwikReports');
         $fromEmailAddress = Piwik_Config::getInstance()->General['noreply_email_address'];
         $attachmentName = $subject;
         $mail->setFrom($fromEmailAddress, $fromEmailName);
         switch ($report['format']) {
             case 'html':
                 // Needed when using images as attachment with cid
                 $mail->setType(Zend_Mime::MULTIPART_RELATED);
                 $message .= "<br/>" . Piwik_Translate('PDFReports_PleaseFindBelow', array($periods[$report['period']], $websiteName));
                 $mail->setBodyHtml($message . "<br/><br/>" . $contents);
                 break;
             default:
             case 'pdf':
                 $message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $websiteName));
                 $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_Config::getInstance()->superuser['login']) {
                 $emails[] = Piwik::getSuperUserEmail();
             } else {
                 try {
                     $user = Piwik_UsersManager_API::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();
         }
     }
 }
コード例 #7
0
ファイル: API.php プロジェクト: Gninety/Microweber
 protected function sendReportEmailPdfAttached($emails, $outputFilename, $prettyDate, $websiteName, $report)
 {
     $periods = self::getPeriodToFrequency();
     $message = Piwik_Translate('PDFReports_EmailHello');
     $message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $websiteName));
     $subject = Piwik_Translate('General_Report') . ' ' . $websiteName . " - " . $prettyDate;
     if (!file_exists($outputFilename)) {
         throw new Exception("The PDF file wasn't found in {$outputFilename}");
     }
     $filename = basename($outputFilename);
     $handle = fopen($outputFilename, "r");
     $contents = fread($handle, filesize($outputFilename));
     fclose($handle);
     $mail = new Piwik_Mail();
     $mail->setSubject($subject);
     $mail->setBodyText($message);
     $fromEmailName = Piwik_Translate('PDFReports_PiwikReports');
     $fromEmailAddress = Zend_Registry::get('config')->General->noreply_email_address;
     $attachmentName = $subject;
     $mail->setFrom($fromEmailAddress, $fromEmailName);
     $mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf');
     foreach ($emails as $email) {
         $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()) . ". \n    \t\t\t\t\t\t\t\tError was '" . $e->getMessage() . "'");
             }
         }
         $mail->clearRecipients();
     }
     // Update flag in DB
     Zend_Registry::get('db')->update(Piwik_Common::prefixTable('pdf'), array('ts_last_sent' => Piwik_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']) {
         unlink($outputFilename);
     }
 }
コード例 #8
0
ファイル: Controller.php プロジェクト: Doluci/tomatocart
 /**
  * Validate user (by username or email address).
  *
  * @param string $loginMail (user name or email address)
  * @param string $urlToRedirect (URL to redirect to, if successfully validated)
  * @return string (failure message if unable to validate)
  */
 protected function lostPasswordFormValidated($loginMail, $urlToRedirect)
 {
     $user = self::getUserInformation($loginMail);
     if ($user === null) {
         return Piwik_Translate('Login_InvalidUsernameEmail');
     }
     $view = Piwik_View::factory('passwordsent');
     $login = $user['login'];
     $email = $user['email'];
     // construct a password reset token from user information
     $resetToken = self::generatePasswordResetToken($user);
     $ip = Piwik_Common::getIpString();
     $url = Piwik_Url::getCurrentUrlWithoutQueryString() . "?module=Login&action=resetPassword&token={$resetToken}";
     // send email with new password
     try {
         $mail = new Piwik_Mail();
         $mail->addTo($email, $login);
         $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordRecovery'));
         $mail->setBodyText(str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordRecoveryBody'), $login, $ip, $url, $resetToken)) . "\n");
         $piwikHost = $_SERVER['HTTP_HOST'];
         if (strlen($piwikHost) == 0) {
             $piwikHost = 'piwik.org';
         }
         $fromEmailName = Zend_Registry::get('config')->General->login_password_recovery_email_name;
         $fromEmailAddress = Zend_Registry::get('config')->General->login_password_recovery_email_address;
         $fromEmailAddress = str_replace('{DOMAIN}', $piwikHost, $fromEmailAddress);
         $mail->setFrom($fromEmailAddress, $fromEmailName);
         @$mail->send();
     } catch (Exception $e) {
         $view->ErrorString = $e->getMessage();
     }
     $view->linkTitle = Piwik::getRandomTitle();
     $view->urlToRedirect = $urlToRedirect;
     echo $view->render();
     exit;
 }
コード例 #9
0
ファイル: Controller.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Sends email confirmation link for a password reset request.
  * 
  * @param array $user User info for the requested password reset.
  */
 private function sendEmailConfirmationLink($user)
 {
     $login = $user['login'];
     $email = $user['email'];
     // construct a password reset token from user information
     $resetToken = self::generatePasswordResetToken($user);
     $ip = Piwik_IP::getIpFromHeader();
     $url = Piwik_Url::getCurrentUrlWithoutQueryString() . "?module=Login&action=confirmResetPassword&login="******"&resetToken=" . urlencode($resetToken);
     // send email with new password
     $mail = new Piwik_Mail();
     $mail->addTo($email, $login);
     $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordChange'));
     $bodyText = str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordChangeBody'), $login, $ip, $url)) . "\n";
     $mail->setBodyText($bodyText);
     $fromEmailName = Piwik_Config::getInstance()->General['login_password_recovery_email_name'];
     $fromEmailAddress = Piwik_Config::getInstance()->General['login_password_recovery_email_address'];
     $mail->setFrom($fromEmailAddress, $fromEmailName);
     @$mail->send();
 }
コード例 #10
0
 protected function lostPasswordFormValidated($loginMail, $urlToRedirect)
 {
     Piwik::setUserIsSuperUser();
     $user = null;
     $isSuperUser = false;
     if ($loginMail == Zend_Registry::get('config')->superuser->email || $loginMail == Zend_Registry::get('config')->superuser->login) {
         $isSuperUser = true;
         $user = array('login' => Zend_Registry::get('config')->superuser->login, 'email' => Zend_Registry::get('config')->superuser->email);
     } else {
         if (Piwik_UsersManager_API::userExists($loginMail)) {
             $user = Piwik_UsersManager_API::getUser($loginMail);
         } else {
             if (Piwik_UsersManager_API::userEmailExists($loginMail)) {
                 $user = Piwik_UsersManager_API::getUserByEmail($loginMail);
             }
         }
     }
     if ($user === null) {
         $messageNoAccess = Piwik_Translate('Login_InvalidUsernameEmail');
     } else {
         $view = new Piwik_View('Login/templates/passwordsent.tpl');
         $login = $user['login'];
         $email = $user['email'];
         $randomPassword = Piwik_Common::getRandomString(8);
         if ($isSuperUser) {
             $user['password'] = md5($randomPassword);
             Zend_Registry::get('config')->superuser = $user;
         } else {
             Piwik_UsersManager_API::updateUser($login, $randomPassword);
         }
         // send email with new password
         try {
             $mail = new Piwik_Mail();
             $mail->addTo($email, $login);
             $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordRecovery'));
             $mail->setBodyText(str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordRecoveryBody'), $login, $randomPassword, Piwik_Url::getCurrentUrlWithoutQueryString())));
             $piwikHost = $_SERVER['HTTP_HOST'];
             if (strlen($piwikHost) == 0) {
                 $piwikHost = 'piwik.org';
             }
             $fromEmailName = Zend_Registry::get('config')->General->login_password_recovery_email_name;
             $fromEmailAddress = Zend_Registry::get('config')->General->login_password_recovery_email_address;
             $fromEmailAddress = str_replace('{DOMAIN}', $piwikHost, $fromEmailAddress);
             $mail->setFrom($fromEmailAddress, $fromEmailName);
             @$mail->send();
         } catch (Exception $e) {
             $view->ErrorString = $e->getMessage();
         }
         $view->linkTitle = Piwik::getRandomTitle();
         $view->urlToRedirect = $urlToRedirect;
         echo $view->render();
     }
 }
コード例 #11
0
 /**
  * Validate user (by username or email address).
  *
  * @param string $loginMail user name or email address
  * @return string failure message if unable to validate
  */
 protected function lostPasswordFormValidated($loginMail)
 {
     if ($loginMail === 'anonymous') {
         return Piwik_Translate('Login_InvalidUsernameEmail');
     }
     $user = self::getUserInformation($loginMail);
     if ($user === null) {
         return Piwik_Translate('Login_InvalidUsernameEmail');
     }
     $view = Piwik_View::factory('passwordsent');
     $login = $user['login'];
     $email = $user['email'];
     // construct a password reset token from user information
     $resetToken = self::generatePasswordResetToken($user);
     $ip = Piwik_IP::getIpFromHeader();
     $url = Piwik_Url::getCurrentUrlWithoutQueryString() . "?module=Login&action=resetPassword&token={$resetToken}";
     // send email with new password
     try {
         $mail = new Piwik_Mail();
         $mail->addTo($email, $login);
         $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordRecovery'));
         $bodyText = str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordRecoveryBody'), $login, $ip, $url, $resetToken)) . "\n";
         $mail->setBodyText($bodyText);
         $fromEmailName = Piwik_Config::getInstance()->General['login_password_recovery_email_name'];
         $fromEmailAddress = Piwik_Config::getInstance()->General['login_password_recovery_email_address'];
         $mail->setFrom($fromEmailAddress, $fromEmailName);
         @$mail->send();
     } catch (Exception $e) {
         $view->ErrorString = $e->getMessage();
     }
     $this->configureView($view);
     echo $view->render();
     exit;
 }