api.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. require(__DIR__ . '/access/installation.php');
  29. exit();
  30. }
  31. # Connect to database
  32. $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName);
  33. # Load settings
  34. $settings = new Settings($database);
  35. $settings = $settings->get();
  36. # Init plugins
  37. $plugins = explode(';', $settings['plugins']);
  38. $plugins = new Plugins($plugins, $database);
  39. # Escape
  40. foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
  41. foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
  42. # Validate parameters
  43. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  44. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  45. if (isset($_POST['albumID'])&&preg_match('/^[0-9sf]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  46. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  47. # Fallback for switch statement
  48. if (!isset($_POST['function'])) $_POST['function'] = '';
  49. if (!isset($_GET['function'])) $_GET['function'] = '';
  50. if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
  51. /**
  52. * Admin Access
  53. * Full access to Lychee. Only with correct password/session.
  54. */
  55. define('LYCHEE_ACCESS_ADMIN', true);
  56. require(__DIR__ . '/access/admin.php');
  57. } else {
  58. /**
  59. * Guest Access
  60. * Access to view all public folders and photos in Lychee.
  61. */
  62. define('LYCHEE_ACCESS_GUEST', true);
  63. require(__DIR__ . '/access/guest.php');
  64. }
  65. } else {
  66. exit('Error: No permission!');
  67. }
  68. ?>