From 2dc44c2f31ee71cda30624e527a4b34d6b3d8d75 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Fri, 26 Nov 2021 18:44:17 +0000 Subject: [PATCH] Fix ersatz server so it actually serves stuff. Rm accidental hotlinking of images in template, and rm included headers. --- fake-dw/fake-dw.py | 61 +++++++++++++++++++++++--- fake-dw/templates/login | 96 ++++++++++++++++------------------------- 2 files changed, 92 insertions(+), 65 deletions(-) diff --git a/fake-dw/fake-dw.py b/fake-dw/fake-dw.py index d69bbe9..7a15445 100644 --- a/fake-dw/fake-dw.py +++ b/fake-dw/fake-dw.py @@ -6,10 +6,11 @@ from http import HTTPStatus import requests import argparse import os +import random class GatewayHandler(http.server.BaseHTTPRequestHandler): - server_version = 'fake-dw/0.0.1' + server_version = 'fake-dw-gateway/0.0.1' keep_headers = [ 'content-type', @@ -71,15 +72,61 @@ class GatewayHandler(http.server.BaseHTTPRequestHandler): class ErsatzHandler(http.server.BaseHTTPRequestHandler): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + server_version = 'fake-dw-ersatz/0.0.1' - self.template_dir = os.path.join( - os.path.dirname(__file__), - 'templates', + def do_GET(self): + fields = { + 'content-type': 'text/html', + 'status': 200, + } + + if self.path=='/login': + session = hex(random.randint(0, 65535)) + self.server.session_id = session + fields['template-name']= 'login' + fields['set-cookie'] = f"ljuniq={session}; domain=localhost; path=/; expires=Sun, 23-Jan-2200 19:18:56 GMT" + fields['session'] = session + else: + self.send_error(404) + return + + with open( + os.path.join( + os.path.dirname(__file__), + 'templates', + fields['template-name'], + ), + 'r', + ) as template: + content = template.read() % fields + + self.send_response(fields['status']) + self.send_header( + 'Content-Type', + fields['content-type'], + ) + self.send_header( + 'Content-Length', + len(content), + ) + self.send_header( + 'Access-Control-Allow-Origin', + '*', ) - print(self.template_dir) + for f in [ + 'Set-Cookie', + ]: + if f.lower() in fields: + self.send_header(f, fields[f.lower()]) + + self.end_headers() + + self.wfile.write( + bytes( + content, + encoding='UTF-8', + )) class TCPServerWithSettings(socketserver.TCPServer): diff --git a/fake-dw/templates/login b/fake-dw/templates/login index 003ab9c..3735585 100644 --- a/fake-dw/templates/login +++ b/fake-dw/templates/login @@ -1,23 +1,3 @@ - HTTP/1.1 200 OK - Date: Wed, 24 Nov 2021 19:18:56 GMT - Content-Type: text/html; charset=utf-8 - Transfer-Encoding: chunked - Connection: keep-alive - CF-Ray: 6b34fc6adb96777a-LHR - Cache-Control: private, proxy-revalidate - Content-Language: en - ETag: W/"1bc66171be1d3ac34df7fdb81376235a-gzip" - Expires: Wed, 24 Nov 2021 19:18:56 GMT - Set-Cookie: ljuniq=09Z5PuIllU4vZho%3A1637781536; domain=.dreamwidth.org; path=/; expires=Sun, 23-Jan-2022 19:18:56 GMT; secure - Vary: Accept-Encoding - CF-Cache-Status: DYNAMIC - Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Pragma: no-cache - Server: cloudflare -Length: unspecified [text/html] - - - @@ -32,27 +12,27 @@ Length: unspecified [text/html] var site_p = {"user_domain": "dreamwidth.org", "ctx_popup": 1, -"imgprefix": "https://www.dreamwidth.org/img", +"imgprefix": "https:/img", "cmax_comment": 16000, "media_embed_enabled": 1, "ctx_popup_icons": 1, "currentJournalBase": "", "inbox_update_poll": 1, -"siteroot": "https://www.dreamwidth.org", +"siteroot": "https:", "iconprefix": "https://v.dreamwidth.org", "esn_async": 1, "ctx_popup_userhead": 1, "has_remote": 0, "currentJournal": "", -"statprefix": "https://www.dreamwidth.org/stc"}; +"statprefix": "https:/stc"}; var site_k = ["user_domain", "ctx_popup", "imgprefix", "cmax_comment", "media_embed_enabled", "ctx_popup_icons", "currentJournalBase", "inbox_update_poll", "siteroot", "iconprefix", "esn_async", "ctx_popup_userhead", "has_remote", "currentJournal", "statprefix"]; for (var i = 0; site_k.length > i; i++) { Site[site_k[i]] = site_p[site_k[i]]; } - - - + + + @@ -62,7 +42,7 @@ Length: unspecified [text/html] _gaq.push(['_trackPageview']); @@ -74,7 +54,7 @@ Length: unspecified [text/html] @@ -82,17 +62,17 @@ Length: unspecified [text/html]
-