Move settings and started file into SETTINGS directory
This commit is contained in:
parent
0d7d49e033
commit
f1d6b92267
7 changed files with 22 additions and 10 deletions
|
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var TeamsDir string
|
||||
|
||||
func init() {
|
||||
router.GET("/api/public.json", apiHandler(getPublic))
|
||||
router.DELETE("/api/public.json", apiHandler(deletePublic))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var TeamsDir string
|
||||
var SettingsDir string
|
||||
|
||||
func init() {
|
||||
router.GET("/api/settings.json", apiHandler(getSettings))
|
||||
|
|
@ -22,8 +22,8 @@ func init() {
|
|||
}
|
||||
|
||||
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
if settings.ExistsSettings(path.Join(TeamsDir, settings.SettingsFile)) {
|
||||
return settings.ReadSettings(path.Join(TeamsDir, settings.SettingsFile))
|
||||
if settings.ExistsSettings(path.Join(SettingsDir, settings.SettingsFile)) {
|
||||
return settings.ReadSettings(path.Join(SettingsDir, settings.SettingsFile))
|
||||
} else {
|
||||
return settings.FICSettings{"Challenge FIC", "Laboratoire SRS, ÉPITA", time.Unix(0,0), time.Unix(0,0), time.Unix(0,0), fic.FirstBlood, fic.SubmissionCostBase, false, false, false, true, true}, nil
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err := settings.SaveSettings(path.Join(TeamsDir, settings.SettingsFile), config); err != nil {
|
||||
if err := settings.SaveSettings(path.Join(SettingsDir, settings.SettingsFile), config); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return config, err
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ func main() {
|
|||
flag.StringVar(&PKIDir, "pki", "./pki/", "Base directory where found PKI scripts")
|
||||
flag.StringVar(&StaticDir, "static", "./htdocs-admin/", "Directory containing static files")
|
||||
flag.StringVar(&api.TeamsDir, "teams", "./TEAMS", "Base directory where save teams JSON files")
|
||||
flag.StringVar(&api.SettingsDir, "settings", "./SETTINGS", "Base directory where load and save settings")
|
||||
flag.StringVar(&fic.FilesDir, "files", "./FILES/", "Base directory where found challenges files, local part")
|
||||
flag.StringVar(&api.CloudDAVBase, "clouddav", "https://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016",
|
||||
"Base directory where found challenges files, cloud part")
|
||||
|
|
@ -92,6 +93,9 @@ func main() {
|
|||
if api.TeamsDir, err = filepath.Abs(api.TeamsDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if api.SettingsDir, err = filepath.Abs(api.SettingsDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if fic.FilesDir, err = filepath.Abs(fic.FilesDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
func init() {
|
||||
api.Router().GET("/time.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if config, err := settings.ReadSettings(path.Join(api.TeamsDir, settings.SettingsFile)); err != nil {
|
||||
if config, err := settings.ReadSettings(path.Join(api.SettingsDir, settings.SettingsFile)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError)
|
||||
} else {
|
||||
time.ChallengeStart = config.Start
|
||||
|
|
|
|||
Reference in a new issue