api.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. ###
  3. # @name API
  4. # @copyright 2015 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. # 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-9sfr]{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. # Function for switch statement
  46. if (isset($_POST['function'])) $fn = $_POST['function'];
  47. else $fn = $_GET['function'];
  48. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  49. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===$settings['identifier'])) {
  50. ###
  51. # Admin Access
  52. # Full access to Lychee. Only with correct password/session.
  53. ###
  54. define('LYCHEE_ACCESS_ADMIN', true);
  55. $admin = new Admin($database, $plugins, $settings);
  56. $admin->check($fn);
  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. $guest = new Guest($database, $plugins, $settings);
  64. $guest->check($fn);
  65. }
  66. } else {
  67. exit('Error: Called function not found!');
  68. }
  69. ?>