admin: add missing default settings

This commit is contained in:
nemunaire 2019-07-12 19:22:05 +02:00
parent ba5642da8f
commit 3e5b4ebad2

View File

@ -35,7 +35,7 @@ func (r ResponseWriterPrefix) Header() http.Header {
func (r ResponseWriterPrefix) WriteHeader(s int) { func (r ResponseWriterPrefix) WriteHeader(s int) {
if v, exists := r.real.Header()["Location"]; exists { if v, exists := r.real.Header()["Location"]; exists {
r.real.Header().Set("Location", r.prefix + v[0]) r.real.Header().Set("Location", r.prefix+v[0])
} }
r.real.WriteHeader(s) r.real.WriteHeader(s)
} }
@ -50,7 +50,7 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
} }
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if prefix != "/" && r.URL.Path == "/" { if prefix != "/" && r.URL.Path == "/" {
http.Redirect(w, r, prefix + "/", http.StatusFound) http.Redirect(w, r, prefix+"/", http.StatusFound)
} else if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { } else if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) {
r2 := new(http.Request) r2 := new(http.Request)
*r2 = *r *r2 = *r
@ -169,12 +169,18 @@ func main() {
Authors: "Laboratoire SRS, ÉPITA", Authors: "Laboratoire SRS, ÉPITA",
FirstBlood: fic.FirstBlood, FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase, SubmissionCostBase: fic.SubmissionCostBase,
ExerciceCurCoefficient: 1,
HintCurCoefficient: 1,
WChoiceCurCoefficient: 1,
AllowRegistration: false, AllowRegistration: false,
CanJoinTeam: false, CanJoinTeam: false,
DenyNameChange: false, DenyNameChange: false,
EnableResolutionRoute: false, EnableResolutionRoute: false,
PartialValidation: true, PartialValidation: true,
UnlockedChallengeDepth:0, UnlockedChallengeDepth: 0,
SubmissionUniqueness: false,
DisplayAllFlags: false,
EventKindness: false,
}); err != nil { }); err != nil {
log.Fatal("Unable to initialize settings.json:", err) log.Fatal("Unable to initialize settings.json:", err)
} }
@ -200,12 +206,12 @@ func main() {
} }
// Update base URL on main page // Update base URL on main page
log.Println("Changing base URL to", *baseURL + "/", "...") log.Println("Changing base URL to", *baseURL+"/", "...")
if file, err := os.OpenFile(path.Join(StaticDir, "index.html"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0644)); err != nil { if file, err := os.OpenFile(path.Join(StaticDir, "index.html"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0644)); err != nil {
log.Println("Unable to open index.html: ", err) log.Println("Unable to open index.html: ", err)
} else if indexTmpl, err := template.New("index").Parse(indextpl); err != nil { } else if indexTmpl, err := template.New("index").Parse(indextpl); err != nil {
log.Println("Cannot create template: ", err) log.Println("Cannot create template: ", err)
} else if err = indexTmpl.Execute(file, map[string]string{"urlbase": path.Clean(path.Join(*baseURL + "/", "nuke"))[:len(path.Clean(path.Join(*baseURL + "/", "nuke"))) - 4]}); err != nil { } else if err = indexTmpl.Execute(file, map[string]string{"urlbase": path.Clean(path.Join(*baseURL+"/", "nuke"))[:len(path.Clean(path.Join(*baseURL+"/", "nuke")))-4]}); err != nil {
log.Println("An error occurs during template execution: ", err) log.Println("An error occurs during template execution: ", err)
} }