about summary refs log tree commit diff
diff options
context:
space:
mode:
authormaride <maride@darknebu.la>2018-08-14 23:25:49 +0200
committermaride <maride@darknebu.la>2018-08-14 23:25:49 +0200
commit612f9df18d322def591d0bd4142fa633cc3136fc (patch)
tree8bc06715e122563e7b6c95eccfe98eae61963deb
parent83537a94d26509be51e4458e6c9c09df5970de93 (diff)
Host /challenges statically
-rw-r--r--src/http.go14
1 files changed, 14 insertions, 0 deletions
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")