forked from I2P_Developers/i2p.i2p
Console: Add jsps to view entire router.log and wrapper.log files
Add links to /logs Add some headers to the history.txt jsp javadocs
This commit is contained in:
@ -63,6 +63,7 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
|||||||
pathInContext = "/index.jsp";
|
pathInContext = "/index.jsp";
|
||||||
} else if (pathInContext.indexOf("/", 1) < 0 &&
|
} else if (pathInContext.indexOf("/", 1) < 0 &&
|
||||||
(!pathInContext.endsWith(".jsp")) &&
|
(!pathInContext.endsWith(".jsp")) &&
|
||||||
|
(!pathInContext.endsWith(".log")) &&
|
||||||
(!pathInContext.endsWith(".txt"))) {
|
(!pathInContext.endsWith(".txt"))) {
|
||||||
// add .jsp to pages at top level
|
// add .jsp to pages at top level
|
||||||
pathInContext += ".jsp";
|
pathInContext += ".jsp";
|
||||||
|
@ -75,7 +75,7 @@ public class LogsHelper extends HelperBase {
|
|||||||
*/
|
*/
|
||||||
public String getLogs() {
|
public String getLogs() {
|
||||||
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
|
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
|
||||||
return "<p>" + _t("File location") + ": <b><code>" + _context.logManager().currentFile() + "</code></b></p>" + str;
|
return "<p>" + _t("File location") + ": <a href=\"/router.log\">" + _context.logManager().currentFile() + "</a></p>" + str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,9 +88,11 @@ public class LogsHelper extends HelperBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Does not necessarily exist.
|
* Does not necessarily exist.
|
||||||
* @since 0.9.1
|
*
|
||||||
|
* @return non-null, doesn't necessarily exist
|
||||||
|
* @since 0.9.1, public since 0.9.27
|
||||||
*/
|
*/
|
||||||
static File wrapperLogFile(I2PAppContext ctx) {
|
public static File wrapperLogFile(I2PAppContext ctx) {
|
||||||
File f = null;
|
File f = null;
|
||||||
if (ctx.hasWrapper()) {
|
if (ctx.hasWrapper()) {
|
||||||
String wv = System.getProperty("wrapper.version");
|
String wv = System.getProperty("wrapper.version");
|
||||||
@ -129,7 +131,7 @@ public class LogsHelper extends HelperBase {
|
|||||||
return "<p>" + _t("File not found") + ": <b><code>" + f.getAbsolutePath() + "</code></b></p>";
|
return "<p>" + _t("File not found") + ": <b><code>" + f.getAbsolutePath() + "</code></b></p>";
|
||||||
} else {
|
} else {
|
||||||
str = str.replace("&", "&").replace("<", "<").replace(">", ">");
|
str = str.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||||
return "<p>" + _t("File location") + ": <b><code>" + f.getAbsolutePath() + "</code></b></p><pre>" + str + "</pre>";
|
return "<p>" + _t("File location") + ": <a href=\"/wrapper.log\">" + f.getAbsolutePath() + "</a></p><pre>" + str + "</pre>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%
|
<%@page pageEncoding="UTF-8"%><%
|
||||||
/*
|
/*
|
||||||
* USE CAUTION WHEN EDITING
|
* USE CAUTION WHEN EDITING
|
||||||
* Trailing whitespace OR NEWLINE on the last line will cause
|
* Trailing whitespace OR NEWLINE on the last line will cause
|
||||||
@ -8,6 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.setHeader("X-Content-Type-Options", "nosniff");
|
response.setHeader("X-Content-Type-Options", "nosniff");
|
||||||
|
response.setDateHeader("Expires", 0);
|
||||||
|
response.addHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
|
||||||
|
response.addHeader("Pragma", "no-cache");
|
||||||
String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath();
|
String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath();
|
||||||
try {
|
try {
|
||||||
net.i2p.util.FileUtil.readFile("history.txt", base, response.getOutputStream());
|
net.i2p.util.FileUtil.readFile("history.txt", base, response.getOutputStream());
|
||||||
|
46
apps/routerconsole/jsp/viewrouterlog.jsp
Normal file
46
apps/routerconsole/jsp/viewrouterlog.jsp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<%@page pageEncoding="UTF-8"%><%
|
||||||
|
/*
|
||||||
|
* USE CAUTION WHEN EDITING
|
||||||
|
* Trailing whitespace OR NEWLINE on the last line will cause
|
||||||
|
* IllegalStateExceptions !!!
|
||||||
|
*
|
||||||
|
* Do not tag this file for translation.
|
||||||
|
*/
|
||||||
|
net.i2p.I2PAppContext ctx = net.i2p.I2PAppContext.getGlobalContext();
|
||||||
|
net.i2p.util.LogManager mgr = ctx.logManager();
|
||||||
|
mgr.flush();
|
||||||
|
java.io.File f = new java.io.File(mgr.currentFile());
|
||||||
|
long length = f.length();
|
||||||
|
if (length <= 0 || !f.isFile()) {
|
||||||
|
response.sendError(404, "Not Found");
|
||||||
|
} else {
|
||||||
|
response.setContentType("text/plain");
|
||||||
|
response.setHeader("X-Content-Type-Options", "nosniff");
|
||||||
|
response.setHeader("Content-Length", Long.toString(length));
|
||||||
|
response.setDateHeader("Expires", 0);
|
||||||
|
response.addHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
|
||||||
|
response.addHeader("Pragma", "no-cache");
|
||||||
|
java.io.InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = new java.io.FileInputStream(f);
|
||||||
|
java.io.OutputStream bout = response.getOutputStream();
|
||||||
|
int read = 0;
|
||||||
|
byte buf[] = new byte[4*1024];
|
||||||
|
while ((read = in.read(buf)) != -1) {
|
||||||
|
bout.write(buf, 0, read);
|
||||||
|
}
|
||||||
|
} catch (java.io.IOException ioe) {
|
||||||
|
// prevent 'Committed' IllegalStateException from Jetty
|
||||||
|
if (!response.isCommitted()) {
|
||||||
|
response.sendError(403, ioe.toString());
|
||||||
|
} else {
|
||||||
|
// not an error, happens when the browser closes the stream
|
||||||
|
// Jetty doesn't log this
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (in != null)
|
||||||
|
try { in.close(); } catch (java.io.IOException ioe) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%>
|
44
apps/routerconsole/jsp/viewwrapperlog.jsp
Normal file
44
apps/routerconsole/jsp/viewwrapperlog.jsp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<%@page pageEncoding="UTF-8"%><%
|
||||||
|
/*
|
||||||
|
* USE CAUTION WHEN EDITING
|
||||||
|
* Trailing whitespace OR NEWLINE on the last line will cause
|
||||||
|
* IllegalStateExceptions !!!
|
||||||
|
*
|
||||||
|
* Do not tag this file for translation.
|
||||||
|
*/
|
||||||
|
net.i2p.I2PAppContext ctx = net.i2p.I2PAppContext.getGlobalContext();
|
||||||
|
java.io.File f = net.i2p.router.web.LogsHelper.wrapperLogFile(ctx);
|
||||||
|
long length = f.length();
|
||||||
|
if (length <= 0 || !f.isFile()) {
|
||||||
|
response.sendError(404, "Not Found");
|
||||||
|
} else {
|
||||||
|
response.setContentType("text/plain");
|
||||||
|
response.setHeader("X-Content-Type-Options", "nosniff");
|
||||||
|
response.setHeader("Content-Length", Long.toString(length));
|
||||||
|
response.setDateHeader("Expires", 0);
|
||||||
|
response.addHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
|
||||||
|
response.addHeader("Pragma", "no-cache");
|
||||||
|
java.io.InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = new java.io.FileInputStream(f);
|
||||||
|
java.io.OutputStream bout = response.getOutputStream();
|
||||||
|
int read = 0;
|
||||||
|
byte buf[] = new byte[4*1024];
|
||||||
|
while ((read = in.read(buf)) != -1) {
|
||||||
|
bout.write(buf, 0, read);
|
||||||
|
}
|
||||||
|
} catch (java.io.IOException ioe) {
|
||||||
|
// prevent 'Committed' IllegalStateException from Jetty
|
||||||
|
if (!response.isCommitted()) {
|
||||||
|
response.sendError(403, ioe.toString());
|
||||||
|
} else {
|
||||||
|
// not an error, happens when the browser closes the stream
|
||||||
|
// Jetty doesn't log this
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (in != null)
|
||||||
|
try { in.close(); } catch (java.io.IOException ioe) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%>
|
@ -43,6 +43,16 @@
|
|||||||
<url-pattern>/history.txt</url-pattern>
|
<url-pattern>/history.txt</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>net.i2p.router.web.jsp.viewrouterlog_jsp</servlet-name>
|
||||||
|
<url-pattern>/router.log</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>net.i2p.router.web.jsp.viewwrapperlog_jsp</servlet-name>
|
||||||
|
<url-pattern>/wrapper.log</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<session-config>
|
<session-config>
|
||||||
<session-timeout>
|
<session-timeout>
|
||||||
30
|
30
|
||||||
|
@ -37,6 +37,7 @@ class FileLogWriter extends LogWriter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* File may not exist or have old logs in it if not opened yet
|
* File may not exist or have old logs in it if not opened yet
|
||||||
|
* @return non-null
|
||||||
*/
|
*/
|
||||||
public synchronized String currentFile() {
|
public synchronized String currentFile() {
|
||||||
if (_currentFile != null)
|
if (_currentFile != null)
|
||||||
|
@ -264,6 +264,10 @@ public class LogManager implements Flushable {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File may not exist or have old logs in it if not opened yet
|
||||||
|
* @return non-null
|
||||||
|
*/
|
||||||
public String currentFile() {
|
public String currentFile() {
|
||||||
if (_writer == null)
|
if (_writer == null)
|
||||||
return ("No log file created yet");
|
return ("No log file created yet");
|
||||||
|
@ -37,7 +37,12 @@ abstract class LogWriter implements Runnable {
|
|||||||
_lastReadConfig = Clock.getInstance().now();
|
_lastReadConfig = Clock.getInstance().now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File may not exist or have old logs in it if not opened yet
|
||||||
|
* @return non-null
|
||||||
|
*/
|
||||||
public abstract String currentFile();
|
public abstract String currentFile();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the provided LogRecord to the writer.
|
* Write the provided LogRecord to the writer.
|
||||||
* @param rec the LogRecord to write.
|
* @param rec the LogRecord to write.
|
||||||
|
Reference in New Issue
Block a user