source: github/plugins/autologon/autologon.php @ 48e9c14e

Revision 48e9c14e, 1.0 KB checked in by thomasb, 7 weeks ago (diff)

Move plugins repository into roundcubemail root folder; svn:externals are not defined anymore

  • Property mode set to 100644
Line 
1<?php
2
3/**
4 * Sample plugin to try out some hooks.
5 * This performs an automatic login if accessed from localhost
6 *
7 * @license GNU GPLv3+
8 * @author Thomas Bruederli
9 */
10class autologon extends rcube_plugin
11{
12  public $task = 'login';
13
14  function init()
15  {
16    $this->add_hook('startup', array($this, 'startup'));
17    $this->add_hook('authenticate', array($this, 'authenticate'));
18  }
19
20  function startup($args)
21  {
22    $rcmail = rcmail::get_instance();
23
24    // change action to login
25    if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
26      $args['action'] = 'login';
27
28    return $args;
29  }
30
31  function authenticate($args)
32  {
33    if (!empty($_GET['_autologin']) && $this->is_localhost()) {
34      $args['user'] = 'me';
35      $args['pass'] = '******';
36      $args['host'] = 'localhost';
37      $args['cookiecheck'] = false;
38      $args['valid'] = true;
39    }
40 
41    return $args;
42  }
43
44  function is_localhost()
45  {
46    return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
47  }
48
49}
50
Note: See TracBrowser for help on using the repository browser.