Offer access with ip address on invalid host error

This commit is contained in:
shortcutme 2019-09-02 02:10:52 +02:00
parent 9ac96cdd50
commit f999f167b1
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -5,6 +5,7 @@ import mimetypes
import json
import html
import urllib
import socket
import gevent
@ -83,7 +84,16 @@ class UiRequest(object):
# Check if host allowed to do request
if not self.isHostAllowed(self.env.get("HTTP_HOST")):
return self.error403("Invalid host: %s" % self.env.get("HTTP_HOST"), details=False)
ret_error = next(self.error403("Invalid host: %s" % self.env.get("HTTP_HOST"), details=False))
http_get = self.env["PATH_INFO"]
if self.env["QUERY_STRING"]:
http_get += "?{0}".format(self.env["QUERY_STRING"])
self_host = self.env["HTTP_HOST"].split(":")[0]
self_ip = self.env["HTTP_HOST"].replace(self_host, socket.gethostbyname(self_host))
link = "http://{0}{1}".format(self_ip, http_get)
ret_link = """<h4>Access via ip: <a href="{0}">{0}</a>""".format(html.escape(link)).encode("utf8")
return iter([ret_error, ret_link])
# Prepend .bit host for transparent proxy
if self.server.site_manager.isDomain(self.env.get("HTTP_HOST")):