Skip to content
Permalink
Browse files

New feature #12603: emailsmtppassword and bounceaccountpass settings …

…are saved encrypted in database
  • Loading branch information...
dominikvitt committed Jun 12, 2019
1 parent baf4aad commit fdc3241d9d65feccbec5ce3c100b40bbb1aad8ef
@@ -12,8 +12,8 @@
*/
$config['versionnumber'] ='4.0.0-beta';
$config['dbversionnumber'] = 415;
$config['dbversionnumber'] = 416;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30087';
$config['assetsversionnumber'] = '30088';
return $config;
@@ -260,15 +260,15 @@ private function _saveSettings()
SettingGlobal::setSetting('emailmethod', strip_tags(Yii::app()->getRequest()->getPost('emailmethod')));
SettingGlobal::setSetting('emailsmtphost', strip_tags(returnGlobal('emailsmtphost')));
if (returnGlobal('emailsmtppassword') != 'somepassword') {
SettingGlobal::setSetting('emailsmtppassword', strip_tags(returnGlobal('emailsmtppassword')));
SettingGlobal::setSetting('emailsmtppassword', LSActiveRecord::encryptSingle(strip_tags(returnGlobal('emailsmtppassword'))));
}
SettingGlobal::setSetting('bounceaccounthost', strip_tags(returnGlobal('bounceaccounthost')));
SettingGlobal::setSetting('bounceaccounttype', Yii::app()->request->getPost('bounceaccounttype', 'off'));
SettingGlobal::setSetting('bounceencryption', Yii::app()->request->getPost('bounceencryption', 'off'));
SettingGlobal::setSetting('bounceaccountuser', strip_tags(returnGlobal('bounceaccountuser')));
if (returnGlobal('bounceaccountpass') != 'enteredpassword') {
SettingGlobal::setSetting('bounceaccountpass', strip_tags(returnGlobal('bounceaccountpass')));
SettingGlobal::setSetting('bounceaccountpass', LSActiveRecord::encryptSingle(strip_tags(returnGlobal('bounceaccountpass'))));
}
SettingGlobal::setSetting('emailsmtpssl', sanitize_paranoid_string(Yii::app()->request->getPost('emailsmtpssl', '')));
@@ -98,13 +98,13 @@ public function bounceprocessing($iSurveyId)
$accounttype = strtoupper(getGlobalSetting('bounceaccounttype'));
$hostname = getGlobalSetting('bounceaccounthost');
$username = getGlobalSetting('bounceaccountuser');
$pass = getGlobalSetting('bounceaccountpass');
$pass = LSActiveRecord::decryptSingle(getGlobalSetting('bounceaccountpass'));
$hostencryption = strtoupper(getGlobalSetting('bounceencryption'));
} else {
$accounttype = strtoupper($thissurvey['bounceaccounttype']);
$hostname = $thissurvey['bounceaccounthost'];
$username = $thissurvey['bounceaccountuser'];
$pass = $thissurvey['bounceaccountpass'];
$pass = LSActiveRecord::decryptSingle($thissurvey['bounceaccountpass']);
$hostencryption = strtoupper($thissurvey['bounceaccountencryption']);
}
@@ -2354,7 +2354,7 @@ public function bouncesettings($iSurveyId)
if (Yii::app()->request->getPost('bounceprocessing') == 'L') {
$fieldvalue['bounceaccountencryption'] = Yii::app()->request->getPost('bounceaccountencryption');
$fieldvalue['bounceaccountuser'] = Yii::app()->request->getPost('bounceaccountuser');
$fieldvalue['bounceaccountpass'] = Yii::app()->request->getPost('bounceaccountpass');
$fieldvalue['bounceaccountpass'] = LSActiveRecord::encryptSingle(Yii::app()->request->getPost('bounceaccountpass'));
$fieldvalue['bounceaccounttype'] = Yii::app()->request->getPost('bounceaccounttype');
$fieldvalue['bounceaccounthost'] = Yii::app()->request->getPost('bounceaccounthost');
}
@@ -68,6 +68,10 @@ public function __construct($aApplicationConfig = null)
}
}
$this->config = array_merge($this->config, $lsConfig);
/* encrypt emailsmtppassword value, because emailsmtppassword in database is also encrypted
it would be decrypted in LimeMailer when needed */
$this->config['emailsmtppassword'] = LSActiveRecord::encryptSingle($this->config['emailsmtppassword']);
/* Load the database settings : if available */
try {
@@ -155,8 +155,13 @@ public function setConfigs() {
/* User file config */
$userConfigs = require(__DIR__.'/../config/config.php');
if (is_array($userConfigs['config'])) {
$this->config = array_merge($this->config, $userConfigs['config']);
$this->config = array_merge($this->config, $userConfigs['config']);
}
/* encrypt emailsmtppassword value, because emailsmtppassword in database is also encrypted
it would be decrypted in LimeMailer when needed */
$this->config['emailsmtppassword'] = LSActiveRecord::encryptSingle($this->config['emailsmtppassword']);
/* Check DB : let throw error if DB is broken issue #14875 */
$settingsTableExist = Yii::app()->db->schema->getTable('{{settings_global}}');
/* No table settings_global : not installable or updatable */
@@ -179,7 +184,8 @@ public function setConfigs() {
$this->getConfig('dbversionnumber',0).
$this->getConfig('customassetversionnumber',1)
);
}
}
/**
* Loads a helper
*
@@ -128,7 +128,7 @@ public function __construct($exceptions = false)
$emailmethod = Yii::app()->getConfig('emailmethod');
$emailsmtphost = Yii::app()->getConfig("emailsmtphost");
$emailsmtpuser = Yii::app()->getConfig("emailsmtpuser");
$emailsmtppassword = Yii::app()->getConfig("emailsmtppassword");
$emailsmtppassword = LSActiveRecord::decryptSingle(Yii::app()->getConfig("emailsmtppassword"));
$emailsmtpdebug = Yii::app()->getConfig("emailsmtpdebug");
$emailsmtpssl = Yii::app()->getConfig("emailsmtpssl");
$defaultlang = Yii::app()->getConfig("defaultlang");
@@ -2835,6 +2835,27 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$oTransaction->commit();
}
if($iOldDBVersion < 416) {
$oTransaction = $oDB->beginTransaction();
// encrypt values in db
SettingGlobal::setSetting('emailsmtppassword', LSActiveRecord::encryptSingle(getGlobalSetting('emailsmtppassword')));
SettingGlobal::setSetting('bounceaccountpass', LSActiveRecord::encryptSingle(getGlobalSetting('bounceaccountpass')));
// encrypt bounceaccountpass value in db
alterColumn('{{surveys}}','bounceaccountpass',"text",true,'NULL');
$aSurveys = Survey::model()->findAll();
foreach($aSurveys as $oSurvey){
if (!empty($oSurvey->bounceaccountpass)){
$oSurvey->bounceaccountpass = LSActiveRecord::encryptSingle($oSurvey->bounceaccountpass);
$oSurvey->save();
}
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>416),"stg_name='DBVersion'");
$oTransaction->commit();
}
} catch (Exception $e) {
Yii::app()->setConfig('Updating', false);
$oTransaction->rollback();
@@ -854,7 +854,7 @@ function createDatabase($oDB)
'bounceprocessing' => "string(1) default 'N'",
'bounceaccounttype' => "string(4)",
'bounceaccounthost' => "string(200)",
'bounceaccountpass' => "string(100)",
'bounceaccountpass' => "text NULL",
'bounceaccountencryption' => "string(3)",
'bounceaccountuser' => "string(200)",
'showwelcome' => "string(1) default 'Y'",

1 comment on commit fdc3241

@Shnoulle

This comment has been minimized.

Copy link
Collaborator

commented on fdc3241 Jun 12, 2019

\o/ Great

Please sign in to comment.
You can’t perform that action at this time.