diff --git a/README.md b/README.md index b925b13..2a7497c 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ uberspace web backend set yourdyndnsservice.net/nic --http --port 8080 Check with `supervisorctl status` and `uberspace web backend list`. Errors and requests are logged to `~/logs/` (or `supervisorctl tail snap-dyndns stderr`). +The service also answers `/` with a short start page, but with the backend registered for `/nic` only `/nic` and `/nic/` reach it. To show the page on the domain's root as well, register the whole domain instead: `uberspace web backend set yourdyndnsservice.net --http --port 8080`. + ### Client IP address Behind the reverse proxy the TCP peer is the proxy, not the device. On Uberspace the proxy puts the device's address into `X-Forwarded-For`, which is already set in `config.toml.sample`: diff --git a/snap_dyndns.py b/snap_dyndns.py index e98b8af..dc99315 100644 --- a/snap_dyndns.py +++ b/snap_dyndns.py @@ -224,11 +224,28 @@ def handle(env, cfg, update=inwx_update): return 200, "\n".join(lines) +INDEX_HTML = """ + +
+ +This is a Dynamic DNS service. It is running with the Snap DynDNS Server software.
+Please contact the site owner for more information on this specific service.
+ + +""" + + class RequestHandler(http.server.BaseHTTPRequestHandler): timeout = 30 # do not let stalled connections hold a thread forever def do_GET(self): url = urllib.parse.urlsplit(self.path) + if url.path in ("/", "/nic", "/nic/"): + return self._reply(200, INDEX_HTML, "text/html") if url.path != "/nic/update": return self._reply(404, "not found") try: @@ -253,10 +270,10 @@ class RequestHandler(http.server.BaseHTTPRequestHandler): return self.headers.get(name, "").split(",")[-1].strip() return self.client_address[0] - def _reply(self, status, body): - data = (body + "\n").encode() + def _reply(self, status, body, content_type="text/plain"): + data = (body if body.endswith("\n") else body + "\n").encode() self.send_response(status) - self.send_header("Content-Type", "text/plain; charset=utf-8") + self.send_header("Content-Type", f"{content_type}; charset=utf-8") self.send_header("Content-Length", str(len(data))) self.send_header("Cache-Control", "no-store") if status == 401: diff --git a/test_snap_dyndns.py b/test_snap_dyndns.py index 1cc73df..e55a357 100644 --- a/test_snap_dyndns.py +++ b/test_snap_dyndns.py @@ -334,9 +334,16 @@ token_sha256 = "{hashlib.sha256(TOKEN.encode()).hexdigest()}" status, challenge, body = self.get(server, Authorization=basic(HOST, "bad")) self.assertEqual((status, challenge, body), (401, 'Basic realm="Snap DynDNS"', "badauth\n")) + def test_start_page_without_credentials(self): + server = self.start() + for path in ("/", "/nic", "/nic/"): + status, challenge, body = self.get(server, path, Authorization="") + self.assertEqual((status, challenge), (200, None), path) + self.assertIn("