Retrieve time through X-FIC-Time header instead of time.json
This commit is contained in:
parent
c33390fa80
commit
6034246015
11 changed files with 107 additions and 131 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
|
|
||||||
|
@ -60,6 +61,8 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
|
||||||
resStatus = http.StatusNotFound
|
resStatus = http.StatusNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set("X-FIC-Time", fmt.Sprintf("%f", float64(time.Now().UnixNano()/1000)/1000000))
|
||||||
|
|
||||||
if str, found := ret.(string); found {
|
if str, found := ret.(string); found {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
|
|
|
@ -432,19 +432,31 @@ angular.module("FICApp")
|
||||||
|
|
||||||
.controller("SettingsController", function($scope, $rootScope, Settings, ROSettings, $location, $http) {
|
.controller("SettingsController", function($scope, $rootScope, Settings, ROSettings, $location, $http) {
|
||||||
$scope.config = Settings.get();
|
$scope.config = Settings.get();
|
||||||
|
$scope.config.$promise.then(function(response) {
|
||||||
|
$rootScope.settings.start = new Date(response.start);
|
||||||
|
$rootScope.settings.end = new Date(response.end);
|
||||||
|
$rootScope.settings.generation = new Date(response.generation);
|
||||||
|
})
|
||||||
$scope.configro = ROSettings.get();
|
$scope.configro = ROSettings.get();
|
||||||
$scope.duration = 240;
|
$scope.duration = 240;
|
||||||
|
|
||||||
$scope.saveSettings = function(msg) {
|
$scope.saveSettings = function(msg) {
|
||||||
if (msg === undefined) { msg = 'New settings saved!'; }
|
if (msg === undefined) { msg = 'New settings saved!'; }
|
||||||
|
var nStart = this.config.start;
|
||||||
|
var nEnd = this.config.end;
|
||||||
|
var nGen = this.config.generation;
|
||||||
this.config.$update(function() {
|
this.config.$update(function() {
|
||||||
$rootScope.newBox('success', msg);
|
$rootScope.newBox('success', msg);
|
||||||
|
$rootScope.settings.start = new Date(nStart);
|
||||||
|
$rootScope.settings.end = new Date(nEnd);
|
||||||
|
$rootScope.settings.generation = new Date(nGen);
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
$rootScope.newBox('danger', 'An error occurs when saving settings:', response.data);
|
$rootScope.newBox('danger', 'An error occurs when saving settings:', response.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$scope.regenerate = function() {
|
$scope.regenerate = function() {
|
||||||
this.config.generation = (new Date()).toISOString();
|
this.config.generation = (new Date()).toISOString();
|
||||||
|
$rootScope.settings.generation = new Date(this.config.generation);
|
||||||
$scope.saveSettings("Regeneration in progress...");
|
$scope.saveSettings("Regeneration in progress...");
|
||||||
}
|
}
|
||||||
$scope.launchChallenge = function() {
|
$scope.launchChallenge = function() {
|
||||||
|
@ -850,7 +862,7 @@ angular.module("FICApp")
|
||||||
"id_assignee": $scope.whoami,
|
"id_assignee": $scope.whoami,
|
||||||
"content": $scope.ndescription
|
"content": $scope.ndescription
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function(response) {
|
||||||
$location.url("/claims/" + $scope.claim.id + "/");
|
$location.url("/claims/" + $scope.claim.id + "/");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1288,21 +1300,26 @@ angular.module("FICApp")
|
||||||
presenceCal($scope, "#presenceCal", res);
|
presenceCal($scope, "#presenceCal", res);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.controller("CountdownController", function($scope, $rootScope, $http, $timeout) {
|
.controller("CountdownController", function(Settings, $scope, $rootScope, $http, $interval) {
|
||||||
$scope.time = {};
|
$scope.time = {};
|
||||||
|
|
||||||
function updTime() {
|
function updTime() {
|
||||||
$timeout.cancel($scope.cbm);
|
if (sessionStorage.userService && $rootScope.settings) {
|
||||||
$scope.cbm = $timeout(updTime, 1000);
|
|
||||||
if (sessionStorage.userService) {
|
|
||||||
var time = angular.fromJson(sessionStorage.userService);
|
var time = angular.fromJson(sessionStorage.userService);
|
||||||
var srv_cur = (Date.now() + (time.cu * 1000 - time.he)) / 1000;
|
var settings = $rootScope.settings;
|
||||||
var remain = time.du;
|
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
||||||
if (time.st > 0 && time.st <= srv_cur) {
|
|
||||||
|
var remain = 0;
|
||||||
|
if (settings.start > 0 && settings.start > srv_cur) {
|
||||||
|
$scope.startIn = Math.floor((settings.start - srv_cur) / 1000);
|
||||||
|
remain = settings.end - settings.start;
|
||||||
|
} else if (settings.end > srv_cur) {
|
||||||
$scope.startIn = 0;
|
$scope.startIn = 0;
|
||||||
remain = time.st + time.du - srv_cur;
|
remain = settings.end - srv_cur;
|
||||||
} else if (time.st > 0) {
|
|
||||||
$scope.startIn = Math.floor(time.st - srv_cur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remain = remain / 1000;
|
||||||
|
|
||||||
if (remain < 0) {
|
if (remain < 0) {
|
||||||
remain = 0;
|
remain = 0;
|
||||||
$scope.time.end = true;
|
$scope.time.end = true;
|
||||||
|
@ -1314,22 +1331,35 @@ angular.module("FICApp")
|
||||||
$scope.time.end = false;
|
$scope.time.end = false;
|
||||||
$scope.time.expired = false;
|
$scope.time.expired = false;
|
||||||
}
|
}
|
||||||
$scope.time.start = time.st * 1000;
|
|
||||||
$scope.time.duration = time.du * 1000;
|
|
||||||
$scope.time.remaining = remain;
|
$scope.time.remaining = remain;
|
||||||
$scope.time.hours = Math.floor(remain / 3600);
|
$scope.time.hours = Math.floor(remain / 3600);
|
||||||
$scope.time.minutes = Math.floor((remain % 3600) / 60);
|
$scope.time.minutes = Math.floor((remain % 3600) / 60);
|
||||||
$scope.time.seconds = Math.floor(remain % 60);
|
$scope.time.seconds = Math.floor(remain % 60);
|
||||||
$rootScope.time = $scope.time;
|
$rootScope.time = $scope.time;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
$interval(updTime, 1000);
|
||||||
|
|
||||||
|
$rootScope.updTime = function(response) {
|
||||||
|
sessionStorage.userService = angular.toJson({
|
||||||
|
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
||||||
|
"he": (new Date()).getTime(),
|
||||||
|
});
|
||||||
|
updTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
$http.get("/time.json").then(function(response) {
|
function refresh() {
|
||||||
var time = response.data;
|
$http.get("/api/settings.json").then(function(response) {
|
||||||
time.he = (new Date()).getTime();
|
response.data.start = new Date(response.data.start);
|
||||||
sessionStorage.userService = angular.toJson(time);
|
response.data.end = new Date(response.data.end);
|
||||||
updTime();
|
response.data.generation = new Date(response.data.generation);
|
||||||
});
|
$rootScope.settings = response.data;
|
||||||
|
$rootScope.updTime(response);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
$interval(refresh, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function solvedByLevelPie(location, data) {
|
function solvedByLevelPie(location, data) {
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/admin/api"
|
|
||||||
"srs.epita.fr/fic-server/frontend/time"
|
|
||||||
"srs.epita.fr/fic-server/settings"
|
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
api.Router().GET("/time.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
||||||
if config, err := settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError)
|
|
||||||
} else {
|
|
||||||
time.ChallengeStart = config.Start
|
|
||||||
time.ChallengeEnd = config.End
|
|
||||||
time.TimeHandler{}.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -160,18 +160,6 @@ server {
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /time.json {
|
|
||||||
proxy_pass http://localhost:8080/time.json;
|
|
||||||
proxy_method GET;
|
|
||||||
proxy_pass_request_body off;
|
|
||||||
proxy_set_header Content-Length "";
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_set_header Host localhost;
|
|
||||||
proxy_redirect off;
|
|
||||||
proxy_cache STATIC;
|
|
||||||
proxy_cache_valid 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
location = /events.json {
|
location = /events.json {
|
||||||
proxy_pass http://localhost:8081/api/events/;
|
proxy_pass http://localhost:8081/api/events/;
|
||||||
proxy_method GET;
|
proxy_method GET;
|
||||||
|
|
|
@ -131,6 +131,7 @@ server {
|
||||||
location = /settings.json {
|
location = /settings.json {
|
||||||
root /srv/SETTINGS/;
|
root /srv/SETTINGS/;
|
||||||
expires epoch;
|
expires epoch;
|
||||||
|
add_header X-FIC-time $msec;
|
||||||
add_header Cache-Control no-cache;
|
add_header Cache-Control no-cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,15 +162,4 @@ server {
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
proxy_set_header X-Forwarded-For $remote_addr;
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /time.json {
|
|
||||||
proxy_pass http://frontend:8080/time.json;
|
|
||||||
proxy_method GET;
|
|
||||||
proxy_pass_request_body off;
|
|
||||||
proxy_set_header Content-Length "";
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_redirect off;
|
|
||||||
proxy_cache STATIC;
|
|
||||||
proxy_cache_valid 1s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
fronttime "srs.epita.fr/fic-server/frontend/time"
|
|
||||||
"srs.epita.fr/fic-server/settings"
|
"srs.epita.fr/fic-server/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +50,6 @@ func main() {
|
||||||
http.Handle(fmt.Sprintf("%s/registration/", *prefix), http.StripPrefix(fmt.Sprintf("%s/registration/", *prefix), submissionChecker{"registration", RegistrationHandler}))
|
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/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}))
|
||||||
http.Handle(fmt.Sprintf("%s/time.json", *prefix), http.StripPrefix(*prefix, fronttime.TimeHandler{}))
|
|
||||||
|
|
||||||
if *simulator != "" {
|
if *simulator != "" {
|
||||||
if _, err := os.Stat(path.Join(*teamsDir, *simulator)); os.IsNotExist(err) {
|
if _, err := os.Stat(path.Join(*teamsDir, *simulator)); os.IsNotExist(err) {
|
||||||
|
|
|
@ -5,13 +5,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
fronttime "srs.epita.fr/fic-server/frontend/time"
|
|
||||||
"srs.epita.fr/fic-server/settings"
|
"srs.epita.fr/fic-server/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var startedFile = "started"
|
var startedFile = "started"
|
||||||
|
|
||||||
var touchTimer *time.Timer = nil
|
var touchTimer *time.Timer = nil
|
||||||
|
var challengeStart time.Time
|
||||||
|
var challengeEnd time.Time
|
||||||
|
|
||||||
func touchStartedFile() {
|
func touchStartedFile() {
|
||||||
if fd, err := os.Create(startedFile); err == nil {
|
if fd, err := os.Create(startedFile); err == nil {
|
||||||
|
@ -23,10 +24,21 @@ func touchStartedFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadSettings(config settings.FICSettings) {
|
func reloadSettings(config settings.FICSettings) {
|
||||||
if fronttime.ChallengeStart != config.Start || fronttime.ChallengeEnd != config.End {
|
if challengeStart != config.Start || challengeEnd != config.End {
|
||||||
if touchTimer != nil {
|
if touchTimer != nil {
|
||||||
touchTimer.Stop()
|
touchTimer.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Start.Unix() == 0 {
|
||||||
|
log.Println("WARNING: No challenge start defined!")
|
||||||
|
|
||||||
|
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
|
||||||
|
os.Remove(startedFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
startSub := config.Start.Sub(time.Now())
|
startSub := config.Start.Sub(time.Now())
|
||||||
if startSub > 0 {
|
if startSub > 0 {
|
||||||
log.Println("Challenge will starts at", config.Start, "in", startSub)
|
log.Println("Challenge will starts at", config.Start, "in", startSub)
|
||||||
|
@ -42,8 +54,8 @@ func reloadSettings(config settings.FICSettings) {
|
||||||
}
|
}
|
||||||
log.Println("Challenge ends on", config.End)
|
log.Println("Challenge ends on", config.End)
|
||||||
|
|
||||||
fronttime.ChallengeStart = config.Start
|
challengeStart = config.Start
|
||||||
fronttime.ChallengeEnd = config.End
|
challengeEnd = config.End
|
||||||
} else {
|
} else {
|
||||||
log.Println("Configuration reloaded, but start/end times doesn't change.")
|
log.Println("Configuration reloaded, but start/end times doesn't change.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,22 +19,22 @@
|
||||||
<div class="navbar navbar-expand-lg navbar-dark bg-dark text-light">
|
<div class="navbar navbar-expand-lg navbar-dark bg-dark text-light">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="col-md-auto">
|
<div class="col-md-auto">
|
||||||
<a href="https://www.forum-fic.com/" ng-if="!(time.start || my.team_id)">
|
<a href="https://www.forum-fic.com/" ng-if="!(time.remaining === undefined || my.team_id)">
|
||||||
<img src="/img/fic.png" alt="Forum International de la Cybersécurité" class="center-block">
|
<img src="/img/fic.png" alt="Forum International de la Cybersécurité" class="center-block">
|
||||||
</a>
|
</a>
|
||||||
<a href="/" ng-if="(time.start || my.team_id)" ng-cloak>
|
<a href="/" ng-if="(time.remaining === undefined || my.team_id)" ng-cloak>
|
||||||
<img src="/img/fic.png" alt="Forum International de la Cybersécurité" class="center-block">
|
<img src="/img/fic.png" alt="Forum International de la Cybersécurité" class="center-block">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="clock" class="col-md-auto text-center" ng-hide="1">Chargement...</div>
|
<div id="clock" class="col-md-auto text-center" ng-hide="1">Chargement...</div>
|
||||||
<div id="clock" class="col-md-auto text-center" ng-class="{expired: time.expired, end: time.end}" ng-if="time.start || my.team_id" ng-cloak>
|
<div id="clock" class="col-md-auto text-center" ng-class="{expired: time.expired, end: time.end}" ng-if="time.remaining !== undefined && settings.end - settings.start > 0" ng-cloak>
|
||||||
<span id="hours">{{ time.hours | time }}</span>
|
<span id="hours">{{ time.hours | time }}</span>
|
||||||
<span class="point">:</span>
|
<span class="point">:</span>
|
||||||
<span id="min">{{ time.minutes | time }}</span>
|
<span id="min">{{ time.minutes | time }}</span>
|
||||||
<span class="point">:</span>
|
<span class="point">:</span>
|
||||||
<span id="sec">{{ time.seconds | time }}</span>
|
<span id="sec">{{ time.seconds | time }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="clock" class="col-md-auto btn-group btn-group-lg" ng-if="!(time.start || my.team_id)" ng-cloak>
|
<div id="clock" class="col-md-auto btn-group btn-group-lg" ng-if="time.remaining === undefined || settings.end - settings.start <= 0" ng-cloak>
|
||||||
<a class="btn btn-light" href="/">
|
<a class="btn btn-light" href="/">
|
||||||
<span class="glyphicon glyphicon-home"></span> Accueil
|
<span class="glyphicon glyphicon-home"></span> Accueil
|
||||||
</a>
|
</a>
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
<span class="teamname">{{ my.name }}</span>
|
<span class="teamname">{{ my.name }}</span>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
<span class="navbar-text text-light" ng-show="!my.team_id && time.start" ng-cloak>
|
<span class="navbar-text text-light" ng-show="!my.team_id && time.remaining === undefined" ng-cloak>
|
||||||
<a ng-href="/register" class="badge badge-warning" role="button">
|
<a ng-href="/register" class="badge badge-warning" role="button">
|
||||||
Inscription
|
Inscription
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -45,17 +45,37 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
|
|
||||||
$('[data-toggle="popover"]').popover();
|
$('[data-toggle="popover"]').popover();
|
||||||
|
|
||||||
|
$rootScope.recvTime = function(response) {
|
||||||
|
sessionStorage.userService = angular.toJson({
|
||||||
|
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
||||||
|
"he": (new Date()).getTime(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updTime() {
|
function updTime() {
|
||||||
if (sessionStorage.userService) {
|
if (sessionStorage.userService && $rootScope.settings) {
|
||||||
var time = angular.fromJson(sessionStorage.userService);
|
var time = angular.fromJson(sessionStorage.userService);
|
||||||
var srv_cur = (Date.now() + (time.cu * 1000 - time.he)) / 1000;
|
var settings = $rootScope.settings;
|
||||||
var remain = time.du;
|
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
||||||
if (time.st == Math.floor(srv_cur)) {
|
|
||||||
|
if (Math.floor(settings.start / 1000) == Math.floor(srv_cur / 1000)) {
|
||||||
$rootScope.refresh(true);
|
$rootScope.refresh(true);
|
||||||
}
|
}
|
||||||
if (time.st > 0 && time.st <= srv_cur) {
|
|
||||||
remain = time.st + time.du - srv_cur;
|
var remain = 0;
|
||||||
|
if (settings.start == 0) {
|
||||||
|
$rootScope.time = {};
|
||||||
|
return
|
||||||
|
} else if (settings.start > srv_cur) {
|
||||||
|
$rootScope.startIn = Math.floor((settings.start - srv_cur) / 1000);
|
||||||
|
remain = settings.end - settings.start;
|
||||||
|
} else if (settings.end > srv_cur) {
|
||||||
|
$rootScope.startIn = 0;
|
||||||
|
remain = settings.end - srv_cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remain = remain / 1000;
|
||||||
|
|
||||||
if (remain < 0) {
|
if (remain < 0) {
|
||||||
remain = 0;
|
remain = 0;
|
||||||
$rootScope.time.end = true;
|
$rootScope.time.end = true;
|
||||||
|
@ -67,8 +87,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
$rootScope.time.end = false;
|
$rootScope.time.end = false;
|
||||||
$rootScope.time.expired = false;
|
$rootScope.time.expired = false;
|
||||||
}
|
}
|
||||||
$rootScope.time.start = time.st * 1000;
|
|
||||||
$rootScope.time.duration = time.du;
|
|
||||||
$rootScope.time.remaining = remain;
|
$rootScope.time.remaining = remain;
|
||||||
$rootScope.time.hours = Math.floor(remain / 3600);
|
$rootScope.time.hours = Math.floor(remain / 3600);
|
||||||
$rootScope.time.minutes = Math.floor((remain % 3600) / 60);
|
$rootScope.time.minutes = Math.floor((remain % 3600) / 60);
|
||||||
|
@ -95,13 +114,12 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
if (!justMy) {
|
if (!justMy) {
|
||||||
$timeout.cancel($scope.cbr);
|
$timeout.cancel($scope.cbr);
|
||||||
$scope.cbr = $timeout($rootScope.refresh, 42000);
|
$scope.cbr = $timeout($rootScope.refresh, 42000);
|
||||||
$http.get("/time.json").then(function(response) {
|
|
||||||
var time = response.data;
|
|
||||||
time.he = (new Date()).getTime();
|
|
||||||
sessionStorage.userService = angular.toJson(time);
|
|
||||||
});
|
|
||||||
$http.get("/settings.json").then(function(response) {
|
$http.get("/settings.json").then(function(response) {
|
||||||
$scope.settings = response.data;
|
$rootScope.recvTime(response);
|
||||||
|
response.data.start = new Date(response.data.start);
|
||||||
|
response.data.end = new Date(response.data.end);
|
||||||
|
response.data.generation = new Date(response.data.generation);
|
||||||
|
$rootScope.settings = response.data;
|
||||||
});
|
});
|
||||||
$http.get("/themes.json").then(function(response) {
|
$http.get("/themes.json").then(function(response) {
|
||||||
$scope.themes = response.data;
|
$scope.themes = response.data;
|
||||||
|
|
|
@ -6,12 +6,10 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
fronttime "srs.epita.fr/fic-server/frontend/time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
|
func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
|
||||||
if time.Now().Sub(fronttime.ChallengeEnd) > 0 {
|
if time.Now().Sub(challengeEnd) > 0 {
|
||||||
http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusForbidden)
|
http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package time
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ChallengeStart time.Time
|
|
||||||
var ChallengeEnd time.Time = time.Unix(0, 0)
|
|
||||||
|
|
||||||
type TimeHandler struct {}
|
|
||||||
|
|
||||||
type timeObject struct {
|
|
||||||
Started int64 `json:"st"`
|
|
||||||
Time int64 `json:"cu"`
|
|
||||||
Duration int `json:"du"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TimeHandler) 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]\n", r.RemoteAddr, r.Method, r.URL.Path, r.UserAgent())
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
if j, err := json.Marshal(timeObject{ChallengeStart.Unix(), time.Now().Unix(), int(ChallengeEnd.Sub(ChallengeStart).Seconds())}); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write(j)
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue