Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

58 linhas
1.4 KiB

  1. # -*- python -*-
  2. import bobo
  3. import json
  4. import fnmatch
  5. import os
  6. import os.path
  7. import syslog
  8. import sys
  9. import jinja2
  10. import webob
  11. import mimetypes
  12. try:
  13. config = json.load(open("/srv/dehacker/dehacker.cfg", "r"))
  14. except:
  15. config = dict()
  16. try:
  17. sys.path.append(os.path.dirname(__file__))
  18. except:
  19. pass
  20. import namegenerators
  21. @bobo.resource("/", content_type="text/html")
  22. def index(request):
  23. return open("hackersite.template", "r").read()
  24. @bobo.query("/namegen", content_type="application/json")
  25. def namegen(bobo_request, govid="Bobby Smith"):
  26. namegenerators.filters.filter_random.seed(govid)
  27. namegenerators.hacker.hacker_random.seed(govid)
  28. name = namegenerators.hacker.hacker_name()
  29. return json.dumps({"govid": govid, "hackername": name})
  30. @bobo.resource("/statics/:f")
  31. @bobo.resource("/resources/:f")
  32. def statics(bobo_request, f):
  33. f = f.replace("..", "fuuuuuuuuuuuuuuuuuuuug")
  34. f = f.replace("/", "asssssssssssssssssssss")
  35. pth = os.path.join("resources", f)
  36. response = webob.Response()
  37. content_type = mimetypes.guess_type(pth)[0]
  38. if content_type is not None:
  39. response.content_type = content_type
  40. try:
  41. response.body = open(pth, "rb").read()
  42. except IOError:
  43. raise bobo.NotFound
  44. return response
  45. if not __name__ == "bobo__main__":
  46. application = bobo.Application(bobo_resources=__name__)