From 2ded642feaadf01154de47db91d0f15cea514951 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 17 Aug 2021 19:59:11 +0200 Subject: [PATCH] delegate setquota to salt --- .../de/hsadmin/hostsharing/QuotaLimit.java | 10 ------- .../hsadmin/mods/pac/PacProcessorFactory.java | 29 +++---------------- .../mods/user/UnixUserProcessorFactory.java | 29 ++++--------------- 3 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java diff --git a/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java b/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java deleted file mode 100644 index fb6d5bb..0000000 --- a/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.hsadmin.hostsharing; - -public class QuotaLimit { - - public static final double BLOCK_QUOTA_FACTOR = 1.00; - public static final double BLOCK_LIMIT_FACTOR = 1.50; - public static final double FILE_QUOTA_FACTOR = 1.00; - public static final double FILE_LIMIT_FACTOR = 1.50; - -} diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index 16cddbe..e65df28 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -24,7 +24,6 @@ import de.hsadmin.core.util.Config; import de.hsadmin.core.util.HSAdminException; import de.hsadmin.core.util.PasswordTool; import de.hsadmin.hostsharing.BasePacType; -import de.hsadmin.hostsharing.QuotaLimit; import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.user.UnixUser; @@ -43,7 +42,6 @@ public class PacProcessorFactory implements EntityProcessorFactory { String password = PasswordTool.generatePassword(); WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(new CompoundProcessor( createAddUserProc(pacName, unixUser, password), - createSetQuotaProc(pac), createEtcHostsProc(hive), createNetworkInterfacesProc(hive), createIPTablesProc(), @@ -78,8 +76,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { createNetworkInterfacesProc(hive), createProftpdConfProc(hive), createHttpdVirtualProc(hive), - createSaltCallProc(), - createSetQuotaProc(pac) + createSaltCallProc() )); final Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.dns").split(",")) { @@ -109,7 +106,8 @@ public class PacProcessorFactory implements EntityProcessorFactory { createHttpdVirtualProc(hive), createUnlinkSiteProc(pac.getName() + ".hostsharing.net"), createHiveDNSRemoveProcessor(domainName), - createAccountingRulesProc()), "remove packet"); + createAccountingRulesProc(), + new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1")), "remove packet"); final Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.dns").split(",")) { waiting.appendProcessor(queueName, createDNSServerConfigProcessor(em), queueName + ".hostsharing.net"); @@ -234,32 +232,13 @@ public class PacProcessorFactory implements EntityProcessorFactory { + ":" + unixUser.getShell() + "\n"); } - private Processor createSetQuotaProc(Pac pac) { - int quota = 1024; - Set pacComponents = pac.getPacComponents(); - for (PacComponent pacComponent : pacComponents) { - BaseComponent baseComponent = pacComponent.getBaseComponent(); - String feature = baseComponent.getFeature(); - if ("QUOTA".equals(feature)) { - quota = pacComponent.getQuantity() * 1024; - } - } - int blocksSoft = ((Double) (quota * QuotaLimit.BLOCK_QUOTA_FACTOR)).intValue(); - int blocksHard = ((Double) (quota * QuotaLimit.BLOCK_LIMIT_FACTOR)).intValue(); - int inodesSoft = ((Double) (quota * QuotaLimit.FILE_QUOTA_FACTOR)).intValue(); - int inodesHard = ((Double) (quota * QuotaLimit.FILE_LIMIT_FACTOR)).intValue(); - return new ShellProcessor("setquota -g " + pac.getName() + " " - + blocksSoft + " " + blocksHard + " " - + inodesSoft + " " + inodesHard + " " - + "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"); - } - private Processor createDelUserProc(String pacName) { Processor killProcessesProc = new ShellProcessor("killall -TERM -u " + pacName + " && sleep 5 && killall -KILL -u " + pacName + " && sleep 5 || true"); Processor userdelProc = new ShellProcessor("deluser --remove-home " + pacName); CompoundProcessor proc = new CompoundProcessor(killProcessesProc, userdelProc); proc.appendProcessor(new ShellProcessor("rm -f '/var/spool/cron/crontabs/" + pacName + "'")); proc.appendProcessor(new ShellProcessor("rm -f '/var/mail/" + pacName + "'")); + proc.appendProcessor(new ShellProcessor("rm -rf '/home/storage/" + pacName + "/'")); return proc; } diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java b/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java index 81477f5..7f1d15d 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java @@ -28,8 +28,8 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory { + ":" + user.getComment() + ":" + user.getHomedir() + ":" + user.getShell() + "\n")); appendSetHomeACLProcessor(aCP, user); - appendSetQuotaProcessor(aCP, user); appendMakeMaildirProcessor(aCP, user); + aCP.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1")); return aCP; } @@ -46,7 +46,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory { if (user.getPassword() != null && user.getPassword().length() > 0) aCP.appendProcessor(new ShellProcessor("chpasswd ", user.getName() + ":" + user.getPassword() + "\n")); - appendSetQuotaProcessor(aCP, user); + aCP.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1")); return aCP; } @@ -56,6 +56,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory { public Processor createDeleteProcessor(EntityManager em, T entity) { UnixUser user = (UnixUser) entity; String uid = user.getName(); + String pac = user.getPac().getName(); if (uid != null && uid.length() > 4) { Processor killProcessesProc = new ShellProcessor("killall -TERM -u " + uid + " && sleep 5 && killall -KILL -u " + uid + " && sleep 5 || true"); Processor userdelProc = null; @@ -67,6 +68,8 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory { CompoundProcessor proc = new CompoundProcessor(killProcessesProc, userdelProc); proc.appendProcessor(new ShellProcessor("rm -f '/var/spool/cron/crontabs/" + uid + "'")); proc.appendProcessor(new ShellProcessor("rm -f '/var/mail/" + uid + "'")); + proc.appendProcessor(new ShellProcessor("rm -rf '/home/storage/" + pac + "/users/" + uid + "/'")); + proc.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1")); return proc; } return null; @@ -76,28 +79,6 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory { aCP.appendProcessor(new ShellProcessor("chmod 700 " + user.getHomedir())); } - private void appendSetQuotaProcessor(CompoundProcessor aCP, UnixUser user) { - Integer quotaSoft = user.getQuotaSoftlimit(); - if (quotaSoft == null) { - quotaSoft = Integer.valueOf(0); - } else { - quotaSoft = quotaSoft * 1024; - } - if (quotaSoft.intValue() == 0) { - aCP.appendProcessor(new ShellProcessor( - "setquota -u " + user.getName() + " 0 0 0 0 " + "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`")); - return; - } - Integer quotaHard = user.getQuotaHardlimit(); - if (quotaHard == null) { - quotaHard = Integer.valueOf(0); - } else { - quotaHard = quotaHard * 1024; - } - aCP.appendProcessor(new ShellProcessor("setquota -u " + user.getName() + " " + quotaSoft + " " + quotaHard - + " 0 0 " + "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`")); - } - private void appendMakeMaildirProcessor(CompoundProcessor aCP, UnixUser user) { aCP.appendProcessor( new ShellProcessor(