This commit is contained in:
nemunaire 2016-01-23 13:19:28 +01:00
commit 645f40f0c6
8 changed files with 32 additions and 37 deletions

View file

@ -29,8 +29,8 @@ func touchStartedFile(startSub time.Duration) {
func main() {
var bind = flag.String("bind", "0.0.0.0:8080", "Bind port/socket")
var prefix = flag.String("prefix", "", "Request path prefix to strip (from proxy)")
var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix() / 60 * 60 + 120))
var duration = flag.Duration("duration", 180 * time.Minute, "Challenge duration")
var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix()/60*60+120))
var duration = flag.Duration("duration", 180*time.Minute, "Challenge duration")
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
flag.Parse()

View file

@ -11,7 +11,7 @@ import (
"time"
)
type SubmissionHandler struct{
type SubmissionHandler struct {
ChallengeEnd time.Time
}
@ -20,7 +20,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Check request type and size
if r.Method != "POST" {
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
@ -30,7 +29,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// Extract URL arguments
var sURL = strings.Split(r.URL.Path, "/")
@ -61,14 +59,12 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
// Previous submission not treated
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) {
http.Error(w, "{\"errmsg\":\"Du calme ! une tentative est déjà en cours de traitement.\"}", http.StatusPaymentRequired)
return
}
// Read request body
var body []byte
if r.ContentLength > 0 {
@ -84,7 +80,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
// Store content in file
if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil {
log.Println("Unable to open exercice file:", err)

View file

@ -7,15 +7,15 @@ import (
"time"
)
type TimeHandler struct{
type TimeHandler struct {
StartTime time.Time
Duration time.Duration
}
type timeObject struct {
Started int64 `json:"st"`
Time int64 `json:"cu"`
Duration int `json:"du"`
Started int64 `json:"st"`
Time int64 `json:"cu"`
Duration int `json:"du"`
}
func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {