i2ptunnel: Check port mapper for webapp presence (ticket #2161)

This commit is contained in:
zzz
2018-03-14 14:09:41 +00:00
parent 66ee7b563a
commit 6eb09bd0c8
5 changed files with 82 additions and 12 deletions

View File

@@ -773,19 +773,23 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
out.write(("</a></th>\n<th align=\"center\">" +
"<a href=\"" + conflictURL + "\">").getBytes("UTF-8"));
out.write(_t("Conflicting address helper destination").getBytes("UTF-8"));
out.write(("</a></th></tr>\n<tr><td align=\"center\">" +
out.write(("</a></th></tr>\n").getBytes("UTF-8"));
if (_context.portMapper().getPort(PortMapper.SVC_IMAGEGEN) > 0) {
out.write(("<tr><td align=\"center\">" +
"<a href=\"" + trustedURL + "\">" +
"<img src=\"" +
conURL + "imagegen/id?s=160&amp;c=" +
h1.toBase64().replace("=", "%3d") +
"\" width=\"160\" height=\"160\"></a>\n").getBytes("UTF-8"));
out.write(("</td>\n<td align=\"center\">" +
"\" width=\"160\" height=\"160\"></a>\n" +
"</td>\n<td align=\"center\">" +
"<a href=\"" + conflictURL + "\">" +
"<img src=\"" +
conURL + "imagegen/id?s=160&amp;c=" +
h2.toBase64().replace("=", "%3d") +
"\" width=\"160\" height=\"160\"></a>\n").getBytes("UTF-8"));
out.write("</td></tr></table>".getBytes("UTF-8"));
"\" width=\"160\" height=\"160\"></a>\n" +
"</td></tr>").getBytes("UTF-8"));
}
out.write("</table>".getBytes("UTF-8"));
}
out.write("</div>".getBytes("UTF-8"));
writeFooter(out);

View File

@@ -7,9 +7,11 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.Socket;
@@ -542,18 +544,48 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
char[] buf = new char[512];
StringBuilder out = new StringBuilder(2048);
try {
boolean hasSusiDNS = ctx.portMapper().getPort(PortMapper.SVC_SUSIDNS) > 0;
boolean hasI2PTunnel = ctx.portMapper().getPort(PortMapper.SVC_I2PTUNNEL) > 0;
if (hasSusiDNS && hasI2PTunnel) {
reader = new TranslateReader(ctx, BUNDLE_NAME, new FileInputStream(file));
} else {
// strip out the addressbook links
reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
int len;
while((len = reader.read(buf)) > 0) {
out.append(buf, 0, len);
}
reader.close();
if (!hasSusiDNS) {
DataHelper.replace(out, "<a href=\"http://127.0.0.1:7657/susidns/index\">_(\"Addressbook\")</a>", "");
}
if (!hasI2PTunnel) {
// there are also a couple in auth-header.ht that aren't worth stripping, for auth only
DataHelper.replace(out,
"<span class=\"script\">_(\"You may want to {0}retry{1} as this will randomly reselect an outproxy from the pool you have defined {2}here{3} (if you have more than one configured).\", \"<a href=\\\"javascript:parent.window.location.reload()\\\">\", \"</a>\", \"<a href=\\\"http://127.0.0.1:7657/i2ptunnel/index.jsp\\\">\", \"</a>\")</span>",
"");
DataHelper.replace(out,
"<noscript>_(\"You may want to retry as this will randomly reselect an outproxy from the pool you have defined {0}here{1} (if you have more than one configured).\", \"<a href=\\\"http://127.0.0.1:7657/i2ptunnel/index.jsp\\\">\", \"</a>\")</noscript>",
"");
DataHelper.replace(out,
"_(\"If you continue to have trouble you may want to edit your outproxy list {0}here{1}.\", \"<a href=\\\"http://127.0.0.1:7657/i2ptunnel/edit.jsp?tunnel=0\\\">\", \"</a>\")",
"");
}
String s = out.toString();
out.setLength(0);
reader = new TranslateReader(ctx, BUNDLE_NAME, new StringReader(s));
}
int len;
reader = new TranslateReader(ctx, BUNDLE_NAME, new FileInputStream(file));
while((len = reader.read(buf)) > 0) {
out.append(buf, 0, len);
}
String rv = out.toString();
// Do we need to replace http://127.0.0.1:7657 console links in the error page?
// Get the registered host and port from the PortMapper.
String url = ctx.portMapper().getConsoleURL();
if (!url.equals("http://127.0.0.1:7657/")) {
rv = rv.replace("http://127.0.0.1:7657/", url);
DataHelper.replace(out, "http://127.0.0.1:7657/", url);
}
String rv = out.toString();
return rv;
} finally {
try {

View File

@@ -18,6 +18,7 @@ import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnelHTTPClient;
import net.i2p.util.FileUtil;
import net.i2p.util.PortMapper;
import net.i2p.util.Translate;
/**
@@ -199,7 +200,8 @@ public abstract class LocalHTTPServer {
else
tbook = book;
String conURL = I2PAppContext.getGlobalContext().portMapper().getConsoleURL();
PortMapper pm = I2PAppContext.getGlobalContext().portMapper();
String conURL = pm.getConsoleURL();
out.write(("HTTP/1.1 200 OK\r\n"+
"Content-Type: text/html; charset=UTF-8\r\n"+
"Referrer-Policy: no-referrer\r\n"+
@@ -214,8 +216,10 @@ public abstract class LocalHTTPServer {
"</head><body>\n" +
"<div class=logo>\n" +
"<a href=\"" + conURL + "\" title=\"" + _t("Router Console") + "\"><img src=\"http://proxy.i2p/themes/console/images/i2plogo.png\" alt=\"I2P Router Console\" border=\"0\"></a><hr>\n" +
"<a href=\"" + conURL + "config\">" + _t("Configuration") + "</a> <a href=\"" + conURL + "help.jsp\">" + _t("Help") + "</a> <a href=\"" + conURL + "susidns/index\">" + _t("Addressbook") + "</a>\n" +
"</div>" +
"<a href=\"" + conURL + "config\">" + _t("Configuration") + "</a> <a href=\"" + conURL + "help.jsp\">" + _t("Help") + "</a>").getBytes("UTF-8"));
if (pm.getPort(PortMapper.SVC_SUSIDNS) > 0)
out.write((" <a href=\"" + conURL + "susidns/index\">" + _t("Addressbook") + "</a>\n").getBytes("UTF-8"));
out.write(("</div>" +
"<div class=warning id=warning>\n" +
"<h3>" +
(success ?