diff options
Diffstat (limited to 'src/main/java/net/libertacasa/pubsh/web/WebApplication.java')
-rw-r--r-- | src/main/java/net/libertacasa/pubsh/web/WebApplication.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/main/java/net/libertacasa/pubsh/web/WebApplication.java b/src/main/java/net/libertacasa/pubsh/web/WebApplication.java index bd497d9..4c06c29 100644 --- a/src/main/java/net/libertacasa/pubsh/web/WebApplication.java +++ b/src/main/java/net/libertacasa/pubsh/web/WebApplication.java @@ -158,7 +158,7 @@ public class WebApplication { System.out.printf("Deletion triggered for ID %s by %s (%s)\n", id, userid, username); //Docker.deleteContainer(id); - Docker.deleteShell(username, id); + Docker.deleteShell(username, id); //to-do: move to separate mapping return("redirect:/portal"); } @@ -220,6 +220,36 @@ public class WebApplication { return("redirect:/portal"); } + @PostMapping(path="/frontend/shell/add",consumes=MediaType.APPLICATION_FORM_URLENCODED_VALUE) + public static String addShell(@RequestBody MultiValueMap<String, String> body, HttpServletRequest request, RedirectAttributes redirectAttributes) { + KeycloakAuthenticationToken principal = (KeycloakAuthenticationToken) request.getUserPrincipal(); + String username = null; + String userid = principal.getName(); + IDToken token = principal.getAccount().getKeycloakSecurityContext().getIdToken(); + Map<String, Object> customClaims = token.getOtherClaims(); + username = String.valueOf(customClaims.get("username")); + String os = (String) body.getFirst("osChoice"); + + System.out.printf("New shell with OS %s requested by %s (%s)\n", os, userid, username); + + Random rand = new Random(); + Integer randomInt = rand.nextInt(9999999-1111); + Integer count = randomInt; + + try { + String containerid = Docker.createShell(username, os, count); + String returnmessage = "Success - spawned shell " + username + "_" + os + "_" + count + " - internal ID: " + containerid; + redirectAttributes.addFlashAttribute("message", returnmessage); + } catch (Exception exception) { + redirectAttributes.addFlashAttribute("message", "Success!"); + String returnmessage = "Error - failed to build image :-("; + redirectAttributes.addFlashAttribute("message", returnmessage); + System.out.println(exception); + } + + return("redirect:/portal"); + } + @GetMapping(path = "/logout") public String logout(HttpServletRequest request) throws ServletException { request.logout(); |