about summary refs log tree commit diff
path: root/src/http.go
diff options
context:
space:
mode:
authormaride <maride@darknebu.la>2019-10-06 16:02:47 +0200
committermaride <maride@darknebu.la>2019-10-06 16:02:47 +0200
commitaa9d6793abf64d0762904b043243222a6db03c4b (patch)
treee23bbf7b2a4a58e303a22d1daec19c9c0f326cb7 /src/http.go
parente4637ddf366231de52c05d0092ff8ea8583a1601 (diff)
Add non-protected handler for statistics, /api/getStats
Diffstat (limited to 'src/http.go')
-rw-r--r--src/http.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/http.go b/src/http.go
index 6feeb33..480e356 100644
--- a/src/http.go
+++ b/src/http.go
@@ -37,6 +37,7 @@ func setupHTTPServer() (http.Server) {
 	r.HandleFunc("/api/stopContainer", stopContainerHandler).Methods("POST")
 	r.HandleFunc("/api/getAccess", getAccessHandler).Methods("GET")
 	r.HandleFunc("/api/getTimeLimit", getTimeLimitHandler).Methods("GET")
+	r.HandleFunc("/api/getStats", getStatsHandler).Methods("GET")
 
 	return http.Server{
 		Addr: fmt.Sprintf("0.0.0.0:%d", *port),
@@ -203,6 +204,17 @@ func getChallengesHandler(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
+func getStatsHandler(w http.ResponseWriter, r *http.Request) {
+	json, jsonErr := generateJSONFromChallengesForStats()
+
+	if jsonErr == nil {
+		w.Write([]byte(json))
+	} else {
+		log.Println(jsonErr)
+		w.WriteHeader(500)
+	}
+}
+
 func submitFlagHandler(w http.ResponseWriter, r *http.Request) {
 	r.ParseForm()
 	challengeName := r.Form.Get("challengeName")