From dedf7c9c7b54ba443d5c8980d6593101903a19d9 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 28 May 2020 13:35:16 +0200 Subject: [PATCH] need all zones list with acmeupdate info --- .../de/hsadmin/pillar/JsonPillarServlet.java | 62 ++++++++++++++----- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java b/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java index 671dbc9..ae0fc32 100644 --- a/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java +++ b/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java @@ -29,6 +29,7 @@ import de.hsadmin.mods.pac.Hive; import de.hsadmin.mods.pac.INetAddress; import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.pac.PacComponent; +import de.hsadmin.mods.user.UnixUser; public class JsonPillarServlet extends HttpServlet { @@ -57,7 +58,7 @@ public class JsonPillarServlet extends HttpServlet { hiveQuery.setParameter("hive", hiveName); final Object hiveResult = hiveQuery.getSingleResult(); final Hive hive = (Hive) hiveResult; - final Set dnsZones = new TreeSet(); + final Map dnsZones = new HashMap<>(); final Query pacsQuery = em.createQuery("SELECT p FROM Pacs p WHERE p.hive.name = :hive AND p.basepac.name = 'PAC/WEB'"); pacsQuery.setParameter("hive", hiveName); final List pacsResult = pacsQuery.getResultList(); @@ -75,12 +76,12 @@ public class JsonPillarServlet extends HttpServlet { writer.println(" , \"currenttimeseconds\": \"" + currentTimeSeconds + "\""); writer.println(" , \"pacs\": ["); final Iterator pacsIterator = pacsResult.iterator(); - boolean firstLoop = true; + boolean firstLoopPacs = true; while (pacsIterator.hasNext()) { final Object result = pacsIterator.next(); final Pac pac = (Pac) result; - if (firstLoop) { - firstLoop = false; + if (firstLoopPacs) { + firstLoopPacs = false; writer.println(" {"); } else { writer.println(" , {"); @@ -88,7 +89,7 @@ public class JsonPillarServlet extends HttpServlet { final String pacName = pac.getName(); final String pacDomain = pacName + ".hostsharing.net"; final INetAddress curINetAddr = pac.getCurINetAddr(); - dnsZones.add(pacDomain); + dnsZones.put(pacDomain, Boolean.FALSE); writer.println(" \"pac\": \"" + pacName + "\""); writer.println(" , \"ipv4\": \"" + curINetAddr.getInet4Addr() + "\""); try { @@ -114,12 +115,11 @@ public class JsonPillarServlet extends HttpServlet { final List domsResult = domsQuery.getResultList(); writer.println(" , \"doms\": ["); final Iterator domsIterator = domsResult.iterator(); - firstLoop = true; + boolean firstLoopDoms = true; while (domsIterator.hasNext()) { - final Object result = domsIterator.next(); - final Domain dom = (Domain) result; + final Domain dom = (Domain) domsIterator.next(); final String domName = dom.getName(); - dnsZones.add(domName); + dnsZones.put(domName, Boolean.FALSE); final Map domainOpts = new HashMap<>(); for (final SelectableValue val : domainOptionValues.get()) { domainOpts.put(val.getName(), Boolean.FALSE); @@ -129,27 +129,57 @@ public class JsonPillarServlet extends HttpServlet { final String optName = opt.getName(); domainOpts.put(optName, Boolean.TRUE); } - if (firstLoop) { - firstLoop = false; + if (firstLoopDoms) { + firstLoopDoms = false; writer.println(" {"); } else { writer.println(" , {"); } + final UnixUser domUser = dom.getUser(); + final Pac domPac = domUser.getPac(); + final INetAddress domINetAddr = domPac.getCurINetAddr(); writer.println(" \"domain\": \"" + domName + "\""); + writer.println(" , \"pac\": \"" + domPac.getName() + "\""); + writer.println(" , \"user\": \"" + domUser.getName() + "\""); + writer.println(" , \"ipv4\": \"" + domINetAddr.getInet4Addr() + "\""); + try { + writer.println(" , \"ipv6\": \"" + domINetAddr.getInet6Addr() + "\""); + } catch (HSAdminException e) { + // dont care + } writer.println(" , \"opts\": {"); - firstLoop = true; + boolean firstLoopOpts = true; for (final SelectableValue val : domainOptionValues.get()) { - if (firstLoop) { - firstLoop = false; - writer.println(" \"" + val.getName() + "\": " + domainOpts.get(val.getName()).toString().toLowerCase()); + final String optName = val.getName(); + final Boolean optValue = domainOpts.get(optName); + if ("letsencrypt".equals(domName)) { + dnsZones.put(domName, optValue); + } + if (firstLoopOpts) { + firstLoopOpts = false; + writer.println(" \"" + optName + "\": " + optValue.toString().toLowerCase()); } else { - writer.println(" , \"" + val.getName() + "\": " + domainOpts.get(val.getName()).toString().toLowerCase()); + writer.println(" , \"" + optName + "\": " + optValue.toString().toLowerCase()); } } writer.println(" }"); writer.println(" }"); } writer.println(" ]"); + boolean firstLoopZones = true; + writer.println(" , \"zones\": ["); + for (final String zone : dnsZones.keySet()) { + if (firstLoopZones) { + firstLoopZones = false; + writer.println(" {"); + } else { + writer.println(" , {"); + } + writer.println(" \"zone\": \"" + zone + "\""); + writer.println(" , \"acmeupdates\": " + dnsZones.get(zone).toString().toLowerCase()); + writer.println(" }"); + } + writer.println(" ]"); writer.println("}"); writer.close(); transaction.close();