From 166669c287e1bde5dc249f7296495945414c0fdc Mon Sep 17 00:00:00 2001 From: Flavien Date: Wed, 9 Aug 2023 11:42:14 +0200 Subject: [PATCH] + Added CTConf bean and postData formatting --- src/main/java/fr/sixthemes/beans/CTConf.java | 63 +++++++++++++++++++ src/main/java/fr/sixthemes/beans/NetConf.java | 10 +++ src/main/java/fr/sixthemes/beans/SysConf.java | 13 ++++ .../sixthemes/servlets/CreateCTHandler.java | 4 ++ 4 files changed, 90 insertions(+) create mode 100644 src/main/java/fr/sixthemes/beans/CTConf.java diff --git a/src/main/java/fr/sixthemes/beans/CTConf.java b/src/main/java/fr/sixthemes/beans/CTConf.java new file mode 100644 index 0000000..5e5e6f0 --- /dev/null +++ b/src/main/java/fr/sixthemes/beans/CTConf.java @@ -0,0 +1,63 @@ +package fr.sixthemes.beans; + +import java.util.HashMap; +import java.util.Map; + +public class CTConf { + + protected SysConf systemConfiguration; + protected NetConf inet4Configuration; + protected NetConf6 inet6Configuration; + + + public CTConf() { + this.systemConfiguration = new SysConf(); + this.inet4Configuration = new NetConf(); + this.inet6Configuration = new NetConf6(); + } + + public CTConf(SysConf system, NetConf inet4, NetConf6 inet6) { + this.systemConfiguration = system; + this.inet4Configuration = inet4; + this.inet6Configuration = inet6; + } + + public Map getParameters() { + Map parameters = new HashMap<>(); + + parameters.put("unprivileged", "1"); + parameters.put("features", "nesting=1"); + // TODO : Remove hardcoded password + parameters.put("password", "12345"); + + parameters.putAll(systemConfiguration.getParameters()); + parameters.putAll(inet4Configuration.getParameters()); + + return parameters; + } + + public SysConf getSystemConfiguration() { + return this.systemConfiguration; + } + + public NetConf getInet4Configuration() { + return this.inet4Configuration; + } + + public NetConf6 getInet6Configuration() { + return this.inet6Configuration; + } + + public void setSystemConfiguration(SysConf systemConfiguration) { + this.systemConfiguration = systemConfiguration; + } + + public void setInet4Configuration(NetConf inet4Configuration) { + this.inet4Configuration = inet4Configuration; + } + + public void setInet6Configuration(NetConf6 inet6Configuration) { + this.inet6Configuration = inet6Configuration; + } + +} diff --git a/src/main/java/fr/sixthemes/beans/NetConf.java b/src/main/java/fr/sixthemes/beans/NetConf.java index ca168e3..fa43908 100644 --- a/src/main/java/fr/sixthemes/beans/NetConf.java +++ b/src/main/java/fr/sixthemes/beans/NetConf.java @@ -1,5 +1,7 @@ package fr.sixthemes.beans; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,6 +64,14 @@ public class NetConf { return builder.toString(); } + public Map getParameters() { + Map parameters = new HashMap<>(); + + parameters.put("net0", "name=eth0,bridge=" + this.network + ",ip=" + (this.ipAddress.isEmpty() ? "dhcp" : this.ipAddress + ",gw=" + this.gateway)); + + return parameters; + } + /* * ╔═════════╗ * ║ GETTERS ║ diff --git a/src/main/java/fr/sixthemes/beans/SysConf.java b/src/main/java/fr/sixthemes/beans/SysConf.java index 3dfceef..6957551 100644 --- a/src/main/java/fr/sixthemes/beans/SysConf.java +++ b/src/main/java/fr/sixthemes/beans/SysConf.java @@ -1,5 +1,8 @@ package fr.sixthemes.beans; +import java.util.HashMap; +import java.util.Map; + import fr.sixthemes.utils.Utils; public class SysConf { @@ -35,6 +38,16 @@ public class SysConf { this.setDisk(disk); } + public Map getParameters() { + Map parameters = new HashMap<>(); + + parameters.put("hostname", this.hostname); + parameters.put("cores", this.cores); + parameters.put("rootfs", "local-zfs:" + this.disk); + + return parameters; + } + /* * ╔═════════╗ * ║ GETTERS ║ diff --git a/src/main/java/fr/sixthemes/servlets/CreateCTHandler.java b/src/main/java/fr/sixthemes/servlets/CreateCTHandler.java index 56113ad..5073ec3 100644 --- a/src/main/java/fr/sixthemes/servlets/CreateCTHandler.java +++ b/src/main/java/fr/sixthemes/servlets/CreateCTHandler.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import fr.sixthemes.beans.CTConf; import fr.sixthemes.beans.NetConf; import fr.sixthemes.beans.NetConf6; import fr.sixthemes.beans.SysConf; @@ -50,6 +51,9 @@ public class CreateCTHandler extends HttpServlet { NetConf6 netconf6 = new NetConf6(ipaddress6, gateway6, network, ipconf6); req.setAttribute("netconf6", netconf6); + CTConf conf = new CTConf(sysconf, netconf4, netconf6); + req.getSession().setAttribute("conf", conf); + // -------------------- this.getServletContext().getRequestDispatcher("/WEB-INF/createct.jsp").forward(req, resp);