Merge pull request #168 from zeronet-conservancy/redirect_bit_domains
redirect bit domains
This commit is contained in:
commit
76d96043d6
3 changed files with 12 additions and 3 deletions
|
@ -1,3 +1,5 @@
|
|||
## please note that this file uses custom db cursor and thus may surprise you with how sql queries are performed
|
||||
|
||||
import sqlite3
|
||||
import json
|
||||
import time
|
||||
|
|
|
@ -35,7 +35,6 @@ class Site(object):
|
|||
def __init__(self, address, allow_create=True, settings=None):
|
||||
self.address = str(re.sub("[^A-Za-z0-9]", "", address)) # Make sure its correct address
|
||||
self.address_hash = hashlib.sha256(self.address.encode("ascii")).digest()
|
||||
self.address_sha1 = hashlib.sha1(self.address.encode("ascii")).digest()
|
||||
self.address_short = "%s..%s" % (self.address[:6], self.address[-4:]) # Short address for logging
|
||||
self.log = logging.getLogger("Site:%s" % self.address_short)
|
||||
self.addEventListeners()
|
||||
|
|
|
@ -372,7 +372,7 @@ class UiRequest(object):
|
|||
# Redirect to an url
|
||||
def actionRedirect(self, url):
|
||||
self.start_response('301 Redirect', [('Location', str(url))])
|
||||
yield self.formatRedirect(url)
|
||||
return self.formatRedirect(url)
|
||||
|
||||
def actionIndex(self):
|
||||
return self.actionRedirect("/" + config.homepage + "/")
|
||||
|
@ -634,7 +634,9 @@ class UiRequest(object):
|
|||
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"]):
|
||||
addr = path_parts["address"]
|
||||
if self.isDomain(addr):
|
||||
path_parts["domain"] = addr
|
||||
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("/")
|
||||
|
@ -651,6 +653,12 @@ class UiRequest(object):
|
|||
except SecurityError as err:
|
||||
return self.error403(err)
|
||||
|
||||
if "domain" in path_parts:
|
||||
addr = path_parts['address']
|
||||
path = path_parts['inner_path']
|
||||
query = self.env['QUERY_STRING']
|
||||
return self.actionRedirect(f"/{addr}/{path}?{query}")
|
||||
|
||||
if not path_parts:
|
||||
return self.error404(path)
|
||||
|
||||
|
|
Loading…
Reference in a new issue