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

var tuto_progress = [
{
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"},
},
{
100: { title: "HTTP", label: "HTTP"},
101: { title: "HTTPS", label: "HTTPS"},
102: { title: "DNS", label: "DNS"},
103: { title: "Matrix", label: "Matrix"},
},
{
200: { title: "HTTP", label: "HTTP"},
201: { title: "HTTPS", label: "HTTPS"},
202: { title: "DNS", label: "DNS"},
203: { title: "Matrix", label: "Matrix"},
},
];
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")
})
.factory("StudentProgression", function($resource) {
return $resource("/api/students/:studentId/progress", { studentId: '@id' })
})
.factory("Challenge", function($resource) {
return $resource("/challenge/:challengeId", { challengeId: '@id' })
});
angular.module("AdLinApp")
.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;
}
})
.controller("StudentsController", function($scope, $interval, Student) {
$scope.students = Student.query();
var refreshStd = function() {
$scope.students = Student.query();
}
$interval(refreshStd, 1600000);
})
.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) {
if (ch.time && challenges[chid] !== undefined) {
challenges[chid].time = new Date(ch.time);
challenges[chid].recent = (Date.now() - ch.time)/1000;
if (recent < challenges[chid].time && tmpstats[chid] !== undefined)
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);
})
})
.controller("PingController", function($scope, $interval, $http) {
$scope.PING = false;
$scope.PING_time = '';
$scope.PING_ok = false;
var refreshPing = function() {
$http.get("/api/students/" + $scope.student.id + "/ping").then(function(response) {
$scope.PING_ok = response.data.State;
$scope.PING_time = new Date(response.data.Date);
$scope.PING = (Date.now() - $scope.PING_time)/1000;
});
}
$scope.$watch("student", function(student) {
student.$promise.then(function(std) {
refreshPing();
$interval(refreshPing, 15000);
})
})
})
.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) {
$scope.tuto_progress = tuto_progress;
$scope.mychallenges = {};
var refreshChal = function() {
$http.get("/api/students/" + $scope.student.id + "/progress").then(function(response) {
angular.forEach(response.data, function(ch, chid) {
if (ch.time) {
response.data[chid].time = new Date(ch.time);
response.data[chid].recent = (Date.now() - response.data[chid].time)/1000;
}
});
$scope.mychallenges = response.data
});
}
refreshChal();
$interval(refreshChal, 15750);
})