Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
057c88ebc5 | ||
|
|
41186b613e | ||
|
|
3e41e57888 | ||
|
|
0925fca08a | ||
|
|
67dc78a48c | ||
|
|
1b7d90a92b |
@@ -1,2 +1,6 @@
|
|||||||
# ident_switch
|
# ident_switch
|
||||||
ident_switch plugin for Roundcube
|
ident_switch plugin for Roundcube
|
||||||
|
|
||||||
|
This plugin allows users to switch between different accounts (including remote) in single Roundcube session.
|
||||||
|
|
||||||
|
*Inspired by identities_imap plugin that is no longer supported.*
|
||||||
@@ -22,6 +22,9 @@
|
|||||||
"php": ">=5.3.0",
|
"php": ">=5.3.0",
|
||||||
"roundcube/plugin-installer": ">=0.1.3"
|
"roundcube/plugin-installer": ">=0.1.3"
|
||||||
},
|
},
|
||||||
|
"conflict": {
|
||||||
|
"elm/identity_smtp": "*"
|
||||||
|
},
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://bitbucket.org/BoresExpress/ident_switch/issues"
|
"issues": "https://bitbucket.org/BoresExpress/ident_switch/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Password encryption:
|
|
||||||
'rcmail': encrypt passwords by default Roundcube methods.
|
|
||||||
'secure': encrypt passwords by using the IMAP password as encryption key.
|
|
||||||
NOTE: When using 'secure' encryption, If IMAP passwords are changed
|
|
||||||
using methods other than Roundcube Webmail interface
|
|
||||||
(hmail_password or password plugin) then IMAP server identities
|
|
||||||
passwords must be re-entered by users.
|
|
||||||
*/
|
|
||||||
$rcmail_config['identities_imap_crypt'] = 'rcmail';
|
|
||||||
|
|
||||||
/* password encryption salt (only used for secure encryption) */
|
|
||||||
$rcmail_config['identities_imap_salt'] = '!kQm*fF3pXe1Kbm%9';
|
|
||||||
|
|
||||||
/* predefined imap hosts (associated with the domain part of the identity email property) */
|
|
||||||
$rcmail_config['identities_imap_external'] = array(
|
|
||||||
);
|
|
||||||
|
|
||||||
$rcmail_config['identities_imap_internal'] = array(
|
|
||||||
'BoresSoft Webmail' => array(
|
|
||||||
'host' =>'localhost',
|
|
||||||
'delimiter' => '/',
|
|
||||||
'readonly' => false, // on match prevent field editing
|
|
||||||
),
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
@@ -1,44 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Password encryption:
|
|
||||||
'rcmail': encrypt passwords by default Roundcube methods.
|
|
||||||
'secure': encrypt passwords by using the IMAP password as encryption key.
|
|
||||||
NOTE: When using 'secure' encryption, If IMAP passwords are changed
|
|
||||||
using methods other than Roundcube Webmail interface
|
|
||||||
(hmail_password or password plugin) then IMAP server identities
|
|
||||||
passwords must be re-entered by users.
|
|
||||||
*/
|
|
||||||
$rcmail_config['identities_imap_crypt'] = 'rcmail';
|
|
||||||
|
|
||||||
/* password encryption salt (only used for secure encryption) */
|
|
||||||
$rcmail_config['identities_imap_salt'] = '!kQm*fF3pXe1Kbm%9';
|
|
||||||
|
|
||||||
/* predefined imap hosts (associated with the domain part of the identity email property) */
|
|
||||||
$rcmail_config['identities_imap_external'] = array(
|
|
||||||
'gmail.com' => array(
|
|
||||||
'host' =>'ssl://imap.gmail.com:993',
|
|
||||||
'delimiter' => '/',
|
|
||||||
'readonly' => true, // on match prevent field editing
|
|
||||||
),
|
|
||||||
'googlemail.com' => array(
|
|
||||||
'host' =>'ssl://imap.gmail.com:993',
|
|
||||||
'delimiter' => '/',
|
|
||||||
'readonly' => true, // on match prevent field editing
|
|
||||||
),
|
|
||||||
'freenet.de' => array(
|
|
||||||
'host' =>'mx.freenet.de',
|
|
||||||
'delimiter' => '.',
|
|
||||||
'readonly' => false, // on match prevent field editing
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$rcmail_config['identities_imap_internal'] = array(
|
|
||||||
'mydomain.tld' => array(
|
|
||||||
'host' =>'ssl://imap.mydomain.tld:993',
|
|
||||||
'delimiter' => '/',
|
|
||||||
'readonly' => true, // on match prevent field editing
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/* auto-detect IMAP server */
|
|
||||||
$rcmail_config['identities_imap_autodetect'] = false;
|
|
||||||
?>
|
|
||||||
@@ -13,3 +13,8 @@ function plugin_switchIdent_switch(val) {
|
|||||||
console.log("qwe1");
|
console.log("qwe1");
|
||||||
rcmail.http_post('plugin.ident_switch.switch', { '_ident-id': val });
|
rcmail.http_post('plugin.ident_switch.switch', { '_ident-id': val });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function plugin_switchIdent_fixIdent(iid) {
|
||||||
|
if (parseInt(iid) > 0)
|
||||||
|
$("#_from").val(iid);
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class ident_switch extends rcube_plugin
|
|||||||
public $task='?(?!login|logout).*';
|
public $task='?(?!login|logout).*';
|
||||||
|
|
||||||
private $table = 'ident_switch';
|
private $table = 'ident_switch';
|
||||||
|
private $my_postfix = '_iswitch';
|
||||||
|
|
||||||
// Flags user in database
|
// Flags user in database
|
||||||
private $db_enabled = 1;
|
private $db_enabled = 1;
|
||||||
@@ -22,10 +23,11 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
$this->add_hook('startup', array($this, 'on_startup'));
|
$this->add_hook('startup', array($this, 'on_startup'));
|
||||||
$this->add_hook('render_page', array($this, 'on_render_page'));
|
$this->add_hook('render_page', array($this, 'on_render_page'));
|
||||||
# $this->add_hook('smtp_connect', array($this, 'on_smtp_connect'));
|
$this->add_hook('smtp_connect', array($this, 'on_smtp_connect'));
|
||||||
$this->add_hook('identity_form', array($this, 'on_identity_form'));
|
$this->add_hook('identity_form', array($this, 'on_identity_form'));
|
||||||
$this->add_hook('identity_update', array($this, 'on_identity_update'));
|
$this->add_hook('identity_update', array($this, 'on_identity_update'));
|
||||||
$this->add_hook('identity_delete', array($this, 'on_identity_delete'));
|
$this->add_hook('identity_delete', array($this, 'on_identity_delete'));
|
||||||
|
$this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders'));
|
||||||
|
|
||||||
$this->register_action('plugin.ident_switch.switch', array($this, 'on_switch'));
|
$this->register_action('plugin.ident_switch.switch', array($this, 'on_switch'));
|
||||||
}
|
}
|
||||||
@@ -33,8 +35,9 @@ class ident_switch extends rcube_plugin
|
|||||||
function on_startup($args)
|
function on_startup($args)
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
error_log('Task: ' . $args['task'] . ', action: ' . $args['action']);
|
||||||
|
|
||||||
if (strtolower($rc->user->data['username']) != strtolower($_SESSION['username']))
|
if (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 1)
|
||||||
{ // We are impersonating
|
{ // We are impersonating
|
||||||
$rc->config->set('imap_cache', null);
|
$rc->config->set('imap_cache', null);
|
||||||
$rc->config->set('messages_cache', false);
|
$rc->config->set('messages_cache', false);
|
||||||
@@ -52,6 +55,7 @@ class ident_switch extends rcube_plugin
|
|||||||
function on_render_page($args)
|
function on_render_page($args)
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
error_log('Template: ' . $args['template']);
|
||||||
|
|
||||||
// Get list of alternative accounts
|
// Get list of alternative accounts
|
||||||
$sOpt = '';
|
$sOpt = '';
|
||||||
@@ -103,7 +107,19 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
function on_smtp_connect($args)
|
function on_smtp_connect($args)
|
||||||
{
|
{
|
||||||
error_log('on_smtp_connect');
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
|
// TODO: Rewrite with full settings!
|
||||||
|
|
||||||
|
if (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 1)
|
||||||
|
{
|
||||||
|
if ($args['smtp_user'] == '%u')
|
||||||
|
$args['smtp_user'] = $rc->user->data['username'];
|
||||||
|
if ($args['smtp_pass'] == '%p')
|
||||||
|
$args['smtp_pass'] = $rc->decrypt($_SESSION['password' . $this->my_postfix]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_identity_form($args)
|
function on_identity_form($args)
|
||||||
@@ -198,46 +214,64 @@ class ident_switch extends rcube_plugin
|
|||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
|
$sql = 'DELETE FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
|
||||||
$rc->db->query($sql, $args['id'], $rc->user->ID);
|
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
|
||||||
|
|
||||||
// TODO: Affected rows count for log
|
if ($rc->db->affected_rows($q))
|
||||||
|
$rc->write_log($this->my_log, 'Deleted associated information for identity with ID = ' . $args['id'] . '.');
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function on_template_object_composeheaders($args)
|
||||||
|
{
|
||||||
|
if ($args['id'] == '_from')
|
||||||
|
{
|
||||||
|
$rc = rcmail::get_instance();
|
||||||
|
if (strcasecmp($_SESSION['username'], $rc->user->data['username']) !== 0)
|
||||||
|
{
|
||||||
|
if (isset($_SESSION['iid' . $this->my_postfix]))
|
||||||
|
$rc->output->add_script('plugin_switchIdent_fixIdent(' . $_SESSION['iid' . $this->my_postfix] . ');', 'docready');
|
||||||
|
else
|
||||||
|
$rc->write_log($this->my_log, 'Special session variable with active identity ID not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function on_switch()
|
function on_switch()
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
$my_postfix = '_iswitch';
|
$my_postfix_len = strlen($this->my_postfix);
|
||||||
$my_postfix_len = strlen($my_postfix);
|
|
||||||
|
|
||||||
error_log('Switcing account!'); // TODO: Add nornal logging here!
|
|
||||||
|
|
||||||
$identId = rcube_utils::get_input_value('_ident-id', RCUBE_INPUT_POST);
|
$identId = rcube_utils::get_input_value('_ident-id', RCUBE_INPUT_POST);
|
||||||
error_log($identId);
|
|
||||||
|
|
||||||
if (-1 == $identId)
|
if (-1 == $identId)
|
||||||
{ // Switch to main account
|
{ // Switch to main account
|
||||||
|
$rc->write_log($this->my_log, 'Switching mailbox back to default.');
|
||||||
|
|
||||||
foreach ($_SESSION as $k => $v)
|
foreach ($_SESSION as $k => $v)
|
||||||
{
|
{
|
||||||
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $my_postfix, -$my_postfix_len, $my_postfix_len) === 0)
|
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $this->my_postfix, -$my_postfix_len, $my_postfix_len) === 0)
|
||||||
{
|
{
|
||||||
error_log($k . '=>' . $v);
|
$_SESSION[$k] = $_SESSION[$k . $this->my_postfix];
|
||||||
$_SESSION[$k] = $_SESSION[$k . $my_postfix];
|
$rc->session->remove($k . $this->my_postfix);
|
||||||
$rc->session->remove($k . $my_postfix);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_SESSION['username'] = $rc->user->data['username'];
|
$_SESSION['username'] = $rc->user->data['username'];
|
||||||
$_SESSION['password'] = $_SESSION['password' . $my_postfix];
|
$_SESSION['password'] = $_SESSION['password' . $this->my_postfix];
|
||||||
|
$_SESSION['iid' . $this->my_postfix] = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = 'SELECT host, flags, port, username, password FROM ' . $rc->db->table_name($this->table) . ' WHERE id = ? AND user_id = ?';
|
$sql = 'SELECT host, flags, port, username, password, iid FROM ' . $rc->db->table_name($this->table) . ' WHERE id = ? AND user_id = ?';
|
||||||
$q = $rc->db->query($sql, $identId ,$rc->user->ID);
|
$q = $rc->db->query($sql, $identId ,$rc->user->ID);
|
||||||
$r = $rc->db->fetch_assoc($q);
|
$r = $rc->db->fetch_assoc($q);
|
||||||
if (is_array($r))
|
if (is_array($r))
|
||||||
{
|
{
|
||||||
|
$rc->write_log(
|
||||||
|
$this->my_log,
|
||||||
|
'Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').'
|
||||||
|
);
|
||||||
|
|
||||||
$port = $r['port'];
|
$port = $r['port'];
|
||||||
$ssl = false;
|
$ssl = false;
|
||||||
if ($r['flags'] & $this->db_secure)
|
if ($r['flags'] & $this->db_secure)
|
||||||
@@ -255,28 +289,28 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
foreach ($_SESSION as $k => $v)
|
foreach ($_SESSION as $k => $v)
|
||||||
{
|
{
|
||||||
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $my_postfix, -$my_postfix_len, $my_postfix_len) !== 0)
|
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $this->my_postfix, -$my_postfix_len, $my_postfix_len) !== 0)
|
||||||
{
|
{
|
||||||
error_log($k . '=>' . $v);
|
$_SESSION[$k . $this->my_postfix] = $_SESSION[$k];
|
||||||
$_SESSION[$k . $my_postfix] = $_SESSION[$k];
|
|
||||||
$rc->session->remove($k);
|
$rc->session->remove($k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_SESSION['password' . $my_postfix] = $_SESSION['password'];
|
$_SESSION['password' . $this->my_postfix] = $_SESSION['password'];
|
||||||
|
|
||||||
$_SESSION['storage_host'] = $r['host'];
|
$_SESSION['storage_host'] = $r['host'];
|
||||||
$_SESSION['storage_ssl'] = $ssl;
|
$_SESSION['storage_ssl'] = $ssl;
|
||||||
$_SESSION['storage_port'] = $port;
|
$_SESSION['storage_port'] = $port;
|
||||||
$_SESSION['username'] = $r['username'];
|
$_SESSION['username'] = $r['username'];
|
||||||
$_SESSION['password'] = $r['password'];
|
$_SESSION['password'] = $r['password'];
|
||||||
|
$_SESSION['iid' . $this->my_postfix] = $r['iid'];
|
||||||
|
|
||||||
$rc->session->remove('folders');
|
$rc->session->remove('folders');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Show message in browser
|
// TODO: Show message in browser
|
||||||
error_log('Requested account not found!');
|
$rc->write_log($this->my_log, 'Requested remote mailbox with ID = ' . $identId . ' not found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user