BUG #853
*edit - encryptedFields - auto encrypt and decrypt in ConfigController + possibility to unset that fieldpull/854/head
parent
23959c4151
commit
ff2947c00c
|
@ -293,7 +293,7 @@ $sm_lang = array(
|
||||||
'email_smtp_security_none' => 'None',
|
'email_smtp_security_none' => 'None',
|
||||||
'email_smtp_username' => 'SMTP username',
|
'email_smtp_username' => 'SMTP username',
|
||||||
'email_smtp_password' => 'SMTP password',
|
'email_smtp_password' => 'SMTP password',
|
||||||
'email_smtp_password_description' => 'Fill only to set or change.',
|
//'email_smtp_password_description' => '',
|
||||||
'email_smtp_noauth' => 'Leave blank for no authentication',
|
'email_smtp_noauth' => 'Leave blank for no authentication',
|
||||||
'sms_status' => 'Allow sending text messages',
|
'sms_status' => 'Allow sending text messages',
|
||||||
'sms_gateway' => 'Gateway to use for sending messages',
|
'sms_gateway' => 'Gateway to use for sending messages',
|
||||||
|
|
|
@ -67,7 +67,6 @@ class ConfigController extends AbstractController
|
||||||
'email_smtp_host',
|
'email_smtp_host',
|
||||||
'email_smtp_port',
|
'email_smtp_port',
|
||||||
'email_smtp_username',
|
'email_smtp_username',
|
||||||
//'email_smtp_password', // not typical input - and saved encrypted
|
|
||||||
'sms_gateway_username',
|
'sms_gateway_username',
|
||||||
'sms_gateway_password',
|
'sms_gateway_password',
|
||||||
'sms_from',
|
'sms_from',
|
||||||
|
@ -75,6 +74,14 @@ class ConfigController extends AbstractController
|
||||||
'telegram_api_token',
|
'telegram_api_token',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fields for saving encrypted.
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $encryptedFields = [
|
||||||
|
'email_smtp_password'
|
||||||
|
];
|
||||||
|
|
||||||
private $default_tab = 'general';
|
private $default_tab = 'general';
|
||||||
|
|
||||||
public function __construct(Database $db, \Twig_Environment $twig)
|
public function __construct(Database $db, \Twig_Environment $twig)
|
||||||
|
@ -177,6 +184,14 @@ class ConfigController extends AbstractController
|
||||||
foreach ($this->fields as $input_key) {
|
foreach ($this->fields as $input_key) {
|
||||||
$tpl_data[$input_key] = (isset($config[$input_key])) ? $config[$input_key] : '';
|
$tpl_data[$input_key] = (isset($config[$input_key])) ? $config[$input_key] : '';
|
||||||
}
|
}
|
||||||
|
// encrypted fields
|
||||||
|
foreach ($this->encryptedFields as $encryptedField) {
|
||||||
|
if (true === isset($config[$encryptedField]) && trim($config[$encryptedField])) {
|
||||||
|
$tpl_data[$encryptedField] = psm_password_decrypt($config['password_encrypt_key'], $config[$encryptedField]);
|
||||||
|
} else {
|
||||||
|
$tpl_data[$encryptedField] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$tpl_data[$this->default_tab . '_active'] = 'active';
|
$tpl_data[$this->default_tab . '_active'] = 'active';
|
||||||
|
|
||||||
|
@ -204,9 +219,7 @@ class ConfigController extends AbstractController
|
||||||
{
|
{
|
||||||
if (!empty($_POST)) {
|
if (!empty($_POST)) {
|
||||||
// save new config
|
// save new config
|
||||||
$emailSmtpPassword = filter_input(INPUT_POST, 'email_smtp_password');
|
$clean = array(
|
||||||
|
|
||||||
$clean = array(
|
|
||||||
'language' => $_POST['language'],
|
'language' => $_POST['language'],
|
||||||
'sms_gateway' => $_POST['sms_gateway'],
|
'sms_gateway' => $_POST['sms_gateway'],
|
||||||
'alert_type' => $_POST['alert_type'],
|
'alert_type' => $_POST['alert_type'],
|
||||||
|
@ -218,10 +231,7 @@ class ConfigController extends AbstractController
|
||||||
'log_retention_period' => intval(psm_POST('log_retention_period', 365)),
|
'log_retention_period' => intval(psm_POST('log_retention_period', 365)),
|
||||||
'password_encrypt_key' => psm_POST('password_encrypt_key', sha1(microtime())),
|
'password_encrypt_key' => psm_POST('password_encrypt_key', sha1(microtime())),
|
||||||
);
|
);
|
||||||
if ($emailSmtpPassword !== null && $emailSmtpPassword !== '') {
|
foreach ($this->checkboxes as $input_key) {
|
||||||
$clean['email_smtp_password'] = psm_password_encrypt(psm_get_conf('password_encrypt_key'), $emailSmtpPassword);
|
|
||||||
}
|
|
||||||
foreach ($this->checkboxes as $input_key) {
|
|
||||||
$clean[$input_key] = (isset($_POST[$input_key])) ? '1' : '0';
|
$clean[$input_key] = (isset($_POST[$input_key])) ? '1' : '0';
|
||||||
}
|
}
|
||||||
foreach ($this->fields as $input_key) {
|
foreach ($this->fields as $input_key) {
|
||||||
|
@ -229,6 +239,14 @@ class ConfigController extends AbstractController
|
||||||
$clean[$input_key] = $_POST[$input_key];
|
$clean[$input_key] = $_POST[$input_key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($this->encryptedFields as $encryptedField) {
|
||||||
|
$value = filter_input(INPUT_POST, $encryptedField);
|
||||||
|
if ($value !== null && $value !== '') {
|
||||||
|
$clean[$encryptedField] = psm_password_encrypt(psm_get_conf('password_encrypt_key'), $value);
|
||||||
|
} else {
|
||||||
|
$clean[$encryptedField] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
$language_refresh = ($clean['language'] != psm_get_conf('language'));
|
$language_refresh = ($clean['language'] != psm_get_conf('language'));
|
||||||
foreach ($clean as $key => $value) {
|
foreach ($clean as $key => $value) {
|
||||||
psm_update_conf($key, $value);
|
psm_update_conf($key, $value);
|
||||||
|
|
Loading…
Reference in New Issue