Merge branch 'master' of ssh://hsh04-source@hsh04.hostsharing.net/home/doms/source.hostsharing.net/source/hsadmin.git/

This commit is contained in:
Peter Hormanns 2012-09-21 16:19:03 +02:00
commit 3f23cec1c2
4 changed files with 49 additions and 10 deletions

View File

@ -213,9 +213,12 @@ public class CLIClientConnectorServlet extends HttpServlet {
while (wkeys.hasNext()) {
String k = (String) wkeys.next();
String kname = hasGetter(eType, k);
String kvalue = ( (k.equals("id"))
? ( AbstractEntity.escapeString(where.get(k)) )
: ( "'" + AbstractEntity.escapeString(where.get(k)) + "'" ) );
if (kname != null) {
rval += (first ? "" : " and ")
+ "(obj." + AbstractEntity.escapeString(kname) + " = '" + AbstractEntity.escapeString(where.get(k)) + "')";
+ "(obj." + AbstractEntity.escapeString(kname) + " = " + kvalue + ")";
first = false;
} else {
throw new ServletException("illegal input (unknown field: " + k + ")");

View File

@ -1,6 +1,7 @@
package de.hsadmin.mods.dom;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -89,8 +90,25 @@ public class DomainModuleImpl extends AbstractModuleImpl {
if (admin == null || admin.getName() == null || admin.getName().length() == 0) {
throw new HSAdminException("domain admin required");
}
// Standard domainoptions setzen. TODO: Alle defaults über eigene Klasse aus der Datenbank holen.
HashSet<DomainOption> domainOptions = new HashSet<DomainOption>();
DomainOption domainOption = new DomainOption();
domainOption.setName("greylisting");
domainOptions.add(domainOption);
EntityManager em = getTransaction().getEntityManager();
Query q = em.createQuery("SELECT opt FROM " +
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
" opt WHERE opt.name=:optName");
for (DomainOption opt : domainOptions) {
q.setParameter("optName", opt.getName());
List<?> list = q.getResultList();
if (list.size() != 1) {
throw new HSAdminException("invalid domain option: " + opt.getName());
} else {
opt.setId(((DomainOption) list.get(0)).getId());
}
dom.setDomainoptions(domainOptions);
UnixUser loginUser = getTransaction().getLoginUser();
if (!loginUser.hasHostmasterRole()) {
// search for domains superior to dom

View File

@ -375,17 +375,32 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
String domDir = pacDir + "/doms/" + pac.getName() + ".hostsharing.net";
String[] sourceDirs = new String[] { "web", "web-ssl", "cgi", "cgi-ssl", "fastcgi", "fastcgi-ssl" } ;
String[] targetDirs = new String[] { "htdocs", "htdocs-ssl", "cgi", "cgi-ssl", "fastcgi", "fastcgi-ssl" } ;
CompoundProcessor processor = new CompoundProcessor(
new ShellProcessor("rm -rf " + domDir + "/subs " + domDir + "/htdocs/.htaccess "
+ domDir + "/subs-ssl " + domDir + "/htdocs-ssl/.htaccess "));
CompoundProcessor processor = new CompoundProcessor();
for (int idx = 0; idx < targetDirs.length; idx++) {
processor.appendProcessor(
new ShellProcessor("rm -rf " + domDir + targetDirs[idx]));
}
for (int idx = 0; idx < sourceDirs.length; idx++) {
processor.appendProcessor(
new ShellProcessor("shopt -s dotglob && ls " + pacDir + "/" + sourceDirs[idx] + " >/dev/null 2>&1" +
" && mv " + pacDir + "/" + sourceDirs[idx] + "/* " + domDir + "/" + targetDirs[idx] + "/ " +
" && ( rmdir " + pacDir + "/" + sourceDirs[idx] + " || rm " + pacDir + "/" + sourceDirs[idx] + " ) " +
" && mv " + pacDir + "/" + sourceDirs[idx] + domDir + "/" + targetDirs[idx] +
" || echo 'directory " + pacDir + "/" + sourceDirs[idx] + " not found'"));
}
return processor;
}
processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs" +
" && `stat -c '%N' " + domDir + "/htdocs |sed -e's/^.*`//' -e\"s/'$//\"` = web-ssl " +
" && cd " + domDir +
" && rm " + domDir + "/htdocs" +
" && ln -sf htdocs-ssl htdocs" +
" && chown -h " + pac + ":" + pac + " " + domDir + "/htdocs"));
processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs-ssl" +
" && `stat -c '%N' " + domDir + "/htdocs-ssl |sed -e's/^.*`//' -e\"s/'$//\"` = web " +
" && cd " + domDir +
" && rm " + domDir + "/htdocs-ssl" +
" && ln -sf htdocs htdocs-ssl" +
" && chown -h " + pac + ":" + pac + " " + domDir + "/htdocs-ssl"));
return processor;
}
private String selectVHostTemplate(Domain dom) {

View File

@ -88,7 +88,7 @@ public class DomainTest {
}
@Test
public void testCreate() {
public void testCreate() throws UnknownHostException, IOException {
int count = getDomsCount();
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
@ -105,6 +105,9 @@ public class DomainTest {
fail(e.getMessage());
}
assertEquals(count + 1, getDomsCount());
// TODO die beiden folgenden Tests sind etwas spezifisch für Version 2.2
assertEquals("eine neue Domain sollte nur die Domainoption 'greylisting' haben.",1,getDomOptionsCount());
testGreylistingOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
}
@Test