Skip to content

Commit

Permalink
Resolve domain in parsePath function
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Oct 6, 2019
1 parent 924a613 commit 43a5742
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 0 additions & 10 deletions plugins/Zeroname/UiRequestPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ def __init__(self, *args, **kwargs):
self.site_manager = SiteManager.site_manager
super(UiRequestPlugin, self).__init__(*args, **kwargs)

# Media request
def actionSiteMedia(self, path, **kwargs):
match = re.match(r"/media/(?P<address>[A-Za-z0-9-]+\.[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)", path)
if match: # Its a valid domain, resolve first
domain = match.group("address")
address = self.site_manager.resolveDomain(domain)
if address:
path = "/media/" + address + match.group("inner_path")
return super(UiRequestPlugin, self).actionSiteMedia(path, **kwargs) # Get the wrapper frame output

@PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object):
def createArguments(self):
Expand Down
4 changes: 4 additions & 0 deletions src/Ui/UiRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def sendHeader(self, status=200, content_type="text/html", noscript=False, allow
# Renders a template
def render(self, template_path, *args, **kwargs):
template = open(template_path, encoding="utf8").read()

def renderReplacer(m):
return "%s" % kwargs.get(m.group(1), "")

Expand Down Expand Up @@ -559,6 +560,8 @@ def parsePath(self, path):
match = re.match(r"/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
if match:
path_parts = match.groupdict()
if self.isDomain(path_parts["address"]):
path_parts["address"] = self.resolveDomain(path_parts["address"])
path_parts["request_address"] = path_parts["address"] # Original request address (for Merger sites)
path_parts["inner_path"] = path_parts["inner_path"].lstrip("/")
if not path_parts["inner_path"]:
Expand All @@ -578,6 +581,7 @@ def actionSiteMedia(self, path, header_length=True, header_noscript=False):
return self.error404(path)

address = path_parts["address"]

file_path = "%s/%s/%s" % (config.data_dir, address, path_parts["inner_path"])

if (config.debug or config.merge_media) and file_path.split("/")[-1].startswith("all."):
Expand Down

0 comments on commit 43a5742

Please sign in to comment.