Use initial name instead of ID

This commit is contained in:
nemunaire 2016-04-28 17:34:37 +02:00 committed by Pierre-Olivier Mercier
parent 467641f4f2
commit 61f96a643c
2 changed files with 8 additions and 6 deletions

View File

@ -22,7 +22,7 @@ func nginxGenTeam() (string, error) {
} else {
ret := ""
for _, team := range teams {
ret += fmt.Sprintf(" if ($ssl_client_s_dn ~ \"/C=FR/ST=France/O=Epita/OU=SRS/CN=%s\") { set $team %d; }\n", team.InitialName, team.Id)
ret += fmt.Sprintf(" if ($ssl_client_s_dn ~ \"/C=FR/ST=France/O=Epita/OU=SRS/CN=%s\") { set $team \"%s\"; }\n", team.InitialName, team.InitialName)
}
return ret, nil

View File

@ -44,13 +44,15 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// Parse arguments
if team, err := strconv.Atoi(sURL[1]); err != nil {
if _, err := os.Stat(path.Join(TeamsDir, sURL[1])); os.IsNotExist(err) || len(sURL[1]) < 1 || sURL[1][0] == '_' {
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
return
} else if pex, err := strconv.Atoi(sURL[2]); (s.DenyChName || sURL[2] != "name") && err != nil {
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
return
} else {
team := sURL[1]
var exercice string
if sURL[2] == "name" {
exercice = sURL[2]
@ -64,9 +66,9 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team))); os.IsNotExist(err) {
if _, err := os.Stat(path.Join(SubmissionDir, team)); os.IsNotExist(err) {
log.Println("Creating submission directory for", team)
if err := os.MkdirAll(path.Join(SubmissionDir, fmt.Sprintf("%d", team)), 0777); err != nil {
if err := os.MkdirAll(path.Join(SubmissionDir, team), 0777); err != nil {
log.Println("Unable to create submission directory: ", err)
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
return
@ -74,7 +76,7 @@ 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), exercice)); !os.IsNotExist(err) {
if _, err := os.Stat(path.Join(SubmissionDir, team, exercice)); !os.IsNotExist(err) {
http.Error(w, "{\"errmsg\":\"Du calme ! une requête est déjà en cours de traitement.\"}", http.StatusPaymentRequired)
return
}
@ -95,7 +97,7 @@ 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), exercice)); err != nil {
if file, err := os.Create(path.Join(SubmissionDir, team, exercice)); err != nil {
log.Println("Unable to open exercice file:", err)
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
return