]> git.donarmstrong.com Git - roundcube.git/blob - plugins/autologon/autologon.php
Imported Debian patch 0.5.1+dfsg-7
[roundcube.git] / plugins / autologon / autologon.php
1 <?php
2
3 /**
4  * Sample plugin to try out some hooks.
5  * This performs an automatic login if accessed from localhost
6  */
7 class autologon extends rcube_plugin
8 {
9   public $task = 'login';
10
11   function init()
12   {
13     $this->add_hook('startup', array($this, 'startup'));
14     $this->add_hook('authenticate', array($this, 'authenticate'));
15   }
16
17   function startup($args)
18   {
19     $rcmail = rcmail::get_instance();
20
21     // change action to login
22     if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
23       $args['action'] = 'login';
24
25     return $args;
26   }
27
28   function authenticate($args)
29   {
30     if (!empty($_GET['_autologin']) && $this->is_localhost()) {
31       $args['user'] = 'me';
32       $args['pass'] = '******';
33       $args['host'] = 'localhost';
34     }
35   
36     return $args;
37   }
38
39   function is_localhost()
40   {
41     return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
42   }
43
44 }
45