index.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. ###
  3. # @name API
  4. # @author Tobias Reich
  5. # @copyright 2015 by Tobias Reich
  6. ###
  7. namespace Lychee;
  8. use Lychee\Modules\Config;
  9. use Lychee\Modules\Settings;
  10. use Lychee\Access\Installation;
  11. use Lychee\Access\Admin;
  12. use Lychee\Access\Guest;
  13. require(__DIR__ . '/define.php');
  14. require(__DIR__ . '/autoload.php');
  15. require(__DIR__ . '/helpers/fastImageCopyResampled.php');
  16. require(__DIR__ . '/helpers/getExtension.php');
  17. require(__DIR__ . '/helpers/getGraphHeader.php');
  18. require(__DIR__ . '/helpers/getHashedString.php');
  19. require(__DIR__ . '/helpers/hasPermissions.php');
  20. require(__DIR__ . '/helpers/search.php');
  21. # Define the called function
  22. if (isset($_POST['function'])) $fn = $_POST['function'];
  23. else if (isset($_GET['function'])) $fn = $_GET['function'];
  24. else $fn = null;
  25. # Check if a function has been specified
  26. if (!empty($fn)) {
  27. # Start the session and set the default timezone
  28. session_start();
  29. date_default_timezone_set('UTC');
  30. # Validate parameters
  31. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  32. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  33. if (isset($_POST['albumID'])&&preg_match('/^[0-9sfr]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  34. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  35. # Check if a configuration exists
  36. if (Config::exists()===false) {
  37. ###
  38. # Installation Access
  39. # Limited access to configure Lychee. Only available when the config.php file is missing.
  40. ###
  41. $installation = new Installation();
  42. $installation->check($fn);
  43. exit();
  44. }
  45. # Check if user is logged
  46. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  47. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
  48. ###
  49. # Admin Access
  50. # Full access to Lychee. Only with correct password/session.
  51. ###
  52. $admin = new Admin();
  53. $admin->check($fn);
  54. exit();
  55. }
  56. ###
  57. # Guest Access
  58. # Access to view all public folders and photos in Lychee.
  59. ###
  60. $guest = new Guest();
  61. $guest->check($fn);
  62. } else {
  63. exit('Error: No API function specified!');
  64. }
  65. ?>