Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: brandonsmith on June 13, 2012, 12:57:36 PM

Title: Autologin fails in 0.7
Post by: brandonsmith on June 13, 2012, 12:57:36 PM
I have tried all the post i can find to get RoundCube autologin to work, every time is results in "Your session is invalid or expired." 

I added the $args['valid']=true; to the autologin.php file.

Any thoughts?
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 13, 2012, 10:06:46 PM
Why don't you post your autologin.php file.
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 14, 2012, 03:41:25 PM
<?php

/**
* This plugin performs an automatic login if accessed
* with post Data from other Site an Portal or CMS
* Based on sample autologon PlugIn
*
* @version 0.2
* @author Eric Appelt (lacri)
*
* show into README to install and config
*
* changes
* 0.2 make a little bit secure with base64_encode strrev
* and a key thats replace after submitting encoded pass data
*
*/

class autologin 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();

    $autologin = get_input_value('_autologin', RCUBE_INPUT_POST);

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

      // decode pass, revert and replace key
   $_POST['_pass'] = str_replace('1800','',base64_decode(strrev(get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'))));

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

  function authenticate($args)
  {
    $autologin = get_input_value('_autologin', RCUBE_INPUT_POST);

    if (!empty($autologin)) {
      $args['user'] = get_input_value('_user', RCUBE_INPUT_POST);
      $args['pass'] = get_input_value('_pass', RCUBE_INPUT_POST);
      $args['host'] = get_input_value('_host', RCUBE_INPUT_POST);
      $args['cookiecheck'] = false;
      $args['valid'] = true;
    }
    return $args;
  }
}
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 02:18:09 AM
Try the following instead of what your using, if you still have problems post the form that submits to RoundCube.

<?php
class autologon extends rcube_plugin
{
  public 
$task 'login';

  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 (empty($_SESSION['user_id']) && !empty($_POST['_autologin']))
      
$args['action'] = 'login';

    return 
$args;
  }

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

}
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 11:54:54 AM
still takes me to "Your session is invalid or expired."
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 11:55:50 AM
how do i post to roundcube ? does this not?
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 12:19:55 PM
Are you expecting to just go to RoundCube and be automatically logged in or are you trying to login from a different place like a form on a website?
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 12:47:06 PM
I have an intranet side that users already log into that already has their loging information stores in a database. I was trying to build a "click here" that logs into the roundcube mail app.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 01:25:54 PM
Ah well then your missing some steps, the plugin that you've posted is only setup to accept posts from another form. Where you trying to pass the login information in the link?
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 01:33:57 PM
Either way (post or get). I had been tryin with a hidden form submit to http://<server ip>/?task=login. The form would fill out everything except the password and the form would error out.  But whatever is easier.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 01:46:59 PM
Well you'd need to have the password in order to login.
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 01:53:20 PM
I know, and I would submit it in the form.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 02:01:55 PM
Ok then can post the form you are trying to use?
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 02:44:07 PM
<?
// set the passwort in session to fill the text login form with revertet and base64 encoded pass
// the *yourkey* must the same string as in autologin.php to replace this after revert and decode

echo '<form name="roundcubelogin" action="http://10.145.66.139/roundcube/?_task=mail" method="post" target="roundcube">
<input type="text" name="_timezone" value="_default_" />
<input type="text" name="_task" value="mail" />
<input type="text" name="_autologin" value="1" />
<input type="text" name="_user" value="<email address>" />
<input type="text" name="_host" value="imap.emailsrvr.com:143" />
<input type="text" name="_pass" value="<password>" />
<a href="#" onclick="document.forms.roundcubelogin.submit()">linktext image</a>
</form>';
?>


This is the same code as was given in the plugin sans the removal of the "encrypted" password line

*note .. the username and password were removed.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 05:17:23 PM
Ok try this for the autologon.php plugin file:

<?php
class autologon extends rcube_plugin
{
  public 
$task 'login';

  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 (empty($_SESSION['user_id']) && !empty($_POST['_autologin']))
      
$args['action'] = 'login';

    return 
$args;
  }

  function 
authenticate($args)
  {
    if (!empty(
$_POST['_autologin'])) {
      
$args['user'] = $_POST['_user'];
      
$args['pass'] = str_replace('1800','',base64_decode(strrev(get_input_value('_pass'RCUBE_INPUT_POSTtrue'ISO-8859-1'))));
      
$args['host'] = $_POST['_host'];
      
$args['cookiecheck'] = false;
      
$args['valid'] = true;
    }
  
    return 
$args;
  }

}

And the following for the form:

echo '<form name="roundcubelogin" action="http://10.145.66.139/roundcube/" method="post" target="roundcube">
<input type="text" name="_autologin" value="1" />
<input type="text" name="_user" value="<email address>" />
<input type="text" name="_host" value="imap.emailsrvr.com:143" />
<input type="text" name="_pass" value="<password>" />
<a href="#" onclick="document.forms.roundcubelogin.submit()">linktext image</a>
</form>';
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 05:41:06 PM
ok ... that no longer errors, but it just takes me to the login screen and input the information (sans the password) into the form.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 06:03:59 PM
Probably the password is wrong. If you replace:

str_replace('1800','',base64_decode(strrev(get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'))))

with the account password in clear text (ie "password") does it work?
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 06:09:27 PM
i changed it to:

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


that goes back to returning "your session is invalid or expired"
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 06:12:58 PM
There shouldn't be a space between $args and ['user'].
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 06:17:05 PM
there isn't .... miss copied. (i am doing this from a vm)
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 06:20:00 PM
Ok then add die('<pre>'. print_r($args, true)); before: return $args; and post whats returned after a login attempt.
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 06:27:58 PM
now reads:

function authenticate($args) {
  if (!empty($_POST['_autologin'])) {
    $args['user']= $_POST['_user'];
    $args['pass']='<password>';
    $args['host']=$_POST['_host'];
    $args['cookiecheck']= false;
    $args['valid'] = true;
  }
  die ('<pre>'. print_r($args, true));
  return $args;
}


That take me back to the login screen with error: "Your session is invalid or expired."

as a side note ... i also tried in the die field die('<pre>'.implode(",",$args)); and die ('<pre>'; print_r($args,true)); I was unsure if php accepted a print_r after a '.'
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 06:40:44 PM
Hmm it doesn't look like its getting to the authenticate function, try changing the form action to point to http://10.145.66.139/roundcube/?_task=login
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 06:47:36 PM
that bring me back to login page with everything but the password filled in. No errors. No dump from the die line.
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 15, 2012, 07:40:42 PM
Hmm maybe its doing a ajax post at that point for some reason, its hard to guess without being able to see/test it. Is there anyway I could get test access to it?
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 15, 2012, 08:41:55 PM
Unfortunately no. It is internal only. Does it make any difference that it is most current release of roundcube. Or that the install was done with aptitude? Is there anyway to know that the plugin is working (I have the plugin added to the config file)?
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 16, 2012, 04:56:39 PM
Shame, it shouldn't make a difference that it was installed aptitude and the code should work with any version of the 0.7.x series. You could try this code to see if the plugin is working in its most basic form:

<?php
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 (empty($_SESSION['user_id']))
      
$args['action'] = 'login';

    return 
$args;
  }

  function 
authenticate($args)
  {
    
$args['user'] = '<username>';
    
$args['pass'] = '<password>';
    
$args['host'] = '<host>';
    
$args['cookiecheck'] = false;
    
$args['valid'] = true;
  
    return 
$args;
  }

}

That should automatically log you into RoundCube when you go directly to it.
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 18, 2012, 01:48:07 PM
no joy.

That just runs me to the login screen with the username and host pre-filled out ... No error however.

But with that information pre-filled in, if i just add my password, it does login.
Title: Re: Autologin fails in 0.7
Post by: brandonsmith on June 18, 2012, 05:05:29 PM
after some additional testing ... i am finding that none of the plugins I am adding seem to work. I tired a rather easy one with "html5_notifier" with a chrome browser and got no notification that the plugin was working or trying to work.

The line in the main.inc.php.dist file for plugins reads:
$rcmail_config['plugins'] = array('autologin','html5_notifier');

the plugins directory contains:
autologin , filesystem_attachments, html5_notifier , jqueryui

is there something i am missing?
Title: Re: Autologin fails in 0.7
Post by: ASeques on June 27, 2012, 05:17:36 AM
I am experiencing exactly the same issue as you, and followed all the steps here, unfortunately there's no solution. Still, the rest of the plugins work fine for me (fail2ban, google_ads, and others)

The strange thing is that I can see in the errors file for every time i try the autologon this:
[27-Jun-2012 11:11:34 +0200]: PHP Error: No handler found for action plugin.wrapper in /var/www/webmail.example.com/program/include/rcube_plugin_api.php on line 300 (GET /?_task=mail&_default_width=1000&_screen_width=806&_action=plugin.wrapper)
Title: Re: Autologin fails in 0.7
Post by: SKaero on June 27, 2012, 04:01:12 PM
Quote from: ASeques on June 27, 2012, 05:17:36 AM
I am experiencing exactly the same issue as you, and followed all the steps here, unfortunately there's no solution. Still, the rest of the plugins work fine for me (fail2ban, google_ads, and others)

The strange thing is that I can see in the errors file for every time i try the autologon this:
[27-Jun-2012 11:11:34 +0200]: PHP Error: No handler found for action plugin.wrapper in /var/www/webmail.example.com/program/include/rcube_plugin_api.php on line 300 (GET /?_task=mail&_default_width=1000&_screen_width=806&_action=plugin.wrapper)
Your getting errors form another plugin, try disabling all other plugins and test just the autologin plugin.
Title: Re: Autologin fails in 0.7
Post by: ASeques on June 28, 2012, 05:57:11 AM
Ok, the plugin that caused the log errors was google_ads. Still, it seems that the problem persists afterwards :(
After all I still cannot yet login.

I have been trying on a ubuntu server 10.10 with php 5.3.2, I will try on another server with debian squeeze to see if it could be related.
Title: Re: Autologin fails in 0.7
Post by: ASeques on June 29, 2012, 09:29:30 AM
Finally got the solution, it seems that the parameters were incorrect. That's what I found in my case.

We are passing via POST the variables:
  _user,_host,_pass

In my case I passed _host=localhost and in main.inc.php I had 127.0.0.1

In the file program/include/rcmail.php there is this code that validates the default_host, since '127.0.0.1' is different from 'localhost' it simply fails.
It would be much better if it gave a proper error message.

    // Validate that selected host is in the list of configured hosts
    if (is_array($config['default_host'])) {
      $allowed = false;
      foreach ($config['default_host'] as $key => $host_allowed) {
        if (!is_numeric($key))
          $host_allowed = $key;
        if ($host == $host_allowed) {
          $allowed = true;
          break;
        }
      }


I am trying to prepare a patch so the users with problems get notified, but meanwhile you know my solution.
Title: Re: Autologin fails in 0.7
Post by: ASeques on July 02, 2012, 04:53:07 AM
The bug report was http://trac.roundcube.net/ticket/1488550 and has been fixed only after a couple of days in https://github.com/roundcube/roundcubemail/commit/7c8fd8031038e7958ef4dbb059e86decd6fefa28

Amazing support !
Title: Re: Autologin fails in 0.7
Post by: bhargavpandya on July 06, 2012, 06:43:41 PM
I am Still facing problem.. Your session is in valid or expired..
My autologon script is as under

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?
$_POST['password'] = 'test@123';
$_SESSION['userpassword'] = strrev(base64_encode('1234'.$_POST
['password']));
?>
<form name="roundcubelogin" action="http://ns2.ctns.info/rcube/?_task=mail" method="post" target="rcube">
<input type="hidden" name="_timezone" value="_default_" />
<input type="hidden" name="_task" value="mail" />
<input type="hidden" name="_autologin" value="1" />
<input type="text" name="_user" value="[email protected]" />
<input type="password" name="_pass" value="<?echo $_SESSION['userpassword']?>" />
<input type="submit" name="submit" value="SUBMIT" />
</form>
</body>
</html>

user ID and passwordd changed..

My Autologin.php Plugin is as follows

<?php

/**
* This plugin performs an automatic login if accessed
* with post Data from other Site an Portal or CMS
* Based on sample autologon PlugIn
*
* @version 0.2
* @author Eric Appelt (lacri)
*
* show into README to install and config
*
* changes
* 0.2 make a little bit secure with base64_encode strrev
* and a key thats replace after submitting encoded pass data
*
*/

class autologin 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();

    $autologin = get_input_value('_autologin', RCUBE_INPUT_POST);

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

      // decode pass, revert and replace key
        $_POST['_pass'] = str_replace('1234','',base64_decode(strrev(get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'))));

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

  function authenticate($args)
  {
    $autologin = get_input_value('_autologin', RCUBE_INPUT_POST);

    if (!empty($autologin)) {
      $args['user'] = get_input_value('_user', RCUBE_INPUT_POST);
      $args['pass'] = get_input_value('_pass', RCUBE_INPUT_POST);
      $args['host'] = 'localhost';
      $args['cookiecheck'] = false;
      $args['valid'] = true;

    }
    die('<pre>'. print_r($args, true));
    return $args;
  }
}


Hope someone can really help... I need this working desperately.. I am using Windows Platform with Hmailserver and roundcube..

This is what i get in my session logs

[07-Jul-2012 04:16:35 +0530]: Aborted session nuuu14r3a0on62njgns8g356g1; no valid session data found


Regards
Title: Re: Autologin fails in 0.7
Post by: SKaero on July 06, 2012, 10:26:22 PM
You don't need the "$_COOKIE['roundcube_sessid'] = session_id();" line.