alecpl
2009-10-06 ffeab7fe7e0ccf1d458d6a863600359c38769950
commit | author | age
cc97ea 1 <?php
T 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
10   function init()
11   {
12     $this->add_hook('startup', array($this, 'startup'));
13     $this->add_hook('authenticate', array($this, 'authenticate'));
14   }
15
16   function startup($args)
17   {
18     $rcmail = rcmail::get_instance();
19
20     // change action to login
21     if ($args['task'] == 'mail' && empty($args['action']) && empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
22       $args['action'] = 'login';
23
24     return $args;
25   }
26
27   function authenticate($args)
28   {
29     if (!empty($_GET['_autologin']) && $this->is_localhost()) {
30       $args['user'] = 'me';
31       $args['pass'] = '******';
32       $args['host'] = 'localhost';
33     }
34   
35     return $args;
36   }
37
38   function is_localhost()
39   {
40     return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
41   }
42
43 }
44