UiRequestPlugin.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import re
  2. from Plugin import PluginManager
  3. @PluginManager.registerTo("UiRequest")
  4. class UiRequestPlugin(object):
  5. def __init__(self, server = None):
  6. from Site import SiteManager
  7. self.site_manager = SiteManager.site_manager
  8. super(UiRequestPlugin, self).__init__(server)
  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_site_address = re.match(r"/(?P<address>[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)", referer_path).group("address")
  22. if referer_site_address == site_address: # Referer site address as simple address
  23. return True
  24. elif self.site_manager.resolveDomain(referer_site_address) == site_address: # Referer site address as dns
  25. return True
  26. else: # Invalid referer
  27. return False