commit c51b324e13e11ac7451ea72c816c0332f59bd445 Author: Karsten Loesing karsten.loesing@gmx.net Date: Mon Apr 2 17:25:29 2012 +0200
Make Onionoo out/ directory configurable. --- .gitignore | 1 + build.xml | 4 +++ etc/web.xml | 29 -------------------- etc/web.xml.template | 33 +++++++++++++++++++++++ src/org/torproject/onionoo/ResourceServlet.java | 13 ++++++--- 5 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/.gitignore b/.gitignore index 4ee5771..2848bda 100755 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ lib/ classes/ out/ onionoo.war +etc/web.xml etc/context.xml GeoIP.dat GeoIPASNum.dat diff --git a/build.xml b/build.xml index 652a49b..878c07f 100644 --- a/build.xml +++ b/build.xml @@ -7,6 +7,9 @@ <property name="contextxmltemplate" value="${config}/context.xml.template"/> <property name="contextxml" value="${config}/context.xml"/> + <property name="webxmltemplate" + value="${config}/web.xml.template"/> + <property name="webxml" value="${config}/web.xml"/> <property name="warfile" value="onionoo.war"/> <path id="classpath"> <pathelement path="${classes}"/> @@ -18,6 +21,7 @@ </path> <target name="init"> <copy file="${contextxmltemplate}" tofile="${contextxml}"/> + <copy file="${webxmltemplate}" tofile="${webxml}"/> <mkdir dir="${classes}"/> </target> <target name="compile" diff --git a/etc/web.xml b/etc/web.xml deleted file mode 100644 index 7855706..0000000 --- a/etc/web.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<web-app version="2.4" - xmlns="http://java.sun.com/xml/ns/j2ee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee - http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > - - <servlet> - <servlet-name>Resource</servlet-name> - <servlet-class> - org.torproject.onionoo.ResourceServlet - </servlet-class> - </servlet> - <servlet-mapping> - <servlet-name>Resource</servlet-name> - <url-pattern>/summary/*</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>Resource</servlet-name> - <url-pattern>/details/*</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>Resource</servlet-name> - <url-pattern>/bandwidth/*</url-pattern> - </servlet-mapping> - -</web-app> - diff --git a/etc/web.xml.template b/etc/web.xml.template new file mode 100644 index 0000000..4cba2b5 --- /dev/null +++ b/etc/web.xml.template @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<web-app version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee + http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > + + <servlet> + <servlet-name>Resource</servlet-name> + <servlet-class> + org.torproject.onionoo.ResourceServlet + </servlet-class> + <init-param> + <param-name>outDir</param-name> + <param-value>/srv/onionoo/out/</param-value> + </init-param> + </servlet> + <servlet-mapping> + <servlet-name>Resource</servlet-name> + <url-pattern>/summary/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>Resource</servlet-name> + <url-pattern>/details/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>Resource</servlet-name> + <url-pattern>/bandwidth/*</url-pattern> + </servlet-mapping> + +</web-app> + diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java index 037657e..55a96ff 100644 --- a/src/org/torproject/onionoo/ResourceServlet.java +++ b/src/org/torproject/onionoo/ResourceServlet.java @@ -15,6 +15,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern;
+import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -28,7 +29,11 @@ public class ResourceServlet extends HttpServlet {
private static final long serialVersionUID = 7236658979947465319L;
- public void init() { + private String outDirString; + + public void init(ServletConfig config) throws ServletException { + super.init(config); + this.outDirString = config.getInitParameter("outDir"); this.readSummaryFile(); }
@@ -41,7 +46,7 @@ public class ResourceServlet extends HttpServlet { relayFingerprintSummaryLines = new HashMap<String, String>(), bridgeFingerprintSummaryLines = new HashMap<String, String>(); private void readSummaryFile() { - File summaryFile = new File("/srv/onionoo/out/summary.json"); + File summaryFile = new File(this.outDirString + "summary.json"); if (!summaryFile.exists()) { readSummaryFile = false; return; @@ -427,7 +432,7 @@ public class ResourceServlet extends HttpServlet { return ""; } fingerprint = fingerprint.substring(0, 40); - File detailsFile = new File("/srv/onionoo/out/details/" + File detailsFile = new File(this.outDirString + "details/" + fingerprint); StringBuilder sb = new StringBuilder(); String detailsLines = null; @@ -472,7 +477,7 @@ public class ResourceServlet extends HttpServlet { return ""; } fingerprint = fingerprint.substring(0, 40); - File detailsFile = new File("/srv/onionoo/out/bandwidth/" + File detailsFile = new File(this.outDirString + "bandwidth/" + fingerprint); StringBuilder sb = new StringBuilder(); String bandwidthLines = null;