CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
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.
 
 
 

55 lines
1.8 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2020 by The CAT-SOOP Developers <catsoop-dev@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import json
  17. import mimetypes
  18. path = cs_form.get("path", None)
  19. fname = cs_form.get("fname", None)
  20. cs_handler = "raw_response"
  21. error = None
  22. if path is None or fname is None:
  23. error = "Please specify a path and a filename"
  24. if error is None:
  25. try:
  26. fname = os.path.basename(fname)
  27. path = json.loads(path)
  28. except:
  29. error = "Could not interpret path and/or filename."
  30. if error is None:
  31. # try:
  32. upload_dir = os.path.realpath(os.path.join(cs_data_root, "_logs", "_uploads"))
  33. loc = os.path.realpath(os.path.join(upload_dir, *path, fname))
  34. assert loc.startswith(upload_dir)
  35. with open(os.path.join(loc, "info"), "rb") as f:
  36. content_type = (
  37. mimetypes.guess_type(csm_cslog.unprep(f.read())["filename"])[0]
  38. or "text/plain"
  39. )
  40. with open(os.path.join(loc, "content"), "rb") as f:
  41. response = csm_cslog.decompress_decrypt(f.read())
  42. # except:
  43. # error = 'There was an error retrieving the file.'
  44. if error is not None:
  45. response = error
  46. content_type = "text/plain"