Mercurial > hg > rc1
comparison plugins/autologon/autologon.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
| author | Charlie Root |
|---|---|
| date | Thu, 04 Jan 2018 15:50:29 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1e000243b222 |
|---|---|
| 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 */ | |
| 10 class 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 // change action to login | |
| 23 if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost()) | |
| 24 $args['action'] = 'login'; | |
| 25 | |
| 26 return $args; | |
| 27 } | |
| 28 | |
| 29 function authenticate($args) | |
| 30 { | |
| 31 if (!empty($_GET['_autologin']) && $this->is_localhost()) { | |
| 32 $args['user'] = 'me'; | |
| 33 $args['pass'] = '******'; | |
| 34 $args['host'] = 'localhost'; | |
| 35 $args['cookiecheck'] = false; | |
| 36 $args['valid'] = true; | |
| 37 } | |
| 38 | |
| 39 return $args; | |
| 40 } | |
| 41 | |
| 42 function is_localhost() | |
| 43 { | |
| 44 return $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '127.0.0.1'; | |
| 45 } | |
| 46 | |
| 47 } | |
| 48 |
