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. # Load required files
  16. require(__DIR__ . '/define.php');
  17. require(__DIR__ . '/autoload.php');
  18. require(__DIR__ . '/modules/misc.php');
  19. if (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
  20. else {
  21. ###
  22. # Installation Access
  23. # Limited access to configure Lychee. Only available when the config.php file is missing.
  24. ###
  25. define('LYCHEE_ACCESS_INSTALLATION', true);
  26. $installation = new Installation(null, null, null);
  27. $installation->check($_POST['function']);
  28. exit();
  29. }
  30. # Define the table prefix
  31. if (!isset($dbTablePrefix)) $dbTablePrefix = '';
  32. defineTablePrefix($dbTablePrefix);
  33. # Connect to database
  34. $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName);
  35. # Load settings
  36. $settings = new Settings($database);
  37. $settings = $settings->get();
  38. # Init plugins
  39. $plugins = explode(';', $settings['plugins']);
  40. $plugins = new Plugins($plugins, $database, $settings);
  41. # Escape
  42. foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
  43. foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
  44. # Validate parameters
  45. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  46. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  47. if (isset($_POST['albumID'])&&preg_match('/^[0-9sfr]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  48. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  49. # Function for switch statement
  50. if (isset($_POST['function'])) $fn = $_POST['function'];
  51. else $fn = $_GET['function'];
  52. if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
  53. ###
  54. # Admin Access
  55. # Full access to Lychee. Only with correct password/session.
  56. ###
  57. define('LYCHEE_ACCESS_ADMIN', true);
  58. $admin = new Admin($database, $plugins, $settings);
  59. $admin->check($fn);
  60. } else {
  61. ###
  62. # Guest Access
  63. # Access to view all public folders and photos in Lychee.
  64. ###
  65. define('LYCHEE_ACCESS_GUEST', true);
  66. $guest = new Guest($database, $plugins, $settings);
  67. $guest->check($fn);
  68. }
  69. } else {
  70. exit('Error: Called function not found!');
  71. }
  72. ?>