From 64f9da154916d8402ea65fff78519ff3069aeff8 Mon Sep 17 00:00:00 2001
From: Nathan Coad
Date: Wed, 10 Dec 2025 14:27:04 +1100
Subject: [PATCH] change to golang
---
.gitignore | 2 +
Dockerfile | 29 ++-
common.py | 69 ------
docker-compose.yml | 17 ++
footer.html | 20 --
header.html | 6 -
index.cgi | 5 -
index.html | 10 -
longrandom.py | 21 --
main.go | 577 +++++++++++++++++++++++++++++++++++++++++++++
makedict | 16 --
ppform.html | 33 ---
ppgen.cgi | 12 -
ppgen.py | 102 --------
pwform.html | 25 --
pwgen.cgi | 12 -
pwgen.py | 74 ------
worddict.py | 37 ---
18 files changed, 612 insertions(+), 455 deletions(-)
create mode 100644 .gitignore
delete mode 100644 common.py
create mode 100644 docker-compose.yml
delete mode 100644 footer.html
delete mode 100644 header.html
delete mode 100755 index.cgi
delete mode 100644 index.html
delete mode 100644 longrandom.py
create mode 100644 main.go
delete mode 100755 makedict
delete mode 100644 ppform.html
delete mode 100755 ppgen.cgi
delete mode 100755 ppgen.py
delete mode 100644 pwform.html
delete mode 100755 pwgen.cgi
delete mode 100755 pwgen.py
delete mode 100644 worddict.py
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('| %s: | %s%s%s |
' % (
- a, pre, b, post ))
-def table_start(): print('
')
-def table_end(): print('
')
-
-def dumpfile(filename, dict=None):
- # Always resolve relative to this file's directory
- here = os.path.dirname(__file__)
- path = os.path.join(here, filename)
-
- with open(path, encoding="utf-8") as f:
- data = f.read()
-
- if dict is not None:
- data = data % dict
-
- sys.stdout.write(data)
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..b6f1c94
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,17 @@
+version: "3.9"
+
+services:
+ passgen:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ container_name: passphrase-generator
+ environment:
+ # Path to the wordlist inside the container
+ WORDLIST: /app/words.txt
+ # Port the Go server listens on inside the container
+ PORT: "8000"
+ ports:
+ # host:container
+ - "8000:8000"
+ restart: unless-stopped
diff --git a/footer.html b/footer.html
deleted file mode 100644
index 545302b..0000000
--- a/footer.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-Notes:
-
-- No data generated by this page is stored on the server at any point.
-In other words, we aren't recording your passwords.
-
-- The data used to generate the passwords is derived from Linux's
-/dev/urandom secure data source, and is carefully masked to prevent
-biasing or truncation.
-
-- Unless this form is accessed via a secure session (ie HTTPS or a
-tunnel), the password will be susceptible to being sniffed as it is
-being transmitted. Use the appropriate precautions.
-
-
-
-
-