Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: pstephan1187 on October 26, 2011, 11:21:21 AM

Title: Autologon Plugin
Post by: pstephan1187 on October 26, 2011, 11:21:21 AM
I cannot seem to get the autologon plugin to work. I have tried numerous things that other forum posts have suggested, but what others have found to work, I find to fail. I have an email administration system that allows domain administrators to manage the email accounts on their domain. Within this system, a logged on user can click "webmail" to redirect them to roundcube without logging in again. The button submits a form.

Here is the form to redirect to roundcube:






And here is the autologon plugin after the many attempts to get it to work:

class autologon extends rcube_plugin
{

  function init()
  {
    $this->add_hook('startup', array($this, 'startup'));
    $this->add_hook('authenticate', array($this, 'authenticate'));
  }

  function startup($args)
  {
    $rcmail = rcmail::get_instance();

    // change action to login
    if ($args['task'] == 'mail' && empty($args['action']) && empty($_SESSION['user_id']) && !empty($_POST['_autologin']))
      $args['action'] = 'login';

    // set initial cookie without this cookie login is not possible
    $_COOKIE['roundcube_sessid'] = session_id();

    return $args;
  }

  function authenticate($args)
  {
    if (!empty($_POST['_autologin'])) {
      $args['user'] = $_POST['_user'];
      $args['pass'] = $_POST['_pass'];
      if (!empty($_POST['_host']))
        $args['host'] = $_POST['_host'];
    }
 
    return $args;
  }

 }

?>


The plugin is set in the config file as well.
The error I get from roundcube is "Your session is invalid or expired."
Any help on resolving this problem will be greatly appreciated.
Title: Autologon Plugin
Post by: bakhtiyor on October 26, 2011, 12:29:35 PM
I need this feature also.
Title: Autologon Plugin
Post by: SKaero on October 26, 2011, 07:59:57 PM
You need to add:
$args['cookiecheck'] = false;
$args['valid'] = true;

to the authenticate function.
Title: Autologon Plugin
Post by: bakhtiyor on October 27, 2011, 07:10:56 AM
But it is not working for me. Could you manage to make it work @pstephan1187? Thank you
Title: Autologon Plugin
Post by: pstephan1187 on October 27, 2011, 05:42:23 PM
It still is not working. I am getting the same "Your session is invalid or expired." error.

Here is the updated autologon plugin:


class autologon extends rcube_plugin
{

  function init()
  {
    $this->add_hook('startup', array($this, 'startup'));
    $this->add_hook('authenticate', array($this, 'authenticate'));
  }

  function startup($args)
  {
    $rcmail = rcmail::get_instance();

    // change action to login
    if ($args['task'] == 'mail' && empty($args['action']) && empty($_SESSION['user_id']) && !empty($_POST['_autologin']))
      $args['action'] = 'login';

    // set initial cookie without this cookie login is not possible
    $_COOKIE['roundcube_sessid'] = session_id();

    return $args;
  }

  function authenticate($args)
  {
    if (!empty($_POST['_autologin'])) {
      $args['user'] = $_POST['_user'];
      $args['pass'] = $_POST['_pass'];
      $args['cookiecheck'] = false;
      $args['valid'] = true;
      if (!empty($_POST['_host']))
        $args['host'] = $_POST['_host'];
    }
 
    return $args;
  }

 }

?>


Is it possible that there might be something wrong with the config file? If so, I included that as well:

$rcmail_config = array();
$rcmail_config['debug_level'] = 1;
$rcmail_config['log_driver'] = 'file';
$rcmail_config['log_date_format'] = 'd-M-Y H:i:s O';
$rcmail_config['syslog_id'] = 'roundcube';
$rcmail_config['syslog_facility'] = LOG_USER;
$rcmail_config['smtp_log'] = true;
$rcmail_config['log_logins'] = false;
$rcmail_config['log_session'] = false;
$rcmail_config['sql_debug'] = false;
$rcmail_config['imap_debug'] = false;
$rcmail_config['ldap_debug'] = false;
$rcmail_config['smtp_debug'] = false;
$rcmail_config['default_host'] = 'mail.mydomaine.net';
$rcmail_config['default_port'] = 143;
$rcmail_config['imap_auth_type'] = null;
$rcmail_config['imap_delimiter'] = null;
$rcmail_config['imap_ns_personal'] = null;
$rcmail_config['imap_ns_other']    = null;
$rcmail_config['imap_ns_shared']   = null;
$rcmail_config['imap_force_caps'] = false;
$rcmail_config['imap_force_lsub'] = false;
$rcmail_config['imap_timeout'] = 0;
$rcmail_config['imap_auth_cid'] = null;
$rcmail_config['imap_auth_pw'] = null;
$rcmail_config['imap_cache'] = null;
$rcmail_config['messages_cache'] = false;
$rcmail_config['smtp_server'] = 'mail.mydomaine.net';
$rcmail_config['smtp_port'] = 25;
$rcmail_config['smtp_user'] = '%u';
$rcmail_config['smtp_pass'] = '%p';
$rcmail_config['smtp_auth_type'] = 'LOGIN';
$rcmail_config['smtp_auth_cid'] = null;
$rcmail_config['smtp_auth_pw'] = null;
$rcmail_config['smtp_helo_host'] = '';
$rcmail_config['smtp_timeout'] = 0;
$rcmail_config['enable_installer'] = false;
$rcmail_config['log_dir'] = 'logs/';
$rcmail_config['temp_dir'] = 'temp/';
$rcmail_config['message_cache_lifetime'] = '10d';
$rcmail_config['force_https'] = false;
$rcmail_config['use_https'] = false;
$rcmail_config['login_autocomplete'] = 0;
$rcmail_config['login_lc'] = false;
$rcmail_config['auto_create_user'] = true;
$rcmail_config['skin_logo'] = null;
$rcmail_config['skin_include_php'] = false;
$rcmail_config['session_lifetime'] = 10;
$rcmail_config['session_domain'] = '';
$rcmail_config['session_storage'] = 'db';
$rcmail_config['memcache_hosts'] = null;
$rcmail_config['ip_check'] = false;
$rcmail_config['referer_check'] = false;
$rcmail_config['x_frame_options'] = 'sameorigin';
$rcmail_config['des_key'] = 'rcmail-!24ByteDESkey*Str';
$rcmail_config['username_domain'] = '';
$rcmail_config['mail_domain'] = '';
$rcmail_config['password_charset'] = 'ISO-8859-1';
$rcmail_config['sendmail_delay'] = 0;
$rcmail_config['max_recipients'] = 0;
$rcmail_config['max_group_members'] = 0;
$rcmail_config['useragent'] = 'Roundcube Webmail/'.RCMAIL_VERSION;
$rcmail_config['product_name'] = 'Roundcube Webmail';
$rcmail_config['include_host_config'] = false;
$rcmail_config['generic_message_footer'] = '';
$rcmail_config['generic_message_footer_html'] = '';
$rcmail_config['http_received_header'] = false;
$rcmail_config['http_received_header_encrypt'] = false;
$rcmail_config['mail_header_delimiter'] = NULL;
$rcmail_config['line_length'] = 72;
$rcmail_config['send_format_flowed'] = true;
$rcmail_config['dont_override'] = array();
$rcmail_config['identities_level'] = 0;
$rcmail_config['client_mimetypes'] = null;
$rcmail_config['mime_magic'] = '/usr/share/misc/magic';
$rcmail_config['im_identify_path'] = null;
$rcmail_config['im_convert_path'] = null;
$rcmail_config['contact_photo_size'] = 160;
$rcmail_config['email_dns_check'] = false;
$rcmail_config['plugins'] = array('autologon');
$rcmail_config['message_sort_col'] = '';
$rcmail_config['message_sort_order'] = 'DESC';
$rcmail_config['list_cols'] = array('subject', 'status', 'from', 'date', 'size', 'flag', 'attachment');
$rcmail_config['language'] = null;
$rcmail_config['date_short'] = 'D H:i';
$rcmail_config['date_long'] = 'd.m.Y H:i';
$rcmail_config['date_today'] = 'H:i';
$rcmail_config['date_format'] = 'Y-m-d';
$rcmail_config['drafts_mbox'] = 'Drafts';
$rcmail_config['junk_mbox'] = 'Junk';
$rcmail_config['sent_mbox'] = 'Sent';
$rcmail_config['trash_mbox'] = 'Trash';
$rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent', 'Junk', 'Trash');
$rcmail_config['create_default_folders'] = true;
$rcmail_config['protect_default_folders'] = true;
$rcmail_config['quota_zero_as_unlimited'] = false;
$rcmail_config['enable_spellcheck'] = true;
$rcmail_config['spellcheck_engine'] = 'googie';
$rcmail_config['spellcheck_uri'] = '';
$rcmail_config['spellcheck_languages'] = NULL;
$rcmail_config['max_pagesize'] = 200;
$rcmail_config['min_keep_alive'] = 60;
$rcmail_config['upload_progress'] = false;
$rcmail_config['undo_timeout'] = 0;
$rcmail_config['address_book_type'] = 'sql';
$rcmail_config['ldap_public'] = array();
$rcmail_config['autocomplete_addressbooks'] = array('sql');
$rcmail_config['autocomplete_min_length'] = 1;
$rcmail_config['autocomplete_threads'] = 0;
$rcmail_config['autocomplete_max'] = 15;
$rcmail_config['address_template'] = '{street}
{locality} {zipcode}
{country} {region}';
$rcmail_config['default_charset'] = 'ISO-8859-1';
$rcmail_config['skin'] = 'default';
$rcmail_config['pagesize'] = 40;
$rcmail_config['timezone'] = 'auto';
$rcmail_config['dst_active'] = (bool)date('I');
$rcmail_config['prefer_html'] = true;
$rcmail_config['show_images'] = 0;
$rcmail_config['htmleditor'] = 0;
$rcmail_config['prettydate'] = true;
$rcmail_config['draft_autosave'] = 300;
$rcmail_config['preview_pane'] = false;
$rcmail_config['preview_pane_mark_read'] = 0;
$rcmail_config['logout_purge'] = false;
$rcmail_config['logout_expunge'] = false;
$rcmail_config['inline_images'] = true;
$rcmail_config['mime_param_folding'] = 1;
$rcmail_config['skip_deleted'] = false;
$rcmail_config['read_when_deleted'] = true;
$rcmail_config['flag_for_deletion'] = false;
$rcmail_config['keep_alive'] = 60;
$rcmail_config['check_all_folders'] = false;
$rcmail_config['display_next'] = false;
$rcmail_config['autoexpand_threads'] = 0;
$rcmail_config['top_posting'] = false;
$rcmail_config['strip_existing_sig'] = true;
$rcmail_config['show_sig'] = 1;
$rcmail_config['sig_above'] = false;
$rcmail_config['force_7bit'] = false;
$rcmail_config['search_mods'] = null;
$rcmail_config['addressbook_search_mods'] = null;
$rcmail_config['delete_always'] = false;
$rcmail_config['mdn_requests'] = 0;
$rcmail_config['mdn_default'] = 0;
$rcmail_config['dsn_default'] = 0;
$rcmail_config['reply_same_folder'] = false;
$rcmail_config['forward_attachment'] = false;
$rcmail_config['default_addressbook'] = null;
$rcmail_config['spellcheck_before_send'] = false;


Obviously mail.mydomaine.net is replaced with the correct domain. Thank you for your help.
Title: Autologon Plugin
Post by: pstephan1187 on October 28, 2011, 10:09:57 AM
OK. I just realized that I am using a custom session handler for the Email manager program. The roundcube installation is located within the same domain, but is not utilizing the custom session handler. Could that be causing the problem? If so, how do I get roundcube to utilize the custom handler?
Title: Autologon Plugin
Post by: pstephan1187 on October 28, 2011, 10:35:29 AM
I included my custom session handler in the inlude/rcmail.php file because that is the only place that I found a session_start() command. I included my script at the very top of the file. Here it is:


ini_set('session.gc_maxlifetime',60*60*2);//2 hours
ini_set("session.gc_probability",10);//10% chance

$s = new Sessions('localhost','sessions','s1t3Chat','settings');
session_set_save_handler (
array(&$s, 'open'),
array(&$s, 'close'),
array(&$s, 'read'),
array(&$s, 'write'),
array(&$s, 'destroy'),
array(&$s, 'gc')
);
class Sessions {...}


It still does not work. Any ideas?
Title: Autologon Plugin
Post by: pstephan1187 on October 31, 2011, 09:05:24 AM
Has anyone actually gotten this plugin to work? It is baffling me for some reason.