frontend: don't use path to give team's ID, use a dedicated header
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f4dcaa23a3
commit
0d792dcd8f
@ -180,55 +180,49 @@ server {
|
||||
location /submit/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/(.*)$ /submission/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/submission;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /submit/issue {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/.*$ /issue/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/issue;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /submit/name {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/.*$ /chname/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/chname;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /registration {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/registration /registration/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /openhint/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/openhint/(.*)$ /openhint/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /wantchoices/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/wantchoices/(.*)$ /wantchoices/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
}
|
||||
|
@ -172,55 +172,49 @@ server {
|
||||
location /submit/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/(.*)$ /submission/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/submission;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /submit/issue {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/.*$ /issue/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/issue;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /submit/name {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/submit/.*$ /chname/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080/chname;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /registration {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/registration /registration/$team break;
|
||||
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /openhint/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/openhint/(.*)$ /openhint/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
location /wantchoices/ {
|
||||
include fic-auth.conf;
|
||||
|
||||
rewrite ^/wantchoices/(.*)$ /wantchoices/$team/$1 break;
|
||||
|
||||
proxy_pass http://frontend:8080/;
|
||||
proxy_pass http://frontend:8080;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-FIC-Team $team;
|
||||
proxy_redirect off;
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ func main() {
|
||||
settings.LoadAndWatchSettings(path.Join(settings.SettingsDir, settings.SettingsFile), reloadSettings)
|
||||
|
||||
// Register handlers
|
||||
http.Handle(fmt.Sprintf("%s/chname/", *prefix), http.StripPrefix(fmt.Sprintf("%s/chname/", *prefix), submissionTeamChecker{"name change", ChNameHandler, *teamsDir}))
|
||||
http.Handle(fmt.Sprintf("%s/issue/", *prefix), http.StripPrefix(fmt.Sprintf("%s/issue/", *prefix), submissionTeamChecker{"issue", IssueHandler, *teamsDir}))
|
||||
http.Handle(fmt.Sprintf("%s/openhint/", *prefix), http.StripPrefix(fmt.Sprintf("%s/openhint/", *prefix), submissionTeamChecker{"opening hint", HintHandler, *teamsDir}))
|
||||
http.Handle(fmt.Sprintf("%s/wantchoices/", *prefix), http.StripPrefix(fmt.Sprintf("%s/wantchoices/", *prefix), submissionTeamChecker{"wantint choices", WantChoicesHandler, *teamsDir}))
|
||||
http.Handle(fmt.Sprintf("%s/registration/", *prefix), http.StripPrefix(fmt.Sprintf("%s/registration/", *prefix), submissionChecker{"registration", RegistrationHandler}))
|
||||
http.Handle(fmt.Sprintf("%s/chname/", *prefix), http.StripPrefix(fmt.Sprintf("%s/chname/", *prefix), submissionTeamChecker{"name change", ChNameHandler, *teamsDir, *simulator}))
|
||||
http.Handle(fmt.Sprintf("%s/issue/", *prefix), http.StripPrefix(fmt.Sprintf("%s/issue/", *prefix), submissionTeamChecker{"issue", IssueHandler, *teamsDir, *simulator}))
|
||||
http.Handle(fmt.Sprintf("%s/openhint/", *prefix), http.StripPrefix(fmt.Sprintf("%s/openhint/", *prefix), submissionTeamChecker{"opening hint", HintHandler, *teamsDir, *simulator}))
|
||||
http.Handle(fmt.Sprintf("%s/wantchoices/", *prefix), http.StripPrefix(fmt.Sprintf("%s/wantchoices/", *prefix), submissionTeamChecker{"wantint choices", WantChoicesHandler, *teamsDir, *simulator}))
|
||||
http.Handle(fmt.Sprintf("%s/registration", *prefix), http.StripPrefix(fmt.Sprintf("%s/registration", *prefix), submissionChecker{"registration", RegistrationHandler}))
|
||||
http.Handle(fmt.Sprintf("%s/resolution/", *prefix), http.StripPrefix(fmt.Sprintf("%s/resolution/", *prefix), ResolutionHandler{}))
|
||||
http.Handle(fmt.Sprintf("%s/submission/", *prefix), http.StripPrefix(fmt.Sprintf("%s/submission/", *prefix), submissionTeamChecker{"submission", SubmissionHandler, *teamsDir}))
|
||||
http.Handle(fmt.Sprintf("%s/submission/", *prefix), http.StripPrefix(fmt.Sprintf("%s/submission/", *prefix), submissionTeamChecker{"submission", SubmissionHandler, *teamsDir, *simulator}))
|
||||
|
||||
if *simulator != "" {
|
||||
if _, err := os.Stat(path.Join(*teamsDir, *simulator)); os.IsNotExist(err) {
|
||||
@ -120,7 +120,6 @@ loop:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.Print("The service is shutting down...")
|
||||
srv.Shutdown(context.Background())
|
||||
log.Println("done")
|
||||
|
@ -15,11 +15,13 @@ func RegistrationHandler(w http.ResponseWriter, r *http.Request, sURL []string)
|
||||
return
|
||||
}
|
||||
|
||||
if len(sURL) < 1 || len(sURL[0]) == 0 {
|
||||
http.Error(w, "{\"errmsg\":\"Arguments manquants.\"}", http.StatusBadRequest)
|
||||
teamInitialName := "-"
|
||||
if t := r.Header.Get("X-FIC-Team"); t != "" {
|
||||
teamInitialName = t
|
||||
} else {
|
||||
http.Error(w, "{\"errmsg\":\"Votre jeton d'authentification semble invalide. Contactez l'équipe serveur.\"}", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
teamInitialName := sURL[0]
|
||||
|
||||
// Check request type and size
|
||||
if r.Method != "POST" {
|
||||
|
@ -21,13 +21,18 @@ type submissionTeamChecker struct{
|
||||
kind string
|
||||
next submissionTeamHandler
|
||||
teamsDir string
|
||||
simulator string
|
||||
}
|
||||
|
||||
func (c submissionChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
|
||||
r.RemoteAddr = addr
|
||||
}
|
||||
log.Printf("%s \"%s %s\" => %s [%s]\n", r.RemoteAddr, r.Method, r.URL.Path, c.kind, r.UserAgent())
|
||||
team := "-"
|
||||
if t := r.Header.Get("X-FIC-Team"); t != "" {
|
||||
team = t
|
||||
}
|
||||
log.Printf("%s %s \"%s %s\" => %s [%s]\n", r.RemoteAddr, team, r.Method, r.URL.Path, c.kind, r.UserAgent())
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@ -41,21 +46,20 @@ func (c submissionChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Extract URL arguments
|
||||
var sURL = strings.Split(r.URL.Path, "/")
|
||||
var sURL = strings.Split(strings.TrimPrefix(r.URL.Path, "/"), "/")
|
||||
|
||||
c.next(w, r, sURL)
|
||||
}
|
||||
|
||||
func (c submissionTeamChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
submissionChecker{c.kind, func(w http.ResponseWriter, r *http.Request, sURL []string) {
|
||||
if len(sURL) < 1 {
|
||||
http.Error(w, "{\"errmsg\":\"Arguments manquants.\"}", http.StatusBadRequest)
|
||||
return
|
||||
team := c.simulator
|
||||
if t := r.Header.Get("X-FIC-Team"); t != "" {
|
||||
team = t
|
||||
}
|
||||
team := sURL[0]
|
||||
|
||||
// Check team validity and existance
|
||||
if len(team) < 1 || team == "public" {
|
||||
if len(team) < 1 || team == "-" || team == "public" {
|
||||
log.Println("INVALID TEAM:", team)
|
||||
http.Error(w, "{\"errmsg\":\"Équipe inexistante.\"}", http.StatusBadRequest)
|
||||
return
|
||||
@ -65,6 +69,6 @@ func (c submissionTeamChecker) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
c.next(w, r, team, sURL[1:])
|
||||
c.next(w, r, team, sURL)
|
||||
}}.ServeHTTP(w, r)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user