api.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, $settings);
  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. $admin = new Admin($database, $plugins, $settings);
  57. $admin->check($_POST['function']);
  58. } else {
  59. ###
  60. # Guest Access
  61. # Access to view all public folders and photos in Lychee.
  62. ###
  63. define('LYCHEE_ACCESS_GUEST', true);
  64. require(__DIR__ . '/access/guest.php');
  65. }
  66. } else {
  67. exit('Error: Called function not found!');
  68. }
  69. ?>