chiark / gitweb /
Fix ersatz server so it actually serves stuff.
authorMarnanel Thurman <marnanel@thurman.org.uk>
Fri, 26 Nov 2021 18:44:17 +0000 (18:44 +0000)
committerMarnanel Thurman <marnanel@thurman.org.uk>
Fri, 26 Nov 2021 18:44:17 +0000 (18:44 +0000)
Rm accidental hotlinking of images in template, and rm included headers.

fake-dw/fake-dw.py
fake-dw/templates/login

index d69bbe97a5bf0ff8bfda1854fb53c4dc4ec01fb8..7a1544582ecbc6852ba5165acae70107e5fa86de 100644 (file)
@@ -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):
 
index 003ab9c3b3f8df2afce7b5e55b8f2fcddf6a793a..3735585b8d81276562b5b9a5f11e1960641862cc 100644 (file)
@@ -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]
-
-
 <!DOCTYPE html>
 <html lang="en">
     <head>
@@ -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]];
                 }
            </script>
-        <link rel="stylesheet" type="text/css" href="https://www.dreamwidth.org/stc/??lj_base.css,esn.css,contextualhover.css,jquery/jquery.ui.theme.smoothness.css,lj_base-app.css,base-colors-light.css,reset.css,tropo/tropo-base.css,tropo/tropo-red.css?v=1593299549" />
-<link rel="stylesheet" type="text/css" href="https://www.dreamwidth.org/stc/??widgets/login.css?v=1587938565" />
-<script type="text/javascript" src="//www.dreamwidth.org/js/??6alib/core.js,6alib/dom.js,6alib/httpreq.js,livejournal.js,esn.js,6alib/ippu.js,lj_ippu.js,6alib/hourglass.js,contextualhover.js,nav.js?v=1595720038"></script>
+        <link rel="stylesheet" type="text/css" href="https:/stc/??lj_base.css,esn.css,contextualhover.css,jquery/jquery.ui.theme.smoothness.css,lj_base-app.css,base-colors-light.css,reset.css,tropo/tropo-base.css,tropo/tropo-red.css?v=1593299549" />
+<link rel="stylesheet" type="text/css" href="https:/stc/??widgets/login.css?v=1587938565" />
+<script type="text/javascript" src="/js/??6alib/core.js,6alib/dom.js,6alib/httpreq.js,livejournal.js,esn.js,6alib/ippu.js,lj_ippu.js,6alib/hourglass.js,contextualhover.js,nav.js?v=1595720038"></script>
 
     
 
@@ -62,7 +42,7 @@ Length: unspecified [text/html]
   _gaq.push(['_trackPageview']);</script>
 
     <!--[if lte IE 8]>
-    <script src="//www.dreamwidth.org/js/html5.js" type="text/javascript"></script>
+    <script src="/js/html5.js" type="text/javascript"></script>
     <![endif]-->
 </head>
     <body >
@@ -74,7 +54,7 @@ Length: unspecified [text/html]
                 
                 <div id="masthead" role="banner">
                     <span id="logo">
-                        <a href="https://www.dreamwidth.org/"><img alt="Dreamwidth Studios" src='https://www.dreamwidth.org/img/tropo-red/dw_logo.png' /></a>
+                        <a href="https:/"><img alt="Dreamwidth Studios" src='https:/img/tropo-red/dw_logo.png' /></a>
                     </span>
                 </div>
 
@@ -82,17 +62,17 @@ Length: unspecified [text/html]
                 <table summary='' cellpadding='0' cellspacing='0'><tr><td style='padding-right:20px; vertical-align: top'><div class='columns-2-r300 pkg'>
 <div class='columns-2-left'>
 <div class='appwidget appwidget-login' id='LJWidget_24'>
-<form action='https://www.dreamwidth.org/login' method='post' class='lj_login_form pkg'>
-<input type='hidden' name="lj_form_auth" value="c0:1637780400:1136:86400:5Asn7kYkEd-0-09Z5PuIllU4vZho:f738ddb050a4c83e380ac95c665689ac" /><h2>Welcome to Dreamwidth!</h2>
+<form action='/login' method='post' class='lj_login_form pkg'>
+<input type='hidden' name="lj_form_auth" value="c0:1637780400:1136:86400:5Asn7kYkEd-0-09Z5PuIllU4vZho:%(session)s" /><h2>Welcome to Dreamwidth!</h2>
 <fieldset class='pkg nostyle'>
 <label for='user' class='left'>Account name:</label>
 <input type='text' value='' name='user' id='user' class='text' size='18' maxlength='27' style='' tabindex='11' />
 </fieldset>
 <fieldset class='pkg nostyle'>
 <label for='lj_loginwidget_password' class='left'>Password</label>
-<input type='password' id='lj_loginwidget_password' name='password' class='lj_login_password text' size='20' maxlength='72' tabindex='12' /><a href='https://www.dreamwidth.org/lostinfo' class='small-link' tabindex='16'>Forgot your password?</a>
+<input type='password' id='lj_loginwidget_password' name='password' class='lj_login_password text' size='20' maxlength='72' tabindex='12' /><a href='https:/lostinfo' class='small-link' tabindex='16'>Forgot your password?</a>
 </fieldset>
-<p><input type='checkbox' name='remember_me' id='remember_me' value='1' tabindex='13' /> <label for='remember_me'>Remember me</label></p><p><input name='action:login' type='submit' value='Log in' tabindex='14' /> <a href='https://www.dreamwidth.org/openid/' class='small-link' tabindex='15'>Log in with OpenID</a></p></form>
+<p><input type='checkbox' name='remember_me' id='remember_me' value='1' tabindex='13' /> <label for='remember_me'>Remember me</label></p><p><input name='action:login' type='submit' value='Log in' tabindex='14' /> <a href='https:/openid/' class='small-link' tabindex='15'>Log in with OpenID</a></p></form>
 </div><!-- end .appwidget-login -->
 <div class='login-create-account'>
 <hr class='hr' />
@@ -106,38 +86,38 @@ Length: unspecified [text/html]
                 </div>
 
                  
-<div id="account-links" role="navigation" aria-label="Account Links"> <form action='https://www.dreamwidth.org/login?ret=1' method='post' class='lj_login_form'><input type="hidden" name="returnto" value="" /><input type='hidden' name='chal' class='lj_login_chal' value='c0:1637780400:1136:300:vDj8O3s4LdBsZAZiYqFI:2056608643f72ae24a1bdac9f9990ad6' />
+<div id="account-links" role="navigation" aria-label="Account Links"> <form action='https:/login?ret=1' method='post' class='lj_login_form'><input type="hidden" name="returnto" value="" /><input type='hidden' name='chal' class='lj_login_chal' value='c0:1637780400:1136:300:vDj8O3s4LdBsZAZiYqFI:2056608643f72ae24a1bdac9f9990ad6' />
     <input type='hidden' name='response' class='lj_login_response' value='' />
-    <table summary='' id='login-table'><tr><td><label for='login_user'>Account name:</label></td><td class='input-cell' colspan='2'><input name="user" id="login_user" size="20" maxlength="27" tabindex="1" aria-required="true" /> <a href='https://www.dreamwidth.org/openid/' tabindex=5>Log in with OpenID?</a></td></tr><tr><td><label for='login_password'>Password:</label></td><td class='input-cell' colspan='2'><input type="password" name="password" id="login_password" size="20" tabindex="2" aria-required="true" class="lj_login_password"> <a href='https://www.dreamwidth.org/lostinfo' tabindex=6>Forget your password?</a></td></tr><tr><td>&nbsp;</td><td class='remember-me-cell'><input type="checkbox" name="remember_me" id="login_remember_me" value="1" tabindex="3" /> <label for='login_remember_me'>Remember me</label></td><td><input type="submit" name="login" value="Log in" tabindex="4"/></td></tr></table></form> 
+    <table summary='' id='login-table'><tr><td><label for='login_user'>Account name:</label></td><td class='input-cell' colspan='2'><input name="user" id="login_user" size="20" maxlength="27" tabindex="1" aria-required="true" /> <a href='https:/openid/' tabindex=5>Log in with OpenID?</a></td></tr><tr><td><label for='login_password'>Password:</label></td><td class='input-cell' colspan='2'><input type="password" name="password" id="login_password" size="20" tabindex="2" aria-required="true" class="lj_login_password"> <a href='https:/lostinfo' tabindex=6>Forget your password?</a></td></tr><tr><td>&nbsp;</td><td class='remember-me-cell'><input type="checkbox" name="remember_me" id="login_remember_me" value="1" tabindex="3" /> <label for='login_remember_me'>Remember me</label></td><td><input type="submit" name="login" value="Log in" tabindex="4"/></td></tr></table></form> 
 </div> 
                 
                 <nav role="navigation" aria-label="Site Navigation">
-                    <ul class="left"><li id='create_topnav' class='topnav has-dropdown'><a href='https://www.dreamwidth.org/nav/create'>Create</a>
+                    <ul class="left"><li id='create_topnav' class='topnav has-dropdown'><a href='https:/nav/create'>Create</a>
 <ul id='create_subnav' class='subnav_container dropdown'>
-                <li class='subnav'><a href='https://www.dreamwidth.org/create'>Create Account</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/manage/settings/?cat=display'>Display Preferences</a></li>
+                <li class='subnav'><a href='https:/create'>Create Account</a></li>
+                <li class='subnav'><a href='https:/manage/settings/?cat=display'>Display Preferences</a></li>
 </ul>
-</li><li id='explore_topnav' class='topnav has-dropdown'><a href='https://www.dreamwidth.org/nav/explore'>Explore</a>
+</li><li id='explore_topnav' class='topnav has-dropdown'><a href='https:/nav/explore'>Explore</a>
 <ul id='explore_subnav' class='subnav_container dropdown'>
-                <li class='subnav'><a href='https://www.dreamwidth.org/interests'>Interests</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/directorysearch'>Directory Search</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/search'>Site and Journal Search</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/latest'>Latest Things</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/random'>Random Journal</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/community/random'>Random Community</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/support/faq'>FAQ</a></li>
+                <li class='subnav'><a href='https:/interests'>Interests</a></li>
+                <li class='subnav'><a href='https:/directorysearch'>Directory Search</a></li>
+                <li class='subnav'><a href='https:/search'>Site and Journal Search</a></li>
+                <li class='subnav'><a href='https:/latest'>Latest Things</a></li>
+                <li class='subnav'><a href='https:/random'>Random Journal</a></li>
+                <li class='subnav'><a href='https:/community/random'>Random Community</a></li>
+                <li class='subnav'><a href='https:/support/faq'>FAQ</a></li>
 </ul>
-</li><li id='shop_topnav' class='topnav has-dropdown'><a href='https://www.dreamwidth.org/nav/shop'>Shop</a>
+</li><li id='shop_topnav' class='topnav has-dropdown'><a href='https:/nav/shop'>Shop</a>
 <ul id='shop_subnav' class='subnav_container dropdown'>
-                <li class='subnav'><a href='https://www.dreamwidth.org/shop'>Buy Dreamwidth Services</a></li>
-                <li class='subnav'><a href='https://www.dreamwidth.org/shop/randomgift'>Gift a Random User</a></li>
+                <li class='subnav'><a href='https:/shop'>Buy Dreamwidth Services</a></li>
+                <li class='subnav'><a href='https:/shop/randomgift'>Gift a Random User</a></li>
                 <li class='subnav'><a href='https://www.zazzle.com/dreamwidth*'>DW Merchandise</a></li>
 </ul>
 </li>
 </ul>
                     <div role="search">
                     <div class='appwidget appwidget-search' id='LJWidget_25'>
-<form action='https://www.dreamwidth.org/multisearch' method='post'>
+<form action='https:/multisearch' method='post'>
 <input type="text" title="Search" name="q" class="text" id="search" size="20" /> <select name="type" class="select">
 <option value="int" selected='selected'>Interest</option>
 <option value="region">Region</option>
@@ -151,16 +131,16 @@ Length: unspecified [text/html]
                 </nav>
                 <footer role="contentinfo">
                     <ul>
-    <li><a href="https://www.dreamwidth.org/legal/privacy">Privacy Policy</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/legal/tos">Terms of Service</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/legal/diversity">Diversity Statement</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/legal/principles">Guiding Principles</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/site/">Site Map</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/site/suggest">Make a Suggestion</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/site/opensource">Open Source</a> &bull; </li>
-    <li><a href="https://www.dreamwidth.org/support">Help/Support</a></li>
+    <li><a href="https:/legal/privacy">Privacy Policy</a> &bull; </li>
+    <li><a href="https:/legal/tos">Terms of Service</a> &bull; </li>
+    <li><a href="https:/legal/diversity">Diversity Statement</a> &bull; </li>
+    <li><a href="https:/legal/principles">Guiding Principles</a> &bull; </li>
+    <li><a href="https:/site/">Site Map</a> &bull; </li>
+    <li><a href="https:/site/suggest">Make a Suggestion</a> &bull; </li>
+    <li><a href="https:/site/opensource">Open Source</a> &bull; </li>
+    <li><a href="https:/support">Help/Support</a></li>
 </ul>
-<p>Copyright &copy; 2009-2021 Dreamwidth Studios, LLC. <a href="//www.dreamwidth.org/site/opensource">Some</a> rights reserved.</p>
+<p>Copyright &copy; 2009-2021 Dreamwidth Studios, LLC. <a href="/site/opensource">Some</a> rights reserved.</p>
                 </footer>
             </div>
         </div>