api.php 1.9 KB

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