Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a97816d1c | ||
|
|
6849c47fd9 | ||
|
|
ecbadcd866 | ||
|
|
9ebacf0d61 | ||
|
|
ab7bae56b5 | ||
|
|
d93dd2be03 | ||
|
|
f7b650db3e | ||
|
|
4da9b48776 |
5
SQL/mysql/2016060200.sql
Normal file
5
SQL/mysql/2016060200.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE
|
||||
ident_switch
|
||||
MODIFY
|
||||
username
|
||||
varchar(64);
|
||||
5
SQL/postgres/2016060200.sql
Normal file
5
SQL/postgres/2016060200.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE
|
||||
ident_switch
|
||||
ALTER COLUMN
|
||||
username
|
||||
DROP NOT NULL;
|
||||
@@ -14,14 +14,23 @@ $(function() {
|
||||
}
|
||||
}
|
||||
|
||||
var $enFld = $("INPUT[name='_ident_switch.form.enabled']");
|
||||
if ($enFld.size() == 1)
|
||||
$enFld.change();
|
||||
$("INPUT[name='_ident_switch.form.enabled']").change();
|
||||
$("SELECT[name='_ident_switch.form.secure']").change();
|
||||
});
|
||||
|
||||
function plugin_switchIdent_enabled_onChange(e) {
|
||||
var $enFld = $("INPUT[name='_ident_switch.form.enabled']");
|
||||
$("INPUT[name!='_ident_switch.form.enabled']", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked"));
|
||||
$("INPUT[name!='_ident_switch.form.enabled'], SELECT", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked"));
|
||||
}
|
||||
|
||||
function plugin_switchIdent_secure_onChange(e) {
|
||||
var $secSel = $("SELECT[name='_ident_switch.form.secure']");
|
||||
var $portFld = $("INPUT[name='_ident_switch.form.port']");
|
||||
|
||||
if ('SSL' === $secSel.val().toUpperCase())
|
||||
$portFld.attr("placeholder", 993);
|
||||
else
|
||||
$portFld.attr("placeholder", 143);
|
||||
}
|
||||
|
||||
function plugin_switchIdent_switch(val) {
|
||||
|
||||
@@ -14,10 +14,12 @@ class ident_switch extends rcube_plugin
|
||||
|
||||
private $table = 'ident_switch';
|
||||
private $my_postfix = '_iswitch';
|
||||
private $my_log = 'ident_switch';
|
||||
|
||||
// Flags user in database
|
||||
private $db_enabled = 1;
|
||||
private $db_secure = 2;
|
||||
private $db_secure_ssl = 2;
|
||||
private $db_secure_tls = 4;
|
||||
|
||||
function init()
|
||||
{
|
||||
@@ -57,20 +59,40 @@ class ident_switch extends rcube_plugin
|
||||
$rc = rcmail::get_instance();
|
||||
error_log('Template: ' . $args['template']);
|
||||
|
||||
// Currently selected identity
|
||||
$iid = $_SESSION['iid' . $this->my_postfix];
|
||||
|
||||
$iid_int = 0;
|
||||
if (is_int($iid))
|
||||
$iid_int = $iid;
|
||||
elseif ($iid === '-1')
|
||||
$iid_int = -1;
|
||||
elseif (ctype_digit($iid))
|
||||
$iid_int = intval($iid);
|
||||
|
||||
// Get list of alternative accounts
|
||||
$sOpt = '';
|
||||
$sql = 'SELECT id, label, username FROM ' . $rc->db->table_name($this->table) . ' WHERE user_id = ? AND flags & ? > 0';
|
||||
$sql = 'SELECT id, iid, label, username FROM ' . $rc->db->table_name($this->table) . ' WHERE user_id = ? AND flags & ? > 0';
|
||||
$q = $rc->db->query($sql, $rc->user->data['user_id'], $this->db_enabled);
|
||||
while ($r = $rc->db->fetch_assoc($q))
|
||||
{
|
||||
$opts = array('value' => $r['id']);
|
||||
if (strcasecmp($_SESSION['username'], $r['username']) === 0)
|
||||
if ($iid_int == $r['iid'])
|
||||
$opts['selected'] = 'selected';
|
||||
|
||||
// Make label
|
||||
$lbl = $r['label'];
|
||||
if (!$lbl)
|
||||
{
|
||||
if (!$r['username'])
|
||||
{ // Load email from identity
|
||||
$sql = 'SELECT email FROM ' . $rc->db->table_name('identities') . ' WHERE identity_id = ?';
|
||||
$q = $rc->db->query($sql, $r['iid']);
|
||||
$rIid = $rc->db->fetch_assoc($q);
|
||||
|
||||
$r['username'] = $rIid['email'];
|
||||
}
|
||||
|
||||
if (strpos($r['username'], '@') === false)
|
||||
$lbl = $r['username'] . '@' . ($r['host'] ? $r['host'] : 'localhost');
|
||||
else
|
||||
@@ -89,7 +111,7 @@ class ident_switch extends rcube_plugin
|
||||
{
|
||||
// Add main account
|
||||
$opts = array('value' => -1);
|
||||
if (strcasecmp($_SESSION['username'], $rc->user->data['username']) === 0)
|
||||
if (!$iid || $iid_int == -1)
|
||||
$opts['selected'] = 'selected';
|
||||
|
||||
$sOpt = html::tag(
|
||||
@@ -120,7 +142,7 @@ class ident_switch extends rcube_plugin
|
||||
|
||||
// TODO: Rewrite with full settings!
|
||||
|
||||
if (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 1)
|
||||
if (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0)
|
||||
{
|
||||
if ($args['smtp_user'] == '%u')
|
||||
$args['smtp_user'] = $rc->user->data['username'];
|
||||
@@ -146,13 +168,17 @@ class ident_switch extends rcube_plugin
|
||||
'name' => $this->gettext('form.caption'),
|
||||
'content' => array(
|
||||
'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.label' => array('type' => 'text', 'size' => 32, 'placeholder' => $args['record']['email']),
|
||||
'ident_switch.form.host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
|
||||
'ident_switch.form.secure' => array(
|
||||
'type' => 'select',
|
||||
'options' => array('ssl' => 'SSL', 'tls' => 'TLS'),
|
||||
'onchange' => 'plugin_switchIdent_secure_onChange();'
|
||||
),
|
||||
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
|
||||
'ident_switch.form.username' => array('type' => 'text', 'size' => 64),
|
||||
'ident_switch.form.username' => array('type' => 'text', 'size' => 64, 'placeholder' => $args['record']['email']),
|
||||
'ident_switch.form.password' => array('type' => 'password', 'size' => 64),
|
||||
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1),
|
||||
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1, 'placeholder' => '.'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -170,8 +196,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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,8 +218,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))
|
||||
{
|
||||
@@ -225,10 +251,6 @@ class ident_switch extends rcube_plugin
|
||||
if (strlen($fUser) > 64)
|
||||
$errMsg = 'user.long';
|
||||
else
|
||||
{
|
||||
if (!$fUser)
|
||||
$errMsg = 'user.empty';
|
||||
else
|
||||
{
|
||||
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
|
||||
if (strlen($fDelim) > 1)
|
||||
@@ -238,7 +260,6 @@ class ident_switch extends rcube_plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errMsg)
|
||||
{
|
||||
@@ -248,6 +269,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);
|
||||
@@ -348,21 +376,36 @@ class ident_switch extends rcube_plugin
|
||||
$r = $rc->db->fetch_assoc($q);
|
||||
if (is_array($r))
|
||||
{
|
||||
if (!$r['username'])
|
||||
{ // Load email from identity
|
||||
$sql = 'SELECT email FROM ' . $rc->db->table_name('identities') . ' WHERE identity_id = ?';
|
||||
$q = $rc->db->query($sql, $r['iid']);
|
||||
$rIid = $rc->db->fetch_assoc($q);
|
||||
|
||||
$r['username'] = $rIid['email'];
|
||||
}
|
||||
|
||||
$rc->write_log(
|
||||
$this->my_log,
|
||||
'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
|
||||
@@ -372,11 +415,13 @@ class ident_switch extends rcube_plugin
|
||||
{
|
||||
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $this->my_postfix, -$my_postfix_len, $my_postfix_len) !== 0)
|
||||
{
|
||||
if (!$_SESSION[$k . $this->my_postfix])
|
||||
$_SESSION[$k . $this->my_postfix] = $_SESSION[$k];
|
||||
$rc->session->remove($k);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$_SESSION['password' . $this->my_postfix])
|
||||
$_SESSION['password' . $this->my_postfix] = $_SESSION['password'];
|
||||
|
||||
$_SESSION['storage_host'] = $r['host'] ? $r['host'] : 'localhost'; // Default host here!
|
||||
|
||||
@@ -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';
|
||||
@@ -31,9 +31,6 @@ $labels['form.password'] = 'Password';
|
||||
// Folder hierarchy delimiter
|
||||
$labels['form.delimiter'] = 'Folder hierarchy delimiter';
|
||||
|
||||
// \'Username\' field in IMAP section cannot be empty.
|
||||
$labels['err.user.empty'] = '\'Username\' field in IMAP section cannot be empty.';
|
||||
|
||||
// Value in \'Label\' field of IMAP section is too long (32 chars max).
|
||||
$labels['err.label.long'] = 'Value in \'Label\' field of IMAP section is too long (32 chars max).';
|
||||
|
||||
|
||||
@@ -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'] = 'Порт';
|
||||
@@ -31,9 +31,6 @@ $labels['form.password'] = 'Пароль';
|
||||
// Folder hierarchy delimiter
|
||||
$labels['form.delimiter'] = 'Разделитель в иерархии папок';
|
||||
|
||||
// \'Username\' field in IMAP section cannot be empty.
|
||||
$labels['err.user.empty'] = '\'Имя пользователя\' в разделе IMAP не может быть пустым.';
|
||||
|
||||
// Value in \'Label\' field of IMAP section is too long (32 chars max).
|
||||
$labels['err.label.long'] = '\'Название\' в разделе IMAP должно быть не длинее 32 символов.';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user