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

@ -25,7 +25,7 @@ import (
var StaticDir string
type ResponseWriterPrefix struct {
real http.ResponseWriter
real http.ResponseWriter
prefix string
}
@ -35,7 +35,7 @@ func (r ResponseWriterPrefix) Header() http.Header {
func (r ResponseWriterPrefix) WriteHeader(s int) {
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)
}
@ -50,7 +50,7 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
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) {
r2 := new(http.Request)
*r2 = *r
@ -165,16 +165,22 @@ func main() {
// Initialize settings and load them
if !settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
if err = settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), settings.FICSettings{
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
AllowRegistration: false,
CanJoinTeam: false,
DenyNameChange: false,
EnableResolutionRoute: false,
PartialValidation: true,
UnlockedChallengeDepth:0,
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
ExerciceCurCoefficient: 1,
HintCurCoefficient: 1,
WChoiceCurCoefficient: 1,
AllowRegistration: false,
CanJoinTeam: false,
DenyNameChange: false,
EnableResolutionRoute: false,
PartialValidation: true,
UnlockedChallengeDepth: 0,
SubmissionUniqueness: false,
DisplayAllFlags: false,
EventKindness: false,
}); err != nil {
log.Fatal("Unable to initialize settings.json:", err)
}
@ -200,12 +206,12 @@ func main() {
}
// 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 {
log.Println("Unable to open index.html: ", err)
} else if indexTmpl, err := template.New("index").Parse(indextpl); err != nil {
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)
}
@ -214,7 +220,7 @@ func main() {
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
srv := &http.Server{
Addr: *bind,
Addr: *bind,
Handler: StripPrefix(*baseURL, api.Router()),
}