You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

5 years ago
  1. <?php include "conf.php"; /* load a local configuration */ ?>
  2. <?php session_start(); ?>
  3. <?php require 'vendor/autoload.php'; /* composer includes */ ?>
  4. <?php include "modulekit/loader.php"; /* loads all php-includes */ ?>
  5. <?php call_hooks("init"); /* initialize submodules */ ?>
  6. <?php
  7. $allRepositories = getRepositories();
  8. $repoId = $_REQUEST['repo'];
  9. if (!array_key_exists($repoId, $allRepositories)) {
  10. Header("HTTP/1.1 404 Repository not found");
  11. exit(0);
  12. }
  13. $repoData = $allRepositories[$repoId];
  14. $repo = getRepo($repoId, $repoData);
  15. if (array_key_exists('list', $_REQUEST)) {
  16. $contents = array();
  17. foreach ($repo->scandir($_REQUEST['dir']) as $f) {
  18. if (substr($f, 0, 1) !== '.') {
  19. $contents[] = array('name' => $f);
  20. }
  21. }
  22. $mime_type = 'application/json; charset=utf-8';
  23. $contents = json_encode($contents);
  24. }
  25. else {
  26. $tmpfile = tempnam('/tmp', 'osb-asset-');
  27. $contents = $repo->file_get_contents((array_key_exists('dir', $_REQUEST) ? "{$_REQUEST['dir']}/" : '') . $_REQUEST['file']);
  28. if ($contents === false) {
  29. Header("HTTP/1.1 401 Permission denied");
  30. exit(0);
  31. }
  32. file_put_contents($tmpfile, $contents);
  33. $mime_type = mime_content_type($tmpfile);
  34. }
  35. Header("Content-Type: {$mime_type}; charset=utf-8");
  36. Header("Cache-Control: max-age=86400");
  37. print $contents;