This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/token-validator/htdocs/js/adlin-dashboard.js

183 lines
6.0 KiB
JavaScript
Raw Normal View History

2019-03-25 22:14:53 +00:00
var tuto_progress = [
{
2020-02-27 14:29:41 +00:00
1: { title: "Is alive?", label: "t1"},
2: { title: "DMZ reached", label: "t2"},
3: { title: "HTTPS on + time", label: "t3"},
4: { title: "DNS ok", label: "t4"},
5: { title: "On Internet", label: "t5"},
6: { title: "Bonus caché", label: "b0"},
7: { title: "Bonus ICMP", label: "b1"},
8: { title: "Bonus disk", label: "b2"},
9: { title: "Bonus email", label: "b3"},
10: { title: "Uploaded SSH key", label: "ssh"},
2019-03-25 22:14:53 +00:00
},
{
100: { title: "HTTP", label: "HTTP"},
101: { title: "HTTPS", label: "HTTPS"},
102: { title: "DNS", label: "DNS"},
2019-03-26 12:16:02 +00:00
103: { title: "Matrix", label: "Matrix"},
2019-03-25 22:14:53 +00:00
},
2020-04-02 14:08:47 +00:00
{
200: { title: "HTTP", label: "HTTP"},
201: { title: "HTTPS", label: "HTTPS"},
202: { title: "DNS", label: "DNS"},
203: { title: "Matrix", label: "Matrix"},
},
2019-03-25 22:14:53 +00:00
];
2019-03-04 08:00:22 +00:00
angular.module("AdLinApp", ["ngResource", "ngSanitize"])
.factory("Student", function($resource) {
return $resource("/api/students/:studentId", { studentId: '@id' }, {
'update': {method: 'PUT'},
})
})
.factory("Progression", function($resource) {
return $resource("/api/progress")
})
2020-02-27 14:29:41 +00:00
.factory("StudentProgression", function($resource) {
return $resource("/api/students/:studentId/progress", { studentId: '@id' })
2020-02-27 14:29:41 +00:00
})
2019-03-04 08:00:22 +00:00
.factory("Challenge", function($resource) {
return $resource("/challenge/:challengeId", { challengeId: '@id' })
});
angular.module("AdLinApp")
2019-03-26 01:23:04 +00:00
.run(function($rootScope, $location) {
if (window.location.pathname.split("/").length >= 3) {
$rootScope.tutoid = parseInt(window.location.pathname.split("/")[2], 10);
if (isNaN($rootScope.tutoid)) {
$rootScope.onestudent = window.location.pathname.split("/")[2];
}
}
if (!$rootScope.tutoid || isNaN($rootScope.tutoid)) {
$rootScope.tutoid = 1;
}
$rootScope.tutoid--;
$rootScope.show_dropdown = false;
$rootScope.toogleDropdown = function() {
$rootScope.show_dropdown = !$rootScope.show_dropdown;
}
2019-03-26 01:23:04 +00:00
})
2019-03-04 08:00:22 +00:00
.controller("StudentsController", function($scope, $interval, Student) {
$scope.students = Student.query();
var refreshStd = function() {
$scope.students = Student.query();
}
$interval(refreshStd, 1600000);
})
2020-02-27 14:29:41 +00:00
.controller("StudentsProgressionController", function($scope, $interval, Progression) {
$scope.tuto_progress = tuto_progress;
$scope.stats = {};
$scope.students = {};
var refreshStd = function() {
var students = Progression.get();
students.$promise.then(function(response) {
var recent = new Date(Date.now() - 120000);
var tmpstats = {total:0};
angular.forEach(tuto_progress, function(tuto) {
angular.forEach(tuto, function(ch, chid) {
tmpstats[chid] = {"success":0, "warning":0};
});
});
angular.forEach(response, function(challenges, login) {
if (login[0] == "$") return;
tmpstats.total++;
angular.forEach(challenges, function(ch, chid) {
2020-03-27 12:10:05 +00:00
if (ch.time && challenges[chid] !== undefined) {
2020-02-27 14:29:41 +00:00
challenges[chid].time = new Date(ch.time);
challenges[chid].recent = (Date.now() - ch.time)/1000;
2020-03-27 12:10:05 +00:00
if (recent < challenges[chid].time && tmpstats[chid] !== undefined)
2020-02-27 14:29:41 +00:00
tmpstats[chid].success++;
}
if (tmpstats[chid] !== undefined)
tmpstats[chid].warning++;
});
if (login == "nemunaire")
challenges["img"] = "mercie_d"
else
challenges["img"] = login
$scope.students[login] = challenges;
});
$scope.stats = tmpstats;
})
}
refreshStd();
$interval(refreshStd, 9750);
})
.controller("StudentProgressionController", function($scope, $interval, $http, Student, StudentProgression) {
$scope.tuto_progress = tuto_progress;
var refreshStd = function() {
$scope.student = Student.get({studentId: $scope.onestudent})
$scope.img = $scope.onestudent == "nemunaire" ? "mercie_d" : $scope.onestudent
$scope.mychallenges = StudentProgression.get({studentId: $scope.onestudent})
$scope.mychallenges.$promise.then(function(mychallenges) {
angular.forEach(mychallenges, function(ch, chid) {
if (ch.time) {
mychallenges[chid].time = new Date(ch.time);
mychallenges[chid].recent = (Date.now() - mychallenges[chid].time)/1000;
}
});
})
$scope.student.$promise.then(function(student) {
$http.get("/api/students/" + $scope.student.id + "/ips").then(function(response) {
$scope.ips = response.data;
});
})
}
$scope.$watch("onestudent", function(onestudent) {
refreshStd();
$interval(refreshStd, 15000);
})
})
2019-03-04 08:00:22 +00:00
.controller("PingController", function($scope, $interval, $http) {
$scope.PING = false;
2019-03-26 12:16:02 +00:00
$scope.PING_time = '';
2020-02-27 14:29:41 +00:00
$scope.PING_ok = false;
var refreshPing = function() {
2019-03-04 08:00:22 +00:00
$http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) {
2020-02-27 14:29:41 +00:00
$scope.PING_ok = response.data.State;
$scope.PING_time = new Date(response.data.Date);
2019-03-26 23:28:41 +00:00
$scope.PING = (Date.now() - $scope.PING_time)/1000;
2019-03-04 08:00:22 +00:00
});
}
$scope.$watch("student", function(student) {
student.$promise.then(function(std) {
refreshPing();
$interval(refreshPing, 15000);
})
})
2019-03-04 08:00:22 +00:00
})
.controller("SSHController", function($scope, $interval, $http) {
$scope.SSH = false;
var refreshSSH = function() {
$http.get("/api/students/" + $scope.student.id + "/hassshkeys").then(function(response) {
$scope.SSH = response.data
});
}
refreshSSH();
$interval(refreshSSH, 15500);
})
.controller("ProgressionController", function($scope, $interval, $http) {
2019-03-25 22:14:53 +00:00
$scope.tuto_progress = tuto_progress;
2019-03-04 08:00:22 +00:00
$scope.mychallenges = {};
var refreshChal = function() {
$http.get("/api/students/" + $scope.student.id + "/progress").then(function(response) {
2019-03-26 01:23:04 +00:00
angular.forEach(response.data, function(ch, chid) {
if (ch.time) {
response.data[chid].time = new Date(ch.time);
2019-03-26 23:28:41 +00:00
response.data[chid].recent = (Date.now() - response.data[chid].time)/1000;
2019-03-26 01:23:04 +00:00
}
});
2019-03-04 08:00:22 +00:00
$scope.mychallenges = response.data
});
}
refreshChal();
$interval(refreshChal, 15750);
})