Author Topic: Custom login and logout scripts  (Read 7505 times)

Offline pedrusko

  • Newbie
  • *
  • Posts: 4
Custom login and logout scripts
« on: February 06, 2009, 04:38:31 AM »
Hello all,

I think it would be nice to have a custom login and logout scripts.

i.e. a place to change the username or server provided by the uses.

I have now squirrelmail with custom login plugin that matches mail domains to servers, and changes username in a form the server can use.

The user writes his/her mail address as login, and then it is rewited like:

user1@domaina.tld -> username = user1, server = server 1
user2@domainb.tld -> username = user2.domaind.tld, server = server 2

I use a single page for login to various servers with different configurations.

I think it could be a nice feature.

Thanks to all for this great software :)

Offline oSIRus

  • Newbie
  • *
  • Posts: 1
Custom login and logout scripts
« Reply #1 on: February 06, 2009, 05:23:50 AM »
Hello pedrusko,

very interesting, because I need to provide similar functionality for our school.

Did you use the plugin architecture?

I already tried to implement the sample plugin (automatic login if on localhost, URL), but it doesn't seem to work. Do you somehow have to activate the plugin architecture in the first place?

Thank you,

oSIRus

Offline pedrusko

  • Newbie
  • *
  • Posts: 4
Custom login and logout scripts
« Reply #2 on: February 06, 2009, 05:33:50 AM »
Hello,

The plugin is for squirrelmail only :(

Is there a document explaining the plugin interface?
I could adapt the plugin or make a new one if necessary.

I'm working for an academic institution too ;)

Regards,

  Pedro

Offline pedrusko

  • Newbie
  • *
  • Posts: 4
Custom login and logout scripts
« Reply #3 on: February 06, 2009, 06:34:20 AM »
As seen on roadmap, plugins will not be available until 0.3 :(

Roadmap ? RoundCube Webmail ? Trac

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Custom login and logout scripts
« Reply #4 on: February 06, 2009, 07:44:49 AM »
There is no documentation yet. But you can analize the example plugins ...

/branches/devel-api ? RoundCube Webmail ? Trac
« Last Edit: February 09, 2009, 10:37:51 AM by rosali »
Regards,
Rosali
__________________
MyRoundcube Project (commercial)

Offline pedrusko

  • Newbie
  • *
  • Posts: 4
Sample plugin
« Reply #5 on: February 09, 2009, 07:34:42 AM »
I have made a sample plugin, not tested yet.

Any suggestions would be apreciated :)


File milogin.php
<?php
// Change username / host based on email address.
// Author: Pedro R. Benito <pedro@ubu.es>
// Last modified: 09/02/2009
//
// 1.- User enters email address instead username.
// 2.- Username and host are selected automaticaly.

class milogin 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();
        
        return  
$args;
    }
    
    function 
authenticate($args)
    {
        
// File containing domain names and associated config.
        // Sample content:
        //
        // <?php
        // $domains = array();
        //
        // $domains['domain1.tld']['type'] = 'simple';
        // $domains['domain1.tld']['host'] = 'host.name.tld';
        // ? >
        
include 'milogin_domains.conf.php';
        
        
// Discover user and domain name.
        // $parts[0] holds login name.
        // $parts[1] holds domain name.
        
$parts explode('@',$args['user']);
        
        switch(
$domains[$parts[1]]['type'])
        {
            case 
'simple':
                
// username = login name
                
$args['username'] = $parts[0];
                break;
            case 
'dotted':
                
// username = loginname.domainname
                
$args['username'] = $parts[0].".".$parts[1];
                break;
                
        }

        
// Extract host from domain config.
        
$args['host'] = $domains[$parts[1]]['host'];
        
        return 
$args;
    }
}

?>

File milogin_domains.conf.php
<?php
$domains 
= array();

$domains['domain1.tld']['type'] = 'simple';
$domains['domain1.tld']['host'] = 'server1.tld';

$domains['domain2.tld']['type'] = 'dotted';
$domains['domain2.tld']['host'] = 'server2.tld';

?>