HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2011-08-03 f5c673054e023574bcfb2758a0032ba5bfbee93a
setquota, traffic accounting
1 files added
7 files modified
144 ■■■■■ changed files
hsarback/src/de/hsadmin/core/util/PasswordTool.java 25 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 35 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/Pac.java 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java 62 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/InitDataTest.java 2 ●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/MysqlUserTest.java 1 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/PgsqlUserTest.java 1 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/RemoteTest.java 14 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/util/PasswordTool.java
New 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;
    }
}
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -25,6 +25,9 @@
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 @@
    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,18 +225,20 @@
        domDirsProcessor.appendProcessor(
                new CreateFileProcessor("/de/hsadmin/mods/dom/index.html.jtpl", templateVars, domainDir + "/subs-ssl/www/index.html", userName, pacName, "644")
            );
        domDirsProcessor.appendProcessor(
                new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.jtpl", templateVars, domainDir + "/cgi/test.cgi", userName, pacName, "755")
        if (dynamicWeb) {
            domDirsProcessor.appendProcessor(
                    new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.jtpl", templateVars, domainDir + "/cgi/test.cgi", userName, pacName, "755")
                );
            domDirsProcessor.appendProcessor(
                    new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.jtpl", templateVars, domainDir + "/cgi-ssl/test.cgi", userName, pacName, "755")
                );
            domDirsProcessor.appendProcessor(
                    new CopyFileProcessor("/usr/local/src/phpstub/phpstub", domainDir + "/fastcgi/phpstub", userName, pacName, "755")
                );
            domDirsProcessor.appendProcessor(
                    new CopyFileProcessor("/usr/local/src/phpstub/phpstub", domainDir + "/fastcgi-ssl/phpstub", userName, pacName, "755")
            );
        domDirsProcessor.appendProcessor(
                new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.jtpl", templateVars, domainDir + "/cgi-ssl/test.cgi", userName, pacName, "755")
            );
        domDirsProcessor.appendProcessor(
                new CopyFileProcessor("/usr/local/src/phpstub/phpstub", domainDir + "/fastcgi/phpstub", userName, pacName, "755")
            );
        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 @@
        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";
hsarback/src/de/hsadmin/mods/pac/Pac.java
@@ -272,6 +272,10 @@
                || super.isReadAllowedFor(loginUser);
    }
    public boolean isDynamicWeb() {
        return getBasepac().getName().startsWith("DW");
    }
    public static String restriction() {
        return
            // all pacs of customer
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
@@ -4,7 +4,6 @@
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.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 @@
        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),
                createNetworkInterfacesProc(hiveValues, pacValuesList),
                createIPTablesProc(),
                createSudouersProc(hiveValues, pacValuesList), 
                createProftpdConfProc(hiveValues, pacValuesList), 
                createMakePacDirectoryStructure(unixUser));
@@ -65,8 +55,7 @@
    }
    @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 @@
        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 @@
                        + ":" + 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 " + 
hsarback/test/de/hsadmin/remote/InitDataTest.java
@@ -55,7 +55,7 @@
        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 };
hsarback/test/de/hsadmin/remote/MysqlUserTest.java
@@ -12,7 +12,6 @@
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 {
hsarback/test/de/hsadmin/remote/PgsqlUserTest.java
@@ -12,7 +12,6 @@
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 {
hsarback/test/de/hsadmin/remote/RemoteTest.java
@@ -6,16 +6,16 @@
@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
})