protected static function setConfigForKey($key, $value) { if ($key == 'bounceImapPassword') { $value = ZurmoPasswordSecurityUtil::encrypt($value); } ZurmoConfigurationUtil::setByModuleName(static::CONFIG_MODULE_NAME, $key, $value); }
/** * @covers ZurmoSendGridMailer::sendTestEmail * @covers ZurmoSendGridMailer::sendEmail */ public function testSendEmail() { $sendGridEmailAccount = new SendGridEmailAccount(); $sendGridEmailAccount->apiUsername = static::$apiUsername; $sendGridEmailAccount->apiPassword = ZurmoPasswordSecurityUtil::encrypt(static::$apiPassword); $from = array('name' => 'Test User', 'address' => '*****@*****.**'); $emailMessage = EmailMessageHelper::processAndCreateTestEmailMessage($from, static::$testEmailAddress); $mailer = new ZurmoSendGridMailer($emailMessage, $sendGridEmailAccount); $emailMessage = $mailer->sendTestEmail(true); $this->assertEquals('EmailMessage', get_class($emailMessage)); $this->assertEquals(EmailFolder::TYPE_SENT, $emailMessage->folder->type); }
public function testEncryptAndDecrypt() { // No need to encrypt empty string $encryptedString = ZurmoPasswordSecurityUtil::encrypt('', 'someKey'); $this->assertEquals('', $encryptedString); // No need to decrypt empty string $decryptedString = ZurmoPasswordSecurityUtil::decrypt('', 'someKey'); $this->assertEquals('', $decryptedString); $string = '357'; $salt = "123"; $encryptedString = ZurmoPasswordSecurityUtil::encrypt($string, $salt); $this->assertTrue($string != $encryptedString); $decryptedString = ZurmoPasswordSecurityUtil::decrypt($encryptedString, $salt); $this->assertEquals($string, $decryptedString); // Ensure that data will not be decrypted with random salt $decryptedString = ZurmoPasswordSecurityUtil::decrypt($encryptedString, '567'); $this->assertTrue($string != $decryptedString); }
public function testMakeFormAndSetConfigurationFromForm() { $form = BounceConfigurationFormAdapter::makeFormFromGlobalConfiguration(); $this->assertNull($form->imapHost); $this->assertNull($form->imapPort); $this->assertNull($form->imapUsername); $this->assertNull($form->imapPassword); $this->assertNull($form->imapSSL); $this->assertNull($form->imapFolder); $this->assertNull($form->returnPath); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapHost', 'bounce.com'); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapPort', '420'); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapSSL', '1'); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapUsername', 'bouncy'); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapPassword', ZurmoPasswordSecurityUtil::encrypt('bounces')); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceImapFolder', 'BOUNCES'); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceReturnPath', '*****@*****.**'); $form = BounceConfigurationFormAdapter::makeFormFromGlobalConfiguration(); $this->assertEquals('bounce.com', $form->imapHost); $this->assertEquals('420', $form->imapPort); $this->assertEquals('bouncy', $form->imapUsername); $this->assertEquals('bounces', $form->imapPassword); $this->assertEquals('1', $form->imapSSL); $this->assertEquals('BOUNCES', $form->imapFolder); $this->assertEquals('*****@*****.**', $form->returnPath); $form = BounceConfigurationFormAdapter::makeFormFromGlobalConfiguration(); $form->imapHost = 'example.com'; $form->imapPort = '111'; $form->imapSSL = '0'; $form->imapUsername = '******'; $form->imapPassword = '******'; $form->imapFolder = 'folder'; $form->returnPath = 'path'; BounceConfigurationFormAdapter::setConfigurationFromForm($form); $form = BounceConfigurationFormAdapter::makeFormFromGlobalConfiguration(); $this->assertEquals('example.com', $form->imapHost); $this->assertEquals('111', $form->imapPort); $this->assertEquals('user', $form->imapUsername); $this->assertEquals('password', $form->imapPassword); $this->assertEquals('0', $form->imapSSL); $this->assertEquals('folder', $form->imapFolder); $this->assertEquals('path', $form->returnPath); }
/** * @param $hash * @param bool $validateQueryStringArray * @param bool $validateForTracking * @return array * @throws NotSupportedException */ public static function resolveQueryStringArrayForHash($hash, $validateQueryStringArray = true, $validateForTracking = true) { $hash = base64_decode($hash); if (StringUtil::isValidHash($hash)) { $queryStringArray = array(); $decryptedString = ZurmoPasswordSecurityUtil::decrypt($hash); if ($decryptedString) { parse_str($decryptedString, $queryStringArray); if ($validateQueryStringArray) { if ($validateForTracking) { static::validateAndResolveFullyQualifiedQueryStringArrayForTracking($queryStringArray); } else { static::validateQueryStringArrayForMarketingListsExternalController($queryStringArray); } } return $queryStringArray; } } throw new NotSupportedException(); }
/** * Send Test Message * @param SendGridWebApiConfigurationForm $configurationForm * @param string $fromNameToSendMessagesFrom * @param string $fromAddressToSendMessagesFrom */ public static function sendTestMessage($configurationForm, $fromNameToSendMessagesFrom = null, $fromAddressToSendMessagesFrom = null) { if ($configurationForm->aTestToAddress != null) { $sendGridEmailAccount = new SendGridEmailAccount(); $sendGridEmailAccount->apiUsername = $configurationForm->username; $sendGridEmailAccount->apiPassword = ZurmoPasswordSecurityUtil::encrypt($configurationForm->password); $isUser = false; if ($fromNameToSendMessagesFrom != null && $fromAddressToSendMessagesFrom != null) { $isUser = true; $from = array('name' => $fromNameToSendMessagesFrom, 'address' => $fromAddressToSendMessagesFrom); } else { $user = BaseControlUserConfigUtil::getUserToRunAs(); $userToSendMessagesFrom = User::getById((int) $user->id); $from = array('name' => Yii::app()->emailHelper->resolveFromNameForSystemUser($userToSendMessagesFrom), 'address' => Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom)); } $emailMessage = EmailMessageHelper::processAndCreateTestEmailMessage($from, $configurationForm->aTestToAddress); $mailer = new ZurmoSendGridMailer($emailMessage, $sendGridEmailAccount); $emailMessage = $mailer->sendTestEmail($isUser); $messageContent = EmailHelper::prepareMessageContent($emailMessage); } else { $messageContent = Zurmo::t('EmailMessagesModule', 'A test email address must be entered before you can send a test email.') . "\n"; } return $messageContent; }
/** * Set api settings into the database. */ public function setApiSettings() { foreach ($this->settingsToLoad as $keyName) { if ($keyName == 'apiPassword') { $password = ZurmoPasswordSecurityUtil::encrypt($this->{$keyName}); ZurmoConfigurationUtil::setByModuleName('SendGridModule', $keyName, $password); } else { ZurmoConfigurationUtil::setByModuleName('SendGridModule', $keyName, $this->{$keyName}); } } }
/** * Set outbound settings into the database. */ public function setOutboundSettings() { foreach ($this->settingsToLoad as $keyName) { if ($keyName == 'outboundPassword') { $password = ZurmoPasswordSecurityUtil::encrypt($this->{$keyName}); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $password); } else { ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $this->{$keyName}); } } }
public function actionEmailConfiguration($id, $redirectUrl = null) { UserAccessUtil::resolveCanCurrentUserAccessAction(intval($id)); $user = User::getById(intval($id)); UserAccessUtil::resolveCanCurrentUserAccessRootUser($user); UserAccessUtil::resolveAccessingASystemUser($user); $title = Zurmo::t('EmailMessagesModule', 'Email Configuration'); $breadCrumbLinks = array(strval($user) => array('default/details', 'id' => $id), $title); $emailAccount = EmailAccount::resolveAndGetByUserAndName($user); $userEmailConfigurationForm = new UserEmailConfigurationForm($emailAccount); $userEmailConfigurationForm->emailSignatureHtmlContent = $user->getEmailSignature()->htmlContent; $postVariableName = get_class($userEmailConfigurationForm); if (isset($_POST[$postVariableName])) { $userEmailConfigurationForm->setAttributes($_POST[$postVariableName]); if ($userEmailConfigurationForm->validate()) { $userEmailConfigurationForm->save(); Yii::app()->user->setFlash('notification', Zurmo::t('UsersModule', 'User email configuration saved successfully.')); if ($redirectUrl != null) { $this->redirect($redirectUrl); } else { $this->redirect(array($this->getId() . '/details', 'id' => $user->id)); } } else { $userEmailConfigurationForm->outboundPassword = ZurmoPasswordSecurityUtil::decrypt($userEmailConfigurationForm->outboundPassword); } } $titleBarAndEditView = new UserActionBarAndEmailConfigurationEditView($this->getId(), $this->getModule()->getId(), $user, $userEmailConfigurationForm); $titleBarAndEditView->setCssClasses(array('AdministrativeArea')); $view = new UsersPageView($this->resolveZurmoDefaultOrAdminView($titleBarAndEditView, $breadCrumbLinks, 'UserBreadCrumbView')); echo $view->render(); }
public function testActionConfigurationEditImapModifyBounce() { $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->setGetArray(array('type' => 2)); $this->setPostArray(array('BounceConfigurationForm' => array('imapHost' => 'mail.example.com', 'imapUsername' => '*****@*****.**', 'imapPassword' => 'abcd', 'imapPort' => '143', 'imapSSL' => '0', 'imapFolder' => 'INBOX', 'returnPath' => '*****@*****.**'))); $this->runControllerWithRedirectExceptionAndGetContent('emailMessages/default/configurationEditImap'); $this->assertEquals('Bounce configuration saved successfully.', Yii::app()->user->getFlash('notification')); $this->assertEquals('mail.example.com', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapHost')); $this->assertEquals('*****@*****.**', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapUsername')); $this->assertEquals('abcd', ZurmoPasswordSecurityUtil::decrypt(ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapPassword'))); $this->assertEquals('143', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapPort')); $this->assertEquals('0', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapSSL')); $this->assertEquals('INBOX', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceImapFolder')); $this->assertEquals('*****@*****.**', ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'bounceReturnPath')); }
/** * Set inbound settings into the database. */ public function setInboundSettings() { foreach ($this->settingsToLoad as $keyName) { $attributeName = $this->resolveAttributeNameFromSettingsKey($keyName); if ($keyName == $this->resolvePasswordKeyName()) { $password = ZurmoPasswordSecurityUtil::encrypt($this->{$attributeName}); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $password); } else { ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $this->{$attributeName}); } } }
/** * Given an installSettingsForm, run the install including the schema creation and default data load. This is * used by the interactive install and the command line install. * @param object $form * @param object $messageStreamer */ public static function runInstallation($form, &$messageStreamer) { Yii::app()->params['isFreshInstall'] = true; assert('$form instanceof InstallSettingsForm'); assert('$messageStreamer instanceof MessageStreamer'); if (defined('IS_TEST')) { $perInstanceFilename = "perInstanceTest.php"; $debugFilename = "debugTest.php"; } else { @set_time_limit(1200); $perInstanceFilename = "perInstance.php"; $debugFilename = "debug.php"; } $messageStreamer->add(Zurmo::t('InstallModule', 'Connecting to Database.')); static::connectToDatabase($form->databaseType, $form->databaseHostname, $form->databaseName, $form->databaseUsername, $form->databasePassword, $form->databasePort); ForgetAllCacheUtil::forgetAllCaches(); $messageStreamer->add(Zurmo::t('InstallModule', 'Dropping existing tables.')); ZurmoRedBean::$writer->wipeAll(); $messageStreamer->add(Zurmo::t('InstallModule', 'Creating super user.')); $messageLogger = new MessageLogger($messageStreamer); $messageLogger->logDateTimeStamp = false; Yii::app()->custom->runBeforeInstallationAutoBuildDatabase($messageLogger); $messageStreamer->add(Zurmo::t('InstallModule', 'Starting database schema creation.')); $startTime = microtime(true); $messageStreamer->add('debugOn:' . BooleanUtil::boolToString(YII_DEBUG)); $messageStreamer->add('phpLevelCaching:' . BooleanUtil::boolToString(PHP_CACHING_ON)); $messageStreamer->add('memcacheLevelCaching:' . BooleanUtil::boolToString(MEMCACHE_ON)); static::autoBuildDatabase($messageLogger, false); $endTime = microtime(true); $messageStreamer->add(Zurmo::t('InstallModule', 'Total autobuild time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3)))); if (SHOW_QUERY_DATA) { $messageStreamer->add(FooterView::getTotalAndDuplicateQueryCountContent()); $messageStreamer->add(PageView::makeNonHtmlDuplicateCountAndQueryContent()); } $messageStreamer->add(Zurmo::t('InstallModule', 'Database schema creation complete.')); $messageStreamer->add(Zurmo::t('InstallModule', 'Rebuilding Permissions.')); AllPermissionsOptimizationUtil::rebuild(); $messageStreamer->add(Zurmo::t('InstallModule', 'Rebuilding Read Permissions Subscription tables.')); ReadPermissionsSubscriptionUtil::buildTables(); $messageStreamer->add(Zurmo::t('InstallModule', 'Writing Configuration File.')); static::writeConfiguration(INSTANCE_ROOT, $form->databaseType, $form->databaseHostname, $form->databaseName, $form->databaseUsername, $form->databasePassword, $form->databasePort, $form->memcacheHostname, (int) $form->memcachePortNumber, true, Yii::app()->language, $perInstanceFilename, $debugFilename, $form->hostInfo, $form->scriptUrl, $form->submitCrashToSentry); static::setZurmoTokenAndWriteToPerInstanceFile(INSTANCE_ROOT); ZurmoPasswordSecurityUtil::setPasswordSaltAndWriteToPerInstanceFile(INSTANCE_ROOT); static::createSuperUser('super', $form->superUserPassword); $messageStreamer->add(Zurmo::t('InstallModule', 'Setting up default data.')); DefaultDataUtil::load($messageLogger); static::createBaseControlUserConfigUtilUserAccount(); Yii::app()->custom->runAfterInstallationDefaultDataLoad($messageLogger); // Send notification to super admin to delete test.php file in case if this // installation is used in production mode. $message = new NotificationMessage(); $message->textContent = Zurmo::t('InstallModule', 'If this website is in production mode, please remove the app/test.php file.'); $rules = new RemoveApiTestEntryScriptFileNotificationRules(); NotificationsUtil::submit($message, $rules); // If minify is disabled, inform user that they should fix issues and enable minify $setIncludePathServiceHelper = new SetIncludePathServiceHelper(); if (!$setIncludePathServiceHelper->runCheckAndGetIfSuccessful()) { $message = new NotificationMessage(); $message->textContent = Zurmo::t('InstallModule', 'Minify has been disabled due to a system issue. Try to resolve the problem and re-enable Minify.'); $rules = new EnableMinifyNotificationRules(); NotificationsUtil::submit($message, $rules); } $messageStreamer->add(Zurmo::t('InstallModule', 'Installation Complete.')); Yii::app()->params['isFreshInstall'] = false; }
protected static function resolveHashForQueryStringArray($queryStringArray) { $queryString = http_build_query($queryStringArray); $encryptedString = ZurmoPasswordSecurityUtil::encrypt($queryString); if (!$encryptedString || !static::isValidHash($encryptedString)) { throw new NotSupportedException(); } $encryptedString = base64_encode($encryptedString); return $encryptedString; }
protected function resolveMailerFromEmailAccount(Mailer $mailer, EmailAccount $emailAccount) { if ($emailAccount->useCustomOutboundSettings) { $mailer->host = $emailAccount->outboundHost; $mailer->port = $emailAccount->outboundPort; $mailer->username = $emailAccount->outboundUsername; $mailer->password = ZurmoPasswordSecurityUtil::decrypt($emailAccount->outboundPassword); $mailer->security = $emailAccount->outboundSecurity; } }
protected function resolveValueForUnpacking($packedValue) { return unserialize(ZurmoPasswordSecurityUtil::decrypt($packedValue)); }
/** * Configure sendgrid options. * @param int $id * @param string $redirectUrl * @return void */ protected function processSendGridPostConfiguration($id, $redirectUrl = null) { SendGridAccessUtil::resolveCanCurrentUserAccessAction(intval($id)); $user = User::getById(intval($id)); $emailAccount = SendGridEmailAccount::resolveAndGetByUserAndName($user); $userSendGridConfigurationForm = new UserSendGridConfigurationForm($emailAccount); $userSendGridConfigurationForm->emailSignatureHtmlContent = $user->getEmailSignature()->htmlContent; $postVariableName = get_class($userSendGridConfigurationForm); if (isset($_POST[$postVariableName])) { $userSendGridConfigurationForm->setAttributes($_POST[$postVariableName]); if ($userSendGridConfigurationForm->validate()) { $userSendGridConfigurationForm->save(); Yii::app()->user->setFlash('notification', Zurmo::t('UsersModule', 'User SendGrid API configuration saved successfully.')); if ($redirectUrl != null) { $this->redirect($redirectUrl); } else { $this->redirect(array($this->getId() . '/details', 'id' => $user->id)); } } else { $userSendGridConfigurationForm->apiPassword = ZurmoPasswordSecurityUtil::decrypt($userSendGridConfigurationForm->apiPassword); } } return $userSendGridConfigurationForm; }
public function testResolveAndGetByUserAndName() { //Test a user that not have a Primary Email Address $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $emailAccount = SendGridEmailAccount::resolveAndGetByUserAndName($super); $this->assertEquals('Default', $emailAccount->name); $this->assertEquals($super, $emailAccount->user); $this->assertEquals($super->getFullName(), $emailAccount->fromName); $this->assertEquals($super->primaryEmail->emailAddress, $emailAccount->fromAddress); $emailAccountId = $emailAccount->id; $emailAccount = SendGridEmailAccount::resolveAndGetByUserAndName($super); $this->assertNotEquals($emailAccountId, $emailAccount->id); $emailAccount->apiUsername = static::$apiUsername; $emailAccount->apiPassword = static::$apiPassword; $emailAccount->save(); $this->assertEquals($emailAccount->getError('fromAddress'), 'From Address cannot be blank.'); $emailAccount->fromAddress = '*****@*****.**'; $this->assertTrue($emailAccount->save()); $emailAccountId = $emailAccount->id; $emailAccount = SendGridEmailAccount::resolveAndGetByUserAndName($super); $this->assertEquals($emailAccountId, $emailAccount->id); $this->assertEquals('Default', $emailAccount->name); $this->assertEquals($super, $emailAccount->user); $this->assertEquals($super->getFullName(), $emailAccount->fromName); $this->assertEquals('*****@*****.**', $emailAccount->fromAddress); $this->assertEquals(static::$apiUsername, $emailAccount->apiUsername); $this->assertEquals(static::$apiPassword, ZurmoPasswordSecurityUtil::decrypt($emailAccount->apiPassword)); }
/** * Send email. */ public function sendEmail() { $emailMessage = $this->emailMessage; if ($this->emailAccount == null) { $apiUser = Yii::app()->sendGridEmailHelper->apiUsername; $apiPassword = Yii::app()->sendGridEmailHelper->apiPassword; } else { $apiUser = $this->emailAccount->apiUsername; $apiPassword = ZurmoPasswordSecurityUtil::decrypt($this->emailAccount->apiPassword); } $itemData = EmailMessageUtil::getCampaignOrAutoresponderDataByEmailMessage($this->emailMessage); $sendgrid = new SendGrid($apiUser, $apiPassword, array("turn_off_ssl_verification" => true)); $email = new SendGrid\Email(); $email->setFrom($this->fromUserEmailData['address'])->setFromName($this->fromUserEmailData['name'])->setSubject($emailMessage->subject)->setText($emailMessage->content->textContent)->setHtml($emailMessage->content->htmlContent)->addUniqueArg("zurmoToken", md5(ZURMO_TOKEN))->addHeader('X-Sent-Using', 'SendGrid-API')->addHeader('X-Transport', 'web'); //Check if campaign and if yes, associate to email. if ($itemData != null) { list($itemId, $itemClass, $personId) = $itemData; $email->addUniqueArg("itemId", $itemId); $email->addUniqueArg("itemClass", $itemClass); $email->addUniqueArg("personId", $personId); } foreach ($this->toAddresses as $emailAddress => $name) { $email->addTo($emailAddress, $name); } foreach ($this->ccAddresses as $emailAddress => $name) { $email->addCc($emailAddress); } foreach ($this->bccAddresses as $emailAddress => $name) { $email->addBcc($emailAddress); } //Attachments $attachmentsData = array(); $tempAttachmentPath = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'emailAttachments'; if (!file_exists($tempAttachmentPath)) { mkdir($tempAttachmentPath); } if (!empty($emailMessage->files)) { foreach ($emailMessage->files as $file) { $fileName = tempnam($tempAttachmentPath, 'zurmo_'); $fp = fopen($fileName, 'wb'); fwrite($fp, $file->fileContent->content); fclose($fp); $email->addAttachment($fileName, $file->name); $attachmentsData[] = $fileName; } } $emailMessage->sendAttempts = $emailMessage->sendAttempts + 1; $response = $sendgrid->send($email); if ($response->message == 'success') { //Here we need to check if $emailMessage->error = null; $emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_SENT); $emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); } elseif ($response->message == 'error') { $content = Zurmo::t('EmailMessagesModule', 'Response from Server') . "\n"; foreach ($response->errors as $error) { $content .= $error; } $emailMessageSendError = new EmailMessageSendError(); $data = array(); $data['message'] = $content; $emailMessageSendError->serializedData = serialize($data); $emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_ERROR); $emailMessage->error = $emailMessageSendError; } if (count($attachmentsData) > 0) { foreach ($attachmentsData as $path) { unlink($path); } } $saved = $emailMessage->save(false); if (!$saved) { throw new FailedToSaveModelException(); } }
/** * In the event that the value is not properly encrypted it will just return an empty string */ public function testDecryptWithMalformedEncryptedValue() { $decryptedString = ZurmoPasswordSecurityUtil::decrypt('aweaweawe', 'someKey'); $this->assertEquals('', $decryptedString); }
/** * Encrypt password beforeSave * @return void */ public function afterValidate() { parent::afterValidate(); if ($this->apiPassword !== null && $this->apiPassword !== '') { $this->apiPassword = ZurmoPasswordSecurityUtil::encrypt($this->apiPassword); } }
/** * Get outbound settings. * @return array */ public function getOutboundSettings() { $settings = array(); foreach (static::$settingsToLoad as $keyName) { if ($keyName == 'outboundPassword') { $encryptedKeyValue = ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', $keyName); if ($encryptedKeyValue !== '' && $encryptedKeyValue !== null) { $keyValue = ZurmoPasswordSecurityUtil::decrypt($encryptedKeyValue); } else { $keyValue = null; } } elseif ($keyName == 'outboundType') { $keyValue = ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', 'outboundType'); if ($keyValue == null) { $keyValue = self::OUTBOUND_TYPE_SMTP; } } else { $keyValue = ZurmoConfigurationUtil::getByModuleName('EmailMessagesModule', $keyName); } if (null !== $keyValue) { $settings[$keyName] = $keyValue; } else { $settings[$keyName] = null; } } return $settings; }
/** * Assumes before calling this, the outbound settings have been validated in the form. * Todo: When new user interface is complete, this will be re-worked to be on page instead of modal. */ public function actionSendTestMessage() { $configurationForm = EmailSmtpConfigurationFormAdapter::makeFormFromGlobalConfiguration(); $postVariableName = get_class($configurationForm); if (isset($_POST[$postVariableName]) || isset($_POST['UserEmailConfigurationForm'])) { if (isset($_POST[$postVariableName])) { $configurationForm->setAttributes($_POST[$postVariableName]); } else { //Check for sendgrid if ($_POST['UserEmailConfigurationForm']['useCustomOutboundSettings'] == EmailMessageUtil::OUTBOUND_PERSONAL_SENDGRID_SETTINGS) { $this->processSendTestMessageForSendGrid(); } else { $configurationForm->host = $_POST['UserEmailConfigurationForm']['outboundHost']; $configurationForm->port = $_POST['UserEmailConfigurationForm']['outboundPort']; $configurationForm->username = $_POST['UserEmailConfigurationForm']['outboundUsername']; $configurationForm->password = $_POST['UserEmailConfigurationForm']['outboundPassword']; $configurationForm->security = $_POST['UserEmailConfigurationForm']['outboundSecurity']; $configurationForm->aTestToAddress = $_POST['UserEmailConfigurationForm']['aTestToAddress']; $fromNameToSendMessagesFrom = $_POST['UserEmailConfigurationForm']['fromName']; $fromAddressToSendMessagesFrom = $_POST['UserEmailConfigurationForm']['fromAddress']; } } if ($configurationForm->aTestToAddress != null) { $emailAccount = new EmailAccount(); $emailAccount->outboundHost = $configurationForm->host; $emailAccount->outboundPort = $configurationForm->port; $emailAccount->outboundUsername = $configurationForm->username; $emailAccount->outboundPassword = ZurmoPasswordSecurityUtil::encrypt($configurationForm->password); $emailAccount->outboundSecurity = $configurationForm->security; $isUser = false; if (isset($fromNameToSendMessagesFrom) && isset($fromAddressToSendMessagesFrom)) { $isUser = true; $from = array('name' => $fromNameToSendMessagesFrom, 'address' => $fromAddressToSendMessagesFrom); } else { $user = BaseControlUserConfigUtil::getUserToRunAs(); $userToSendMessagesFrom = User::getById((int) $user->id); $from = array('name' => Yii::app()->emailHelper->resolveFromNameForSystemUser($userToSendMessagesFrom), 'address' => Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom)); } $emailMessage = EmailMessageHelper::processAndCreateEmailMessage($from, $configurationForm->aTestToAddress); $mailer = new ZurmoSwiftMailer($emailMessage, $emailAccount); $emailMessage = $mailer->sendTestEmail($isUser); $messageContent = EmailHelper::prepareMessageContent($emailMessage); } else { $messageContent = Zurmo::t('EmailMessagesModule', 'A test email address must be entered before you can send a test email.') . "\n"; } Yii::app()->getClientScript()->setToAjaxMode(); $messageView = new TestConnectionView($messageContent); $view = new ModalView($this, $messageView); echo $view->render(); } else { throw new NotSupportedException(); } }
* 02110-1301 USA. * * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com. * * The interactive user interfaces in original and modified versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the Zurmo * logo and Zurmo copyright notice. If the display of the logo is not reasonably * feasible for technical reasons, the Appropriate Legal Notices must display the words * "Copyright Zurmo Inc. 2013. All rights reserved". ********************************************************************************/ require_once 'testRoots.php'; require_once 'TestConfigFileUtils.php'; TestConfigFileUtils::configureConfigFiles(); $debug = INSTANCE_ROOT . '/protected/config/debugTest.php'; $yiit = COMMON_ROOT . "/../yii/framework/yiit.php"; $config = INSTANCE_ROOT . "/protected/config/test.php"; require_once COMMON_ROOT . "/version.php"; require_once COMMON_ROOT . "/protected/modules/install/utils/InstallUtil.php"; require_once COMMON_ROOT . "/protected/core/utils/ZurmoPasswordSecurityUtil.php"; InstallUtil::setZurmoTokenAndWriteToPerInstanceFile(INSTANCE_ROOT, 'perInstanceTest.php'); ZurmoPasswordSecurityUtil::setPasswordSaltAndWriteToPerInstanceFile(INSTANCE_ROOT, 'perInstanceTest.php'); require_once $debug; require_once $yiit; require_once COMMON_ROOT . '/protected/core/components/WebApplication.php'; require_once COMMON_ROOT . '/protected/tests/WebTestApplication.php'; Yii::createApplication('WebTestApplication', $config);
/** * Populate settings. * @param EmailAccount $this->emailAccount * @return void */ protected function populateSettings() { if ($this->emailAccount != null && $this->emailAccount->outboundHost != null && $this->emailAccount->outboundPort != null && $this->emailAccount->outboundUsername != null && $this->emailAccount->outboundPassword != null) { $this->host = $this->emailAccount->outboundHost; $this->port = $this->emailAccount->outboundPort; $this->username = $this->emailAccount->outboundUsername; $this->password = ZurmoPasswordSecurityUtil::decrypt($this->emailAccount->outboundPassword); $this->security = $this->emailAccount->outboundSecurity; } else { $this->mailer = Yii::app()->emailHelper->outboundType; $this->host = Yii::app()->emailHelper->outboundHost; $this->port = Yii::app()->emailHelper->outboundPort; $this->username = Yii::app()->emailHelper->outboundUsername; $this->password = Yii::app()->emailHelper->outboundPassword; $this->security = Yii::app()->emailHelper->outboundSecurity; } }