Guest.php 3.8 KB

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