setquota, traffic accounting

This commit is contained in:
Peter Hormanns 2011-08-03 17:05:20 +00:00
parent deea1a494b
commit f5c673054e
8 changed files with 95 additions and 49 deletions

View File

@ -0,0 +1,25 @@
package de.hsadmin.core.util;
import java.util.Random;
import de.rrze.jpwgen.flags.PwGeneratorFlagBuilder;
import de.rrze.jpwgen.impl.PwGenerator;
public class PasswordTool {
public static PwGeneratorFlagBuilder flagBuilder = new PwGeneratorFlagBuilder();
public static Random random = new Random();
static {
flagBuilder.setIncludeCapitals();
flagBuilder.setIncludeNumerals();
// flagBuilder.setIncludeReducedSymbols();
flagBuilder.setFilterAmbiguous();
}
public static String generatePassword() {
String password = PwGenerator.generatePassword(7, flagBuilder.build(), 100, random);
return password;
}
}

View File

@ -25,6 +25,9 @@ import de.hsadmin.mods.user.UnixUser;
public class DomainProcessorFactory implements EntityProcessorFactory {
private static final String[] DW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" };
private static final String[] SW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var" };
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException {
String hiveName = entity.getHiveName();
Domain dom = (Domain) entity;
@ -187,11 +190,13 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
private CompoundProcessor createDomainDirectoriesProcessor(Domain dom, Map<String, String> templateVars) throws ProcessorException {
UnixUser domUser = dom.getUser();
String domName = dom.getName();
String pacName = domUser.getPac().getName();
Pac pac = domUser.getPac();
boolean dynamicWeb = pac.isDynamicWeb();
String pacName = pac.getName();
String domsDir = domUser.getHomedir() + "/doms";
String userName = domUser.getName();
String domainDir = domsDir + "/" + dom.getName();
String[] subDirs = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" };
String[] subDirs = dynamicWeb ? DW_STRUCTURE : SW_STRUCTURE;
Processor mkDomainDirProzessor =
new ShellProcessor(
"mkdir --mode=1550 --parents " + domsDir + " && " +
@ -220,6 +225,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
domDirsProcessor.appendProcessor(
new CreateFileProcessor("/de/hsadmin/mods/dom/index.html.jtpl", templateVars, domainDir + "/subs-ssl/www/index.html", userName, pacName, "644")
);
if (dynamicWeb) {
domDirsProcessor.appendProcessor(
new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.jtpl", templateVars, domainDir + "/cgi/test.cgi", userName, pacName, "755")
);
@ -232,6 +238,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
domDirsProcessor.appendProcessor(
new CopyFileProcessor("/usr/local/src/phpstub/phpstub", domainDir + "/fastcgi-ssl/phpstub", userName, pacName, "755")
);
}
domDirsProcessor.appendProcessor(
new ShellProcessor("ln -s " + domainDir + " /home/doms/ && " +
"chown --no-dereference " + userName + ":httpd /home/doms/" + domName
@ -269,7 +276,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
if (domName.equals(pac.getName() + ".hostsharing.net")) {
return "/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl";
}
if (pac.getBasepac().getName().startsWith("DW")) {
if (pac.isDynamicWeb()) {
return "/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl";
}
return "/de/hsadmin/mods/dom/httpd-vhost-static.jtpl";

View File

@ -272,6 +272,10 @@ public class Pac extends AbstractEntity implements Serializable {
|| super.isReadAllowedFor(loginUser);
}
public boolean isDynamicWeb() {
return getBasepac().getName().startsWith("DW");
}
public static String restriction() {
return
// all pacs of customer

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import javax.persistence.EntityManager;
@ -18,22 +17,11 @@ import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.core.qserv.ShellProcessor;
import de.hsadmin.core.qserv.TemplateProcessor;
import de.hsadmin.core.qserv.WaitingTasksProcessor;
import de.hsadmin.core.util.PasswordTool;
import de.hsadmin.mods.user.UnixUser;
import de.rrze.jpwgen.flags.PwGeneratorFlagBuilder;
import de.rrze.jpwgen.impl.PwGenerator;
public class PacProcessorFactory implements EntityProcessorFactory {
private static PwGeneratorFlagBuilder flagBuilder = new PwGeneratorFlagBuilder();
private static Random random = new Random();
static {
flagBuilder.setIncludeCapitals();
flagBuilder.setIncludeNumerals();
// flagBuilder.setIncludeReducedSymbols();
flagBuilder.setFilterAmbiguous();
}
@Override
public <T extends AbstractEntity> Processor createCreateProcessor(
EntityManager em, T entity) throws ProcessorException {
@ -42,14 +30,16 @@ public class PacProcessorFactory implements EntityProcessorFactory {
String customerEMail = pac.getCustomer().getContractualContact().getEmail();
Hive hive = pac.getHive();
UnixUser unixUser = getPacAdminUser(pac);
String password = PwGenerator.generatePassword(7, flagBuilder.build(), 100, random);
String password = PasswordTool.generatePassword();
Map<String, String> hiveValues = fillHiveValues(hive);
List<Map<String, String>> pacValuesList = fillPacValuesList(hive, null);
Map<String, String> emailVars = fillEMailValues(pacName, customerEMail, password);
Processor priProcessor = new CompoundProcessor(
createAddUserProc(pacName, unixUser, password),
createSetQuotaProc(pac),
createEtcHostsProc(hiveValues, pacValuesList),
createNetworkInterfacesProc(hiveValues, pacValuesList),
createIPTablesProc(),
createSudouersProc(hiveValues, pacValuesList),
createProftpdConfProc(hiveValues, pacValuesList),
createMakePacDirectoryStructure(unixUser));
@ -65,8 +55,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
}
@Override
public <T extends AbstractEntity> Processor createDeleteProcessor(
EntityManager em, T entity) throws ProcessorException {
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
Pac pac = (Pac) entity;
Hive hive = pac.getHive();
Map<String, String> hiveValues = fillHiveValues(hive);
@ -80,32 +69,35 @@ public class PacProcessorFactory implements EntityProcessorFactory {
return waitingProcessor;
}
private TemplateProcessor createEtcHostsProc(
private Processor createEtcHostsProc(
Map<String, String> hiveValues,
List<Map<String, String>> pacValuesList) throws ProcessorException {
return new TemplateProcessor("/de/hsadmin/mods/pac/hosts.jtpl", hiveValues, pacValuesList.iterator(), "/etc/hosts", true);
}
private TemplateProcessor createNetworkInterfacesProc(
private Processor createNetworkInterfacesProc(
Map<String, String> hiveValues,
List<Map<String, String>> pacValuesList) throws ProcessorException {
return new TemplateProcessor("/de/hsadmin/mods/pac/interfaces.jtpl", hiveValues, pacValuesList.iterator(), "/etc/network/interfaces", true);
}
private TemplateProcessor createSudouersProc(
private Processor createIPTablesProc() {
return new ShellProcessor("mk-iptables-rules Accounting");
}
private Processor createSudouersProc(
Map<String, String> hiveValues,
List<Map<String, String>> pacValuesList) throws ProcessorException {
return new TemplateProcessor("/de/hsadmin/mods/pac/sudoers.jtpl", hiveValues, pacValuesList.iterator(), "/etc/sudoers", true);
}
private TemplateProcessor createProftpdConfProc(
private Processor createProftpdConfProc(
Map<String, String> hiveValues,
List<Map<String, String>> pacValuesList) throws ProcessorException {
return new TemplateProcessor("/de/hsadmin/mods/pac/proftpd-conf.jtpl", hiveValues, pacValuesList.iterator(), "/etc/proftpd/proftpd.conf", true);
}
private ShellProcessor createAddUserProc(String pacName, UnixUser unixUser,
String password) {
private Processor createAddUserProc(String pacName, UnixUser unixUser, String password) {
return new ShellProcessor(
"newusers", pacName + ":" + password + ":"
+ unixUser.getUserId() + ":" + unixUser.getUserId()
@ -113,11 +105,31 @@ public class PacProcessorFactory implements EntityProcessorFactory {
+ ":" + unixUser.getShell() + "\n");
}
private ShellProcessor createDelUserProc(String pacName) {
private Processor createSetQuotaProc(Pac pac) {
int quota = 128;
Set<PacComponent> pacComponents = pac.getPacComponents();
for (PacComponent pacComponent : pacComponents) {
BaseComponent baseComponent = pacComponent.getBaseComponent();
String feature = baseComponent.getFeature();
if ("QUOTA".equals(feature)) {
quota = pacComponent.getQuantity();
}
}
int blocksSoft = quota * 1024;
int blocksHard = quota * 1024 * 2;
int inodesSoft = blocksSoft / 4;
int inodesHard = blocksHard / 4;
return new ShellProcessor("setquota -g " + pac.getName() + " "
+ blocksSoft + " " + blocksHard + " "
+ inodesSoft + " " + inodesHard + " "
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`");
}
private Processor createDelUserProc(String pacName) {
return new ShellProcessor("rm -rf /home/pacs/" + pacName + "/* && deluser --remove-all-files " + pacName + ">/dev/null 2>&1");
}
private ShellProcessor createMakePacDirectoryStructure(UnixUser unixUser) {
private Processor createMakePacDirectoryStructure(UnixUser unixUser) {
return new ShellProcessor("chmod 711 " + unixUser.getHomedir() + " && " +
"su -l " + unixUser.getName() + " -s \"/bin/bash\" -c \"mkdir -p " +
unixUser.getHomedir() + "/doms " +

View File

@ -55,7 +55,7 @@ public class InitDataTest {
setParams.put("contact_city", "Musterstadt");
setParams.put("contact_country", "D");
setParams.put("contact_phone_private", "+49 9999 123456");
setParams.put("contact_email", "rainer.mustermann@example.org");
setParams.put("contact_email", "test@ostwall195.de");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };

View File

@ -12,7 +12,6 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class MysqlUserTest {

View File

@ -12,7 +12,6 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class PgsqlUserTest {

View File

@ -6,16 +6,16 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
InitDataTest.class,
PacTest.class,
UnixUserTest.class,
MysqlUserTest.class,
MysqlDbTest.class,
PgsqlUserTest.class,
PgsqlDbTest.class,
// PacTest.class,
// UnixUserTest.class,
// MysqlUserTest.class,
// MysqlDbTest.class,
// PgsqlUserTest.class,
// PgsqlDbTest.class,
// EMailAliasTest.class,
// DomainTest.class,
// EMailAddressTest.class,
CustomerTest.class
// CustomerTest.class
// HostmasterTest.class,
// QueueTaskTest.class
})