From b28c6cfbf32ad0e1ea80bb6ec7fe68f700dc68cc Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 Sep 2017 20:55:34 +0000 Subject: [PATCH] Fixed HTTP --- checkmyip.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/checkmyip.py b/checkmyip.py index f5b8f88..e7e636b 100755 --- a/checkmyip.py +++ b/checkmyip.py @@ -19,10 +19,11 @@ import jinja2 import paramiko import threading + j2log = "Connection from: {{ ip }} ({{ port }}) ({{ proto }})" #j2send = "\n\n\nYour IP Address is {{ ip }} ({{ port }})\n\n\n\n" - + j2send = """{ @@ -35,9 +36,6 @@ j2send = """{ }""" - - - class log_management: def __init__(self): self.logpath = "/etc/checkmyip/" @@ -184,25 +182,14 @@ def http_talker(client, valdict): valdict.update({"proto": "http"}) log(j2format(j2log, valdict)) response_body_raw = j2format(j2send, valdict) - response_headers = { - 'Content-Type': 'text/html; encoding=utf8', - 'Content-Length': len(response_body_raw), - 'Connection': 'close', - } - response_headers_raw = ''.join('%s: %s\n' % (k, v) for k, v in \ - response_headers.iteritems()) - response_proto = 'HTTP/1.1' - response_status = '200' - response_status_text = 'OK' - client.send('%s %s %s' % (response_proto, response_status, response_status_text)) - client.send(response_headers_raw) - client.send('\n') - client.send(response_body_raw) + response_headers_raw = """HTTP/1.1 200 OK +Content-Length: %s +Content-Type: application/json; encoding=utf8 +Connection: close""" % str(len(response_body_raw)) + client.send(response_headers_raw + "\n\n" + response_body_raw) client.close() - - def start(): talkers = {22: ssh_talker, 23: telnet_talker, 80: http_talker} for talker in talkers: