2014-01-22 10:12:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-17 16:01:46 +00:00
|
|
|
* @name Session Module
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Philipp Maurer, Tobias Reich
|
2014-01-22 10:12:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
2014-02-23 18:41:12 +00:00
|
|
|
function init($mode, $version) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-23 18:41:12 +00:00
|
|
|
global $settings, $configVersion;
|
|
|
|
|
|
|
|
// Update
|
|
|
|
if ($configVersion!==$version)
|
|
|
|
if (!update($version)) exit('Error: Updating the database failed!');
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
$return['config'] = $settings;
|
|
|
|
unset($return['config']['password']);
|
|
|
|
|
|
|
|
// No login
|
|
|
|
if ($settings['username']===''&&$settings['password']==='') $return['config']['login'] = false;
|
|
|
|
else $return['config']['login'] = true;
|
|
|
|
|
|
|
|
if ($mode==='admin') {
|
|
|
|
$return['loggedIn'] = true;
|
|
|
|
} else {
|
|
|
|
unset($return['config']['username']);
|
|
|
|
unset($return['config']['thumbQuality']);
|
|
|
|
unset($return['config']['sorting']);
|
2014-02-27 20:51:12 +00:00
|
|
|
unset($return['config']['dropboxKey']);
|
2014-01-22 10:12:51 +00:00
|
|
|
unset($return['config']['login']);
|
|
|
|
$return['loggedIn'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function login($username, $password) {
|
|
|
|
|
|
|
|
global $database, $settings;
|
|
|
|
|
|
|
|
// Check login
|
2014-02-17 16:01:46 +00:00
|
|
|
if ($username===$settings['username']&&$password===$settings['password']) {
|
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
// No login
|
|
|
|
if ($settings['username']===''&&$settings['password']==='') {
|
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout() {
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
session_destroy();
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|