api.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 modules
  17. require('modules/album.php');
  18. require('modules/db.php');
  19. require('modules/misc.php');
  20. require('modules/photo.php');
  21. require('modules/session.php');
  22. require('modules/settings.php');
  23. require('modules/upload.php');
  24. if (file_exists('../data/config.php')) require('../data/config.php');
  25. else {
  26. /**
  27. * Installation Access
  28. * Limited access to configure Lychee. Only available when the config.php file is missing.
  29. */
  30. define('LYCHEE_ACCESS_INSTALLATION', true);
  31. require('access/installation.php');
  32. exit();
  33. }
  34. // Connect and get settings
  35. $database = dbConnect();
  36. $settings = getSettings();
  37. // Escape
  38. foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
  39. foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
  40. // Validate parameters
  41. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  42. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  43. if (isset($_POST['albumID'])&&preg_match('/^[0-9sf]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  44. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  45. // Fallback for switch statement
  46. if (!isset($_POST['function'])) $_POST['function'] = '';
  47. if (!isset($_GET['function'])) $_GET['function'] = '';
  48. if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
  49. /**
  50. * Admin Access
  51. * Full access to Lychee. Only with correct password/session.
  52. */
  53. define('LYCHEE_ACCESS_ADMIN', true);
  54. require('access/admin.php');
  55. } else {
  56. /**
  57. * Guest Access
  58. * Access to view all public folders and photos in Lychee.
  59. */
  60. define('LYCHEE_ACCESS_GUEST', true);
  61. require('access/guest.php');
  62. }
  63. } else {
  64. exit('Error: No permission!');
  65. }
  66. ?>