need all zones list with acmeupdate info

This commit is contained in:
Peter Hormanns 2020-05-28 13:35:16 +02:00
parent cdc84a53e1
commit dedf7c9c7b

View File

@ -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<String> dnsZones = new TreeSet<String>();
final Map<String, Boolean> 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<String, Boolean> 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();