Guest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # $_GET functions
  22. case 'getAlbumArchive': $this->getAlbumArchive(); break;
  23. case 'getPhotoArchive': $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. # $_GET functions
  78. private function getAlbumArchive() {
  79. Module::dependencies(isset($_GET['albumID'], $_GET['password']));
  80. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  81. if ($album->getPublic()) {
  82. # Album Public
  83. if ($album->checkPassword($_GET['password'])) $album->getArchive();
  84. else exit('Warning: Wrong password!');
  85. } else {
  86. # Album Private
  87. exit('Warning: Album private or not downloadable!');
  88. }
  89. }
  90. private function getPhotoArchive() {
  91. Module::dependencies(isset($_GET['photoID'], $_GET['password']));
  92. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  93. # Photo Download
  94. if ($photo->getPublic($_GET['password'])) {
  95. # Photo Public
  96. $photo->getArchive();
  97. } else {
  98. # Photo Private
  99. exit('Warning: Photo private or not downloadable!');
  100. }
  101. }
  102. }
  103. ?>