api.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. ###
  3. # @name API
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!empty($_POST['function'])||!empty($_GET['function'])) {
  7. session_start();
  8. date_default_timezone_set('UTC');
  9. # Load required files
  10. require(__DIR__ . '/define.php');
  11. require(__DIR__ . '/autoload.php');
  12. require(__DIR__ . '/modules/misc.php');
  13. if (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
  14. else {
  15. ###
  16. # Installation Access
  17. # Limited access to configure Lychee. Only available when the config.php file is missing.
  18. ###
  19. define('LYCHEE_ACCESS_INSTALLATION', true);
  20. $installation = new Installation(null, null, null);
  21. $installation->check($_POST['function']);
  22. exit();
  23. }
  24. # Define the table prefix
  25. if (!isset($dbTablePrefix)) $dbTablePrefix = '';
  26. defineTablePrefix($dbTablePrefix);
  27. # Connect to database
  28. $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName);
  29. # Load settings
  30. $settings = new Settings($database);
  31. $settings = $settings->get();
  32. # Init plugins
  33. $plugins = explode(';', $settings['plugins']);
  34. $plugins = new Plugins($plugins, $database, $settings);
  35. # Validate parameters
  36. if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
  37. if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
  38. if (isset($_POST['albumID'])&&preg_match('/^[0-9sfr]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
  39. if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
  40. # Function for switch statement
  41. if (isset($_POST['function'])) $fn = $_POST['function'];
  42. else $fn = $_GET['function'];
  43. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  44. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===$settings['identifier'])) {
  45. ###
  46. # Admin Access
  47. # Full access to Lychee. Only with correct password/session.
  48. ###
  49. define('LYCHEE_ACCESS_ADMIN', true);
  50. $admin = new Admin($database, $plugins, $settings);
  51. $admin->check($fn);
  52. } else {
  53. ###
  54. # Guest Access
  55. # Access to view all public folders and photos in Lychee.
  56. ###
  57. define('LYCHEE_ACCESS_GUEST', true);
  58. $guest = new Guest($database, $plugins, $settings);
  59. $guest->check($fn);
  60. }
  61. } else {
  62. exit('Error: Called function not found!');
  63. }
  64. ?>