|
|
|
@ -19,6 +19,7 @@ var (
@@ -19,6 +19,7 @@ var (
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func topWrapper(r *http.Request) string { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
log.LogInfo(fmt.Sprintf("%s called topWrapper", getSessionIdentifier(r))) |
|
|
|
|
headerTemplate, err := ioutil.ReadFile("./static/header.tpl") |
|
|
|
|
if err != nil { |
|
|
|
@ -36,6 +37,7 @@ func topWrapper(r *http.Request) string {
@@ -36,6 +37,7 @@ func topWrapper(r *http.Request) string {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func bodyWrapper(r *http.Request, template string) string { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
log.LogInfo(fmt.Sprintf("%s called bodyWrapper", getSessionIdentifier(r))) |
|
|
|
|
bodyTemplate, err := ioutil.ReadFile(fmt.Sprintf("./static/%+v.tpl", template)) |
|
|
|
|
if err != nil { |
|
|
|
@ -46,12 +48,14 @@ func bodyWrapper(r *http.Request, template string) string {
@@ -46,12 +48,14 @@ func bodyWrapper(r *http.Request, template string) string {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
func pageBuilder(r *http.Request, pageName string) string { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
pageCode := topWrapper(r) |
|
|
|
|
pageCode += bodyWrapper(r, pageName) |
|
|
|
|
return pageCode |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func greetUser(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
log.LogInfo(fmt.Sprintf("%s called greetUser", getSessionIdentifier(r))) |
|
|
|
|
loggedIn, username := detectUser(r, "greetUser") |
|
|
|
|
fmt.Fprintf(w, pageBuilder(r, "home")) |
|
|
|
@ -61,10 +65,12 @@ func greetUser(w http.ResponseWriter, r *http.Request) {
@@ -61,10 +65,12 @@ func greetUser(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func passPage(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
log.LogInfo(fmt.Sprintf("%s called passPage", getSessionIdentifier(r))) |
|
|
|
|
fmt.Fprintf(w, pageBuilder(r, "pass")) |
|
|
|
|
} |
|
|
|
|
func loginPage(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
log.LogInfo(fmt.Sprintf("%s called loginPage", getSessionIdentifier(r))) |
|
|
|
|
session, err := store.Get(r, "2fa") |
|
|
|
|
if err != nil { |
|
|
|
@ -84,6 +90,7 @@ func loginPage(w http.ResponseWriter, r *http.Request) {
@@ -84,6 +90,7 @@ func loginPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func notFoundPage(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
go log.LogWarn(fmt.Sprintf("%s triggered notFoundPage", getSessionIdentifier(r))) |
|
|
|
|
fmt.Fprintf(w, topWrapper(r)) |
|
|
|
|
|
|
|
|
@ -94,6 +101,7 @@ func notFoundPage(w http.ResponseWriter, r *http.Request) {
@@ -94,6 +101,7 @@ func notFoundPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
func card(title string, content string, footer string) string { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
cardTemplate, err := ioutil.ReadFile("./static/card.tpl") |
|
|
|
|
if err != nil { |
|
|
|
|
log.LogError("Unable to open card template") |
|
|
|
@ -108,6 +116,7 @@ func card(title string, content string, footer string) string {
@@ -108,6 +116,7 @@ func card(title string, content string, footer string) string {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getPending(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
loggedIn, _ := detectUser(r, "getPending") |
|
|
|
|
if loggedIn { |
|
|
|
|
pending, err := json.Marshal(config.Verifications) |
|
|
|
@ -122,6 +131,7 @@ func getPending(w http.ResponseWriter, r *http.Request) {
@@ -122,6 +131,7 @@ func getPending(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runWeb() { |
|
|
|
|
defer log.PanicSafe() |
|
|
|
|
router := mux.NewRouter().StrictSlash(true) |
|
|
|
|
log.LogInfo("Adding HandleFuncs to router") |
|
|
|
|
router.NotFoundHandler = http.HandlerFunc(notFoundPage) |
|
|
|
|