2014-04-30 08:56:04 +00:00
|
|
|
<?php
|
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
namespace Lychee\Access;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
use Lychee\Modules\Album;
|
|
|
|
use Lychee\Modules\Module;
|
|
|
|
use Lychee\Modules\Photo;
|
|
|
|
use Lychee\Modules\Session;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
final class Guest implements Access {
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
public function check($fn) {
|
|
|
|
|
|
|
|
switch ($fn) {
|
|
|
|
|
|
|
|
# Album functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Album::getAll': $this->getAlbums(); break;
|
|
|
|
case 'Album::get': $this->getAlbum(); break;
|
|
|
|
case 'Album::getPublic': $this->checkAlbumAccess(); break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Photo functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Photo::get': $this->getPhoto(); break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Session functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Session::init': $this->init(); break;
|
|
|
|
case 'Session::login': $this->login(); break;
|
|
|
|
case 'Session::logout': $this->logout(); break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# $_GET functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Album::getArchive': $this->getAlbumArchive(); break;
|
|
|
|
case 'Photo::getArchive': $this->getPhotoArchive(); break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Error
|
2014-04-30 09:09:28 +00:00
|
|
|
default: exit('Error: Function not found! Please check the spelling of the called function.');
|
2015-12-07 21:44:42 +00:00
|
|
|
break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Album functions
|
|
|
|
|
|
|
|
private function getAlbums() {
|
|
|
|
|
2016-01-24 21:14:20 +00:00
|
|
|
$album = new Album(null);
|
2014-04-30 08:56:04 +00:00
|
|
|
echo json_encode($album->getAll(true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAlbum() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$album = new Album($_POST['albumID']);
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
if ($album->getPublic()) {
|
|
|
|
|
|
|
|
# Album public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
|
|
|
|
else echo 'Warning: Wrong password!';
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album private
|
|
|
|
echo 'Warning: Album private!';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function checkAlbumAccess() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$album = new Album($_POST['albumID']);
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
if ($album->getPublic()) {
|
|
|
|
|
|
|
|
# Album public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_POST['password'])) echo true;
|
|
|
|
else echo false;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album private
|
|
|
|
echo false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Photo functions
|
|
|
|
|
|
|
|
private function getPhoto() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$photo = new Photo($_POST['photoID']);
|
2014-04-30 08:56:04 +00:00
|
|
|
|
2015-04-06 16:48:52 +00:00
|
|
|
$pgP = $photo->getPublic($_POST['password']);
|
|
|
|
|
|
|
|
if ($pgP===2) echo json_encode($photo->get($_POST['albumID']));
|
|
|
|
else if ($pgP===1) echo 'Warning: Wrong password!';
|
|
|
|
else if ($pgP===0) echo 'Warning: Photo private!';
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Session functions
|
|
|
|
|
|
|
|
private function init() {
|
|
|
|
|
|
|
|
global $dbName;
|
|
|
|
|
2016-01-24 21:14:20 +00:00
|
|
|
$session = new Session();
|
|
|
|
echo json_encode($session->init(true));
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function login() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['user'], $_POST['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$session = new Session();
|
2014-04-30 08:56:04 +00:00
|
|
|
echo $session->login($_POST['user'], $_POST['password']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:44:08 +00:00
|
|
|
private function logout() {
|
|
|
|
|
2016-01-24 21:14:20 +00:00
|
|
|
$session = new Session();
|
2014-06-14 19:44:08 +00:00
|
|
|
echo $session->logout();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-30 08:56:04 +00:00
|
|
|
# $_GET functions
|
|
|
|
|
|
|
|
private function getAlbumArchive() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_GET['albumID'], $_GET['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$album = new Album($_GET['albumID']);
|
2014-04-30 08:56:04 +00:00
|
|
|
|
2014-08-17 18:22:46 +00:00
|
|
|
if ($album->getPublic()&&$album->getDownloadable()) {
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Album Public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_GET['password'])) $album->getArchive();
|
|
|
|
else exit('Warning: Wrong password!');
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album Private
|
|
|
|
exit('Warning: Album private or not downloadable!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPhotoArchive() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_GET['photoID'], $_GET['password']));
|
2016-01-24 21:14:20 +00:00
|
|
|
$photo = new Photo($_GET['photoID']);
|
2014-04-30 08:56:04 +00:00
|
|
|
|
2015-04-06 16:48:52 +00:00
|
|
|
$pgP = $photo->getPublic($_GET['password']);
|
|
|
|
|
2014-04-30 08:56:04 +00:00
|
|
|
# Photo Download
|
2015-04-06 16:48:52 +00:00
|
|
|
if ($pgP===2) {
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Photo Public
|
|
|
|
$photo->getArchive();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Photo Private
|
2015-04-06 16:48:52 +00:00
|
|
|
exit('Warning: Photo private or password incorrect!');
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-07 21:44:42 +00:00
|
|
|
?>
|