domains in pillar

This commit is contained in:
Peter Hormanns 2019-07-29 15:36:29 +02:00
parent 5dae0e3353
commit 77f0da467f

View File

@ -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<String> 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();