Guest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.'); break;
  26. }
  27. return true;
  28. }
  29. # Album functions
  30. private function getAlbums() {
  31. $album = new Album($this->database, $this->plugins, $this->settings, null);
  32. echo json_encode($album->getAll(true));
  33. }
  34. private function getAlbum() {
  35. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  36. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  37. if ($album->getPublic()) {
  38. # Album public
  39. if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
  40. else echo 'Warning: Wrong password!';
  41. } else {
  42. # Album private
  43. echo 'Warning: Album private!';
  44. }
  45. }
  46. private function checkAlbumAccess() {
  47. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  48. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  49. if ($album->getPublic()) {
  50. # Album public
  51. if ($album->checkPassword($_POST['password'])) echo true;
  52. else echo false;
  53. } else {
  54. # Album private
  55. echo false;
  56. }
  57. }
  58. # Photo functions
  59. private function getPhoto() {
  60. Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
  61. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
  62. if ($photo->getPublic($_POST['password'])) echo json_encode($photo->get($_POST['albumID']));
  63. else echo 'Warning: Wrong password!';
  64. }
  65. # Session functions
  66. private function init() {
  67. global $dbName;
  68. $session = new Session($this->plugins, $this->settings);
  69. echo json_encode($session->init($this->database, $dbName, true, $_POST['version']));
  70. }
  71. private function login() {
  72. Module::dependencies(isset($_POST['user'], $_POST['password']));
  73. $session = new Session($this->plugins, $this->settings);
  74. echo $session->login($_POST['user'], $_POST['password']);
  75. }
  76. # $_GET functions
  77. private function getAlbumArchive() {
  78. Module::dependencies(isset($_GET['albumID'], $_GET['password']));
  79. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  80. if ($album->getPublic()) {
  81. # Album Public
  82. if ($album->checkPassword($_GET['password'])) $album->getArchive();
  83. else exit('Warning: Wrong password!');
  84. } else {
  85. # Album Private
  86. exit('Warning: Album private or not downloadable!');
  87. }
  88. }
  89. private function getPhotoArchive() {
  90. Module::dependencies(isset($_GET['photoID'], $_GET['password']));
  91. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  92. # Photo Download
  93. if ($photo->getPublic($_GET['password'])) {
  94. # Photo Public
  95. $photo->getArchive();
  96. } else {
  97. # Photo Private
  98. exit('Warning: Photo private or not downloadable!');
  99. }
  100. }
  101. }
  102. ?>