Simplify and all X-Real-IP header

This commit is contained in:
Viktor Varland 2016-02-28 14:44:38 +01:00
parent 12090a8355
commit acbffce40d

View file

@ -12,16 +12,15 @@ class pubIpHandler(http.server.BaseHTTPRequestHandler):
self.send_response(200) self.send_response(200)
self.send_header('Content-type','text/html') self.send_header('Content-type','text/html')
self.end_headers() self.end_headers()
# Send the html message
c_address, c_port = self.client_address
s_address = self.server.current_ip s_address = self.server.current_ip
path = self.path.split('/') path = self.path.split('/')
if path[1] == '': if path[1].startswith('favico'):
msg = s_address return
elif path[1] == 'update':
if path[1] == 'update':
n_address = path[2] n_address = path[2]
try: try:
@ -34,6 +33,11 @@ class pubIpHandler(http.server.BaseHTTPRequestHandler):
print('IP was identical, skipping...') print('IP was identical, skipping...')
return return
if 'X-Real-IP' in self.headers:
c_address = self.headers['X-Real-IP']
else:
c_address, c_port = self.client_address
if n_address == c_address: if n_address == c_address:
print('Updating dynamic IP: {}'.format(n_address)) print('Updating dynamic IP: {}'.format(n_address))
self.server.current_ip = n_address self.server.current_ip = n_address
@ -41,10 +45,7 @@ class pubIpHandler(http.server.BaseHTTPRequestHandler):
print('Update IP mismatch: {}, {}'.format(c_address, n_address)) print('Update IP mismatch: {}, {}'.format(c_address, n_address))
return return
msg = s_address msg = self.server.current_ip
else:
msg = ''
self.wfile.write(msg.encode('utf-8')) self.wfile.write(msg.encode('utf-8'))
return return