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); }
/** * 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; }
protected function resolveValueForPacking(array $value) { return ZurmoPasswordSecurityUtil::encrypt(serialize($value)); }
/** * Set outbound settings into the database. */ public function setOutboundSettings() { foreach (static::$settingsToLoad as $keyName) { if ($keyName == 'outboundPassword') { $password = ZurmoPasswordSecurityUtil::encrypt($this->{$keyName}); ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $password); } else { ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', $keyName, $this->{$keyName}); } } }
/** * 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}); } } }
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; }
/** * 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(); } }
/** * 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}); } } }
/** * Encrypt password beforeSave * @return void */ public function afterValidate() { parent::afterValidate(); if ($this->apiPassword !== null && $this->apiPassword !== '') { $this->apiPassword = ZurmoPasswordSecurityUtil::encrypt($this->apiPassword); } }