From ada83815ac1a62651b45cc9de9072b6e8a60bfda Mon Sep 17 00:00:00 2001 From: "Silas S. Brown" <ssb22@cam.ac.uk> Date: Tue, 17 May 2016 10:56:34 +0000 Subject: [PATCH] Update Web Adjuster git-svn-id: http://svn.code.sf.net/p/e-guidedog/code/ssb22/adjuster@2494 29193198-4895-4776-b068-10539e920549 --- adjuster.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/adjuster.py b/adjuster.py index 774ddcb..301ab17 100755 --- a/adjuster.py +++ b/adjuster.py @@ -1809,13 +1809,19 @@ document.forms[0].i.focus() # else: do_pdftotext=do_epubtotext=do_epubtozip=do_mp3=False # do not attempt to media-process any body that is sent with this Location: redirect (if it's just a copy of the URL then running it through ebook-convert might hold things up unnecessarily) # -> actually, don't need to process the body AT ALL (doing so and adding our scripts etc is only bloat), we can do our own brief redirect. But not yet, because we might have to set cookies first. else: doRedirect = value # TODO: do we need to check if response.code is in [301,302,303,307] before accepting a Location: ? - if cookie_host and self.request.path=="/" and old_value_1.startswith("http") and not old_value_1.startswith("http://"+cookie_host+"/"): + if cookie_host and self.request.path=="/" and old_value_1.startswith("http") and not (old_value_1.startswith("http://"+cookie_host+"/") or (cookie_host.endswith(".0") and old_value_1.startswith("https://"+cookie_host[:-2]+"/"))): # This'll be a problem. If the user is requesting / and the site's trying to redirect off-site, how do we know that the user isn't trying to get back to the URL box (having forgotten to clear the cookie) and now can't possibly do so because / always results in an off-site Location redirect ? # (The same thing can occur if offsite is False but we're redirecting to one of our other domains, hence we use the old_value_1.startswith condition instead of the 'offsite' flag; the latter is true only if NONE of our domains can do it.) # (DON'T just do this for ANY offsite url when in cookie_host mode - that could mess up images and things. (Could still mess up images etc if they're served from / with query parameters; for now we're assuming path=/ is a good condition to do this. The whole cookie_host thing is a compromise anyway; wildcard_dns is better.)) - if offsite: reason="which this adjuster is not currently set to adjust" - else: reason="which will be adjusted at %s (not here)" % (value[value.index('//')+2:(value+"/").index('/',value.index('/')+2)],) - return self.doResponse2(("<html><body>The server is redirecting you to <a href=\"%s\">%s</a> %s.</body></html>" % (value,old_value_1,reason)),True,False) # and 'Back to URL box' link will be added + if offsite: reason=" which this adjuster is not currently set to adjust" + else: + adjustedAt = value[value.index('//')+2:(value+"/").index('/',value.index('/')+2)] + if adjustedAt.endswith(".0"): + # not a redirect to another adjuster, but quirk of the HTTPS hack in combination with cookie_host + value = "http://" + hostSuffix(0)+publicPortStr() + "?q=" + urllib.quote(old_value_1) + "&" + adjust_domain_cookieName + "=0" # back to URL box, and act as though this had been typed in + reason = "" # "which will be adjusted here, but you have to read the code to understand why it's necessary to follow an extra link in this case :-(" + else: reason=" which will be adjusted at %s (not here)" % (adjustedAt,) + return self.doResponse2(("<html><body>The server is redirecting you to <a href=\"%s\">%s</a>%s.</body></html>" % (value,old_value_1,reason)),True,False) # and 'Back to URL box' link will be added elif "set-cookie" in name.lower(): if not isProxyRequest: value=cookie_domain_process(value,cookie_host) for ckName in upstreamGuard: value=value.replace(ckName,ckName+"1") -- GitLab