Add forward DNS lookup check
Some checks failed
buildbot/travis_bionic Build done.

This commit is contained in:
Peter Šurda 2021-07-31 20:45:50 +08:00
parent 0ee0ac4936
commit 12ee0ab3ec
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -10,7 +10,7 @@ import sys
from ipaddress import AddressValueError, IPv4Address, IPv6Address
import cherrypy
from cherrypy.lib.static import serve_file
# from cherrypy.lib.static import serve_file
from jinja2 import Template
import yaml
@ -59,8 +59,13 @@ class CloudInitApp:
try:
self.hostinfo = socket.gethostbyaddr(self.remoteip)
forward_lookup = socket.gethostbyname(self.hostinfo[0])
if forward_lookup != self.remoteip:
self.hostinfo = ('localhost', )
except socket.herror:
self.hostinfo = ('localhost', )
except socket.gaierror:
self.hostinfo = (self.remoteip, )
def _redirect_if_needed(self):
filepath = os.path.join(PATH, "data", self.hostinfo[0],