provide domain admin role

This commit is contained in:
Peter Hormanns 2022-12-13 20:05:15 +01:00
parent 40f4429922
commit f8870d2575

View File

@ -3,6 +3,7 @@ package de.hsadmin.pillar;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -62,6 +63,7 @@ public class JsonPillarServlet extends HttpServlet {
}
}
}
final Set<String> domainadmins = new HashSet<>();
final Query hiveQuery = em.createQuery("SELECT h FROM Hives h WHERE h.name = :hive");
hiveQuery.setParameter("hive", hiveName);
final Object hiveResult = hiveQuery.getSingleResult();
@ -82,6 +84,80 @@ public class JsonPillarServlet extends HttpServlet {
}
final long currentTimeSeconds = System.currentTimeMillis() / 1000L;
writer.println(" , \"currenttimeseconds\": \"" + currentTimeSeconds + "\"");
final Query domsQuery = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hive ORDER BY d.name");
domsQuery.setParameter("hive", hiveName);
final List<?> domsResult = domsQuery.getResultList();
writer.println(" , \"doms\": [");
final Iterator<?> domsIterator = domsResult.iterator();
boolean firstLoopDoms = true;
while (domsIterator.hasNext()) {
final Domain dom = (Domain) domsIterator.next();
final String domName = dom.getName();
dnsZones.put(domName, Boolean.FALSE);
final Map<String, Boolean> domainOpts = new HashMap<>();
for (final SelectableValue val : domainOptionValues.get()) {
domainOpts.put(val.getName(), Boolean.FALSE);
}
final Set<DomainOption> domainOptionNames = dom.getDomainoptions();
for (final DomainOption opt: domainOptionNames) {
final String optName = opt.getName();
domainOpts.put(optName, Boolean.TRUE);
}
if (firstLoopDoms) {
firstLoopDoms = false;
writer.println(" {");
} else {
writer.println(" , {");
}
final UnixUser domUser = dom.getUser();
final String domUserName = domUser.getName();
domainadmins.add(domUserName);
final Pac domPac = domUser.getPac();
final String validSubdomainNames = dom.getValidsubdomainnames();
final INetAddress domINetAddr = domPac.getCurINetAddr();
writer.println(" \"domain\": \"" + domName + "\"");
writer.println(" , \"pac\": \"" + domPac.getName() + "\"");
writer.println(" , \"user\": \"" + domUserName + "\"");
writer.println(" , \"ipv4\": \"" + domINetAddr.getInet4Addr() + "\"");
try {
writer.println(" , \"ipv6\": \"" + domINetAddr.getInet6Addr() + "\"");
} catch (HSAdminException e) {
// dont care
}
writer.println(" , \"opts\": {");
boolean firstLoopOpts = true;
for (final SelectableValue val : domainOptionValues.get()) {
final String optName = val.getName();
final Boolean optValue = domainOpts.get(optName);
if ("letsencrypt".equals(optName)) {
dnsZones.put(domName, optValue);
}
if (firstLoopOpts) {
firstLoopOpts = false;
writer.println(" \"" + optName + "\": " + optValue.toString().toLowerCase());
} else {
writer.println(" , \"" + optName + "\": " + optValue.toString().toLowerCase());
}
}
writer.println(" }");
writer.println(" , \"validsubdomains\": \"" + validSubdomainNames + "\"");
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(" , \"pacs\": [");
final Iterator<?> pacsIterator = pacsResult.iterator();
boolean firstLoopPacs = true;
@ -129,13 +205,14 @@ public class JsonPillarServlet extends HttpServlet {
}
for (String nextName: sortedUsersMap.keySet()) {
final UnixUser user = sortedUsersMap.get(nextName);
final String fullUsername = user.getName();
boolean isDomainAdmin = domainadmins.contains(fullUsername);
if (firstLoopUsers) {
firstLoopUsers = false;
writer.println(" {");
} else {
writer.println(" , {");
}
final String fullUsername = user.getName();
final String usernamePostfix = fullUsername.length() > 6 ? fullUsername.substring(6) : "_";
writer.println(" \"user\": \"" + fullUsername + "\"");
writer.println(" , \"dirname\": \"" + usernamePostfix + "\"");
@ -147,84 +224,14 @@ public class JsonPillarServlet extends HttpServlet {
writer.println(" , \"quota_hard\": " + user.getQuotaHardlimit());
writer.println(" , \"storage_soft\": " + user.getStorageSoftlimit());
writer.println(" , \"storage_hard\": " + user.getStorageHardlimit());
writer.println(" , \"is_domainadmin\": " + Boolean.toString(isDomainAdmin).toLowerCase());
writer.println(" , \"has_maildir\": " + Boolean.toString(true).toLowerCase());
writer.println(" }");
}
writer.println(" ]");
writer.println(" }");
}
writer.println(" ]");
final Query domsQuery = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hive ORDER BY d.name");
domsQuery.setParameter("hive", hiveName);
final List<?> domsResult = domsQuery.getResultList();
writer.println(" , \"doms\": [");
final Iterator<?> domsIterator = domsResult.iterator();
boolean firstLoopDoms = true;
while (domsIterator.hasNext()) {
final Domain dom = (Domain) domsIterator.next();
final String domName = dom.getName();
dnsZones.put(domName, Boolean.FALSE);
final Map<String, Boolean> domainOpts = new HashMap<>();
for (final SelectableValue val : domainOptionValues.get()) {
domainOpts.put(val.getName(), Boolean.FALSE);
}
final Set<DomainOption> domainOptionNames = dom.getDomainoptions();
for (final DomainOption opt: domainOptionNames) {
final String optName = opt.getName();
domainOpts.put(optName, Boolean.TRUE);
}
if (firstLoopDoms) {
firstLoopDoms = false;
writer.println(" {");
} else {
writer.println(" , {");
}
final UnixUser domUser = dom.getUser();
final Pac domPac = domUser.getPac();
final String validSubdomainNames = dom.getValidsubdomainnames();
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\": {");
boolean firstLoopOpts = true;
for (final SelectableValue val : domainOptionValues.get()) {
final String optName = val.getName();
final Boolean optValue = domainOpts.get(optName);
if ("letsencrypt".equals(optName)) {
dnsZones.put(domName, optValue);
}
if (firstLoopOpts) {
firstLoopOpts = false;
writer.println(" \"" + optName + "\": " + optValue.toString().toLowerCase());
} else {
writer.println(" , \"" + optName + "\": " + optValue.toString().toLowerCase());
}
}
writer.println(" }");
writer.println(" , \"validsubdomains\": \"" + validSubdomainNames + "\"");
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();