#!/usr/bin/env python3 import http.server import os import sys import urllib.parse directory = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else ".") mods_root = os.path.join(directory, "mods") def _path_under_mods(rel: str) -> str | None: """Map URL path segment after /mods to a path only inside ``mods_root``. Returns None if unsafe.""" full = os.path.realpath(os.path.join(mods_root, rel)) root = os.path.realpath(mods_root) if full == root or full.startswith(root + os.sep): return full return None HELLO_PAGE = b"""\ Modpack Install

Modpack Setup

  1. Install Prism Launcher
  2. If on Arch:

    sudo pacman -S prism-launcher
  3. Create a 1.20.1 Forge 47.4.10 instance, launch it once, then close
  4. Download mods:
    wget -rnH -R "index.html*" http://barrys.cloud/mods/
  5. In Prism, right-click the instance → Folder → replace the mods/ dir with the downloaded one
  6. Launch & connect to barrys.cloud
""" class Handler(http.server.SimpleHTTPRequestHandler): def translate_path(self, path): path = urllib.parse.unquote(urllib.parse.urlparse(path).path) if path == "/mods" or path.startswith("/mods/"): rel = path[len("/mods"):].lstrip("/") mapped = _path_under_mods(rel) return mapped if mapped is not None else os.path.join(mods_root, "__invalid__") return os.path.join(mods_root, "__invalid__") def do_GET(self): if self.path == "/": self.send_response(200) self.send_header("Content-Type", "text/html") self.send_header("Content-Length", len(HELLO_PAGE)) self.end_headers() self.wfile.write(HELLO_PAGE) return if not self.path.startswith("/mods"): self.send_error(404) return super().do_GET() def main() -> None: port = 80 try: http.server.HTTPServer(("0.0.0.0", port), Handler).serve_forever() except OSError as e: print(f"bind failed on 0.0.0.0:{port}: {e}", file=sys.stderr) sys.exit(1) if __name__ == "__main__": main()