admin: add missing default settings
This commit is contained in:
parent
ba5642da8f
commit
3e5b4ebad2
@ -25,7 +25,7 @@ import (
|
|||||||
var StaticDir string
|
var StaticDir string
|
||||||
|
|
||||||
type ResponseWriterPrefix struct {
|
type ResponseWriterPrefix struct {
|
||||||
real http.ResponseWriter
|
real http.ResponseWriter
|
||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -165,16 +165,22 @@ func main() {
|
|||||||
// Initialize settings and load them
|
// Initialize settings and load them
|
||||||
if !settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
|
if !settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
|
||||||
if err = settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), settings.FICSettings{
|
if err = settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), settings.FICSettings{
|
||||||
Title: "Challenge FIC",
|
Title: "Challenge FIC",
|
||||||
Authors: "Laboratoire SRS, ÉPITA",
|
Authors: "Laboratoire SRS, ÉPITA",
|
||||||
FirstBlood: fic.FirstBlood,
|
FirstBlood: fic.FirstBlood,
|
||||||
SubmissionCostBase: fic.SubmissionCostBase,
|
SubmissionCostBase: fic.SubmissionCostBase,
|
||||||
AllowRegistration: false,
|
ExerciceCurCoefficient: 1,
|
||||||
CanJoinTeam: false,
|
HintCurCoefficient: 1,
|
||||||
DenyNameChange: false,
|
WChoiceCurCoefficient: 1,
|
||||||
EnableResolutionRoute: false,
|
AllowRegistration: false,
|
||||||
PartialValidation: true,
|
CanJoinTeam: false,
|
||||||
UnlockedChallengeDepth:0,
|
DenyNameChange: false,
|
||||||
|
EnableResolutionRoute: false,
|
||||||
|
PartialValidation: true,
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +220,7 @@ func main() {
|
|||||||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: *bind,
|
Addr: *bind,
|
||||||
Handler: StripPrefix(*baseURL, api.Router()),
|
Handler: StripPrefix(*baseURL, api.Router()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user