delete pac domains

This commit is contained in:
Peter Hormanns 2011-07-27 16:24:38 +00:00
parent 4cd7489996
commit 8ae17912b7
2 changed files with 33 additions and 1 deletions

View File

@ -114,5 +114,33 @@ public class PacModuleImpl extends AbstractModuleImpl {
throws HSAdminException { throws HSAdminException {
throw new AuthorisationException(getLoginUser(), "update", existingEntity); throw new AuthorisationException(getLoginUser(), "update", existingEntity);
} }
@Override
public void delete(AbstractEntity existingEntity) throws HSAdminException {
EntityManager em = getTransaction().getEntityManager();
Pac pac = (Pac) existingEntity;
Date dateCancelled = pac.getCancelled();
if (dateCancelled == null || dateCancelled.getTime() > System.currentTimeMillis()) {
throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
}
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
Query qDoms = em.createQuery("SELECT dom FROM Domains dom WHERE dom.user.pac.name = :pac");
qDoms.setParameter("pac", pac.getName());
List<?> domsList = qDoms.getResultList();
for (Object o : domsList) {
if (o instanceof Domain) {
helperModule.delete((AbstractEntity) o);
}
}
UnixUser admin = pac.owningUser(em);
for (UnixUser user : pac.getUnixUser()) {
if (admin.getId() != user.getId()) {
helperModule.delete(user);
}
}
super.delete(existingEntity);
}
} }

View File

@ -77,7 +77,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
createNetworkInterfacesProc(hiveValues, pacValuesList), createNetworkInterfacesProc(hiveValues, pacValuesList),
createSudouersProc(hiveValues, pacValuesList), createSudouersProc(hiveValues, pacValuesList),
createProftpdConfProc(hiveValues, pacValuesList), createProftpdConfProc(hiveValues, pacValuesList),
createMakePacDirectoryStructure(unixUser)); createDelUserProc(unixUser.getName()));
} }
private TemplateProcessor createEtcHostsProc( private TemplateProcessor createEtcHostsProc(
@ -113,6 +113,10 @@ public class PacProcessorFactory implements EntityProcessorFactory {
+ ":" + unixUser.getShell() + "\n"); + ":" + unixUser.getShell() + "\n");
} }
private ShellProcessor createDelUserProc(String pacName) {
return new ShellProcessor("deluser --remove-all-files " + pacName);
}
private ShellProcessor createMakePacDirectoryStructure(UnixUser unixUser) { private ShellProcessor createMakePacDirectoryStructure(UnixUser unixUser) {
return new ShellProcessor("chmod 711 " + unixUser.getHomedir() + " && " + return new ShellProcessor("chmod 711 " + unixUser.getHomedir() + " && " +
"su -l " + unixUser.getName() + " -s \"/bin/bash\" -c \"mkdir -p " + "su -l " + unixUser.getName() + " -s \"/bin/bash\" -c \"mkdir -p " +