From f7b650db3e18639f2945cfe1dc8d6d732bab2de5 Mon Sep 17 00:00:00 2001 From: Boris Gulay Date: Sat, 28 May 2016 18:19:26 +0300 Subject: [PATCH] Changed the way connection security is set. Now supporting SSL and TLS separatly. Closes #5, thanx to Wouter de Geus. --- ident_switch.php | 42 ++++++++++++++++++++++++++++-------------- localization/en_US.inc | 2 +- localization/ru_RU.inc | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ident_switch.php b/ident_switch.php index ec421f6..f6d2c0b 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -17,8 +17,9 @@ class ident_switch extends rcube_plugin private $my_log = 'ident_switch'; // Flags user in database - private $db_enabled = 1; - private $db_secure = 2; + private $db_enabled = 1; + private $db_secure_ssl = 2; + private $db_secure_tls = 4; function init() { @@ -149,7 +150,7 @@ class ident_switch extends rcube_plugin 'ident_switch.form.enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'), 'ident_switch.form.label' => array('type' => 'text', 'size' => 32), 'ident_switch.form.host' => array('type' => 'text', 'size' => 64), - 'ident_switch.form.secure' => array('type' => 'checkbox'), + 'ident_switch.form.secure' => array('type' => 'select', 'options' => array('ssl' => 'SSL', 'tls' => 'TLS')), 'ident_switch.form.port' => array('type' => 'text', 'size' => 5), 'ident_switch.form.username' => array('type' => 'text', 'size' => 64), 'ident_switch.form.password' => array('type' => 'password', 'size' => 64), @@ -171,8 +172,10 @@ class ident_switch extends rcube_plugin // Parse flags if ($r['flags'] & $this->db_enabled) $args['record']['ident_switch.form.enabled'] = true; - if ($r['flags'] & $this->db_secure) - $args['record']['ident_switch.form.secure'] = true; + if ($r['flags'] & $this->db_secure_tls) // TLS has priority + $args['record']['ident_switch.form.secure'] = 'tls'; + elseif ($r['flags'] & $this->db_secure_ssl) + $args['record']['ident_switch.form.secure'] = 'ssl'; } } @@ -191,8 +194,6 @@ class ident_switch extends rcube_plugin $flags = 0; if (get_input_value('_ident_switch_form_enabled', RCUBE_INPUT_POST)) $flags |= $this->db_enabled; - if (get_input_value('_ident_switch_form_secure', RCUBE_INPUT_POST)) - $flags |= $this->db_secure; if (!($flags & $this->db_enabled)) { @@ -249,6 +250,13 @@ class ident_switch extends rcube_plugin return $args; } + // Parse secure settings + $ssl = get_input_value('_ident_switch_form_secure', RCUBE_INPUT_POST); + if (strcasecmp($ssl, 'tls') === 0) + $flags |= $this->db_secure_tls; + elseif (strcasecmp($ssl, 'ssl') === 0) + $flags |= $this->db_secure_ssl; + $sql = 'SELECT id, password FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?'; $q = $rc->db->query($sql, $args['id'], $rc->user->ID); $r = $rc->db->fetch_assoc($q); @@ -354,16 +362,22 @@ class ident_switch extends rcube_plugin 'Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').' ); - $port = $r['port']; - $ssl = false; - if ($r['flags'] & $this->db_secure) + $def_port = 143; // Default port here! + $ssl = null; + if ($r['flags'] & $this->db_secure_tls) { - $ssl = true; - if (!$port) - $port = 993; // Default SSL/TLS port here! + $ssl = 'tls'; + $def_port = 143; // Default TLS port here! } + elseif ($r['flags'] & $this->db_secure_ssl) + { + $ssl = 'ssl'; + $def_port = 993; // Default SSL port here! + } + + $port = $r['port']; if (!$port) - $port = 143; // Default port here! + $port = $def_port; // If we are in default account now // save everything with STORAGE diff --git a/localization/en_US.inc b/localization/en_US.inc index 07b082d..a03b37a 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -17,7 +17,7 @@ $labels['form.label'] = 'Label'; $labels['form.host']='Server host name'; // Secure connection (SSL/TLS) -$labels['form.secure']='Secure connection (SSL/TLS)'; +$labels['form.secure']='Connection security'; // Port $labels['form.port']='Port'; diff --git a/localization/ru_RU.inc b/localization/ru_RU.inc index 10c3cb8..cf60d0f 100644 --- a/localization/ru_RU.inc +++ b/localization/ru_RU.inc @@ -17,7 +17,7 @@ $labels['form.label'] = 'Название'; $labels['form.host'] = 'Адрес сервера'; // Secure connection (SSL/TLS) -$labels['form.secure'] = 'Безопасное соединение (SSL/TLS)'; +$labels['form.secure'] = 'Защита подключения'; // Port $labels['form.port'] = 'Порт';