api.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. ###
  50. # Admin Access
  51. # Full access to Lychee. Only with correct password/session.
  52. ###
  53. define('LYCHEE_ACCESS_ADMIN', true);
  54. $admin = new Admin($database, $plugins, $settings);
  55. $admin->check($fn);
  56. } else {
  57. ###
  58. # Guest Access
  59. # Access to view all public folders and photos in Lychee.
  60. ###
  61. define('LYCHEE_ACCESS_GUEST', true);
  62. $guest = new Guest($database, $plugins, $settings);
  63. $guest->check($fn);
  64. }
  65. } else {
  66. exit('Error: Called function not found!');
  67. }
  68. ?>