From 77f0da467f800542c88aaf0a7caed788b7ab799b Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 29 Jul 2019 15:36:29 +0200 Subject: [PATCH] domains in pillar --- .../de/hsadmin/pillar/JsonPillarServlet.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java b/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java index c35a2d3..7203bc4 100644 --- a/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java +++ b/hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java @@ -2,6 +2,7 @@ package de.hsadmin.pillar; import java.io.IOException; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -17,7 +18,9 @@ import org.apache.commons.httpclient.HttpStatus; import de.hsadmin.core.model.Transaction; import de.hsadmin.core.qserv.ProcessorException; import de.hsadmin.core.util.IPv6Trick; +import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.pac.Hive; +import de.hsadmin.mods.pac.INetAddress; import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.pac.PacComponent; @@ -46,6 +49,7 @@ public class JsonPillarServlet extends HttpServlet { hiveQuery.setParameter("hive", hiveName); final Object hiveResult = hiveQuery.getSingleResult(); final Hive hive = (Hive) hiveResult; + final List dnsZones = new ArrayList<>(); 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(); @@ -73,10 +77,14 @@ public class JsonPillarServlet extends HttpServlet { } else { writer.println(" , {"); } - writer.println(" \"pac\": \"" + pac.getName() + "\""); - writer.println(" , \"ipv4\": \"" + pac.getCurINetAddr().getInet4Addr() + "\""); + final String pacName = pac.getName(); + final String pacDomain = pacName + ".hostsharing.net"; + final INetAddress curINetAddr = pac.getCurINetAddr(); + dnsZones.add(pacDomain); + writer.println(" \"pac\": \"" + pacName + "\""); + writer.println(" , \"ipv4\": \"" + curINetAddr.getInet4Addr() + "\""); try { - writer.println(" , \"ipv6\": \"" + pac.getCurINetAddr().getInet6Addr() + "\""); + writer.println(" , \"ipv6\": \"" + curINetAddr.getInet6Addr() + "\""); } catch (ProcessorException e) { // dont care } @@ -93,6 +101,37 @@ public class JsonPillarServlet extends HttpServlet { writer.println(" }"); } writer.println(" ]"); + final Query domsQuery = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hive"); + domsQuery.setParameter("hive", hiveName); + final List domsResult = pacsQuery.getResultList(); + writer.println(" , \"doms\": ["); + final Iterator domsIterator = domsResult.iterator(); + firstLoop = true; + while (domsIterator.hasNext()) { + final Object result = domsIterator.next(); + final Domain dom = (Domain) result; + final String domName = dom.getName(); + dnsZones.add(domName); + if (firstLoop) { + firstLoop = false; + writer.println(" {"); + } else { + writer.println(" , {"); + } + writer.println(" \"domain\": \"" + domName + "\""); + writer.println(" }"); + } + writer.println(" , \"zones\": ["); + firstLoop = true; + for (final String zone : dnsZones) { + if (firstLoop) { + firstLoop = false; + writer.println(" \"" + zone + "\""); + } else { + writer.println(" , \"" + zone + "\""); + } + } + writer.println(" ]"); writer.println("}"); writer.close(); em.close();