Cabin Chat 4.0: accounts, https, PWA, mentions, notifications
- accounts with name + password (salted sha256), one account on several devices at once, profile menu: change password, profile picture, link another device (QR code + one-time link), logout, delete account - @mentions with picker and highlighting - https by default with the router web admin's certificate; --http, --cert/--key installer options - logo/favicon, app manifest, service worker (installable PWA) - browser notifications via the service worker, no internet needed - devserver: https option, ignore connections reset by the browser Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
863d30eeba
commit
1459b3228d
+26
-9
@@ -8,6 +8,9 @@ under /cgi-bin/. Python standard library only, so it runs on a notebook
|
||||
python3 devserver.py # http://localhost:8088, reachable from your LAN
|
||||
python3 devserver.py -p 9000 # other port
|
||||
python3 devserver.py --local # only this machine
|
||||
python3 devserver.py --cert c.pem --key k.pem # https (to test the app
|
||||
# install and notifications from a phone;
|
||||
# on localhost they work over http too)
|
||||
|
||||
Chat data is stored in ./data/ and photos in www/img/ (delete both to start
|
||||
fresh); presence and typing state live in $TMPDIR/cabinchat/. CGI scripts are
|
||||
@@ -19,6 +22,7 @@ import functools
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||
@@ -113,13 +117,18 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
else:
|
||||
headers.append((k, v))
|
||||
|
||||
self.send_response(code, reason)
|
||||
for k, v in headers:
|
||||
self.send_header(k, v)
|
||||
self.send_header("Content-Length", str(len(payload)))
|
||||
self.end_headers()
|
||||
if self.command != "HEAD":
|
||||
self.wfile.write(payload)
|
||||
try:
|
||||
self.send_response(code, reason)
|
||||
for k, v in headers:
|
||||
self.send_header(k, v)
|
||||
self.send_header("Content-Length", str(len(payload)))
|
||||
self.end_headers()
|
||||
if self.command != "HEAD":
|
||||
self.wfile.write(payload)
|
||||
except (BrokenPipeError, ConnectionResetError):
|
||||
# the browser gave up on this request (usually an aborted long poll:
|
||||
# tab reopened, phone woke up, page closed) - nothing to do
|
||||
self.close_connection = True
|
||||
|
||||
|
||||
def lan_ip():
|
||||
@@ -139,6 +148,8 @@ def main():
|
||||
ap.add_argument("--local", action="store_true", help="listen on 127.0.0.1 only")
|
||||
ap.add_argument("--root", default=os.path.join(HERE, "www"), help="web root (default: ./www)")
|
||||
ap.add_argument("-q", "--quiet", action="store_true", help="don't log requests")
|
||||
ap.add_argument("--cert", help="TLS certificate (PEM): serve https")
|
||||
ap.add_argument("--key", help="TLS private key (PEM), with --cert")
|
||||
a = ap.parse_args()
|
||||
|
||||
root = os.path.abspath(a.root)
|
||||
@@ -147,12 +158,18 @@ def main():
|
||||
Handler.quiet = a.quiet
|
||||
bind = "127.0.0.1" if a.local else "0.0.0.0"
|
||||
srv = ThreadingHTTPServer((bind, a.port), functools.partial(Handler, directory=root))
|
||||
scheme = "http"
|
||||
if a.cert:
|
||||
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
ctx.load_cert_chain(a.cert, a.key)
|
||||
srv.socket = ctx.wrap_socket(srv.socket, server_side=True)
|
||||
scheme = "https"
|
||||
|
||||
print(f"Cabin Chat dev server - serving {root}")
|
||||
print(f" http://localhost:{a.port}/")
|
||||
print(f" {scheme}://localhost:{a.port}/")
|
||||
ip = None if a.local else lan_ip()
|
||||
if ip:
|
||||
print(f" http://{ip}:{a.port}/ (other devices on your network)")
|
||||
print(f" {scheme}://{ip}:{a.port}/ (other devices on your network)")
|
||||
print("Ctrl+C to stop")
|
||||
try:
|
||||
srv.serve_forever()
|
||||
|
||||
Reference in New Issue
Block a user