api.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. ###
  3. # @name API
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. ###
  7. @ini_set('max_execution_time', '200');
  8. @ini_set('post_max_size', '200M');
  9. @ini_set('upload_max_size', '200M');
  10. @ini_set('upload_max_filesize', '20M');
  11. @ini_set('max_file_uploads', '100');
  12. if (!empty($_POST['function'])||!empty($_GET['function'])) {
  13. session_start();
  14. date_default_timezone_set('UTC');
  15. # Define globals
  16. require(__DIR__ . '/define.php');
  17. # Load autoload
  18. require(__DIR__ . '/autoload.php');
  19. # Load modules
  20. require(__DIR__ . '/modules/misc.php');
  21. if (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
  22. else {
  23. ###
  24. # Installation Access
  25. # Limited access to configure Lychee. Only available when the config.php file is missing.
  26. ###
  27. define('LYCHEE_ACCESS_INSTALLATION', true);
  28. $installation = new Installation(null, null, null);
  29. $installation->check($_POST['function']);
  30. exit();
  31. }
  32. # Connect to database
  33. $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName);
  34. # Load settings
  35. $settings = new Settings($database);
  36. $settings = $settings->get();
  37. # Init plugins
  38. $plugins = explode(';', $settings['plugins']);
  39. $plugins = new Plugins($plugins, $database, $settings);
  40. # Escape
  41. foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
  42. foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
  43. # Validate parameters
  44. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  45. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  46. if (isset($_POST['albumID'])&&preg_match('/^[0-9sf]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  47. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  48. # Fallback for switch statement
  49. if (isset($_POST['function'])) $fn = $_POST['function'];
  50. else $fn = $_GET['function'];
  51. if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
  52. ###
  53. # Admin Access
  54. # Full access to Lychee. Only with correct password/session.
  55. ###
  56. define('LYCHEE_ACCESS_ADMIN', true);
  57. $admin = new Admin($database, $plugins, $settings);
  58. $admin->check($fn);
  59. } else {
  60. ###
  61. # Guest Access
  62. # Access to view all public folders and photos in Lychee.
  63. ###
  64. define('LYCHEE_ACCESS_GUEST', true);
  65. $guest = new Guest($database, $plugins, $settings);
  66. $guest->check($fn);
  67. }
  68. } else {
  69. exit('Error: Called function not found!');
  70. }
  71. ?>