/yaki/webapps.disabled/filemgr/__init__.py

https://github.com/dttocs/Yaki · Python · 96 lines · 59 code · 19 blank · 18 comment · 7 complexity · c48ba2743ec5a56b9e9ddf08731e2325 MD5 · raw file

  1. # configuration for this webapp
  2. from filemgr.users import FileUser
  3. import filemgr.snakelets
  4. import os
  5. import logging
  6. log=logging.getLogger("Snakelets.logger")
  7. name="File Manager"
  8. docroot="docroot"
  9. sessionTimeoutSecs=30*60 # 30 minutes
  10. sharedSession=False # set to True, then also set Frog's one to True --> single signon
  11. defaultOutputEncoding="UTF-8"
  12. # The required privilege is "filemgr_access";
  13. # this is set in the special filemgr user object (filemgr/users.py)
  14. authorizationPatterns={
  15. "*": ["filemgr_access"],
  16. "login.y": None,
  17. "cookiecheck.y": None,
  18. "about": None,
  19. "*.css": None,
  20. "*.js": None
  21. }
  22. def documentAllower(path):
  23. return True # allow all (even .py files)
  24. authenticationMethod = ("loginpage", "login.y")
  25. snakelets= {
  26. "download" : filemgr.snakelets.DownloadFile
  27. }
  28. configItems = {
  29. # The authorised users.
  30. # Use the 'mkuser.py' script to help adding new users.
  31. # (if you use frog and SharedAuth, you can leave this... it will use Frog's userbase)
  32. "knownusers" : {
  33. "rcarmo": FileUser("rcarmo", "Rui Carmo", r"/Users/rcarmo", passwordhash="0e4e429dbb308001663177fbbabfb186f6b73781"), # XXX set this to correct values
  34. },
  35. }
  36. #
  37. # USER AUTHORIZATION
  38. #
  39. def authorizeUser(authmethod, url, username, password, request):
  40. # try to use shared auth (used with Frog webapp)
  41. try:
  42. sharedauth=request.getWebApp().server.getPlugin("SharedAuth")
  43. result=sharedauth.authorizeUser(authmethod, url, username, password, request)
  44. if result:
  45. # auth success!
  46. # but, FileMgr requires FileUser objects instead of regular LoginUser objects,
  47. # so we have to convert it. The directory is set by the other auth method.
  48. return FileUser(result.userid, result.name, result.directory, result.password.encode("hex"))
  49. except KeyError:
  50. # no shared auth available
  51. pass
  52. # no shared auth available, or shared auth failed.
  53. if username in configItems["knownusers"]:
  54. user = configItems["knownusers"][username]
  55. if user.checkPassword(password):
  56. return user
  57. return None
  58. #
  59. # WEBAPP INIT
  60. #
  61. def init(webapp):
  62. import snakeserver.server
  63. version=snakeserver.server.SNAKELETS_VERSION.split()[1]
  64. if version.lower().endswith("cvs"):
  65. version=version[:-3]
  66. if float(version)<1.42:
  67. msg="FileMgr requires Snakelets version 1.42 or newer"
  68. print "ERROR:",msg
  69. raise RuntimeError(msg)
  70. os.umask(0077) # protect written files, only readably by current user.
  71. import mimetypes
  72. mimetypes.types_map[".java"]="text/x-java-source"
  73. mimetypes.types_map[".log"]="text/x-logfile"
  74. mimetypes.types_map[".conf"]="text/x-configfile"
  75. mimetypes.types_map[".sh"]="text/x-shell-script"
  76. def close(webapp):
  77. pass