From 612f9df18d322def591d0bd4142fa633cc3136fc Mon Sep 17 00:00:00 2001 From: maride Date: Tue, 14 Aug 2018 23:25:49 +0200 Subject: Host /challenges statically --- src/http.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/http.go b/src/http.go index 210d8b3..d06ef1b 100644 --- a/src/http.go +++ b/src/http.go @@ -29,6 +29,7 @@ func runHTTPServer() (error) { r.HandleFunc("/login", loginGetHandler).Methods("GET") r.HandleFunc("/login", loginPostHandler).Methods("POST") r.HandleFunc("/logout", logoutHandler).Methods("POST") + r.HandleFunc("/challenges", challengesHandler).Methods("GET") r.HandleFunc("/api/getChallenges", getChallengesHandler).Methods("GET") r.HandleFunc("/api/submitFlag", submitFlagHandler).Methods("POST") @@ -147,6 +148,19 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", http.StatusTemporaryRedirect) } +// Host the challenges index file +func challengesHandler(w http.ResponseWriter, r *http.Request) { + session, cookieNotFoundError := r.Cookie("session") + + if cookieNotFoundError != nil || !isValidSession(session.Value) { + // either no session cookie found, or it contains an invalid session token. Redirect. + http.Redirect(w, r, "/login", http.StatusTemporaryRedirect) + } else { + // valid session token found, redirect to frontpage + readFileToResponse(w, "/challenges.html") + } +} + func getChallengesHandler(w http.ResponseWriter, r *http.Request) { session, cookieNotFoundError := r.Cookie("session") -- cgit 1.4.1