fixed ip parsing and logs page

This commit is contained in:
2026-02-14 01:46:47 -05:00
parent 9d16df6053
commit b6b5e1c17c

View File

@@ -567,22 +567,22 @@ add('MIME Types',navigator.mimeTypes.length);
LOGS_STYLE = '''<!DOCTYPE html><html><head><meta charset="utf-8">
<title>☠ badtests — visitor logs</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{background:#0d1117;color:#c9d1d9;font-family:monospace;font-size:13px;padding:20px 40px}
h1{color:#f85149;margin-bottom:4px}
.sub{color:#484f58;margin-bottom:20px;font-size:12px}
table{border-collapse:collapse;width:100%}
th{text-align:left;color:#58a6ff;padding:8px;border-bottom:2px solid #30363d;position:sticky;top:0;background:#0d1117}
td{padding:6px 8px;border-bottom:1px solid #161b22;max-width:400px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
tr:hover td{background:#161b22}
.ip{color:#7ee787}.path{color:#d2a8ff}.method{color:#d29922}.time{color:#484f58}
details{cursor:pointer}
details pre{background:#161b22;padding:8px;margin-top:4px;border-radius:4px;white-space:pre-wrap;max-height:200px;overflow:auto}
*{{margin:0;padding:0;box-sizing:border-box}}
body{{background:#0d1117;color:#c9d1d9;font-family:monospace;font-size:13px;padding:20px 40px}}
h1{{color:#f85149;margin-bottom:4px}}
.sub{{color:#484f58;margin-bottom:20px;font-size:12px}}
table{{border-collapse:collapse;width:100%}}
th{{text-align:left;color:#58a6ff;padding:8px;border-bottom:2px solid #30363d;position:sticky;top:0;background:#0d1117}}
td{{padding:6px 8px;border-bottom:1px solid #161b22;max-width:400px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}}
tr:hover td{{background:#161b22}}
.ip{{color:#7ee787}}.path{{color:#d2a8ff}}.method{{color:#d29922}}.time{{color:#484f58}}
details{{cursor:pointer}}
details pre{{background:#161b22;padding:8px;margin-top:4px;border-radius:4px;white-space:pre-wrap;max-height:200px;overflow:auto}}
</style></head><body>
<h1>☠ visitor logs</h1>
<p class="sub">Recording all requests. %d entries so far. <a href="/logs" style="color:#58a6ff">Refresh</a> | <a href="/" style="color:#58a6ff">Home</a></p>
<p class="sub">Recording all requests. {count} entries so far. <a href="/logs" style="color:#58a6ff">Refresh</a> | <a href="/" style="color:#58a6ff">Home</a></p>
<table><tr><th>Time</th><th>IP</th><th>Method</th><th>Path</th><th>User-Agent</th><th>Headers</th></tr>
%s
{rows}
</table></body></html>'''
# --- MIME sniff test page (wraps the payload endpoint) ---
@@ -600,6 +600,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
_index = build_index()
_routes = {t[0]: t for t in TESTS}
def _get_client_ip(self):
'''Get real client IP from reverse proxy headers, fallback to socket address.'''
return (self.headers.get('X-Real-IP')
or (self.headers.get('X-Forwarded-For', '').split(',')[0].strip())
or self.client_address[0])
def do_GET(self):
p = self.path.split('?')[0]
self._log_visit()
@@ -626,7 +632,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
headers[k] = self.headers[k]
entry = {
'time': time.strftime('%Y-%m-%d %H:%M:%S'),
'ip': self.client_address[0],
'ip': self._get_client_ip(),
'method': self.command,
'path': self.path,
'ua': self.headers.get('User-Agent', ''),
@@ -649,7 +655,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
<td>{html.escape(e['ua'][:80])}</td>
<td><details><summary>{len(e['headers'])} headers</summary><pre>{html.escape(hdrs_str)}</pre></details></td>
</tr>'''
page = (LOGS_STYLE % (len(VISITOR_LOG), rows)).encode()
page = LOGS_STYLE.format(count=len(VISITOR_LOG), rows=rows).encode()
self._r(200, {'Content-Type': 'text/html; charset=utf-8'}, page)
def _dispatch(self, path):
@@ -836,11 +842,11 @@ document.querySelector('text:last-of-type').textContent = 'JS EXECUTED SUCCESSFU
}, b'<html><body><h1>HSTS Bomb</h1><p>Your browser now thinks this site requires HTTPS for 31 years.</p><p>This header also applies to ALL subdomains and requests preload list inclusion.</p><p>To undo in Chrome: chrome://net-internals/#hsts</p></body></html>')
# --- Misc ---
elif p == '/misc-ipv4':
ip = self.client_address[0]
ip = self._get_client_ip()
body = f'<html><head><title>Your IP: {ip}</title></head><body style="background:#0d1117;color:#c9d1d9;font-family:monospace;padding:40px"><h1 style="color:#7ee787">{ip}</h1></body></html>'
self._r(200, {'Content-Type': 'text/html'}, body.encode())
elif p == '/misc-ipv6':
ip = self.client_address[0]
ip = self._get_client_ip()
body = f'<html><head><title>Your IP: {ip}</title></head><body style="background:#0d1117;color:#c9d1d9;font-family:monospace;padding:40px"><h1 style="color:#7ee787">{ip}</h1><p>For true IPv6, connect to [::1]:{PORT}</p></body></html>'
self._r(200, {'Content-Type': 'text/html'}, body.encode())
elif p == '/fingerprint':