Commit cb678cccb7254e81dfe47cc2ed482825613e2f29
1 parent
6fbad9c5
Changement pour la configuration du réseau
La configuration du réseau se fait maintenant depuis l'interface web sur la page "Paramétrer une mise à jour". Cette fonction n'est accessible qu'au rang ADMIN. Le fichier app.conf est toujours utilisé pour définir un utilisateur ADMIN.
Showing
12 changed files
with
144 additions
and
51 deletions
Show diff stats
PFE06/app.conf
1 | adminEmail: pfe@pfe.fr | 1 | adminEmail: pfe@pfe.fr |
2 | -adminPassword: pfepfe | ||
3 | -nodes: | ||
4 | - - name: AT-001 | ||
5 | - ip: '85.10.201.246' | ||
6 | - arch: ARM | ||
7 | - - name: AT-002 | ||
8 | - ip: '85.10.201.247' | ||
9 | - arch: ARM | ||
10 | - - name: AT-003 | ||
11 | - ip: '85.10.201.248' | ||
12 | - arch: ARM | ||
13 | - - name: ATTTT-004 | ||
14 | - ip: '85.10.201.249' | ||
15 | - arch: ARM | ||
16 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | +adminPassword: pfepfe | ||
17 | \ No newline at end of file | 4 | \ No newline at end of file |
PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java
@@ -3,7 +3,6 @@ package com.PFE.ServerManager; | @@ -3,7 +3,6 @@ package com.PFE.ServerManager; | ||
3 | import org.springframework.beans.factory.annotation.Autowired; | 3 | import org.springframework.beans.factory.annotation.Autowired; |
4 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 4 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
5 | import org.springframework.stereotype.Component; | 5 | import org.springframework.stereotype.Component; |
6 | -import org.yaml.snakeyaml.TypeDescription; | ||
7 | import org.yaml.snakeyaml.Yaml; | 6 | import org.yaml.snakeyaml.Yaml; |
8 | import org.yaml.snakeyaml.constructor.Constructor; | 7 | import org.yaml.snakeyaml.constructor.Constructor; |
9 | 8 | ||
@@ -22,18 +21,28 @@ public class AppConfig { | @@ -22,18 +21,28 @@ public class AppConfig { | ||
22 | RoleRepository roleRepository; | 21 | RoleRepository roleRepository; |
23 | 22 | ||
24 | @Autowired | 23 | @Autowired |
25 | - MajRepository majRepository; | ||
26 | - | ||
27 | - @Autowired | ||
28 | BCryptPasswordEncoder bCryptPasswordEncoder; | 24 | BCryptPasswordEncoder bCryptPasswordEncoder; |
29 | 25 | ||
30 | - @Autowired | ||
31 | - NodeRepository nodeRepository; | ||
32 | - | ||
33 | @PostConstruct | 26 | @PostConstruct |
34 | public void init() { | 27 | public void init() { |
35 | System.out.println("============= Configuration de l'application ============="); | 28 | System.out.println("============= Configuration de l'application ============="); |
36 | 29 | ||
30 | + /* Ajout des rôles si non présent */ | ||
31 | + | ||
32 | + if(roleRepository.count() != 2) { | ||
33 | + roleRepository.deleteAll(); | ||
34 | + Role roleAdmin = new Role(); | ||
35 | + roleAdmin.setRole_id(1); | ||
36 | + roleAdmin.setRole("ADMIN"); | ||
37 | + roleRepository.save(roleAdmin); | ||
38 | + Role roleUser = new Role(); | ||
39 | + roleUser.setRole_id(2); | ||
40 | + roleUser.setRole("USER"); | ||
41 | + roleRepository.save(roleUser); | ||
42 | + } | ||
43 | + | ||
44 | + /* Ajout d'un utilisateur ADMIN avec les informations du fichier de conf*/ | ||
45 | + | ||
37 | Yaml yaml = new Yaml(new Constructor(ConfYAML.class)); | 46 | Yaml yaml = new Yaml(new Constructor(ConfYAML.class)); |
38 | InputStream inputStream = null; | 47 | InputStream inputStream = null; |
39 | try { | 48 | try { |
@@ -56,17 +65,5 @@ public class AppConfig { | @@ -56,17 +65,5 @@ public class AppConfig { | ||
56 | if(temp == null) { | 65 | if(temp == null) { |
57 | customerRepository.save(n); | 66 | customerRepository.save(n); |
58 | } | 67 | } |
59 | - | ||
60 | - Iterator<NodeYAML> iter = conf.getNodes().iterator(); | ||
61 | - while (iter.hasNext()) { | ||
62 | - NodeYAML element = iter.next(); | ||
63 | - Node node = new Node(); | ||
64 | - node.setName(element.getName()); | ||
65 | - node.setArch(element.getArch()); | ||
66 | - node.setIp(element.getIp()); | ||
67 | - node.setNode_id((int)(nodeRepository.count() + 1)); | ||
68 | - nodeRepository.save(node); | ||
69 | - } | ||
70 | - | ||
71 | } | 68 | } |
72 | } | 69 | } |
73 | \ No newline at end of file | 70 | \ No newline at end of file |
PFE06/src/main/java/com/PFE/ServerManager/ConfYAML.java
1 | package com.PFE.ServerManager; | 1 | package com.PFE.ServerManager; |
2 | 2 | ||
3 | -import java.util.List; | ||
4 | - | ||
5 | public class ConfYAML { | 3 | public class ConfYAML { |
6 | 4 | ||
7 | private String adminEmail; | 5 | private String adminEmail; |
8 | private String adminPassword; | 6 | private String adminPassword; |
9 | - private List<NodeYAML> nodes; | ||
10 | 7 | ||
11 | public void setAdminEmail(String adminEmail) { | 8 | public void setAdminEmail(String adminEmail) { |
12 | this.adminEmail = adminEmail; | 9 | this.adminEmail = adminEmail; |
@@ -16,10 +13,6 @@ public class ConfYAML { | @@ -16,10 +13,6 @@ public class ConfYAML { | ||
16 | this.adminPassword = adminPassword; | 13 | this.adminPassword = adminPassword; |
17 | } | 14 | } |
18 | 15 | ||
19 | - public void setNodes(List<NodeYAML> nodes) { | ||
20 | - this.nodes = nodes; | ||
21 | - } | ||
22 | - | ||
23 | public String getAdminEmail() { | 16 | public String getAdminEmail() { |
24 | return adminEmail; | 17 | return adminEmail; |
25 | } | 18 | } |
@@ -28,8 +21,5 @@ public class ConfYAML { | @@ -28,8 +21,5 @@ public class ConfYAML { | ||
28 | return adminPassword; | 21 | return adminPassword; |
29 | } | 22 | } |
30 | 23 | ||
31 | - public List<NodeYAML> getNodes() { | ||
32 | - return nodes; | ||
33 | - } | ||
34 | 24 | ||
35 | } | 25 | } |
PFE06/src/main/java/com/PFE/ServerManager/ConfigNodes.java
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +package com.PFE.ServerManager; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +public class ConfigNodes { | ||
6 | + | ||
7 | + private List<NodeYAML> nodes; | ||
8 | + | ||
9 | + public List<NodeYAML> getNodes() { | ||
10 | + return nodes; | ||
11 | + } | ||
12 | + | ||
13 | + public void setNodes(List<NodeYAML> nodes) { | ||
14 | + this.nodes = nodes; | ||
15 | + } | ||
16 | +} |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
@@ -14,6 +14,8 @@ import java.util.*; | @@ -14,6 +14,8 @@ import java.util.*; | ||
14 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 14 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
15 | import org.springframework.security.core.context.SecurityContextHolder; | 15 | import org.springframework.security.core.context.SecurityContextHolder; |
16 | import org.springframework.security.core.Authentication; | 16 | import org.springframework.security.core.Authentication; |
17 | +import org.yaml.snakeyaml.Yaml; | ||
18 | +import org.yaml.snakeyaml.constructor.Constructor; | ||
17 | 19 | ||
18 | import javax.servlet.annotation.MultipartConfig; | 20 | import javax.servlet.annotation.MultipartConfig; |
19 | 21 | ||
@@ -39,7 +41,7 @@ public class MainController { | @@ -39,7 +41,7 @@ public class MainController { | ||
39 | 41 | ||
40 | @GetMapping(value="/") | 42 | @GetMapping(value="/") |
41 | public String uploadRedirection(){ | 43 | public String uploadRedirection(){ |
42 | - return "redirect:upload"; | 44 | + return "redirect:home"; |
43 | } | 45 | } |
44 | 46 | ||
45 | @GetMapping(value="/home") | 47 | @GetMapping(value="/home") |
@@ -186,6 +188,35 @@ public class MainController { | @@ -186,6 +188,35 @@ public class MainController { | ||
186 | } | 188 | } |
187 | } | 189 | } |
188 | 190 | ||
191 | + @RequestMapping(value = "/config", method = RequestMethod.POST) | ||
192 | + @ResponseStatus(value = HttpStatus.OK) | ||
193 | + public void submitConfig(@RequestParam MultipartFile file) { | ||
194 | + | ||
195 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
196 | + Customer customer = customerRepository.findByEmail(auth.getName()); | ||
197 | + InputStream inputStream = null; | ||
198 | + try { | ||
199 | + inputStream = file.getInputStream(); | ||
200 | + } | ||
201 | + catch (IOException e) { | ||
202 | + e.printStackTrace(); | ||
203 | + } | ||
204 | + | ||
205 | + nodeRepository.deleteAll(); | ||
206 | + Yaml yaml = new Yaml(new Constructor(ConfigNodes.class)); | ||
207 | + ConfigNodes conf = yaml.load(inputStream); | ||
208 | + | ||
209 | + Iterator<NodeYAML> iter = conf.getNodes().iterator(); | ||
210 | + while (iter.hasNext()) { | ||
211 | + NodeYAML element = iter.next(); | ||
212 | + Node node = new Node(); | ||
213 | + node.setName(element.getName()); | ||
214 | + node.setArch(element.getArch()); | ||
215 | + node.setIp(element.getIp()); | ||
216 | + node.setNode_id((int)(nodeRepository.count() + 1)); | ||
217 | + nodeRepository.save(node); | ||
218 | + } | ||
219 | + } | ||
189 | 220 | ||
190 | @GetMapping(path="/login") | 221 | @GetMapping(path="/login") |
191 | public ModelAndView login() { | 222 | public ModelAndView login() { |
PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java
@@ -35,6 +35,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | @@ -35,6 +35,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
35 | .authorizeRequests() | 35 | .authorizeRequests() |
36 | .antMatchers("/home").hasAnyAuthority("USER","ADMIN") | 36 | .antMatchers("/home").hasAnyAuthority("USER","ADMIN") |
37 | .antMatchers("/registration").hasAuthority("ADMIN") | 37 | .antMatchers("/registration").hasAuthority("ADMIN") |
38 | + .antMatchers("/config").hasAuthority("ADMIN") | ||
38 | .antMatchers("/all").hasAuthority("ADMIN") | 39 | .antMatchers("/all").hasAuthority("ADMIN") |
39 | .antMatchers("/login").permitAll() | 40 | .antMatchers("/login").permitAll() |
40 | .antMatchers("/denied").permitAll() | 41 | .antMatchers("/denied").permitAll() |
PFE06/src/main/resources/application.properties
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | #-----------------------------------------------# | 2 | #-----------------------------------------------# |
3 | #---------- Spring Database management ---------# | 3 | #---------- Spring Database management ---------# |
4 | #-----------------------------------------------# | 4 | #-----------------------------------------------# |
5 | -spring.jpa.hibernate.ddl-auto=create | 5 | +spring.jpa.hibernate.ddl-auto=update |
6 | #update | 6 | #update |
7 | #"create" recrée la base de données à chaque lancement | 7 | #"create" recrée la base de données à chaque lancement |
8 | #"update" met à jour la base données | 8 | #"update" met à jour la base données |
PFE06/src/main/resources/data.sql
1 | -/* ce fichier doit être placé dans les ressources afin d'être utilisé */ | ||
2 | - | ||
3 | -INSERT INTO "role" VALUES (1, 'ADMIN'); | ||
4 | -INSERT INTO "role" VALUES (2, 'USER'); | ||
5 | \ No newline at end of file | 1 | \ No newline at end of file |
2 | +/* ce fichier doit être placé dans les ressources afin d'être utilisé */ | ||
6 | \ No newline at end of file | 3 | \ No newline at end of file |
PFE06/src/main/resources/static/js/session.js
1 | $(document).ready(function() { | 1 | $(document).ready(function() { |
2 | 2 | ||
3 | + /********** Configuration file ***********/ | ||
4 | + | ||
5 | + var configName = document.getElementById("config_name"); | ||
6 | + var configSend = document.getElementById("config_send"); | ||
7 | + var file = document.getElementById("configInputFile"); | ||
8 | + var readyToSend = false; | ||
9 | + var formData = new FormData(); | ||
10 | + | ||
11 | + file.addEventListener('change', function() { | ||
12 | + delete formData; | ||
13 | + formData = new FormData(); | ||
14 | + configName.innerHTML = this.files[0].name; | ||
15 | + formData.append("file", this.files[0]); | ||
16 | + readyToSend = true; | ||
17 | + }, false) | ||
18 | + | ||
19 | + configSend.addEventListener('click', function() { | ||
20 | + var modalContent = document.getElementById("modal-content"); | ||
21 | + var modalTitle = document.getElementById("modal-title"); | ||
22 | + if(readyToSend) { | ||
23 | + var request = new XMLHttpRequest(); | ||
24 | + request.open("POST", "/config"); | ||
25 | + | ||
26 | + request.onreadystatechange = function() { | ||
27 | + if(this.readyState === XMLHttpRequest.DONE && this.status === 200) { | ||
28 | + var modalButton = document.getElementById("modal-button"); | ||
29 | + modalButton.addEventListener('click', function(e) { | ||
30 | + location.reload(); | ||
31 | + }) | ||
32 | + modalContent.innerHTML = "Upload terminé !"; | ||
33 | + modalTitle.innerHTML = "Félicitations"; | ||
34 | + $("#warningFilesNumber").modal(); | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + request.send(formData); | ||
39 | + } | ||
40 | + else { | ||
41 | + modalContent.innerHTML = "Veuillez sélectionner un fichier !"; | ||
42 | + $("#warningFilesNumber").modal() | ||
43 | + } | ||
44 | + | ||
45 | + }) | ||
46 | + | ||
3 | /********** Tableau **********/ | 47 | /********** Tableau **********/ |
4 | 48 | ||
5 | var tableNodes = $('#nodes-table').DataTable( { | 49 | var tableNodes = $('#nodes-table').DataTable( { |
PFE06/src/main/resources/templates/home.html
@@ -100,6 +100,5 @@ | @@ -100,6 +100,5 @@ | ||
100 | <script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js" charset="utf-8"></script> | 100 | <script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js" charset="utf-8"></script> |
101 | <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js" charset="utf-8"></script> | 101 | <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js" charset="utf-8"></script> |
102 | <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js" charset="utf-8"></script> | 102 | <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js" charset="utf-8"></script> |
103 | -<script th:src="@{/js/upload.js}"></script> | ||
104 | </body> | 103 | </body> |
105 | </html> | 104 | </html> |
PFE06/src/main/resources/templates/registration.html
@@ -59,7 +59,7 @@ | @@ -59,7 +59,7 @@ | ||
59 | 59 | ||
60 | <form id="Login" th:action="@{/registration}" method="POST"> | 60 | <form id="Login" th:action="@{/registration}" method="POST"> |
61 | <div class="form-group"> | 61 | <div class="form-group"> |
62 | - <input type="text" class="form-control" id="username" placeholder="Entrer le pseudo" name="email"> | 62 | + <input type="email" class="form-control" id="username" placeholder="Entrer l'email" name="email"> |
63 | </div> | 63 | </div> |
64 | <div class="form-group"> | 64 | <div class="form-group"> |
65 | <input type="password" class="form-control" id="password" placeholder="Entrer le mot de passe" name="password"> | 65 | <input type="password" class="form-control" id="password" placeholder="Entrer le mot de passe" name="password"> |
PFE06/src/main/resources/templates/session.html
@@ -44,6 +44,36 @@ | @@ -44,6 +44,36 @@ | ||
44 | </nav> | 44 | </nav> |
45 | 45 | ||
46 | <div class="container" style="padding-bottom: 50px;"> | 46 | <div class="container" style="padding-bottom: 50px;"> |
47 | + | ||
48 | + <div th:remove="tag" th:if="${customerRole} == 'ADMIN'"> | ||
49 | + <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Changer la configuration réseau</h1> | ||
50 | + <div class="input-group mb-3"> | ||
51 | + <div class="input-group-prepend"> | ||
52 | + <button id="config_send" class="btn btn-outline-secondary" type="button">Envoyer</button> | ||
53 | + </div> | ||
54 | + <div class="custom-file"> | ||
55 | + <input type="file" class="custom-file-input" id="configInputFile"> | ||
56 | + <label id="config_name" class="custom-file-label" for="configInputFile">Choisir un fichier</label> | ||
57 | + </div> | ||
58 | + </div> | ||
59 | + | ||
60 | + <div class="form-group"> | ||
61 | + <label for="comment">Exemple :</label> | ||
62 | + <textarea readonly class="form-control" rows="5" id="comment"> | ||
63 | +nodes: | ||
64 | + - name: AT-001 | ||
65 | + ip: '85.10.201.246' | ||
66 | + arch: ARM | ||
67 | + - name: AT-002 | ||
68 | + ip: '85.10.201.247' | ||
69 | + arch: ARM | ||
70 | + - name: AT-003 | ||
71 | + ip: '85.10.201.248' | ||
72 | + arch: ARM | ||
73 | + </textarea> | ||
74 | + </div> | ||
75 | + </div> | ||
76 | + | ||
47 | <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Relancer une mise à jour</h1> | 77 | <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Relancer une mise à jour</h1> |
48 | <div class="form-group"> | 78 | <div class="form-group"> |
49 | <select multiple class="form-control"> | 79 | <select multiple class="form-control"> |
@@ -53,6 +83,7 @@ | @@ -53,6 +83,7 @@ | ||
53 | <button id="start_maj" type="submit" class="btn btn-primary" style="margin-top:20px;">Lancer la mise à jour</button> | 83 | <button id="start_maj" type="submit" class="btn btn-primary" style="margin-top:20px;">Lancer la mise à jour</button> |
54 | </div> | 84 | </div> |
55 | <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Créer une mise à jour</h1> | 85 | <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Créer une mise à jour</h1> |
86 | + | ||
56 | <table id="nodes-table" class="table table-striped table-bordered dt-responsive nowrap"> | 87 | <table id="nodes-table" class="table table-striped table-bordered dt-responsive nowrap"> |
57 | <thead> | 88 | <thead> |
58 | <tr> | 89 | <tr> |