2014-04-04 19:10:32 +00:00
|
|
|
<?php
|
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
namespace Lychee\Modules;
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2016-01-30 20:33:31 +00:00
|
|
|
final class Session {
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
/**
|
|
|
|
* Reads and returns information about the Lychee installation.
|
|
|
|
* @return array Returns an array with the login status and configuration.
|
|
|
|
*/
|
2016-01-30 19:18:10 +00:00
|
|
|
public function init($public = true) {
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Return settings
|
2016-01-24 21:14:20 +00:00
|
|
|
$return['config'] = Settings::get();
|
2015-04-17 20:50:35 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Path to Lychee for the server-import dialog
|
2016-01-19 10:03:28 +00:00
|
|
|
$return['config']['location'] = LYCHEE;
|
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
// Remove sensitive from response
|
2015-04-17 20:50:35 +00:00
|
|
|
unset($return['config']['username']);
|
2014-04-04 19:10:32 +00:00
|
|
|
unset($return['config']['password']);
|
2015-05-14 19:07:42 +00:00
|
|
|
unset($return['config']['identifier']);
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Check if login credentials exist and login if they don't
|
2015-01-23 20:00:27 +00:00
|
|
|
if ($this->noLogin()===true) {
|
|
|
|
$public = false;
|
|
|
|
$return['config']['login'] = false;
|
|
|
|
} else {
|
|
|
|
$return['config']['login'] = true;
|
|
|
|
}
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
if ($public===false) {
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Logged in
|
2015-03-06 22:29:55 +00:00
|
|
|
$return['status'] = LYCHEE_STATUS_LOGGEDIN;
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Logged out
|
2015-03-06 22:29:55 +00:00
|
|
|
$return['status'] = LYCHEE_STATUS_LOGGEDOUT;
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Unset unused vars
|
2016-01-30 19:18:24 +00:00
|
|
|
unset($return['config']['skipDuplicates']);
|
2015-05-14 15:20:33 +00:00
|
|
|
unset($return['config']['sortingAlbums']);
|
2015-05-14 15:47:17 +00:00
|
|
|
unset($return['config']['sortingPhotos']);
|
2014-04-04 19:10:32 +00:00
|
|
|
unset($return['config']['dropboxKey']);
|
|
|
|
unset($return['config']['login']);
|
2014-07-23 19:24:25 +00:00
|
|
|
unset($return['config']['location']);
|
2015-05-14 15:20:33 +00:00
|
|
|
unset($return['config']['imagick']);
|
|
|
|
unset($return['config']['medium']);
|
2014-07-27 12:17:01 +00:00
|
|
|
unset($return['config']['plugins']);
|
2014-04-04 19:10:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return $return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
/**
|
|
|
|
* Sets the session values when username and password correct.
|
|
|
|
* @return boolean Returns true when login was successful.
|
|
|
|
*/
|
2014-04-04 19:10:32 +00:00
|
|
|
public function login($username, $password) {
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2016-01-24 21:14:20 +00:00
|
|
|
$username = crypt($username, Settings::get()['username']);
|
|
|
|
$password = crypt($password, Settings::get()['password']);
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Check login with crypted hash
|
2016-01-24 21:14:20 +00:00
|
|
|
if (Settings::get()['username']===$username&&
|
|
|
|
Settings::get()['password']===$password) {
|
2016-01-30 20:43:57 +00:00
|
|
|
$_SESSION['login'] = true;
|
|
|
|
$_SESSION['identifier'] = Settings::get()['identifier'];
|
2015-02-08 14:36:13 +00:00
|
|
|
return true;
|
2014-04-21 00:19:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// No login
|
2015-05-14 19:07:42 +00:00
|
|
|
if ($this->noLogin()===true) return true;
|
2014-04-04 19:10:32 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
/**
|
|
|
|
* Sets the session values when no there is no username and password in the database.
|
|
|
|
* @return boolean Returns true when no login was found.
|
|
|
|
*/
|
2015-01-23 20:00:27 +00:00
|
|
|
private function noLogin() {
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Check if login credentials exist and login if they don't
|
2016-01-24 21:14:20 +00:00
|
|
|
if (Settings::get()['username']===''&&
|
|
|
|
Settings::get()['password']==='') {
|
2016-01-30 20:43:57 +00:00
|
|
|
$_SESSION['login'] = true;
|
|
|
|
$_SESSION['identifier'] = Settings::get()['identifier'];
|
2015-02-08 14:36:13 +00:00
|
|
|
return true;
|
2015-01-23 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
/**
|
|
|
|
* Unsets the session values.
|
|
|
|
* @return boolean Returns true when logout was successful.
|
|
|
|
*/
|
2014-04-04 19:10:32 +00:00
|
|
|
public function logout() {
|
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2016-02-13 16:32:44 +00:00
|
|
|
session_unset();
|
2014-04-04 19:10:32 +00:00
|
|
|
session_destroy();
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2016-01-30 20:43:57 +00:00
|
|
|
// Call plugins
|
2016-01-29 23:27:50 +00:00
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
2014-04-04 19:12:49 +00:00
|
|
|
|
2014-04-04 19:10:32 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|