[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-web/master] Don't break if URL starts with /ernie/.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed, 13 Oct 2010 21:32:42 +0200
Subject: Don't break if URL starts with /ernie/.
Commit: 00fbc6668b741bd4b5bb6452dd8f84f428195aa7
---
.../ernie/web/ErnieGeneratedFileServlet.java | 7 ++++++-
.../torproject/ernie/web/GraphImageServlet.java | 12 +++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
index 3670eb2..747b16d 100644
--- a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
+++ b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
@@ -13,8 +13,13 @@ public class ErnieGeneratedFileServlet extends HttpServlet {
ServletException {
/* Read file from disk and write it to response. */
+ String requestedURL = request.getRequestURI();
+ if (requestedURL.contains("/")) {
+ requestedURL = requestedURL.substring(requestedURL.
+ lastIndexOf("/"));
+ }
String fn = "/srv/metrics.torproject.org/ernie/website"
- + request.getRequestURI();
+ + requestedURL;
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
diff --git a/src/org/torproject/ernie/web/GraphImageServlet.java b/src/org/torproject/ernie/web/GraphImageServlet.java
index 333ef65..d1d5f21 100644
--- a/src/org/torproject/ernie/web/GraphImageServlet.java
+++ b/src/org/torproject/ernie/web/GraphImageServlet.java
@@ -73,12 +73,18 @@ public class GraphImageServlet extends HttpServlet {
/* Find out which graph type was requested and make sure we know this
* graph type. */
String requestedGraph = request.getRequestURI();
- if (requestedGraph == null || requestedGraph.length() < 6) {
+ if (requestedGraph == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
- requestedGraph = requestedGraph.substring(1,
- requestedGraph.length() - 4);
+ if (requestedGraph.endsWith(".png")) {
+ requestedGraph = requestedGraph.substring(0, requestedGraph.length()
+ - ".png".length());
+ }
+ if (requestedGraph.contains("/")) {
+ requestedGraph = requestedGraph.substring(requestedGraph.
+ lastIndexOf("/") + 1);
+ }
if (!this.availableGraphs.containsKey(requestedGraph)) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
--
1.7.1