Skip to content

Commit f999f16

Browse files
committed
Offer access with ip address on invalid host error
1 parent 9ac96cd commit f999f16

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Ui/UiRequest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import html
77
import urllib
8+
import socket
89

910
import gevent
1011

@@ -83,7 +84,16 @@ def route(self, path):
8384

8485
# Check if host allowed to do request
8586
if not self.isHostAllowed(self.env.get("HTTP_HOST")):
86-
return self.error403("Invalid host: %s" % self.env.get("HTTP_HOST"), details=False)
87+
ret_error = next(self.error403("Invalid host: %s" % self.env.get("HTTP_HOST"), details=False))
88+
89+
http_get = self.env["PATH_INFO"]
90+
if self.env["QUERY_STRING"]:
91+
http_get += "?{0}".format(self.env["QUERY_STRING"])
92+
self_host = self.env["HTTP_HOST"].split(":")[0]
93+
self_ip = self.env["HTTP_HOST"].replace(self_host, socket.gethostbyname(self_host))
94+
link = "http://{0}{1}".format(self_ip, http_get)
95+
ret_link = """<h4>Access via ip: <a href="{0}">{0}</a>""".format(html.escape(link)).encode("utf8")
96+
return iter([ret_error, ret_link])
8797

8898
# Prepend .bit host for transparent proxy
8999
if self.server.site_manager.isDomain(self.env.get("HTTP_HOST")):

0 commit comments

Comments
 (0)