2014-04-04 19:10:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
###
|
|
|
|
# @name Session Module
|
|
|
|
# @author Tobias Reich
|
|
|
|
# @copyright 2014 by Tobias Reich
|
|
|
|
###
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
2014-04-04 19:27:10 +00:00
|
|
|
class Session extends Module {
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2014-04-04 19:27:10 +00:00
|
|
|
private $settings = null;
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
public function __construct($plugins, $settings) {
|
|
|
|
|
|
|
|
# Init vars
|
|
|
|
$this->plugins = $plugins;
|
|
|
|
$this->settings = $settings;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-11 20:25:03 +00:00
|
|
|
public function init($database, $dbName, $public, $version) {
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2014-04-19 19:07:36 +00:00
|
|
|
# Check dependencies
|
2014-06-25 12:50:49 +00:00
|
|
|
self::dependencies(isset($this->settings, $public, $version));
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2014-04-04 19:12:49 +00:00
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 0, func_get_args());
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
# Update
|
2014-05-30 14:55:56 +00:00
|
|
|
if (!isset($this->settings['version'])||$this->settings['version']!==$version) {
|
|
|
|
if (!Database::update($database, $dbName, @$this->settings['version'])) {
|
|
|
|
Log::error($database, __METHOD__, __LINE__, 'Updating the database failed');
|
|
|
|
exit('Error: Updating the database failed!');
|
|
|
|
}
|
|
|
|
}
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
# Return settings
|
|
|
|
$return['config'] = $this->settings;
|
|
|
|
unset($return['config']['password']);
|
|
|
|
|
2014-07-23 19:24:25 +00:00
|
|
|
# Path to Lychee for the server-import dialog
|
|
|
|
$return['config']['location'] = LYCHEE;
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
# No login
|
|
|
|
if ($this->settings['username']===''&&$this->settings['password']==='') $return['config']['login'] = false;
|
|
|
|
else $return['config']['login'] = true;
|
|
|
|
|
|
|
|
if ($public===false) {
|
|
|
|
|
|
|
|
# Logged in
|
|
|
|
$return['loggedIn'] = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Unset unused vars
|
|
|
|
unset($return['config']['username']);
|
|
|
|
unset($return['config']['thumbQuality']);
|
|
|
|
unset($return['config']['sorting']);
|
|
|
|
unset($return['config']['dropboxKey']);
|
|
|
|
unset($return['config']['login']);
|
2014-07-23 19:24:25 +00:00
|
|
|
unset($return['config']['location']);
|
2014-07-27 12:17:01 +00:00
|
|
|
unset($return['config']['plugins']);
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
# Logged out
|
|
|
|
$return['loggedIn'] = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-04 19:12:49 +00:00
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 1, func_get_args());
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return $return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function login($username, $password) {
|
|
|
|
|
2014-04-19 19:07:36 +00:00
|
|
|
# Check dependencies
|
2014-06-25 12:50:49 +00:00
|
|
|
self::dependencies(isset($this->settings, $username, $password));
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2014-04-04 19:12:49 +00:00
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 0, func_get_args());
|
|
|
|
|
2014-04-21 00:19:23 +00:00
|
|
|
# Check login with MD5 hash
|
2014-04-04 19:10:32 +00:00
|
|
|
if ($username===$this->settings['username']&&$password===$this->settings['password']) {
|
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-21 00:19:23 +00:00
|
|
|
# Check login with crypted hash
|
|
|
|
if ($username===$this->settings['username']&&$this->settings['password']===crypt($password, $this->settings['password'])) {
|
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
# No login
|
|
|
|
if ($this->settings['username']===''&&$this->settings['password']==='') {
|
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-04 19:12:49 +00:00
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 1, func_get_args());
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logout() {
|
|
|
|
|
2014-04-04 19:12:49 +00:00
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 0, func_get_args());
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
session_destroy();
|
2014-04-04 19:12:49 +00:00
|
|
|
|
|
|
|
# Call plugins
|
|
|
|
$this->plugins(__METHOD__, 1, func_get_args());
|
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|