From aad95f1e53def6cb6ef0ffe59d3de8752bf9e95e Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 12 May 2023 14:53:15 +0200 Subject: [PATCH] settings: Challenge can never ends --- admin/index.go | 12 +++++++----- admin/static/js/app.js | 15 +++++++++++---- admin/static/js/common.js | 2 +- dashboard/static/index.html | 4 ++-- frontend/choices.go | 2 +- frontend/hint.go | 2 +- frontend/resolution.go | 2 +- frontend/settings.go | 2 +- frontend/submit.go | 2 +- frontend/ui/src/lib/components/HeaderClock.svelte | 4 ++-- libfic/zqsd.go | 7 ++++++- settings/settings.go | 4 ++-- 12 files changed, 36 insertions(+), 22 deletions(-) diff --git a/admin/index.go b/admin/index.go index 13cca410..cd49d7dc 100644 --- a/admin/index.go +++ b/admin/index.go @@ -115,11 +115,13 @@ const indextpl = ` {{"{{ startIn }}"}}" | - {{"{{ time.hours | time }}"}} - : - {{"{{ time.minutes | time }}"}} - : - {{"{{ time.seconds | time }}"}} + + {{"{{ time.hours | time }}"}} + : + {{"{{ time.minutes | time }}"}} + : + {{"{{ time.seconds | time }}"}} + diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 53b2eb72..4a3fa857 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -545,7 +545,8 @@ angular.module("FICApp") response.enableExerciceDepend = response.unlockedChallengeDepth >= 0; response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0; $rootScope.settings.start = new Date(response.start); - $rootScope.settings.end = new Date(response.end); + if (response.end) $rootScope.settings.end = new Date(response.end); + else $rootScope.settings.end = null; $rootScope.settings.generation = new Date(response.generation); $rootScope.settings.activateTime = new Date(response.activateTime); }) @@ -581,8 +582,10 @@ angular.module("FICApp") } $scope.saveSettings = function(msg) { if (msg === undefined) { msg = 'New settings saved!'; } - var nStart = this.config.start; - var nEnd = this.config.end; + if (this.config.end == "") this.config.end = null; + + var nStart = this.config.start; + var nEnd = this.config.end; var nGen = this.config.generation; var state = this.config.enableExerciceDepend; this.config.unlockedChallengeDepth = (this.config.enableExerciceDepend?this.config.unlockedChallengeDepth:-1) @@ -602,7 +605,11 @@ angular.module("FICApp") response.enableExerciceDepend = response.unlockedChallengeDepth >= 0; response.disabledsubmitbutton = response.disablesubmitbutton && response.disablesubmitbutton.length > 0; $rootScope.settings.start = new Date(nStart); - $rootScope.settings.end = new Date(nEnd); + if (nEnd) { + $rootScope.settings.end = new Date(nEnd); + } else { + $rootScope.settings.end = null; + } $rootScope.settings.generation = new Date(nGen); }, function(response) { $scope.addToast('danger', 'An error occurs when saving settings:', response.data.errmsg); diff --git a/admin/static/js/common.js b/admin/static/js/common.js index 29eba62c..0ac92528 100644 --- a/admin/static/js/common.js +++ b/admin/static/js/common.js @@ -263,7 +263,7 @@ angular.module("FICApp") } function updTime() { - if (time && $rootScope.settings) { + if (time && $rootScope.settings && $rootScope.settings.end) { var srv_cur = new Date(Date.now() + (time.cu - time.he)); // Refresh on start/activate time reached diff --git a/dashboard/static/index.html b/dashboard/static/index.html index fbc9eb03..9172f533 100644 --- a/dashboard/static/index.html +++ b/dashboard/static/index.html @@ -510,7 +510,7 @@ -
+
{{ time.hours | time }} @@ -594,7 +594,7 @@ {{ settings.start | date:"HH' h 'mm" }} Début du challenge - + {{ settings.end | date:"HH' h 'mm" }} Fin du challenge diff --git a/frontend/choices.go b/frontend/choices.go index f8a4fbeb..aefa6d54 100644 --- a/frontend/choices.go +++ b/frontend/choices.go @@ -7,7 +7,7 @@ import ( ) func WantChoicesHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { - if time.Now().After(challengeEnd) { + if challengeEnd != nil && time.Now().After(*challengeEnd) { http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard !\"}", http.StatusGone) return } diff --git a/frontend/hint.go b/frontend/hint.go index 1eabec93..bdd09142 100644 --- a/frontend/hint.go +++ b/frontend/hint.go @@ -7,7 +7,7 @@ import ( ) func HintHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { - if time.Now().After(challengeEnd) { + if challengeEnd != nil && time.Now().After(*challengeEnd) { http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard pour un indice !\"}", http.StatusGone) return } diff --git a/frontend/resolution.go b/frontend/resolution.go index 3d553724..70aea061 100644 --- a/frontend/resolution.go +++ b/frontend/resolution.go @@ -17,7 +17,7 @@ const resolutiontpl = ` - Challenge Forensic - Résolution + Résolution diff --git a/frontend/settings.go b/frontend/settings.go index c237d22f..26bfc44f 100644 --- a/frontend/settings.go +++ b/frontend/settings.go @@ -12,7 +12,7 @@ var startedFile = "started" var touchTimer *time.Timer = nil var challengeStart time.Time -var challengeEnd time.Time +var challengeEnd *time.Time func touchStartedFile() { if fd, err := os.Create(startedFile); err == nil { diff --git a/frontend/submit.go b/frontend/submit.go index 76b42cef..f00af98e 100644 --- a/frontend/submit.go +++ b/frontend/submit.go @@ -9,7 +9,7 @@ import ( ) func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) { - if time.Now().After(challengeEnd) { + if challengeEnd != nil && time.Now().After(*challengeEnd) { http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusGone) return } diff --git a/frontend/ui/src/lib/components/HeaderClock.svelte b/frontend/ui/src/lib/components/HeaderClock.svelte index 10291ca8..81cf6268 100644 --- a/frontend/ui/src/lib/components/HeaderClock.svelte +++ b/frontend/ui/src/lib/components/HeaderClock.svelte @@ -8,7 +8,7 @@ import { settings, time } from '$lib/stores/settings.js'; -{#if $settings} +{#if $settings && $settings.end} {#if $settings.end - $settings.start > 0}

- Challenge forensic + {$challengeInfo.title}

{/if} diff --git a/libfic/zqsd.go b/libfic/zqsd.go index e14cd19b..0fe73815 100644 --- a/libfic/zqsd.go +++ b/libfic/zqsd.go @@ -1,6 +1,7 @@ package fic import ( + "fmt" "time" "srs.epita.fr/fic-server/settings" @@ -36,6 +37,10 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi return nil, err } + if s.End == nil { + return nil, fmt.Errorf("Please define an end date") + } + var challenges []*ChallengeZQDS for _, th := range themes { @@ -75,7 +80,7 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi Rules: c.Rules, YourMission: c.YourMission, Start: s.Start, - End: s.End, + End: *s.End, Challenges: challenges, }, nil } diff --git a/settings/settings.go b/settings/settings.go index 9c586105..393b6a0a 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -27,8 +27,8 @@ type Settings struct { // Start is the departure time (expected or effective). Start time.Time `json:"start"` - // End is the expected end time. - End time.Time `json:"end"` + // End is the expected end time (if empty their is no end-date). + End *time.Time `json:"end,omitempty"` // Generation is a value used to regenerate static files. Generation time.Time `json:"generation"` // ActivateTime is the time when the current file should be proceed.