Compare commits

...

1 Commits

Author SHA1 Message Date
nemunaire 0ddd6c4899 Export themes as array 2018-05-13 14:16:16 +02:00
3 changed files with 83 additions and 70 deletions

View File

@ -41,6 +41,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.run(function($rootScope, $interval) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.time = {};
$('[data-toggle="popover"]').popover();
@ -170,29 +171,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.current_exercice = $scope.exercicesUrl[$routeParams.exercice];
} else {
if ($scope.themes && $scope.my && $scope.themes[$scope.current_theme]) {
var exos = Object.keys($scope.themes[$scope.current_theme].exercices);
var exos = $scope.themes[$scope.current_theme].exercices;
var i = 0;
for (; i < exos.length; i++) {
if (!$scope.my.exercices || !$scope.my.exercices[exos[i]] || !$scope.my.exercices[exos[i]].solved)
if (!$scope.my.exercices || !$scope.my.exercices[exos[i].id] || !$scope.my.exercices[exos[i].id].solved)
break;
}
if (i < exos.length) {
$rootScope.current_exercice = exos[i];
$rootScope.current_exercice = i;
} else {
$rootScope.current_exercice = exos[0];
$rootScope.current_exercice = 0;
}
} else {
$rootScope.current_exercice = 0;
}
}
$rootScope.current_exercice_my = $scope.themes[$scope.current_theme].exercices[$rootScope.current_exercice].id;
$scope.hsubmit = function(hint) {
hint.submitted = true;
$http({ url: "/openhint/" + $rootScope.current_exercice, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) {
$http({ url: "/openhint/" + $rootScope.current_exercice_my, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) {
var checkDiffHint = function() {
$http.get("/my.json").then(function(response) {
var my = response.data;
angular.forEach(my.exercices[$rootScope.current_exercice].hints, function(h,hid){
angular.forEach(my.exercices[$rootScope.current_exercice_my].hints, function(h,hid){
if (hint.id == h.id) {
if (hint.content != h.content) {
$rootScope.refresh();
@ -216,24 +218,24 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.sberr = "";
var waitMy = function() {
if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice]) {
if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice_my]) {
$timeout.cancel($scope.cbs);
$scope.cbs = $timeout(waitMy, 420);
} else {
$scope.flags = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].keys, function(key,kid) {
angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].keys, function(key,kid) {
var o = {
id: kid,
name: key,
value: ""
};
if ($scope.my.exercices[$rootScope.current_exercice].solved_matrix != null)
o.found = $scope.my.exercices[$rootScope.current_exercice].solved_matrix[kid];
if ($scope.my.exercices[$rootScope.current_exercice_my].solved_matrix != null)
o.found = $scope.my.exercices[$rootScope.current_exercice_my].solved_matrix[kid];
this.push(o);
}, $scope.flags);
$scope.mcqs = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) {
angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].mcqs, function(mcq,qid) {
var o = {
title: mcq.title,
kind: mcq.kind,
@ -273,7 +275,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
});
}
$http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: resp }).then(function(response, status, header, config) {
$http({ url: "/submit/" + $rootScope.current_exercice_my, method: "POST", data: resp }).then(function(response, status, header, config) {
$rootScope.messageClass = {"text-success": true};
$rootScope.message = response.data.errmsg;
$rootScope.sberr = "";
@ -285,7 +287,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
var checkDiff = function() {
$http.get("/my.json").then(function(response) {
var my = response.data;
if ($scope.my.exercices[$rootScope.current_exercice].tries != my.exercices[$rootScope.current_exercice].tries || $scope.my.exercices[$rootScope.current_exercice].solved_time != my.exercices[$rootScope.current_exercice].solved_time) {
if ($scope.my.exercices[$rootScope.current_exercice_my].tries != my.exercices[$rootScope.current_exercice_my].tries || $scope.my.exercices[$rootScope.current_exercice_my].solved_time != my.exercices[$rootScope.current_exercice_my].solved_time) {
$rootScope.refresh();
$scope.my = my;
waitMy();
@ -298,7 +300,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
checkDiff();
}, function(response, status, header, config) {
if (status >= 500) {
$scope.my.exercices[$rootScope.current_exercice].submitted = false;
$scope.my.exercices[$rootScope.current_exercice_my].submitted = false;
}
$rootScope.messageClass = {"text-danger": true};
$rootScope.message = response.data.errmsg;
@ -306,12 +308,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants.";
}
});
$scope.my.exercices[$rootScope.current_exercice].submitted = true;
$scope.my.exercices[$rootScope.current_exercice_my].submitted = true;
};
})
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
if ($scope.my) {
$rootScope.title = $scope.my.name;
$rootScope.authors = $scope.my.members.map(function (cur) {
@ -373,6 +376,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("RegisterController", function($scope, $rootScope, $location, $http) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Bienvenue au challenge forensic !";
$rootScope.authors = null;
@ -443,6 +447,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("RankController", function($scope, $rootScope) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Classement général";
$rootScope.authors = "";
@ -461,12 +466,14 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("VideosController", function($scope, $rootScope) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Vidéos de résolution";
$rootScope.authors = "";
})
.controller("HomeController", function($scope, $rootScope) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "";
$rootScope.authors = "";
});

View File

@ -12,15 +12,15 @@
</ol>
</nav>
<div class="alert alert-warning" style="margin-top:15px;" ng-if="!(my.exercices[current_exercice])">
<div class="alert alert-warning" style="margin-top:15px;" ng-if="!(my.exercices[current_exercice_my])">
Vous n'avez pas encore accès à cet exercice.
</div>
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="!(my.exercices[current_exercice])">
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="!(my.exercices[current_exercice_my])">
<p class="lead text-justify" ng-bind-html="themes[current_theme].intro"></p>
</div>
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="(my.exercices[current_exercice])">
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="(my.exercices[current_exercice_my])">
<h3 class="display-4">{{ themes[current_theme].exercices[current_exercice].title }}</h3>
<p class="lead text-justify" ng-bind-html="my.exercices[current_exercice].statement"></p>
<p class="lead text-justify" ng-bind-html="my.exercices[current_exercice_my].statement"></p>
<hr class="my-3">
<ul>
<li><strong>Gain&nbsp;:</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> <em ng-if="settings.firstBlood && themes[current_theme].exercices[current_exercice].solved < 1">{{ 1 + settings.firstBlood | coeff }} prem's</em> <em ng-if="themes[current_theme].exercices[current_exercice].curcoeff != 1.0">{{ themes[current_theme].exercices[current_exercice].curcoeff | coeff }} bonus</em></li>
@ -30,13 +30,13 @@
<div class="row">
<div class="col-xl" ng-if="(my.exercices[current_exercice] && my.exercices[current_exercice].files.length)" style="margin-bottom: 15px">
<div class="col-xl" ng-if="(my.exercices[current_exercice_my] && my.exercices[current_exercice_my].files.length)" style="margin-bottom: 15px">
<div class="card" style="margin-bottom: 15px">
<div class="card-header text-white">
<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Téléchargements
</div>
<div class="list-group">
<a ng-href="{{ file.path }}" target="_self" class="list-group-item" ng-repeat="file in my.exercices[current_exercice].files">
<a ng-href="{{ file.path }}" target="_self" class="list-group-item" ng-repeat="file in my.exercices[current_exercice_my].files">
<h1 class="float-left" style="margin: 7px 7px 5px -5px"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1>
<h4 class="list-group-item-heading"><strong><samp>{{ file.name }}</samp></strong></h4>
<p class="list-group-item-text"><nobr>Taille&nbsp;: <span title="{{ file.size }} octets">{{ file.size | size }}</span></nobr> &ndash; <nobr><span title="blake2.net">b2sum</span>&nbsp;: <samp class="cksum" title="{{ file.checksum }}">{{ file.checksum }}</samp></nobr></p>
@ -45,13 +45,13 @@
</div>
</div>
<div class="col-xl" ng-if="(my.exercices[current_exercice] && my.exercices[current_exercice].hints.length)" style="margin-bottom: 15px">
<div class="col-xl" ng-if="(my.exercices[current_exercice_my] && my.exercices[current_exercice_my].hints.length)" style="margin-bottom: 15px">
<div class="card border-info" style="margin-bottom: 15px">
<div class="card-header bg-info text-white">
<span class="glyphicon glyphicon-lamp" aria-hidden="true"></span> Indices
</div>
<div class="list-group">
<a target="_self" class="list-group-item text-light" ng-repeat="hint in my.exercices[current_exercice].hints" ng-href="{{ hint.file }}">
<a target="_self" class="list-group-item text-light" ng-repeat="hint in my.exercices[current_exercice_my].hints" ng-href="{{ hint.file }}">
<button ng-click="hsubmit(hint)" class="float-right btn btn-info" ng-if="!(hint.content || hint.file)" ng-class="{disabled: hint.submitted}"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Débloquer</button>
<button ng-click="hint.hidden = false;" class="float-right btn btn-info" ng-if="!hint.file && hint.hidden"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Afficher</button>
<h1 class="float-left" style="margin: 5px 7px 5px -5px" ng-if="hint.file"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1>
@ -65,15 +65,15 @@
</div>
<div class="col-xl" style="margin-bottom: 25px">
<div class="card border-danger" ng-if="my.team_id && my.exercices[current_exercice] && !(my.exercices[current_exercice].solved)" style="margin-bottom: 15px">
<div class="card border-danger" ng-if="my.team_id && my.exercices[current_exercice_my] && !(my.exercices[current_exercice_my].solved)" style="margin-bottom: 15px">
<div class="card-header bg-danger text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Faire son rapport
</div>
<ul class="list-group" ng-if="(my.exercices[current_exercice].tries || my.exercices[current_exercice].submitted || sberr)">
<li class="list-group-item text-warning" ng-if="my.exercices[current_exercice].tries"><ng-pluralize count="my.exercices[current_exercice].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. <span ng-if="my.exercices[current_exercice].solve_dist"><ng-pluralize count="my.exercices[current_exercice].solve_dist" when="{'one': '{} réponse erronée', 'other': '{} réponses erronées'}"></ng-pluralize>.</span></li>
<li class="list-group-item" ng-class="messageClass" ng-if="my.exercices[current_exercice].submitted || sberr"><strong ng-if="!sberr">Votre solution a bien été envoyée !</strong><strong ng-if="sberr">{{ sberr }}</strong> {{ message }}</li>
<ul class="list-group" ng-if="(my.exercices[current_exercice_my].tries || my.exercices[current_exercice_my].submitted || sberr)">
<li class="list-group-item text-warning" ng-if="my.exercices[current_exercice_my].tries"><ng-pluralize count="my.exercices[current_exercice_my].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice_my].solved_time | date:"mediumTime" }}. <span ng-if="my.exercices[current_exercice_my].solve_dist"><ng-pluralize count="my.exercices[current_exercice_my].solve_dist" when="{'one': '{} réponse erronée', 'other': '{} réponses erronées'}"></ng-pluralize>.</span></li>
<li class="list-group-item" ng-class="messageClass" ng-if="my.exercices[current_exercice_my].submitted || sberr"><strong ng-if="!sberr">Votre solution a bien été envoyée !</strong><strong ng-if="sberr">{{ sberr }}</strong> {{ message }}</li>
</ul>
<div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr">
<div class="card-body" ng-if="!my.exercices[current_exercice_my].submitted || sberr">
<form ng-controller="SubmissionController" ng-submit="ssubmit()">
<div class="form-group" ng-repeat="key in flags">
<label for="sol_{{ key.id }}">{{ key.name }}&nbsp;:</label>
@ -97,19 +97,19 @@
</div>
</div>
<div class="card border-success" ng-if="(my.team_id && my.exercices[current_exercice].solved)">
<div class="card border-success" ng-if="(my.team_id && my.exercices[current_exercice_my].solved)">
<div class="card-header bg-success text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Challenge réussi !
</div>
<div class="card-body">
<p class="card-text">
Vous êtes la {{ my.exercices[current_exercice].solved_rank }}<sup><ng-pluralize count="my.exercices[current_exercice].solved_rank" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="my.exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> !
Vous êtes la {{ my.exercices[current_exercice_my].solved_rank }}<sup><ng-pluralize count="my.exercices[current_exercice_my].solved_rank" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice_my].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="my.exercices[current_exercice_my].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> !
</p>
<a href="/{{ themes[current_theme].urlid }}" class="btn btn-success">Passer au challenge suivant</a>
</div>
</div>
<div class="card border-success" ng-if="(!my.team_id && my.exercices[current_exercice].keys)">
<div class="card border-success" ng-if="(!my.team_id && my.exercices[current_exercice_my].keys)">
<div class="card-header bg-success text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Solution du challenge
</div>
@ -117,13 +117,13 @@
<p>
Vérifiez les clefs que vous trouvez en comparant leur <a href="https://blake2.net/">BLAKE2b</a>&nbsp;:
</p>
<dl class="dl-horizontal" ng-repeat="key in my.exercices[current_exercice].keys">
<dl class="dl-horizontal" ng-repeat="key in my.exercices[current_exercice_my].keys">
<dt title="{{ key.slice(128) }}">{{ key.slice(128) }}</dt>
<dd><samp class="cksum">{{ key.slice(0, 128) }}</samp></dd>
</dl>
<div class="embed-responsive embed-responsive-16by9">
<iframe type="text/html" ng-if="my.exercices[current_exercice].video_uri" ng-src="{{ my.exercices[current_exercice].video_uri }}" class="embed-responsive-item">
Regardez la vidéo de résolution de cet exercice&nbsp;: <a ng-href="{{ my.exercices[current_exercice].video_uri }}">{{ my.exercices[current_exercice].video_uri }}</a>.
<iframe type="text/html" ng-if="my.exercices[current_exercice_my].video_uri" ng-src="{{ my.exercices[current_exercice_my].video_uri }}" class="embed-responsive-item">
Regardez la vidéo de résolution de cet exercice&nbsp;: <a ng-href="{{ my.exercices[current_exercice_my].video_uri }}">{{ my.exercices[current_exercice_my].video_uri }}</a>.
</iframe>
</div>
</div>

View File

@ -2,10 +2,12 @@ package fic
import (
"fmt"
"strings"
)
// exportedExercice is a structure representing a challenge, as exposed to players.
type exportedExercice struct {
// ExportedExercice is a structure representing a challenge, as exposed to players.
type ExportedExercice struct {
Id int64 `json:"id"`
Title string `json:"title"`
URLId string `json:"urlid"`
Gain int64 `json:"gain"`
@ -16,44 +18,48 @@ type exportedExercice struct {
// exportedTheme is a structure representing a Theme, as exposed to players.
type exportedTheme struct {
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Intro string `json:"intro"`
Exercices map[string]exportedExercice `json:"exercices"`
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Intro string `json:"intro"`
Exercices []ExportedExercice `json:"exercices"`
}
// Exportedthemes exports themes from the database, to be displayed to players.
func ExportThemes() (interface{}, error) {
if themes, err := GetThemes(); err != nil {
return nil, err
} else {
ret := map[string]exportedTheme{}
for _, theme := range themes {
if exercices, err := theme.GetExercices(); err != nil {
return nil, err
} else {
exos := map[string]exportedExercice{}
for _, exercice := range exercices {
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{
exercice.Title,
exercice.URLId,
exercice.Gain,
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
}
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name,
theme.URLId,
theme.Authors,
theme.Intro,
exos,
}
}
func ExportThemes() (ret map[string]exportedTheme, err error) {
var themes []Theme
if themes, err = GetThemes(); err != nil {
return
}
ret = map[string]exportedTheme{}
for _, theme := range themes {
var exercices []Exercice
if exercices, err = theme.GetExercices(); err != nil {
return
}
return ret, nil
var exos []ExportedExercice
for _, exercice := range exercices {
exos = append(exos, ExportedExercice{
exercice.Id,
exercice.Title,
exercice.URLId,
exercice.Gain,
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
})
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name[strings.Index(theme.Name, "-")+1:],
theme.URLId,
theme.Authors,
theme.Intro,
exos,
}
}
return
}