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.

47 lines
1.3 KiB

  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('dir', $_REQUEST)) {
  16. $_REQUEST['dir'] = '.';
  17. }
  18. if (array_key_exists('list', $_REQUEST)) {
  19. $contents = array();
  20. foreach ($repo->scandir($_REQUEST['dir']) as $f) {
  21. if (substr($f, 0, 1) !== '.') {
  22. $contents[] = array('name' => $f);
  23. }
  24. }
  25. $mime_type = 'application/json; charset=utf-8';
  26. $contents = json_encode($contents);
  27. }
  28. else {
  29. $tmpfile = tempnam('/tmp', 'osb-asset-');
  30. $contents = $repo->file_get_contents("{$_REQUEST['dir']}/{$_REQUEST['file']}");
  31. if ($contents === false) {
  32. Header("HTTP/1.1 401 Permission denied");
  33. exit(0);
  34. }
  35. file_put_contents($tmpfile, $contents);
  36. $mime_type = mime_content_type($tmpfile);
  37. }
  38. Header("Content-Type: {$mime_type}; charset=utf-8");
  39. print $contents;