Serve local files in the docs/ directory, for CSS and images in error pages, using the reserved address proxy.i2p (similar to p.p in privoxy). This solves the problems with including links to the router console, as assuming the router console is at 127.0.0.1 leads to broken links if it isn't.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LogLogger for this class.private static final StringThese strings go in the jar, not the war.private static final StringReply page for an unknown command.private static final StringReply page when adding a tunnel fails.private static final StringReply page when a base32 address is invalid.private static final StringStylesheet links shared by the reply pages.private static final StringLogo block shared by the reply pages.private static final StringReply page carrying a freshly generated destination.private static final StringReply page for a successful command.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprotected static StringTranslate a message key using the proxy message bundle.protected static StringTranslate a message key with one parameter.protected static StringTranslate a message key with two parameters.static StringDecode percent-encoded (%xx) strings.decodeQuery(String query) Parse an encoded query.static voidserveLocalFile(I2PAppContext context, I2PSocketManager sockMgr, OutputStream out, String method, String targetRequest, String query, String proxyNonce, boolean allowGzip) Very simple web server.private static voidwriteB32RedirectPage(OutputStream out, String host, String url) Write a blinding info redirect page to the output stream.private static voidwriteRedirectPage(OutputStream out, boolean success, String host, String book, String url) Send the redirect result page to the browser.
Field Details
_log
Logger for this class.ERR_404
ERR_ADD
Reply page when adding a tunnel fails.- See Also:
ERR_B32
Reply page when a base32 address is invalid.- See Also:
OK
NEWKEY
Reply page carrying a freshly generated destination.- See Also:
headerLinks
Stylesheet links shared by the reply pages.- See Also:
logo
BUNDLE_NAME
These strings go in the jar, not the war.- See Also:
Constructor Details
LocalHTTPServer
public LocalHTTPServer()Construct the tunnel's local HTTP server.
Method Details
serveLocalFile
public static void serveLocalFile(I2PAppContext context, I2PSocketManager sockMgr, OutputStream out, String method, String targetRequest, String query, String proxyNonce, boolean allowGzip) throws IOException Very simple web server.Serve local files in the docs/ directory, for CSS and images in error pages, using the reserved address proxy.i2p (similar to p.p in privoxy). This solves the problems with including links to the router console, as assuming the router console is at 127.0.0.1 leads to broken links if it isn't.
Ignore all request headers (If-Modified-Since, etc.)
There is basic protection here -
FileUtil.readFile(String, String, OutputStream)prevents traversal above the base directory - but inproxy/gateway ops would be wise to block proxy.i2p to prevent exposing the docs/ directory or perhaps other issues through uncaught vulnerabilities. Restrict to the /themes/ directory for now.- Parameters:
context- the I2P app contextsockMgr- only for /b32, otherwise ignoredout- the output streammethod- the HTTP methodtargetRequest- decoded path only, non-nullquery- raw (encoded), may be nullproxyNonce- the proxy nonceallowGzip- whether gzip is allowed- Throws:
IOException- if an I/O error occurs
writeRedirectPage
private static void writeRedirectPage(OutputStream out, boolean success, String host, String book, String url) throws IOException Send the redirect result page to the browser.- Parameters:
out- the stream to write the HTTP response tosuccess- true if the entry was saved to the addressbook, false to report the failurehost- the host that was added, shown decoded as an IDN in the page titlebook- the addressbook file changed, e.g. "hosts.txt", shown by translated nameurl- the URL to redirect the browser to- Throws:
IOException- if writing to the browser stream fails
writeB32RedirectPage
private static void writeB32RedirectPage(OutputStream out, String host, String url) throws IOException Write a blinding info redirect page to the output stream.- Parameters:
out- the output stream to write tohost- the blinded hosturl- the URL to redirect to- Throws:
IOException- if an I/O error occurs
decodeQuery
decode
_t
_t
_t