diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-04-09 13:14:01 -0500 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-04-09 13:14:01 -0500 |
| commit | 21de12cd6e63adf463674942f1a8f9b658f47945 (patch) | |
| tree | 5229a5300c1e69d637a1e03539dc19de42244440 /modules/services/nixos/jta/main.go | |
| parent | 2147a65b5ff7cef352d95dfa72c705145771f3a3 (diff) | |
jta changes
Diffstat (limited to 'modules/services/nixos/jta/main.go')
| -rw-r--r-- | modules/services/nixos/jta/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
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) |
