diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a04718 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +__pycache__/* diff --git a/Dockerfile b/Dockerfile index 94a8f6a..e7233fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,24 @@ -FROM python:3.12-slim +# Build stage +FROM golang:1.25-bookworm AS build -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - && rm -rf /var/lib/apt/lists/* +WORKDIR /src +COPY main.go . -RUN ln -sf /usr/local/bin/python3 /usr/bin/python3 +# Build a static-ish binary +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o passgen main.go + +# Runtime stage: minimal image with just the binary + wordlist +FROM debian:13-slim WORKDIR /app -COPY . /app/ -RUN mkdir -p /app/cgi-bin \ - && cp /app/*.py /app/*.cgi /app/cgi-bin/ \ - && cp /app/words.txt /app/cgi-bin/ \ - && cp /app/*.html /app/cgi-bin/ +# Copy binary and wordlist +COPY --from=build /src/passgen /app/passgen +COPY words.txt /app/words.txt -RUN chmod +x /app/index.cgi -RUN chmod +x /app/cgi-bin/*.py /app/cgi-bin/*.cgi || true +ENV WORDLIST=/app/words.txt +ENV PORT=8000 EXPOSE 8000 -CMD ["python", "-m", "http.server", "8000", "--cgi"] \ No newline at end of file + +CMD ["/app/passgen"] \ No newline at end of file diff --git a/common.py b/common.py deleted file mode 100644 index 4d29941..0000000 --- a/common.py +++ /dev/null @@ -1,69 +0,0 @@ -import cgitb -cgitb.enable() - -import cgi -import os -import sys - -def bool(s): - try: return int(s) - except ValueError: pass - return s == 'on' - -def commafy(s): - s = str(int(s)) - o = '' - while len(s) > 3: - o = ',' + s[-3:] + o - s = s[:-3] - return s + o - -def escape(s): - return str(s).replace('&', '&').replace('<', '<').replace('>', '>') - -def form_get(form, name, default, conv=str): - try: - item = form[name] - except KeyError: - return default - if item.file: - print("Uploads are not allowed!") - sys.exit(1) - if type(item.value) is not type(''): - print("Multiple values are not allowed!") - sys.exit(1) - try: - value = conv(item.value) - except: - print("'%s' failed to convert" % name) - sys.exit(1) - return value - -class EvalDict: - def __init__(self, values): - self.values = values - def __getitem__(self, key): - return escape(eval(key, self.values)) - -def row(a,b,bold=0): - pre = post = '' - if bold: - pre = '' - post = '' - print('
Notes: