Commit a0f630f257300404d647ae418056c3bd55385dfe
1 parent
11329db5
Il est désormais possible de visualiser l'état du réseau de capteurs
Showing
10 changed files
with
260 additions
and
4 deletions
Show diff stats
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -12,6 +12,10 @@ import org.springframework.web.servlet.ModelAndView; |
12 | 12 | import java.io.*; |
13 | 13 | import java.sql.Timestamp; |
14 | 14 | import java.text.ParseException; |
15 | +import java.time.Duration; | |
16 | +import java.time.LocalDateTime; | |
17 | +import java.time.LocalTime; | |
18 | +import java.time.format.DateTimeFormatter; | |
15 | 19 | import java.util.*; |
16 | 20 | |
17 | 21 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
... | ... | @@ -26,7 +30,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
26 | 30 | |
27 | 31 | import java.text.SimpleDateFormat; |
28 | 32 | import java.util.Date; |
29 | -import java.util.Locale; | |
30 | 33 | |
31 | 34 | @Controller |
32 | 35 | @MultipartConfig(fileSizeThreshold = 100000000) //à changer, taille max des fichiers |
... | ... | @@ -262,7 +265,6 @@ public class MainController { |
262 | 265 | |
263 | 266 | } |
264 | 267 | |
265 | - | |
266 | 268 | @GetMapping(path="/login") |
267 | 269 | public ModelAndView login() { |
268 | 270 | ModelAndView modelAndView = new ModelAndView(); |
... | ... | @@ -274,7 +276,6 @@ public class MainController { |
274 | 276 | public ModelAndView getAllUsers() { |
275 | 277 | ModelAndView modelAndView = new ModelAndView(); |
276 | 278 | modelAndView.setViewName("all"); |
277 | - | |
278 | 279 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
279 | 280 | Customer customer = customerRepository.findByEmail(auth.getName()); |
280 | 281 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
... | ... | @@ -286,6 +287,85 @@ public class MainController { |
286 | 287 | return modelAndView; |
287 | 288 | } |
288 | 289 | |
290 | + public static List<ArrayList<String>> getSensorsUsed(List<Node> nodes) { | |
291 | + Yaml yaml = new Yaml(new Constructor(UpdateYAML.class)); | |
292 | + InputStream inputStream = null; | |
293 | + List<UpdateYAML> updateYAMLS = new ArrayList<>(); | |
294 | + List<String> state_sensor = new ArrayList<>(); | |
295 | + File dir = new File("toflash"); | |
296 | + if(dir.isDirectory()) { | |
297 | + String s[] = dir.list(); | |
298 | + for (int i = 0; i < s.length; i++) { | |
299 | + if(s[i].endsWith("yml.started")) { | |
300 | + state_sensor.add(i,"started"); | |
301 | + } | |
302 | + else{ | |
303 | + state_sensor.add(i,"programmed"); | |
304 | + } | |
305 | + try { | |
306 | + inputStream = new FileInputStream(new File("toflash/" + s[i])); | |
307 | + UpdateYAML update = yaml.load(inputStream); | |
308 | + updateYAMLS.add(update); | |
309 | + } catch (FileNotFoundException e) { | |
310 | + e.printStackTrace(); | |
311 | + } | |
312 | + } | |
313 | + } | |
314 | + List<ArrayList<String>> table = new ArrayList<>(); | |
315 | + System.out.println("size = " + updateYAMLS.size()); | |
316 | + int i=0, j=0, k=0; | |
317 | + | |
318 | + for(Node node : nodes){ | |
319 | + table.add(new ArrayList<>()); | |
320 | + for(Sensor sensor : node.getSensors()){ | |
321 | + for(UpdateYAML update : updateYAMLS) { | |
322 | + for(String sensorUpdate : update.getNodesSplited()){ | |
323 | + if(sensor.getName().equals(sensorUpdate)){ | |
324 | + DateTimeFormatter formatter_date = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"); | |
325 | + DateTimeFormatter formatter_time = DateTimeFormatter.ofPattern("HH:mm"); | |
326 | + LocalDateTime updateDate = LocalDateTime.parse(update.getDate(),formatter_date); | |
327 | + LocalDateTime now = LocalDateTime.now(); | |
328 | + if(state_sensor.get(k).equals("started")){ | |
329 | + System.out.println("Time : " + update.getTime()); | |
330 | + System.out.println("duration between in minutes " + Duration.between(now,updateDate).toMinutes()); | |
331 | + LocalTime duration = LocalTime.parse(update.getTime(),formatter_time); | |
332 | + updateDate = updateDate.plusMinutes(duration.getMinute()); | |
333 | + updateDate = updateDate.plusHours(duration.getHour()); | |
334 | + table.get(i).add(j,"utilisé (disponible dans " + Duration.between(now,updateDate).toHours() + "h " + (Duration.between(now,updateDate).toMinutes())%60 + "min)"); | |
335 | + } | |
336 | + else if(state_sensor.get(k).equals("programmed")){ | |
337 | + table.get(i).add(j,"programmé (débute dans " + Duration.between(now,updateDate).toHours() + "h " + (Duration.between(now,updateDate).toMinutes())%60 + "min)"); | |
338 | + } | |
339 | + } | |
340 | + } | |
341 | + k++; | |
342 | + } | |
343 | + k=0; | |
344 | + if(table.get(i).size()==j){ | |
345 | + System.out.println("fonctionne"); | |
346 | + table.get(i).add(j,"disponible"); | |
347 | + } | |
348 | + j++; | |
349 | + } | |
350 | + j=0; | |
351 | + i++; | |
352 | + } | |
353 | + System.out.println("table : " + table); | |
354 | + return table; | |
355 | + } | |
356 | + | |
357 | + @GetMapping(path="/history") | |
358 | + public ModelAndView displayHistory() { | |
359 | + ModelAndView modelAndView = new ModelAndView(); | |
360 | + modelAndView.setViewName("history"); | |
361 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
362 | + Customer customer = customerRepository.findByEmail(auth.getName()); | |
363 | + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | |
364 | + modelAndView.addObject("customerRole", customer.getRole()); | |
365 | + modelAndView.addObject("nodes", nodeRepository.findAll()); | |
366 | + modelAndView.addObject("is_used", getSensorsUsed(nodeRepository.findAll())); | |
367 | + return modelAndView; | |
368 | + } | |
289 | 369 | |
290 | 370 | public static String findFile(String filename) { |
291 | 371 | File dir = new File("files"); | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java
... | ... | @@ -34,6 +34,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { |
34 | 34 | http |
35 | 35 | .authorizeRequests() |
36 | 36 | .antMatchers("/home").hasAnyAuthority("USER","ADMIN") |
37 | + .antMatchers("/history").hasAnyAuthority("USER","ADMIN") | |
37 | 38 | .antMatchers("/registration").hasAuthority("ADMIN") |
38 | 39 | .antMatchers("/config").hasAuthority("ADMIN") |
39 | 40 | .antMatchers("/all").hasAuthority("ADMIN") | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java
0 → 100644
... | ... | @@ -0,0 +1,80 @@ |
1 | +package com.PFE.ServerManager; | |
2 | + | |
3 | +import java.util.HashSet; | |
4 | +import java.util.Set; | |
5 | + | |
6 | +public class UpdateYAML { | |
7 | + | |
8 | + private String date; | |
9 | + private String file; | |
10 | + private Set<String> nodes; | |
11 | + private String exp_id; | |
12 | + private String name; | |
13 | + private String time; | |
14 | + private String arch; | |
15 | + private String dir; | |
16 | + | |
17 | + public void setDate(String date) { | |
18 | + this.date = date; | |
19 | + } | |
20 | + public String getDate() { | |
21 | + return date; | |
22 | + } | |
23 | + | |
24 | + public void setFile(String file) { | |
25 | + this.file = file; | |
26 | + } | |
27 | + public String getFile() { | |
28 | + return file; | |
29 | + } | |
30 | + | |
31 | + public void setNodes(Set<String> nodes) { | |
32 | + this.nodes = nodes; | |
33 | + } | |
34 | + public Set<String> getNodes() { | |
35 | + return nodes; | |
36 | + } | |
37 | + public Set<String> getNodesSplited() { | |
38 | + Set<String> nodesSplited = new HashSet<>(); | |
39 | + for(String node : nodes){ | |
40 | + nodesSplited.add(node.split("@")[0]); | |
41 | + } | |
42 | + System.out.println(nodesSplited); | |
43 | + return nodesSplited; | |
44 | + } | |
45 | + | |
46 | + public void setArch(String arch) { | |
47 | + this.arch = arch; | |
48 | + } | |
49 | + public String getArch() { | |
50 | + return arch; | |
51 | + } | |
52 | + | |
53 | + public void setExp_id(String exp_id) { | |
54 | + this.exp_id = exp_id; | |
55 | + } | |
56 | + public String getExp_id() { | |
57 | + return exp_id; | |
58 | + } | |
59 | + | |
60 | + public void setDir(String dir) { | |
61 | + this.dir = dir; | |
62 | + } | |
63 | + public String getDir() { | |
64 | + return dir; | |
65 | + } | |
66 | + | |
67 | + public void setName(String name) { | |
68 | + this.name = name; | |
69 | + } | |
70 | + public String getName() { | |
71 | + return name; | |
72 | + } | |
73 | + | |
74 | + public void setTime(String time) { | |
75 | + this.time = time; | |
76 | + } | |
77 | + public String getTime() { | |
78 | + return time; | |
79 | + } | |
80 | +} | ... | ... |
PFE06/src/main/resources/application.properties
... | ... | @@ -14,7 +14,7 @@ spring.datasource.username=postgres |
14 | 14 | spring.datasource.password=glopglop |
15 | 15 | |
16 | 16 | # montre les communications JPA avec la BDD |
17 | -spring.jpa.show-sql = true | |
17 | +# spring.jpa.show-sql = true | |
18 | 18 | |
19 | 19 | # exécute le fichier data.sql pour préciser le role ADMIN |
20 | 20 | spring.datasource.initialization-mode=always | ... | ... |
PFE06/src/main/resources/templates/all.html
... | ... | @@ -23,9 +23,11 @@ |
23 | 23 | <a class="nav-item nav-link" th:href="@{/registration}">Enregistrer des utilisateurs</a> |
24 | 24 | <a class="nav-item nav-link active" th:href="@{/all}">Liste des utilisateurs</a> |
25 | 25 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
26 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
26 | 27 | </div> |
27 | 28 | <div th:remove="tag" th:case="'USER'"> |
28 | 29 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
30 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
29 | 31 | </div> |
30 | 32 | </div> |
31 | 33 | </div> | ... | ... |
... | ... | @@ -0,0 +1,84 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html xmlns:th="http://www.thymeleaf.org"> | |
3 | +<head> | |
4 | + <meta charset="utf-8"> | |
5 | + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
6 | + <link rel="stylesheet" th:href="@{/css/all.css}"> | |
7 | + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | |
8 | + <title>Etat actuel du réseau</title> | |
9 | +</head> | |
10 | +<body> | |
11 | +<!-- NAV BAR --> | |
12 | +<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | |
13 | + <div class="container"> | |
14 | + <a th:href="@{/home}"><span class="navbar-brand"><img style="max-width:32px;" src="/pfelogo.png"></span></a> | |
15 | + <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> | |
16 | + <span class="navbar-toggler-icon"></span> | |
17 | + </button> | |
18 | + <div class="collapse navbar-collapse" id="navbarNavAltMarkup"> | |
19 | + <div class="navbar-nav mr-auto"> | |
20 | + <a class="nav-item nav-link" th:href="@{/upload}">Uploader un fichier</a> | |
21 | + <div th:remove="tag" th:switch="${customerRole}"> | |
22 | + <div th:remove="tag" th:case="'ADMIN'"> | |
23 | + <a class="nav-item nav-link" th:href="@{/registration}">Enregistrer des utilisateurs</a> | |
24 | + <a class="nav-item nav-link" th:href="@{/all}">Liste des utilisateurs</a> | |
25 | + <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> | |
26 | + <a class="nav-item nav-link active" th:href="@{/history}">Etat du réseau</a> | |
27 | + </div> | |
28 | + <div th:remove="tag" th:case="'USER'"> | |
29 | + <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> | |
30 | + <a class="nav-item nav-link active" th:href="@{/history}">Etat du réseau</a> | |
31 | + </div> | |
32 | + </div> | |
33 | + </div> | |
34 | + </div> | |
35 | + <div class="collapse navbar-collapse ml-3" id="navbarNavAltMarkup2" > | |
36 | + <div class="navbar-nav ml-auto"> | |
37 | + <a class="nav-item nav-link btn btn-danger active" th:href="@{/logout}">Déconnexion</a> | |
38 | + </div> | |
39 | + </div> | |
40 | + </div> | |
41 | +</nav> | |
42 | + | |
43 | + | |
44 | +<!-- TABLE PART --> | |
45 | + | |
46 | +<div class="container"> | |
47 | + <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Réseau</h1> | |
48 | + <table class="table table-striped table-bordered"> | |
49 | + <tr> | |
50 | + <th scope="col">Nom</th> | |
51 | + <th scope="col">IP</th> | |
52 | + <th scope="col">Architecture</th> | |
53 | + <th scope="col">Capteurs</th> | |
54 | + <th scope="col">Etat</th> | |
55 | + </tr> | |
56 | + <tr th:each="prod,status : ${nodes}"> | |
57 | + <td th:text="${prod.getName()}">Team</td> | |
58 | + <td th:text="${prod.getIp()}">IP</td> | |
59 | + <td th:text="${prod.getArch()}">Arch</td> | |
60 | + <td> | |
61 | + <div th:each="sensor : ${prod.getSensors()}" th:utext="${sensor.getName()}"></div> | |
62 | + </td> | |
63 | + <td> | |
64 | + <div th:each="value : ${is_used[status.index]}"> | |
65 | + <div th:utext="${value}"></div> | |
66 | + <!--<div th:if="${value}==1">utilisé</div> | |
67 | + <div th:if="${value}==0">disponible</div>--> | |
68 | + </div> | |
69 | + </td> | |
70 | + <!--<td> | |
71 | + <div th:each="sensor : ${prod.getSensors()}"> | |
72 | + <div th:each="update : ${updates}" th:if="${update.getNodesSplited().contains(sensor.getName())}">utilisé</div> | |
73 | + </div> | |
74 | + </td>--> | |
75 | + </tr> | |
76 | + </table> | |
77 | +</div> | |
78 | + | |
79 | +<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> | |
80 | +<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
81 | +<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> | |
82 | +<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> | |
83 | +</body> | |
84 | +</html> | ... | ... |
PFE06/src/main/resources/templates/home.html
... | ... | @@ -28,9 +28,11 @@ |
28 | 28 | <a class="nav-item nav-link" th:href="@{/registration}">Enregistrer des utilisateurs</a> |
29 | 29 | <a class="nav-item nav-link" th:href="@{/all}">Liste des utilisateurs</a> |
30 | 30 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
31 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
31 | 32 | </div> |
32 | 33 | <div th:remove="tag" th:case="'USER'"> |
33 | 34 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
35 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
34 | 36 | </div> |
35 | 37 | </div> |
36 | 38 | </div> | ... | ... |
PFE06/src/main/resources/templates/registration.html
... | ... | @@ -22,9 +22,11 @@ |
22 | 22 | <a class="nav-item nav-link active" th:href="@{/registration}">Enregistrer des utilisateurs</a> |
23 | 23 | <a class="nav-item nav-link" th:href="@{/all}">Liste des utilisateurs</a> |
24 | 24 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
25 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
25 | 26 | </div> |
26 | 27 | <div th:remove="tag" th:case="'USER'"> |
27 | 28 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
29 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
28 | 30 | </div> |
29 | 31 | </div> |
30 | 32 | </div> | ... | ... |
PFE06/src/main/resources/templates/update.html
... | ... | @@ -28,9 +28,11 @@ |
28 | 28 | <a class="nav-item nav-link" th:href="@{/registration}">Enregistrer des utilisateurs</a> |
29 | 29 | <a class="nav-item nav-link" th:href="@{/all}">Liste des utilisateurs</a> |
30 | 30 | <a class="nav-item nav-link active" th:href="@{/update}">Paramétrer une mise à jour</a> |
31 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
31 | 32 | </div> |
32 | 33 | <div th:remove="tag" th:case="'USER'"> |
33 | 34 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
35 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
34 | 36 | </div> |
35 | 37 | </div> |
36 | 38 | </div> |
... | ... | @@ -128,6 +130,7 @@ nodes: |
128 | 130 | <button id="allDone" type="button" class="btn btn-primary">Terminer</button> |
129 | 131 | <button id="nextNode" type="button" class="btn btn-secondary">></button> |
130 | 132 | |
133 | + | |
131 | 134 | <!-- The Modal --> |
132 | 135 | <div class="modal fade" id="networkDisplay"> |
133 | 136 | <div class="modal-dialog modal-dialog-centered"> | ... | ... |
PFE06/src/main/resources/templates/upload.html
... | ... | @@ -28,9 +28,11 @@ |
28 | 28 | <a class="nav-item nav-link" th:href="@{/registration}">Enregistrer des utilisateurs</a> |
29 | 29 | <a class="nav-item nav-link" th:href="@{/all}">Liste des utilisateurs</a> |
30 | 30 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
31 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
31 | 32 | </div> |
32 | 33 | <div th:remove="tag" th:case="'USER'"> |
33 | 34 | <a class="nav-item nav-link" th:href="@{/update}">Paramétrer une mise à jour</a> |
35 | + <a class="nav-item nav-link" th:href="@{/history}">Etat du réseau</a> | |
34 | 36 | </div> |
35 | 37 | </div> |
36 | 38 | </div> | ... | ... |