Roundcube Community Forum

 

Problem with autologon plugin

Started by beerzone, March 05, 2025, 03:26:14 AM

Previous topic - Next topic

beerzone

Hello!
I have Roundcube Webmail 1.6.0 installed with autologon 1.0.
It works, but very strange. I can use link with different parameters (?_autologin=1, ?any_other_parameter=true) and login page is opened always. Autologon plugin works only if I enter wrong username or password to the fields and press LOGIN button. Can anybody explain me what's wrong?
That's my authenticate function for tests only:

    function authenticate($args)
    {
        syslog(LOG_DEBUG, "Entering autologon authenticate");
        // if (!empty($_GET['_autologin']) && $this->is_localhost()) {
        if (true){
            $args['user']        = 'test';
            $args['pass']        = '123';
            $args['host']        = 'localhost';
            $args['cookiecheck'] = false;
            $args['valid']       = true;
        }

        return $args;
    }

It looks like autologon authenticate function works only after standard authentication if it's unsuccessful.

SKaero

You would also need to modify the startup function since that forwards any unauthenticated user to the login process.

beerzone

#2
SKaero, thank you for your reply!
If you mean startup function in autologon class, it's not called due to syslog.
That's my autologon.php for tests now:

<?php
openlog("PHP_autologon_log", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog(LOG_DEBUG, "Entering autologon module");

class autologon extends rcube_plugin
{
    public $task = 'login';

    public function init()
    {
        syslog(LOG_DEBUG, "Initialising autologon");
        $this->add_hook('startup', [$this, 'startup']);
        $this->add_hook('authenticate', [$this, 'authenticate']);
    }

    function startup($args)
    {
        syslog(LOG_DEBUG, "Entering autologon startup");
        $args['user']        = 'test';
        $args['pass']        = '123';
        $args['host']        = 'localhost';
        $args['cookiecheck'] = false;
        $args['valid']       = true;

        return $args;
    }

    function authenticate($args)
    {
        syslog(LOG_DEBUG, "Entering autologon authenticate");
        $args['user']        = 'test';
        $args['pass']        = '123';
        $args['host']        = 'localhost';
        $args['cookiecheck'] = false;
        $args['valid']       = true;

        return $args;
    }
}
closelog();

Now, when I open roundcube page, I see login page and "Entering autologon module" message in syslog.
If I enter valid user credentials, I'l see not users but test user mailbox, "Entering autologon authenticate" and three "Entering autologon module" in syslog.
On logout I see login page and "Entering autologon module", "Initialising autologon" messages in syslog.
If I enter invalid credentials, I'l see test user mailbox and "Entering autologon module", "Entering autologon authenticate" and three "Entering autologon module" messages in syslog.

I've set outologon first in config with no result:
$config['plugins'] = ['autologon', 'acl', 'additional_message_headers', 'archive', 'emoticons', 'identicon', 'identity_select', 'managesieve', 'markasjunk', 'zipdownload'];

I can't understand how does it work.

SKaero

Your not using the startup function correctly. You would want it to look like like:
    public function startup($args)
    {
        // change action to login
        if (empty($_SESSION['user_id'])) {
            $args['action'] = 'login';
        }

        return $args;
    }

beerzone

Thank you very much, SKaero!
The problem is solved.