Guest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. ###
  3. # @name Guest Access (Public Mode)
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  7. if (!defined('LYCHEE_ACCESS_GUEST')) exit('Error: You are not allowed to access this area!');
  8. class Guest extends Access {
  9. public function check($fn) {
  10. switch ($fn) {
  11. # Album functions
  12. case 'Album::getAll': $this->getAlbums(); break;
  13. case 'Album::get': $this->getAlbum(); break;
  14. case 'Album::getPublic': $this->checkAlbumAccess(); break;
  15. # Photo functions
  16. case 'Photo::get': $this->getPhoto(); break;
  17. # Session functions
  18. case 'Session::init': $this->init(); break;
  19. case 'Session::login': $this->login(); break;
  20. case 'Session::logout': $this->logout(); break;
  21. # $_GET functions
  22. case 'Album::getArchive': $this->getAlbumArchive(); break;
  23. case 'Photo::getArchive': $this->getPhotoArchive(); break;
  24. # Error
  25. default: exit('Error: Function not found! Please check the spelling of the called function.');
  26. return false; break;
  27. }
  28. return true;
  29. }
  30. # Album functions
  31. private function getAlbums() {
  32. $album = new Album($this->database, $this->plugins, $this->settings, null);
  33. echo json_encode($album->getAll(true));
  34. }
  35. private function getAlbum() {
  36. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  37. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  38. if ($album->getPublic()) {
  39. # Album public
  40. if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
  41. else echo 'Warning: Wrong password!';
  42. } else {
  43. # Album private
  44. echo 'Warning: Album private!';
  45. }
  46. }
  47. private function checkAlbumAccess() {
  48. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  49. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  50. if ($album->getPublic()) {
  51. # Album public
  52. if ($album->checkPassword($_POST['password'])) echo true;
  53. else echo false;
  54. } else {
  55. # Album private
  56. echo false;
  57. }
  58. }
  59. # Photo functions
  60. private function getPhoto() {
  61. Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
  62. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
  63. if ($photo->getPublic($_POST['password'])) echo json_encode($photo->get($_POST['albumID']));
  64. else echo 'Warning: Wrong password!';
  65. }
  66. # Session functions
  67. private function init() {
  68. global $dbName;
  69. $session = new Session($this->plugins, $this->settings);
  70. echo json_encode($session->init($this->database, $dbName, true, $_POST['version']));
  71. }
  72. private function login() {
  73. Module::dependencies(isset($_POST['user'], $_POST['password']));
  74. $session = new Session($this->plugins, $this->settings);
  75. echo $session->login($_POST['user'], $_POST['password']);
  76. }
  77. private function logout() {
  78. $session = new Session($this->plugins, $this->settings);
  79. echo $session->logout();
  80. }
  81. # $_GET functions
  82. private function getAlbumArchive() {
  83. Module::dependencies(isset($_GET['albumID'], $_GET['password']));
  84. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  85. if ($album->getPublic()&&$album->getDownloadable()) {
  86. # Album Public
  87. if ($album->checkPassword($_GET['password'])) $album->getArchive();
  88. else exit('Warning: Wrong password!');
  89. } else {
  90. # Album Private
  91. exit('Warning: Album private or not downloadable!');
  92. }
  93. }
  94. private function getPhotoArchive() {
  95. Module::dependencies(isset($_GET['photoID'], $_GET['password']));
  96. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  97. # Photo Download
  98. if ($photo->getPublic($_GET['password'])) {
  99. # Photo Public
  100. $photo->getArchive();
  101. } else {
  102. # Photo Private
  103. exit('Warning: Photo private or not downloadable!');
  104. }
  105. }
  106. }
  107. ?>