From e762eb2145f513284a31a5f11326539efa50f7b2 Mon Sep 17 00:00:00 2001
From: Purodha <bli00@hostsharing.net>
Date: Tue, 02 Apr 2013 17:56:29 +0200
Subject: [PATCH] Merge branch 'master' of ssh://hsh04-source@hsh04.hostsharing.net/home/doms/source.hostsharing.net/source/hsadmin.git

---
 hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm              |    2 
 hsarback/conf/WEB-INF/prod-web.xml                           |   30 ++++++++++
 hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm          |    8 ++
 hsarback/conf/META-INF/prod-context.xml                      |   25 ++++++++
 hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm           |    4 
 hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java |   46 ++++++++-------
 hsarback/src/de/hsadmin/mods/dom/htaccess.vm                 |    2 
 hsarjcli/scripting/package_dump.js                           |   14 ++--
 8 files changed, 98 insertions(+), 33 deletions(-)

diff --git a/hsarback/conf/META-INF/prod-context.xml b/hsarback/conf/META-INF/prod-context.xml
index e84ba48..4ccd702 100644
--- a/hsarback/conf/META-INF/prod-context.xml
+++ b/hsarback/conf/META-INF/prod-context.xml
@@ -66,6 +66,16 @@
 		type="javax.jms.Queue"/>
 
 	<ResourceLink
+		name="jms/hsadminSystem-h53"
+		global="jms/hsadminSystem-h53"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-h54"
+		global="jms/hsadminSystem-h54"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
 		name="jms/hsadminSystem-h55"
 		global="jms/hsadminSystem-h55"
 		type="javax.jms.Queue"/>
@@ -86,6 +96,21 @@
 		type="javax.jms.Queue"/>
 
 	<ResourceLink
+		name="jms/hsadminSystem-h59"
+		global="jms/hsadminSystem-h59"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-h60"
+		global="jms/hsadminSystem-h60"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-h61"
+		global="jms/hsadminSystem-h61"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
 		name="jms/hsadminSystem-mail1"
 		global="jms/hsadminSystem-mail1"
 		type="javax.jms.Queue"/>
diff --git a/hsarback/conf/WEB-INF/prod-web.xml b/hsarback/conf/WEB-INF/prod-web.xml
index fd9035e..2366b25 100644
--- a/hsarback/conf/WEB-INF/prod-web.xml
+++ b/hsarback/conf/WEB-INF/prod-web.xml
@@ -230,6 +230,18 @@
         <res-sharing-scope>Shareable</res-sharing-scope>
     </resource-ref>
     <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h53</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h54</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
         <res-ref-name>jms/hsadminSystem-h55</res-ref-name>
         <res-type>javax.jms.Queue</res-type>
         <res-auth>Container</res-auth>
@@ -254,6 +266,24 @@
         <res-sharing-scope>Shareable</res-sharing-scope>
     </resource-ref>
     <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h59</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h60</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h61</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
         <res-ref-name>jms/hsadminSystem-dns1</res-ref-name>
         <res-type>javax.jms.Queue</res-type>
         <res-auth>Container</res-auth>
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
index d329536..8b92cf5 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -39,7 +39,7 @@
 		Domain dom = (Domain) entity;
 		UnixUser domUser = dom.getUser();
 		Pac pac = domUser.getPac();
-		WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(dom));
+		WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(em, dom));
 		mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, dom), "Setup EMail");
 		Config config = Config.getInstance();
 		for (String queueName : config.getProperty("queues.dns").split(",")) {
@@ -82,7 +82,19 @@
 		return mainProcessor;
 	}
 
-	private Processor createHiveDNSSetupProcessor(Domain dom) throws ProcessorException {
+	private Processor createDNSServerConfigProcessor(EntityManager em) {
+		Query query = em.createQuery("SELECT d FROM Domains d");		
+		HashMap<String, Object> templateVars = new HashMap<String, Object>();
+		templateVars.put("domains", query.getResultList());
+		return new CompoundProcessor(
+			new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm",
+						templateVars, "/etc/bind/named-hsh.conf.tmp", true),
+			new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " +
+					"|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )")
+		);		
+	}
+
+	private Processor createHiveDNSSetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
 		Map<String, Object> templateVars = new HashMap<String, Object>();
 		templateVars.put("sio", Long.toString(System.currentTimeMillis()/1000L));
 		String domName = dom.getName();
@@ -91,14 +103,18 @@
 			new VelocityProcessor("/de/hsadmin/mods/dom/zonefile.vm", templateVars, dom, zonefileTargetPath, false);
 		Processor zonefileACLProcessor = 
 			new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath);
-		// TODO Use templates and regenerate the file.
-		Processor prizonesFileProcessor = 
-			new ShellProcessor("echo 'zone \"" + domName + "\" { type master; file \"pri." + domName + "\"; };' >>/etc/bind/named.pri-zones" +
-				" && sort /etc/bind/named.pri-zones | uniq >/etc/bind/named.pri-zones.tmp" +
-				" && mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones");
-		Processor dnsReloadProcessor = new ShellProcessor("invoke-rc.d bind9 reload");
+		Query query = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hivename");	
+		query.setParameter("hivename", dom.getUser().getHiveName());
+		templateVars = new HashMap<String, Object>();
+		templateVars.put("domains", query.getResultList());
+		Processor prizonesFileProcessor = new CompoundProcessor(
+			new VelocityProcessor("/de/hsadmin/mods/dom/named-pri-zones.vm", 
+						templateVars, dom, "/etc/bind/named.pri-zones.tmp", true),
+			new ShellProcessor(" ( diff -q /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && rm /etc/bind/named.pri-zones.tmp ) " +
+					"|| ( mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && invoke-rc.d bind9 reload )")
+		);		
 		Processor dnsSetupProcessor = 
-			new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor, dnsReloadProcessor);
+			new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor);
 		return dnsSetupProcessor;
 	}
 
@@ -122,18 +138,6 @@
 			emailAdrProcessor.appendProcessor(eMailAddressProcessorFactory.createCreateProcessor(em, eMailAddress));
 		}
 		return emailAdrProcessor;
-	}
-
-	private Processor createDNSServerConfigProcessor(EntityManager em) {
-		Query query = em.createQuery("SELECT d FROM Domains d");		
-		HashMap<String, Object> templateVars = new HashMap<String, Object>();
-		templateVars.put("domains", query.getResultList());
-		return new CompoundProcessor(
-			new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm",
-						templateVars, "/etc/bind/named-hsh.conf.tmp", true),
-			new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " +
-					"|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )")
-		);		
 	}
 
 	private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
diff --git a/hsarback/src/de/hsadmin/mods/dom/htaccess.vm b/hsarback/src/de/hsadmin/mods/dom/htaccess.vm
index dd5e6d3..8473496 100644
--- a/hsarback/src/de/hsadmin/mods/dom/htaccess.vm
+++ b/hsarback/src/de/hsadmin/mods/dom/htaccess.vm
@@ -1 +1 @@
-Redirect permanent / ${protocol}://www.${domain.name}/
+Redirect permanent / ${protocol}://www.${dom.name}/
diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm
index 709794b..ee021b5 100644
--- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm
+++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm
@@ -51,7 +51,7 @@
 
     RewriteCond %{REQUEST_URI} !^/cgi-bin/
     RewriteCond %{REQUEST_URI} !^/fastcgi-bin/    
-    RewriteCond %{HTTP_HOST} ^(.+)\.${dom.name}\.?(:[0-9]+)?\$ [novary]
+    RewriteCond %{HTTP_HOST} ^(.+)\.${dom.name}\.?(:[0-9]+)?$ [novary]
     RewriteCond /home/doms/${dom.name}/subs/#[[${tolower:%1} ]]# -d
     RewriteRule ^(.*) /home/doms/${dom.name}/subs/#[[${tolower:%1}$1 ]]# [last]     
     
diff --git a/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
index 09a553c..be4f101 100644
--- a/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
+++ b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
@@ -4,5 +4,5 @@
 //
 
 #foreach( $domain in ${domains} )
-zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetaddr}; }; };
-#end
\ No newline at end of file
+zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; };
+#end
diff --git a/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm b/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm
new file mode 100644
index 0000000..ba2286d
--- /dev/null
+++ b/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm
@@ -0,0 +1,8 @@
+//
+// This file is managed by HSAdmin.
+// Do not edit manually. Changes will be overwritten.
+//
+
+#foreach( $domain in ${domains} )
+zone "${domain.name}" { type master; file "pri.${domain.name}"; };
+#end
diff --git a/hsarjcli/scripting/package_dump.js b/hsarjcli/scripting/package_dump.js
index 134a87a..628747e 100644
--- a/hsarjcli/scripting/package_dump.js
+++ b/hsarjcli/scripting/package_dump.js
@@ -29,14 +29,12 @@
 			+ "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump;
 	runbash(cmd);
 }
-function mysqlpasswddump(pac) {
+function mysqlaclsdump(pac) {
 	var dump = "/home/pacs/" + pac + "/.bak/mysql_passwd.gz";
-	var sql = "select concat('update user set Password=\\\'', Password, '\\\' where User=\\\'', User, '\\\';')"
-	       	+ " as update_passwd from user where user like '" + pac + "%';";
-	var cmd = "( ( echo \"" + sql + "\"|mysql mysql ) ; echo \"flush privileges;\" )"
-			+ "|sed '1d'|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump;
+	var cmd = "mysqldump --no-create-db --skip-opt --no-create-info --replace --where=\"user like '" + pac + "%'\" mysql --tables user > " + dump
+		+ " && mysqldump --no-create-db --skip-opt --no-create-info --replace --where=\"db like '" + pac + "%'\" mysql --tables db tables_priv proc >>" + dump;
 	runbash(cmd);
-}
+} 
 function pgsqlpasswddump(pac) {
 	var dump = "/home/pacs/" + pac + "/.bak/pgsql_passwd.gz";
 	var cmd = "export PGUSER=postgres; pg_dumpall -r | grep ^ALTER | grep " + pac
@@ -129,7 +127,7 @@
 		    file.write('target: [\n');
 		    if (addresses[idx]['target']) {
 				for (jdx=0; jdx<addresses[idx]['target'].length; jdx++) {
-			    	file.write('     "' + addresses[idx]['target'][jdx] + '",\n');
+			    	file.write('     \'' + addresses[idx]['target'][jdx] + '\',\n');
 				}
 			}
 		    file.write('  ]\n');
@@ -207,7 +205,7 @@
 	}
 	file.close();
 	shadowdump(pacname);
-	mysqlpasswddump(pacname);
+	mysqlaclsdump(pacname);
 	pgsqlpasswddump(pacname);
 } else {
     print('run as pac-owner!\n');

--
Gitblit v1.9.0-SNAPSHOT