50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once(dirname(__FILE__)."/config.php");
|
|
|
|
/**
|
|
* Plugin to login from wiki.
|
|
*/
|
|
class fslogin extends rcube_plugin
|
|
{
|
|
public $task = 'login';
|
|
|
|
function init()
|
|
{
|
|
$this->add_hook('startup', array($this, 'startup'));
|
|
$this->add_hook('authenticate', array($this, 'authenticate'));
|
|
}
|
|
|
|
function startup($args)
|
|
{
|
|
$rcmail = rcmail::get_instance();
|
|
|
|
// change action to login
|
|
if (empty($_SESSION['user_id']) && !empty($_POST['_autologin']))
|
|
$args['action'] = 'login';
|
|
|
|
return $args;
|
|
}
|
|
|
|
function authenticate($args)
|
|
{
|
|
|
|
if (!empty($_POST['_autologin']) && !empty($_POST['auth'])) {
|
|
|
|
|
|
$authCode = md5(date('Ymd') . FSLoginConfig::$key);
|
|
// perhaps the code is just a few hours old but from yesterday?
|
|
$authCodePrev = md5(date('Ymd', time() - 3600 * 24) . FSLoginConfig::$key);
|
|
|
|
if ( ($authCode == $_POST['auth']) || ($authCodePrev == $_POST['auth']) ) {
|
|
$args['user'] = FSLoginConfig::$username;
|
|
$args['pass'] = FSLoginConfig::$password;
|
|
$args['valid'] = true;
|
|
}
|
|
}
|
|
|
|
return $args;
|
|
}
|
|
|
|
}
|
|
|