api.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 autoload
  17. require(__DIR__ . '/autoload.php');
  18. // Load modules
  19. require(__DIR__ . '/modules/misc.php');
  20. require(__DIR__ . '/modules/upload.php');
  21. if (file_exists(__DIR__ . '/../data/config.php')) require(__DIR__ . '/../data/config.php');
  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);
  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. require(__DIR__ . '/access/admin.php');
  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. require(__DIR__ . '/access/guest.php');
  64. }
  65. } else {
  66. exit('Error: No permission!');
  67. }
  68. ?>