From d0377a130c9eaf5861a363c1aeb3ddb79becefc5 Mon Sep 17 00:00:00 2001 From: arnas Date: Sat, 3 Oct 2026 21:40:12 +0000 Subject: [PATCH] Upload files to "/" --- Dockerfile | 4 ++++ app.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a164d42 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-alpine +COPY app.py /app.py +EXPOSE 8080 +CMD ["python", "-u", "/app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..b508502 --- /dev/null +++ b/app.py @@ -0,0 +1,52 @@ +import textwrap +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from urllib.parse import unquote + +COW = r""" \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || +""" + + +def cowsay(text, width=40): + lines = textwrap.wrap(text, width) or [""] + w = max(len(line) for line in lines) + out = [" " + "_" * (w + 2)] + if len(lines) == 1: + out.append(f"< {lines[0]} >") + else: + for i, line in enumerate(lines): + line = line.ljust(w) + if i == 0: + out.append(f"/ {line} \\") + elif i == len(lines) - 1: + out.append(f"\\ {line} /") + else: + out.append(f"| {line} |") + out.append(" " + "-" * (w + 2)) + return "\n".join(out) + "\n" + COW + + +class Handler(BaseHTTPRequestHandler): + def do_GET(self): + path = self.path.split("?", 1)[0].lstrip("/") + if path == "favicon.ico": + self.send_response(404) + self.end_headers() + return + # "+" and "_" become spaces, then %xx decoding (so %2B still gives a literal +) + text = unquote(path.replace("+", " ").replace("_", " "))[:500] or "moo" + body = cowsay(text).encode() + self.send_response(200) + self.send_header("Content-Type", "text/plain; charset=utf-8") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +ThreadingHTTPServer(("0.0.0.0", 8080), Handler).serve_forever()