From f88068c08d9f8c6e0762fdf33f698a5cae2faa3e Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 13 Oct 2016 19:34:53 +0200 Subject: [PATCH 0001/2235] Add translation to french --- frontend/static/index.html | 1 + .../static/js/i18n/angular-locale_fr-fr.js | 124 ++++++++++++++++++ frontend/static/public.html | 1 + 3 files changed, 126 insertions(+) create mode 100644 frontend/static/js/i18n/angular-locale_fr-fr.js diff --git a/frontend/static/index.html b/frontend/static/index.html index d15e0777..a81ca4fd 100644 --- a/frontend/static/index.html +++ b/frontend/static/index.html @@ -101,6 +101,7 @@ + diff --git a/frontend/static/js/i18n/angular-locale_fr-fr.js b/frontend/static/js/i18n/angular-locale_fr-fr.js new file mode 100644 index 00000000..745a956b --- /dev/null +++ b/frontend/static/js/i18n/angular-locale_fr-fr.js @@ -0,0 +1,124 @@ +'use strict'; +angular.module("ngLocale", [], ["$provide", function($provide) { +var PLURAL_CATEGORY = {ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"}; +$provide.value("$locale", { + "DATETIME_FORMATS": { + "AMPMS": [ + "AM", + "PM" + ], + "DAY": [ + "dimanche", + "lundi", + "mardi", + "mercredi", + "jeudi", + "vendredi", + "samedi" + ], + "ERANAMES": [ + "avant J\u00e9sus-Christ", + "apr\u00e8s J\u00e9sus-Christ" + ], + "ERAS": [ + "av. J.-C.", + "ap. J.-C." + ], + "FIRSTDAYOFWEEK": 0, + "MONTH": [ + "janvier", + "f\u00e9vrier", + "mars", + "avril", + "mai", + "juin", + "juillet", + "ao\u00fbt", + "septembre", + "octobre", + "novembre", + "d\u00e9cembre" + ], + "SHORTDAY": [ + "dim.", + "lun.", + "mar.", + "mer.", + "jeu.", + "ven.", + "sam." + ], + "SHORTMONTH": [ + "janv.", + "f\u00e9vr.", + "mars", + "avr.", + "mai", + "juin", + "juil.", + "ao\u00fbt", + "sept.", + "oct.", + "nov.", + "d\u00e9c." + ], + "STANDALONEMONTH": [ + "Janvier", + "F\u00e9vrier", + "Mars", + "Avril", + "Mai", + "Juin", + "Juillet", + "Ao\u00fbt", + "Septembre", + "Octobre", + "Novembre", + "D\u00e9cembre" + ], + "WEEKENDRANGE": [ + 5, + 6 + ], + "fullDate": "EEEE d MMMM y", + "longDate": "d MMMM y", + "medium": "d MMM y HH:mm:ss", + "mediumDate": "d MMM y", + "mediumTime": "HH:mm:ss", + "short": "dd/MM/y HH:mm", + "shortDate": "dd/MM/y", + "shortTime": "HH:mm" + }, + "NUMBER_FORMATS": { + "CURRENCY_SYM": "\u20ac", + "DECIMAL_SEP": ",", + "GROUP_SEP": "\u00a0", + "PATTERNS": [ + { + "gSize": 3, + "lgSize": 3, + "maxFrac": 3, + "minFrac": 0, + "minInt": 1, + "negPre": "-", + "negSuf": "", + "posPre": "", + "posSuf": "" + }, + { + "gSize": 3, + "lgSize": 3, + "maxFrac": 2, + "minFrac": 2, + "minInt": 1, + "negPre": "-", + "negSuf": "\u00a0\u00a4", + "posPre": "", + "posSuf": "\u00a0\u00a4" + } + ] + }, + "id": "fr-fr", + "pluralCat": function(n, opt_precision) { var i = n | 0; if (i == 0 || i == 1) { return PLURAL_CATEGORY.ONE; } return PLURAL_CATEGORY.OTHER;} +}); +}]); diff --git a/frontend/static/public.html b/frontend/static/public.html index d2f179b4..b06974fd 100644 --- a/frontend/static/public.html +++ b/frontend/static/public.html @@ -199,6 +199,7 @@ + > From 1129bd68be899edf8b5fdccc2a9eeddd0d2c4290 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 13 Oct 2016 19:40:27 +0200 Subject: [PATCH 0002/2235] frontend: log time.json GET --- frontend/time.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/time.go b/frontend/time.go index 895107b5..ec6bf695 100644 --- a/frontend/time.go +++ b/frontend/time.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "log" "net/http" "time" ) @@ -19,6 +20,8 @@ type timeObject struct { } func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + log.Printf("Handling %s request from %s: %s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent()) + w.Header().Set("Content-Type", "application/json") if j, err := json.Marshal(timeObject{t.StartTime.Unix(), time.Now().Unix(), int(t.Duration.Seconds())}); err != nil { From b618d4f886a6dc77578c003bcb1b86ee09b92f77 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 13 Oct 2016 20:16:42 +0200 Subject: [PATCH 0003/2235] Ready to publish solutions --- frontend/static/index.html | 21 ++++++++++++++++++--- frontend/static/js/app.js | 7 ++++++- frontend/static/views/theme.html | 5 ++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frontend/static/index.html b/frontend/static/index.html index a81ca4fd..5890f8c3 100644 --- a/frontend/static/index.html +++ b/frontend/static/index.html @@ -32,7 +32,12 @@ -
+
-
+
+
{{ e.since | since }}
- - Epita - + + +
@@ -209,5 +302,10 @@ + From 416ad65c875229760c71043153181d0b48ef5a5b Mon Sep 17 00:00:00 2001 From: nemunaire Date: Fri, 20 Jan 2017 19:18:43 +0100 Subject: [PATCH 0114/2235] admin: add public interface management --- admin/api/public.go | 80 ++++++++++++++++++++ admin/index.go | 1 + admin/static.go | 3 + admin/static/index.html | 1 + admin/static/js/app.js | 80 ++++++++++++++++++++ admin/static/views/public.html | 129 +++++++++++++++++++++++++++++++++ 6 files changed, 294 insertions(+) create mode 100644 admin/api/public.go create mode 100644 admin/static/views/public.html diff --git a/admin/api/public.go b/admin/api/public.go new file mode 100644 index 00000000..ceccf230 --- /dev/null +++ b/admin/api/public.go @@ -0,0 +1,80 @@ +package api + +import ( + "encoding/json" + "os" + "path" + + "github.com/julienschmidt/httprouter" +) + +func init() { + router.GET("/api/public.json", apiHandler(getPublic)) + router.DELETE("/api/public.json", apiHandler(deletePublic)) + router.PUT("/api/public.json", apiHandler(savePublic)) +} + +type FICPublicScene struct { + Type string `json:"type"` + Params map[string]interface{} `json:"params"` +} + +func readPublic(path string) ([]FICPublicScene, error) { + var s []FICPublicScene + if fd, err := os.Open(path); err != nil { + return s, err + } else { + defer fd.Close() + jdec := json.NewDecoder(fd) + + if err := jdec.Decode(&s); err != nil { + return s, err + } + + return s, nil + } +} + +func savePublicTo(path string, s []FICPublicScene) error { + if fd, err := os.Create(path); err != nil { + return err + } else { + defer fd.Close() + jenc := json.NewEncoder(fd) + + if err := jenc.Encode(s); err != nil { + return err + } + + return nil + } +} + +func getPublic(_ httprouter.Params, body []byte) (interface{}, error) { + if _, err := os.Stat(path.Join(TeamsDir, "_public", "public.json")); !os.IsNotExist(err) { + return readPublic(path.Join(TeamsDir, "_public", "public.json")) + } else { + return []FICPublicScene{}, nil + } +} + +func deletePublic(_ httprouter.Params, body []byte) (interface{}, error) { + if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), []FICPublicScene{}); err != nil { + return nil, err + } else { + return []FICPublicScene{}, err + } +} + +func savePublic(_ httprouter.Params, body []byte) (interface{}, error) { + var scenes []FICPublicScene + if err := json.Unmarshal(body, &scenes); err != nil { + return nil, err + } + + if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), scenes); err != nil { + return nil, err + } else { + return scenes, err + } +} diff --git a/admin/index.go b/admin/index.go index 85c7448c..7e1270f2 100644 --- a/admin/index.go +++ b/admin/index.go @@ -23,6 +23,7 @@ const indextpl = `
  • Équipes
  • Thèmes
  • Exercices
  • +
  • Public
  • Événements
  • Paramètres
  • diff --git a/admin/static.go b/admin/static.go index ba2bebf5..9d1bb918 100644 --- a/admin/static.go +++ b/admin/static.go @@ -19,6 +19,9 @@ func init() { api.Router().GET("/events/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { http.ServeFile(w, r, path.Join(StaticDir, "index.html")) }) + api.Router().GET("/public", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + http.ServeFile(w, r, path.Join(StaticDir, "index.html")) + }) api.Router().GET("/settings/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { http.ServeFile(w, r, path.Join(StaticDir, "index.html")) }) diff --git a/admin/static/index.html b/admin/static/index.html index dcbd3374..631dd44a 100644 --- a/admin/static/index.html +++ b/admin/static/index.html @@ -21,6 +21,7 @@
  • Équipes
  • Thèmes
  • Exercices
  • +
  • Public
  • Événements
  • Paramètres
  • diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 64a77597..458e49f8 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -37,6 +37,10 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"]) controller: "TeamNewController", templateUrl: "views/team-new.html" }) + .when("/public", { + controller: "PublicController", + templateUrl: "views/public.html" + }) .when("/events", { controller: "EventsListController", templateUrl: "views/event-list.html" @@ -65,6 +69,11 @@ angular.module("FICApp") 'update': {method: 'PUT'}, }) }) + .factory("Scene", function($resource) { + return $resource("/api/public.json", null, { + 'update': {method: 'PUT'}, + }) + }) .factory("Team", function($resource) { return $resource("/api/teams/:teamId", { teamId: '@id' }, { 'update': {method: 'PUT'}, @@ -228,6 +237,77 @@ angular.module("FICApp") } }) + .controller("PublicController", function($scope, Scene, Theme, Teams, Exercice) { + $scope.scenes = Scene.query(); + $scope.themes = Theme.query(); + $scope.teams = Teams.get(); + + $scope.types = { + "welcome": "Messages de bienvenue", + "message": "Message", + "panel": "Boîte", + "exercice": "Exercice", + "table": "Tableau", + "rank": "Classement", + }; + $scope.welcome_types = { + "init": "Accueil des équipes", + "public": "Accueil du public", + "countdown": "Compte à rebours lancement", + }; + $scope.panel_types = { + "panel-default": "Default", + "panel-info": "Info", + "panel-success": "Success", + "panel-warning": "Warning", + "panel-danger": "Danger", + }; + $scope.rank_types = { + "general": "Classement général", + }; + $scope.table_types = { + "levels": "Niveaux d'exercices", + "teams": "Équipes", + }; + $scope.exercices = Exercice.query(); + + $scope.clearScene = function() { + Scene.delete(function() { + $scope.scenes = []; + }); + }; + $scope.saveScenes = function() { + Scene.update($scope.scenes); + }; + $scope.addScene = function() { + $scope.scenes.push({params: {}}); + }; + $scope.delScene = function(s) { + angular.forEach($scope.scenes, function(scene, k) { + if (scene == s) + $scope.scenes.splice(k, 1); + }); + }; + $scope.upScene = function(s) { + angular.forEach($scope.scenes, function(scene, k) { + if (scene == s && k > 0) { + $scope.scenes.splice(k, 1); + $scope.scenes.splice(k - 1, 0, scene); + } + }); + }; + $scope.downScene = function(s) { + var move = true; + angular.forEach($scope.scenes, function(scene, k) { + if (move && scene == s) { + $scope.scenes.splice(k, 1); + $scope.scenes.splice(k + 1, 0, scene); + move = false; + } + }); + }; + }) + .controller("EventsListController", function($scope, Event, $location) { $scope.events = Event.query(); $scope.fields = ["id", "kind", "txt", "time"]; diff --git a/admin/static/views/public.html b/admin/static/views/public.html new file mode 100644 index 00000000..435d30bd --- /dev/null +++ b/admin/static/views/public.html @@ -0,0 +1,129 @@ +
    +

    Interface publique Vider la scène Ajouter un élément +

    + +
    +
    +
    +
    + +
    +
    +
    + Up + Down +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    +
    +
    + +
    +
    +
    + +
    +
    From 544bbb745c7289fd8fe367d8861fe011651e7608 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Fri, 20 Jan 2017 20:52:31 +0100 Subject: [PATCH 0115/2235] admin: new route /members/ --- admin/api/team.go | 22 ++++++++++++++++++++++ libfic/member.go | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/admin/api/team.go b/admin/api/team.go index 828ff18b..5ae6ddee 100644 --- a/admin/api/team.go +++ b/admin/api/team.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" "fmt" + "strconv" "strings" "srs.epita.fr/fic-server/libfic" @@ -62,6 +63,9 @@ func init() { router.GET("/api/teams/:tid/name", apiHandler(teamHandler( func(team fic.Team, _ []byte) (interface{}, error) { return team.InitialName, nil }))) + + router.GET("/api/members/:mid/team", apiHandler(dispMemberTeam)) + router.GET("/api/members/:mid/team/name", apiHandler(dispMemberTeamName)) } func nginxGenMember() (string, error) { @@ -149,3 +153,21 @@ func addTeamMember(team fic.Team, body []byte) (interface{}, error) { return team.GetMembers() } + +func dispMemberTeam(ps httprouter.Params, body []byte) (interface{}, error) { + if mid, err := strconv.Atoi(string(ps.ByName("mid"))); err != nil { + return fic.Team{}, err + } else { + return fic.GetMember(mid) + } +} + +func dispMemberTeamName(ps httprouter.Params, body []byte) (interface{}, error) { + if mid, err := strconv.Atoi(string(ps.ByName("mid"))); err != nil { + return nil, err + } else if team, err := fic.GetMember(mid); err != nil { + return nil, err + } else { + return team.InitialName, nil + } +} diff --git a/libfic/member.go b/libfic/member.go index 7dad3c4c..0b4ce660 100644 --- a/libfic/member.go +++ b/libfic/member.go @@ -10,6 +10,15 @@ type Member struct { Company string `json:"company"` } +func GetMember(cnt int) (Team, error) { + var t Team + if err := DBQueryRow("SELECT T.id_team, T.initial_name, T.name, T.color FROM team_members M RIGHT OUTER JOIN teams T ON T.id_team = M.id_team LIMIT ?, 1", cnt - 1).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil { + return t, err + } + + return t, nil +} + func (t Team) GetMembers() ([]Member, error) { if rows, err := DBQuery("SELECT id_member, firstname, lastname, nickname, company FROM team_members WHERE id_team = ?", t.Id); err != nil { return nil, err From 318bc4bc4d616907f164ae6f198d8760515ee7c5 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Fri, 20 Jan 2017 20:53:32 +0100 Subject: [PATCH 0116/2235] Update openssl settings --- admin/pki/openssl.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/pki/openssl.cnf b/admin/pki/openssl.cnf index 495674f9..1848365b 100644 --- a/admin/pki/openssl.cnf +++ b/admin/pki/openssl.cnf @@ -101,7 +101,7 @@ emailAddress = optional #################################################################### [ req ] -default_bits = 2048 +default_bits = 4096 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes From 17f51f5e7b45821d0f59135b05b39cf4a410c1d5 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:14:28 +0100 Subject: [PATCH 0117/2235] admin: can force page regeneration --- admin/api/settings.go | 2 +- admin/static/js/app.js | 4 ++++ admin/static/views/settings.html | 4 +++- backend/main.go | 6 +++++- settings/settings.go | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/admin/api/settings.go b/admin/api/settings.go index 31bc7446..40afef56 100644 --- a/admin/api/settings.go +++ b/admin/api/settings.go @@ -22,7 +22,7 @@ func getSettings(_ httprouter.Params, body []byte) (interface{}, error) { if settings.ExistsSettings(path.Join(TeamsDir, settings.SettingsFile)) { return settings.ReadSettings(path.Join(TeamsDir, settings.SettingsFile)) } else { - return settings.FICSettings{time.Unix(0,0), time.Unix(0,0), fic.FirstBlood, fic.SubmissionCostBase, false, false, false, true, true}, nil + return settings.FICSettings{time.Unix(0,0), time.Unix(0,0), time.Unix(0,0), fic.FirstBlood, fic.SubmissionCostBase, false, false, false, true, true}, nil } } diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 458e49f8..34366490 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -228,6 +228,10 @@ angular.module("FICApp") $location.url("/"); }); } + $scope.regenerate = function() { + this.config.generation = (new Date()).toISOString(); + $scope.saveSettings(); + } $scope.launchChallenge = function() { var ts = Date.now() - Date.now() % 60000; var d = new Date(ts + 120000); diff --git a/admin/static/views/settings.html b/admin/static/views/settings.html index fe15a1dc..97aebc06 100644 --- a/admin/static/views/settings.html +++ b/admin/static/views/settings.html @@ -1,7 +1,9 @@ -

    Paramètres

    +

    Paramètres Regénérer les fichiers statiques

    + +
    diff --git a/backend/main.go b/backend/main.go index b0d660ee..6b458107 100644 --- a/backend/main.go +++ b/backend/main.go @@ -43,8 +43,12 @@ func watchsubdir(watcher *fsnotify.Watcher, pathname string) error { } } +var lastRegeneration time.Time + func reloadSettings(config settings.FICSettings) { - if fic.PartialValidation != config.PartialValidation || fic.UnlockedChallenges != !config.EnableExerciceDepend || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase { + if lastRegeneration != config.Generation || fic.PartialValidation != config.PartialValidation || fic.UnlockedChallenges != !config.EnableExerciceDepend || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase { + lastRegeneration = config.Generation + fic.PartialValidation = config.PartialValidation fic.UnlockedChallenges = !config.EnableExerciceDepend diff --git a/settings/settings.go b/settings/settings.go index 6775c03c..d327663c 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -15,6 +15,7 @@ const SettingsFile = "settings.json" type FICSettings struct { Start time.Time `json:"start"` End time.Time `json:"end"` + Generation time.Time `json:"generation"` FirstBlood float64 `json:"firstBlood"` SubmissionCostBase float64 `json:"submissionCostBase"` From 4fe641a9f5183a028a39b02cb2893293bac15fa5 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:17:21 +0100 Subject: [PATCH 0118/2235] change the way themes are stored in stats --- admin/static/js/app.js | 6 +++++- libfic/team_stats.go | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 34366490..34d64d68 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -480,7 +480,11 @@ angular.module("FICApp") $scope.teamstats = TeamStats.get({ teamId: $routeParams.teamId }); $scope.teamstats.$promise.then(function(res) { solvedByLevelPie("#pieLevels", res.levels); - solvedByThemesPie("#pieThemes", res.themes); + var themes = []; + angular.forEach(res.themes, function(theme, tid) { + themes.push(theme); + }) + solvedByThemesPie("#pieThemes", themes); }); }) .controller("TeamExercicesController", function($scope, Teams, Themes, TeamMy, Exercice, $routeParams) { diff --git a/libfic/team_stats.go b/libfic/team_stats.go index a9ef4112..300dbe7b 100644 --- a/libfic/team_stats.go +++ b/libfic/team_stats.go @@ -13,8 +13,8 @@ type statLine struct { } type teamStats struct { - Levels []statLine `json:"levels"` - Themes []statLine `json:"themes"` + Levels []statLine `json:"levels"` + Themes map[int64]statLine `json:"themes"` } func (s *teamStats) GetLevel(level int) *statLine { @@ -38,7 +38,10 @@ func (t Team) GetStats() (interface{}, error) { } func GetTeamsStats(t *Team) (interface{}, error) { - stat := teamStats{} + stat := teamStats{ + []statLine{}, + map[int64]statLine{}, + } if themes, err := GetThemes(); err != nil { return nil, err @@ -84,13 +87,13 @@ func GetTeamsStats(t *Team) (interface{}, error) { } } - stat.Themes = append(stat.Themes, statLine{ + stat.Themes[theme.Id] = statLine{ theme.Name, total, solved, tried, tries, - }) + } } return stat, nil From cab95b79856b3a03586fbb56fb167151b415493b Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:18:05 +0100 Subject: [PATCH 0119/2235] libfic: new function to retrieve exercices from a hint --- libfic/hint.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libfic/hint.go b/libfic/hint.go index a47b3501..d329c692 100644 --- a/libfic/hint.go +++ b/libfic/hint.go @@ -84,3 +84,12 @@ func (h EHint) Delete() (int64, error) { return nb, err } } + +func (h EHint) GetExercice() (Exercice, error) { + var eid int64 + if err := DBQueryRow("SELECT id_exercice FROM exercice_hints WHERE id_hint = ?", h.Id).Scan(&eid); err != nil { + return Exercice{}, err + } + + return GetExercice(eid) +} From cb1fe0847b1f9ad99496bf8e643aeceefddb0a82 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:19:49 +0100 Subject: [PATCH 0120/2235] frontend: move file (on the same partition) instead of open, write, close the final file --- frontend/main.go | 6 ++++-- frontend/save.go | 46 +++++++++++++++++----------------------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/frontend/main.go b/frontend/main.go index 30c6cb31..3c939ef4 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -17,6 +17,7 @@ const startedFile = "started" var TeamsDir string var SubmissionDir string +var TmpSubmissionDir string var touchTimer *time.Timer = nil @@ -70,10 +71,11 @@ func main() { log.SetPrefix("[frontend] ") SubmissionDir = path.Clean(SubmissionDir) + TmpSubmissionDir = path.Join(SubmissionDir, ".tmp") log.Println("Creating submission directory...") - if _, err := os.Stat(SubmissionDir); os.IsNotExist(err) { - if err := os.MkdirAll(SubmissionDir, 0777); err != nil { + if _, err := os.Stat(TmpSubmissionDir); os.IsNotExist(err) { + if err := os.MkdirAll(TmpSubmissionDir, 0777); err != nil { log.Fatal("Unable to create submission directory: ", err) } } diff --git a/frontend/save.go b/frontend/save.go index 8e87cbc4..bb2009b9 100644 --- a/frontend/save.go +++ b/frontend/save.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "io/ioutil" "log" "net/http" @@ -42,40 +43,27 @@ func saveFile(dirname string, filename string, r *http.Request) error { } } - var f *os.File + // Write content to temp file + tmpfile, err := ioutil.TempFile(TmpSubmissionDir, "") + if err != nil { + return err + } + + writer := bufio.NewWriter(tmpfile) + reader := bufio.NewReader(r.Body) + if _, err := reader.WriteTo(writer); err != nil { + return err + } + writer.Flush() + tmpfile.Close() if filename == "" { - if fd, err := ioutil.TempFile(dirname, ""); err != nil { - return err - } else { - defer f.Close() - f = fd - } - } else { - if fd, err := os.Create(path.Join(dirname, filename)); err != nil { - return err - } else { - defer f.Close() - f = fd - } + filename = path.Base(tmpfile.Name()) } - // Read request body - var body []byte - if r.ContentLength > 0 { - tmp := make([]byte, 1024) - for { - n, err := r.Body.Read(tmp) - for j := 0; j < n; j++ { - body = append(body, tmp[j]) - } - if err != nil || n <= 0 { - break - } - } + if err := os.Rename(tmpfile.Name(), path.Join(dirname, filename)); err != nil { + log.Println("[ERROR] Unable to move file: ", err) } - f.Write(body) - return nil } From c1c84ba3d1b31c4d8f6a1db814ca16166ee8fe59 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:20:20 +0100 Subject: [PATCH 0121/2235] backend: generate an event when a team open an hint --- backend/hint.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/hint.go b/backend/hint.go index 17124f5b..2a074a31 100644 --- a/backend/hint.go +++ b/backend/hint.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "log" "io/ioutil" "os" @@ -28,6 +29,17 @@ func treatOpeningHint(pathname string, team fic.Team) { } else if err := team.OpenHint(hint); err != nil { log.Println("[ERR]", err) } else { + // Write event + if exercice, err := hint.GetExercice(); err != nil { + log.Println("[WRN]", err) + } else if lvl, err := exercice.GetLevel(); err != nil { + log.Println("[WRN]", err) + } else if theme, err := exercice.GetTheme(); err != nil { + log.Println("[WRN]", err) + } else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le %de challenge %s !", team.Name, lvl, theme.Name), "alert-info"); err != nil { + log.Println("[WRN] Unable to create event:", err) + } + genTeamMyFile(team) if err := os.Remove(pathname); err != nil { log.Println("[ERR]", err) From da0e7facfddaf5380d56e09bad33f250ecd5bb8a Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 24 Jan 2017 02:21:21 +0100 Subject: [PATCH 0122/2235] frontend: improve 401 page thank to initial guide --- frontend/static/css/fic.css | 32 ++++++++ frontend/static/welcome.html | 137 ++++++++++++++++++++++++++++++----- 2 files changed, 151 insertions(+), 18 deletions(-) diff --git a/frontend/static/css/fic.css b/frontend/static/css/fic.css index 0c186d5f..14d20d4f 100644 --- a/frontend/static/css/fic.css +++ b/frontend/static/css/fic.css @@ -1,10 +1,42 @@ +@font-face { + font-family: "Linux Biolinum"; + src: url('../fonts/LinBiolinum_R.woff') format('woff'); +} +@font-face { + font-family: "Linux Biolinum"; + src: url('../fonts/LinBiolinum_RB.woff') format('woff'); + font-weight: bold; +} +@font-face { + font-family: "Linux Biolinum"; + src: url('../fonts/LinBiolinum_RI.woff') format('woff'); + font-style: italic; +} + +[ng-cloak] { + display:none !important; +} + body { overflow-y: scroll; } +.beautiful { + font-family: "Linux Biolinum",Helvetica,Arial,sans-serif; +} +.beautiful ol { + font-size: 133%; +} +.beautiful ol ol { + font-size: 90%; +} + .text-bold { font-weight: bolder; } +.text-indent p { + text-indent: 1em; +} .navbar { margin-bottom: 0; diff --git a/frontend/static/welcome.html b/frontend/static/welcome.html index 20ccbbe1..8455c639 100644 --- a/frontend/static/welcome.html +++ b/frontend/static/welcome.html @@ -1,5 +1,5 @@ - + Challenge Forensic @@ -18,22 +18,22 @@ - +