format
This commit is contained in:
parent
8788eea4f0
commit
645f40f0c6
|
@ -44,7 +44,7 @@ func createExerciceFile(theme fic.Theme, exercice fic.Exercice, args []string, b
|
||||||
return exercice.ImportFile(pathname, uf.URI)
|
return exercice.ImportFile(pathname, uf.URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCloudFile(pathname string, dest string) (error) {
|
func getCloudFile(pathname string, dest string) error {
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil {
|
if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -58,7 +58,7 @@ func getCloudFile(pathname string, dest string) (error) {
|
||||||
if fd, err := os.Create(dest); err != nil {
|
if fd, err := os.Create(dest); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
defer fd.Close();
|
defer fd.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return errors.New(resp.Status)
|
return errors.New(resp.Status)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type staticRouting struct{
|
type staticRouting struct {
|
||||||
StaticDir string
|
StaticDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func genTeamMyFile(team fic.Team) error {
|
||||||
|
|
||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
} else if ! s.IsDir() {
|
} else if !s.IsDir() {
|
||||||
return errors.New("dirPath is not a directory")
|
return errors.New("dirPath is not a directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ func touchStartedFile(startSub time.Duration) {
|
||||||
func main() {
|
func main() {
|
||||||
var bind = flag.String("bind", "0.0.0.0:8080", "Bind port/socket")
|
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 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 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 duration = flag.Duration("duration", 180*time.Minute, "Challenge duration")
|
||||||
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
||||||
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubmissionHandler struct{
|
type SubmissionHandler struct {
|
||||||
ChallengeEnd time.Time
|
ChallengeEnd time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
||||||
// Check request type and size
|
// Check request type and size
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||||||
|
@ -30,7 +29,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Extract URL arguments
|
// Extract URL arguments
|
||||||
var sURL = strings.Split(r.URL.Path, "/")
|
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
|
// Previous submission not treated
|
||||||
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) {
|
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)
|
http.Error(w, "{\"errmsg\":\"Du calme ! une tentative est déjà en cours de traitement.\"}", http.StatusPaymentRequired)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read request body
|
// Read request body
|
||||||
var body []byte
|
var body []byte
|
||||||
if r.ContentLength > 0 {
|
if r.ContentLength > 0 {
|
||||||
|
@ -84,7 +80,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Store content in file
|
// Store content in file
|
||||||
if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil {
|
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)
|
log.Println("Unable to open exercice file:", err)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeHandler struct{
|
type TimeHandler struct {
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
16
libfic/db.go
16
libfic/db.go
|
@ -24,7 +24,7 @@ CREATE TABLE IF NOT EXISTS themes(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS teams(
|
CREATE TABLE IF NOT EXISTS teams(
|
||||||
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS teams(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS team_members(
|
CREATE TABLE IF NOT EXISTS team_members(
|
||||||
id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS team_members(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercices(
|
CREATE TABLE IF NOT EXISTS exercices(
|
||||||
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS exercices(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_files(
|
CREATE TABLE IF NOT EXISTS exercice_files(
|
||||||
id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS exercice_files(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_keys(
|
CREATE TABLE IF NOT EXISTS exercice_keys(
|
||||||
id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS exercice_keys(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_solved(
|
CREATE TABLE IF NOT EXISTS exercice_solved(
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
|
@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_tries(
|
CREATE TABLE IF NOT EXISTS exercice_tries(
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
|
@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user