(w http.ResponseWriter, r *http.Request)
| 10 | ) |
| 11 | |
| 12 | func adminIndex(w http.ResponseWriter, r *http.Request) { |
| 13 | |
| 14 | adminHtml := configs.GetFilePathsConfig().AdminHtml.String() |
| 15 | |
| 16 | tmpl, err := template.New("index.html").Funcs(funcMap).ParseFiles( |
| 17 | adminHtml+"/_header.html", |
| 18 | adminHtml+"/_nav.html", |
| 19 | adminHtml+"/index.html", |
| 20 | adminHtml+"/_footer.html", |
| 21 | ) |
| 22 | if err != nil { |
| 23 | mudlog.Error("HTML ERROR", "error", err) |
| 24 | http.Error(w, "Error parsing template files", http.StatusInternalServerError) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | writeKey := pageWritePermissions[strings.TrimRight(r.URL.Path, "/")] |
| 29 | templateData := map[string]any{ |
| 30 | "CONFIG": configs.GetConfig(), |
| 31 | "STATS": GetStats(), |
| 32 | "NAV": buildAdminNav(), |
| 33 | "AUTHED_USER": GetAuthedUser(r), |
| 34 | "WRITE_PERMISSION": writeKey, |
| 35 | "READ_ONLY": pageReadOnly(r), |
| 36 | } |
| 37 | |
| 38 | if r.URL.Query().Get(`login`) != `` { |
| 39 | scheme := "http" |
| 40 | if r.TLS != nil { |
| 41 | scheme = "https" |
| 42 | } |
| 43 | http.Redirect(w, r, scheme+"://"+r.Host+"/admin/", http.StatusTemporaryRedirect) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | w.Header().Set("Cache-Control", "no-store") |
| 48 | if err := tmpl.Execute(w, templateData); err != nil { |
| 49 | mudlog.Error("HTML ERROR", "action", "Execute", "error", err) |
| 50 | } |
| 51 | } |
nothing calls this directly
no test coverage detected