api.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. ###
  3. # @name API
  4. # @copyright 2014 by Tobias Reich
  5. ###
  6. @ini_set('max_execution_time', '200');
  7. @ini_set('post_max_size', '200M');
  8. @ini_set('upload_max_size', '200M');
  9. @ini_set('upload_max_filesize', '20M');
  10. @ini_set('max_file_uploads', '100');
  11. if (!empty($_POST['function'])||!empty($_GET['function'])) {
  12. session_start();
  13. date_default_timezone_set('UTC');
  14. # Load required files
  15. require(__DIR__ . '/define.php');
  16. require(__DIR__ . '/autoload.php');
  17. require(__DIR__ . '/modules/misc.php');
  18. if (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
  19. else {
  20. ###
  21. # Installation Access
  22. # Limited access to configure Lychee. Only available when the config.php file is missing.
  23. ###
  24. define('LYCHEE_ACCESS_INSTALLATION', true);
  25. $installation = new Installation(null, null, null);
  26. $installation->check($_POST['function']);
  27. exit();
  28. }
  29. # Define the table prefix
  30. if (!isset($dbTablePrefix)) $dbTablePrefix = '';
  31. defineTablePrefix($dbTablePrefix);
  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-9sfr]{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. # Function 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. ?>