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. define('LYCHEE', true);
  15. date_default_timezone_set('UTC');
  16. // Load autoload
  17. require('autoload.php');
  18. // Load modules
  19. require('modules/db.php');
  20. require('modules/misc.php');
  21. require('modules/photo.php');
  22. require('modules/session.php');
  23. require('modules/settings.php');
  24. require('modules/upload.php');
  25. if (file_exists('../data/config.php')) require('../data/config.php');
  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. require('access/installation.php');
  33. exit();
  34. }
  35. // Connect and get settings
  36. $database = dbConnect();
  37. $settings = getSettings();
  38. // Init plugins
  39. $plugins = explode(';', $settings['plugins']);
  40. $plugins = new Plugins($plugins, $database);
  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-9sf]{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. // Fallback for switch statement
  50. if (!isset($_POST['function'])) $_POST['function'] = '';
  51. if (!isset($_GET['function'])) $_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. require('access/admin.php');
  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. require('access/guest.php');
  66. }
  67. } else {
  68. exit('Error: No permission!');
  69. }
  70. ?>