1
0

UiRequestPlugin.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import re
  2. from Plugin import PluginManager
  3. @PluginManager.registerTo("UiRequest")
  4. class UiRequestPlugin(object):
  5. def __init__(self, *args, **kwargs):
  6. from Site import SiteManager
  7. self.site_manager = SiteManager.site_manager
  8. super(UiRequestPlugin, self).__init__(*args, **kwargs)
  9. # Media request
  10. def actionSiteMedia(self, path):
  11. match = re.match(r"/media/(?P<address>[A-Za-z0-9-]+\.[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)", path)
  12. if match: # Its a valid domain, resolve first
  13. domain = match.group("address")
  14. address = self.site_manager.resolveDomain(domain)
  15. if address:
  16. path = "/media/"+address+match.group("inner_path")
  17. return super(UiRequestPlugin, self).actionSiteMedia(path) # Get the wrapper frame output
  18. # Is mediarequest allowed from that referer
  19. def isMediaRequestAllowed(self, site_address, referer):
  20. referer_path = re.sub("http[s]{0,1}://.*?/", "/", referer).replace("/media", "") # Remove site address
  21. referer_path = re.sub(r"\?.*", "", referer_path) # Remove http params
  22. if self.isProxyRequest(): # Match to site domain
  23. referer = re.sub("^http://zero[/]+", "http://", referer) # Allow /zero access
  24. referer_site_address = re.match("http[s]{0,1}://(.*?)(/|$)", referer).group(1)
  25. else: # Match to request path
  26. referer_site_address = re.match(r"/(?P<address>[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)", referer_path).group("address")
  27. if referer_site_address == site_address: # Referer site address as simple address
  28. return True
  29. elif self.site_manager.resolveDomain(referer_site_address) == site_address: # Referer site address as dns
  30. return True
  31. else: # Invalid referer
  32. return False