From 21de12cd6e63adf463674942f1a8f9b658f47945 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Thu, 9 Apr 2026 13:14:01 -0500 Subject: jta changes --- modules/services/nixos/jta/assignments.html | 148 +++++++++++++++++++++ modules/services/nixos/jta/default.nix | 1 + modules/services/nixos/jta/index.html | 199 ++++++++++++++-------------- modules/services/nixos/jta/main.go | 31 +++++ modules/services/nixos/jta/style.css | 29 ++++ 5 files changed, 311 insertions(+), 97 deletions(-) create mode 100644 modules/services/nixos/jta/assignments.html (limited to 'modules/services/nixos') diff --git a/modules/services/nixos/jta/assignments.html b/modules/services/nixos/jta/assignments.html new file mode 100644 index 0000000..3031a29 --- /dev/null +++ b/modules/services/nixos/jta/assignments.html @@ -0,0 +1,148 @@ + + + + + + jta@ganymede + + + + +
Juksere Trives Aldri
+ +
+ + + + diff --git a/modules/services/nixos/jta/default.nix b/modules/services/nixos/jta/default.nix index c1ea012..d2908bc 100644 --- a/modules/services/nixos/jta/default.nix +++ b/modules/services/nixos/jta/default.nix @@ -33,6 +33,7 @@ in { environment = { PORT = toString cfg.port; ROOT_DIR = "/media/jta"; + AUTH_PASSWORD_HASH = "550b6785c4bce2ab41a5e2eaa1eb43172d5abbd58237f1c78cd32cb190edc2c5"; # alfreddabuttlerwithtwots }; serviceConfig = { diff --git a/modules/services/nixos/jta/index.html b/modules/services/nixos/jta/index.html index fd93de6..96b6f5f 100644 --- a/modules/services/nixos/jta/index.html +++ b/modules/services/nixos/jta/index.html @@ -3,127 +3,132 @@ - jta@ganymede + JTA Login -
Juksere Trives Aldri
+
+

JTA Portal

+

Public landing page. Login is required to view assignments and all other pages.

+ +
+ +
-
+
+
diff --git a/modules/services/nixos/jta/main.go b/modules/services/nixos/jta/main.go index 3e5fc1f..1390d7f 100644 --- a/modules/services/nixos/jta/main.go +++ b/modules/services/nixos/jta/main.go @@ -29,8 +29,28 @@ var styleCSS string //go:embed index.html var indexHTML string +//go:embed assignments.html +var assignmentsHTML string + var pageTmpl = template.Must(template.New("md_template.html").Parse(mdTemplate)) +const authCookieName = "jta_auth" + +func isAuthenticated(r *http.Request) bool { + expectedHash := strings.TrimSpace(os.Getenv("AUTH_PASSWORD_HASH")) + if expectedHash == "" { + return false + } + + cookie, err := r.Cookie(authCookieName) + if err != nil { + return false + } + + providedHash := strings.TrimSpace(cookie.Value) + return strings.EqualFold(providedHash, expectedHash) +} + func serveMarkdown(w http.ResponseWriter, r *http.Request) { // Prevent path traversal clean := filepath.Clean(r.URL.Path) @@ -81,6 +101,17 @@ func main() { return } + if !isAuthenticated(r) { + http.Error(w, "unauthorized", http.StatusUnauthorized) + return + } + + if r.URL.Path == "/assignments" || r.URL.Path == "/assignments.html" { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write([]byte(assignmentsHTML)) + return + } + // Intercept markdown files if strings.HasSuffix(r.URL.Path, ".md") { serveMarkdown(w, r) diff --git a/modules/services/nixos/jta/style.css b/modules/services/nixos/jta/style.css index 1d52d19..ec09ca9 100644 --- a/modules/services/nixos/jta/style.css +++ b/modules/services/nixos/jta/style.css @@ -124,6 +124,35 @@ code { border-radius: 6px; } +img { + display: block; + max-width: 100%; + height: auto; + margin: 1rem 0; + border-radius: 10px; +} + +p > img, +li > img { + margin: 0.75rem 0; +} + +a > img { + transition: transform 0.15s ease, box-shadow 0.15s ease; +} + +a:hover > img { + transform: translateY(-1px); + box-shadow: 0 8px 20px rgba(2, 6, 23, 0.45); +} + +img[width], +img[height] { + width: auto; + height: auto; + max-width: 100%; +} + /* Links */ a { color: #93c5fd; -- cgit v1.3.1