Split backend service into checker and generator
Both are linked through a unix socket.
This commit is contained in:
parent
f755d7c998
commit
ed091e761c
34 changed files with 660 additions and 208 deletions
|
|
@ -1,53 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
type wantChoices struct {
|
||||
FlagId int `json:"id"`
|
||||
}
|
||||
|
||||
func treatWantChoices(pathname string, team *fic.Team) {
|
||||
// Generate a unique identifier to follow the request in logs
|
||||
bid := make([]byte, 5)
|
||||
binary.LittleEndian.PutUint32(bid, rand.Uint32())
|
||||
id := "[" + base64.StdEncoding.EncodeToString(bid) + "]"
|
||||
log.Println(id, "New wantChoices receive", pathname)
|
||||
|
||||
var ask wantChoices
|
||||
|
||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else if err = json.Unmarshal(cnt_raw, &ask); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else if ask.FlagId == 0 {
|
||||
log.Printf("%s [WRN] Invalid content in wantChoices file: %s\n", id, pathname)
|
||||
os.Remove(pathname)
|
||||
} else if flag, err := fic.GetFlagKey(ask.FlagId); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else if !team.CanSeeFlag(flag) {
|
||||
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the flag\n", id)
|
||||
} else if exercice, err := flag.GetExercice(); err != nil {
|
||||
log.Printf("%s [ERR] Unable to retrieve the flag's underlying exercice: %s\n", id, err)
|
||||
} else if !team.HasAccess(exercice) {
|
||||
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the exercice\n", id)
|
||||
} else if exercice.Disabled {
|
||||
log.Println("[!!!] The team submits something for a disabled exercice")
|
||||
} else if err = team.DisplayChoices(flag); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else {
|
||||
genTeamQueue <- team
|
||||
if err = os.Remove(pathname); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue