diff --git a/frontend/main.go b/frontend/main.go index 1dbbfb2c..523c7c78 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -33,6 +33,7 @@ func main() { var duration = flag.Duration("duration", 180*time.Minute, "Challenge duration") var denyChName = flag.Bool("denyChName", false, "Deny team to change their name") var allowRegistration = flag.Bool("allowRegistration", false, "New team can add itself") + var resolutionRoute = flag.Bool("resolutionRoute", false, "Enable resolution route") flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files") flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions") flag.Parse() @@ -69,6 +70,9 @@ func main() { log.Println("Registering handlers...") http.Handle(fmt.Sprintf("%s/time.json", *prefix), http.StripPrefix(*prefix, TimeHandler{startTime, *duration})) + if *resolutionRoute { + http.Handle(fmt.Sprintf("%s/resolution/", *prefix), http.StripPrefix(fmt.Sprintf("%s/resolution/", *prefix), ResolutionHandler{})) + } http.Handle(fmt.Sprintf("%s/", *prefix), http.StripPrefix(*prefix, SubmissionHandler{end, *denyChName, *allowRegistration})) log.Println(fmt.Sprintf("Ready, listening on %s", *bind)) diff --git a/frontend/resolution.go b/frontend/resolution.go new file mode 100644 index 00000000..7f739ce8 --- /dev/null +++ b/frontend/resolution.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + "net/http" + "path" + "text/template" +) + +type ResolutionHandler struct {} + +const resolutiontpl = ` + + + + Challenge Forensic - RĂ©solution + + + + + +` + +func (s ResolutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + log.Printf("Handling %s request from %s: /resolution%s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent()) + + w.Header().Set("Content-Type", "text/html") + + if resolutionTmpl, err := template.New("resolution").Parse(resolutiontpl); err != nil { + log.Println("Cannot create template: ", err) + } else if err := resolutionTmpl.Execute(w, path.Join("/vids/", r.URL.Path)); err != nil { + log.Println("An error occurs during template execution: ", err) + } +}