api.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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__ . '/modules/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 (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
  26. else {
  27. ###
  28. # Installation Access
  29. # Limited access to configure Lychee. Only available when the config.php file is missing.
  30. ###
  31. define('LYCHEE_ACCESS_INSTALLATION', true);
  32. $installation = new Installation(null, null, null);
  33. $installation->check($_POST['function']);
  34. exit();
  35. }
  36. # Define the table prefix
  37. defineTablePrefix(@$dbTablePrefix);
  38. # Connect to database
  39. $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName);
  40. # Load settings
  41. $settings = new Settings($database);
  42. $settings = $settings->get();
  43. # Init plugins
  44. $plugins = explode(';', $settings['plugins']);
  45. $plugins = new Plugins($plugins, $database, $settings);
  46. # Check if user is logged
  47. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  48. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===$settings['identifier'])) {
  49. ###
  50. # Admin Access
  51. # Full access to Lychee. Only with correct password/session.
  52. ###
  53. define('LYCHEE_ACCESS_ADMIN', true);
  54. $admin = new Admin($database, $plugins, $settings);
  55. $admin->check($fn);
  56. } else {
  57. ###
  58. # Guest Access
  59. # Access to view all public folders and photos in Lychee.
  60. ###
  61. define('LYCHEE_ACCESS_GUEST', true);
  62. $guest = new Guest($database, $plugins, $settings);
  63. $guest->check($fn);
  64. }
  65. } else {
  66. exit('Error: No API function specified!');
  67. }
  68. ?>