Guest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. 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. $pgP = $photo->getPublic($_POST['password']);
  64. if ($pgP===2) echo json_encode($photo->get($_POST['albumID']));
  65. else if ($pgP===1) echo 'Warning: Wrong password!';
  66. else if ($pgP===0) echo 'Warning: Photo private!';
  67. }
  68. # Session functions
  69. private function init() {
  70. global $dbName;
  71. $session = new Session($this->plugins, $this->settings);
  72. echo json_encode($session->init($this->database, $dbName, true));
  73. }
  74. private function login() {
  75. Module::dependencies(isset($_POST['user'], $_POST['password']));
  76. $session = new Session($this->plugins, $this->settings);
  77. echo $session->login($_POST['user'], $_POST['password']);
  78. }
  79. private function logout() {
  80. $session = new Session($this->plugins, $this->settings);
  81. echo $session->logout();
  82. }
  83. # $_GET functions
  84. private function getAlbumArchive() {
  85. Module::dependencies(isset($_GET['albumID'], $_GET['password']));
  86. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  87. if ($album->getPublic()&&$album->getDownloadable()) {
  88. # Album Public
  89. if ($album->checkPassword($_GET['password'])) $album->getArchive();
  90. else exit('Warning: Wrong password!');
  91. } else {
  92. # Album Private
  93. exit('Warning: Album private or not downloadable!');
  94. }
  95. }
  96. private function getPhotoArchive() {
  97. Module::dependencies(isset($_GET['photoID'], $_GET['password']));
  98. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  99. $pgP = $photo->getPublic($_GET['password']);
  100. # Photo Download
  101. if ($pgP===2) {
  102. # Photo Public
  103. $photo->getArchive();
  104. } else {
  105. # Photo Private
  106. exit('Warning: Photo private or password incorrect!');
  107. }
  108. }
  109. }
  110. ?>