Author: ssolsagl
Date: 2007-04-27 08:17:48 +0200 (Fri, 27 Apr 2007)
New Revision: 4900
Modified:
trunk/war/src/main/java/no/schibstedsok/searchportal/http/servlet/VelocityDebugServlet.java
Log:
Servlet that switches velocitydebug on/off
Modified:
trunk/war/src/main/java/no/schibstedsok/searchportal/http/servlet/VelocityDebugServlet.java
===================================================================
---
trunk/war/src/main/java/no/schibstedsok/searchportal/http/servlet/VelocityDebugServlet.java
2007-04-27 05:55:38 UTC (rev 4899)
+++
trunk/war/src/main/java/no/schibstedsok/searchportal/http/servlet/VelocityDebugServlet.java
2007-04-27 06:17:48 UTC (rev 4900)
@@ -18,23 +18,38 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+/**
+ * Servlet for switcing velocitydebug on/off
+ * @author ola <a mailto="[EMAIL PROTECTED]"> [EMAIL PROTECTED] </a>
+ *
+ */
public class VelocityDebugServlet extends HttpServlet{
- static String VELOCITY_DEBUG = "VELOCITY_DEBUG";
- static String HTML = "html";
- static String BODY = "body";
- static String HEADER = "h2";
- static String ON_OFF = "Velocityborder is ";
+ private static final Logger LOG =
Logger.getLogger(VelocityDebugServlet.class);
+ /* Key for switching velocitydebug on/off */
+ private static final String VELOCITY_DEBUG = "VELOCITY_DEBUG";
+ /* Html tag */
+ private static final String HTML = "html";
+ /* Body tag */
+ private static final String BODY = "body";
+ /* Header tag */
+ private static final String HEADER = "h2";
+ /* Message to user */
+ private static final String ON_OFF = "Velocityborder is ";
- static {
- }
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
+
+ if(!isLocalhost(request)) {
+ LOG.warn("velocitydebug when running localhost only.");
+ return;
+ }
// TODO Auto-generated method stub
String velocityDebug = System.getProperty(VELOCITY_DEBUG);
String debugStatus = "false";
@@ -60,6 +75,14 @@
internalWriteDocument(doc, response.getWriter());
}
+
+ /*
+ * Assure that debug is only used when running localhost
+ */
+ private boolean isLocalhost(HttpServletRequest request) {
+ String ipAddr = (String)request.getAttribute("REMOTE_ADDR") +
"";
+ return ipAddr.startsWith("127.") || ipAddr.startsWith("10.") ||
ipAddr.startsWith("0:0:0:0:0:0:0:1%0");
+ }
// -- Write the document to the writer
private void internalWriteDocument(Document d, Writer w) {
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits