]> git.donarmstrong.com Git - roundcube.git/blob - plugins/autologon/autologon.php
Imported Upstream version 0.5.2+dfsg
[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       $args['cookiecheck'] = false;
35       $args['valid'] = true;
36     }
37   
38     return $args;
39   }
40
41   function is_localhost()
42   {
43     return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
44   }
45
46 }
47