diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index 4299b6d4788e9aa028858c666fd4981fa80ce12b..1f1f9e971d376c7843b3d08efca0cf9c37d8ba7b 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -259,10 +259,9 @@ public class TunnelController implements Logging { /* * Streamr client is a UDP server, use the listenPort field for targetPort - * and the listenOnInterface field for the targetHost */ private void startStreamrClient() { - String targetHost = getListenOnInterface(); + String targetHost = getTargetHost(); String targetPort = getListenPort(); String dest = getTargetDestination(); _tunnel.runStreamrClient(new String[] { targetHost, targetPort, dest }, this); @@ -270,10 +269,9 @@ public class TunnelController implements Logging { /** * Streamr server is a UDP client, use the targetPort field for listenPort - * and the targetHost field for the listenOnInterface */ private void startStreamrServer() { - String listenOn = getTargetHost(); + String listenOn = getListenOnInterface(); if ( (listenOn != null) && (listenOn.length() > 0) ) { _tunnel.runListenOn(new String[] { listenOn }, this); } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java index 87beb689cb3022bf97268321896537c59db2cbef..2184b434f1f02aa968cc9f698e47b84b53a8b758 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java @@ -12,6 +12,7 @@ import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; +import java.util.Set; import net.i2p.data.Base64; import net.i2p.data.Destination; @@ -22,6 +23,7 @@ import net.i2p.i2ptunnel.I2PTunnelHTTPClient; import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase; import net.i2p.i2ptunnel.TunnelController; import net.i2p.i2ptunnel.TunnelControllerGroup; +import net.i2p.util.Addresses; /** * Ugly little accessor for the edit page @@ -314,6 +316,11 @@ public class EditBean extends IndexBean { return _context.isRouterContext(); } + /** @since 0.8.3 */ + public Set<String> interfaceSet() { + return Addresses.getAllAddresses(); + } + public String getI2CPHost(int tunnel) { if (_context.isRouterContext()) return _("internal"); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java index bb1a339c294140da226b3711aa5066c6265eda61..9787078894a7998b4fd3ba6a234ebc497690291b 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java @@ -63,7 +63,6 @@ public class IndexBean { private String _proxyList; private String _port; private String _reachableBy; - private String _reachableByOther; private String _targetDestination; private String _targetHost; private String _targetPort; @@ -432,10 +431,13 @@ public class IndexBean { public String getClientInterface(int tunnel) { TunnelController tun = getController(tunnel); - if (tun != null) - return tun.getListenOnInterface(); - else - return ""; + if (tun != null) { + if ("streamrclient".equals(tun.getType())) + return tun.getTargetHost(); + else + return tun.getListenOnInterface(); + } else + return "127.0.0.1"; } public int getTunnelStatus(int tunnel) { @@ -478,11 +480,38 @@ public class IndexBean { return rv != null ? rv : ""; } + /** + * Call this to see if it is ok to linkify getServerTarget() + * @since 0.8.3 + */ + public boolean isServerTargetLinkValid(int tunnel) { + TunnelController tun = getController(tunnel); + return tun != null && + "httpserver".equals(tun.getType()) && + tun.getTargetHost() != null && + tun.getTargetPort() != null; + } + + /** + * @return valid host:port only if isServerTargetLinkValid() is true + */ public String getServerTarget(int tunnel) { TunnelController tun = getController(tunnel); - if (tun != null) - return tun.getTargetHost() + ':' + tun.getTargetPort(); - else + if (tun != null) { + String host; + if ("streamrserver".equals(tun.getType())) + host = tun.getListenOnInterface(); + else + host = tun.getTargetHost(); + String port = tun.getTargetPort(); + if (host == null) + host = "<font color=\"red\">" + _("Host not set") + "</font>"; + else if (host.indexOf(':') >= 0) + host = '[' + host + ']'; + if (port == null) + port = "<font color=\"red\">" + _("Port not set") + "</font>"; + return host + ':' + port; + } else return ""; } @@ -575,19 +604,11 @@ public class IndexBean { _port = (port != null ? port.trim() : null); } /** - * what interface should this client/httpclient/ircclient listen on (unless - * overridden by the setReachableByOther() field) + * what interface should this client/httpclient/ircclient listen on */ public void setReachableBy(String reachableBy) { _reachableBy = (reachableBy != null ? reachableBy.trim() : null); } - /** - * If specified, defines the exact IP interface to listen for requests - * on (in the case of client/httpclient/ircclient tunnels) - */ - public void setReachableByOther(String reachableByOther) { - _reachableByOther = (reachableByOther != null ? reachableByOther.trim() : null); - } /** What peer does this client tunnel point at */ public void setTargetDestination(String dest) { _targetDestination = (dest != null ? dest.trim() : null); @@ -891,17 +912,22 @@ public class IndexBean { Properties config = new Properties(); updateConfigGeneric(config); - if (isClient(_type)) { - // generic client stuff - if (_port != null) - config.setProperty("listenPort", _port); - if (_reachableByOther != null) - config.setProperty("interface", _reachableByOther); - else if (_reachableBy != null) + if ((isClient(_type) && !"streamrclient".equals(_type)) || "streamrserver".equals(_type)) { + // streamrserver uses interface + if (_reachableBy != null) config.setProperty("interface", _reachableBy); else config.setProperty("interface", ""); + } else { + // streamrclient uses targetHost + if (_targetHost != null) + config.setProperty("targetHost", _targetHost); + } + if (isClient(_type)) { + // generic client stuff + if (_port != null) + config.setProperty("listenPort", _port); config.setProperty("sharedClient", _sharedClient + ""); for (String p : _booleanClientOpts) config.setProperty("option." + p, "" + _booleanOptions.contains(p)); @@ -910,8 +936,6 @@ public class IndexBean { config.setProperty("option." + p, _otherOptions.get(p)); } else { // generic server stuff - if (_targetHost != null) - config.setProperty("targetHost", _targetHost); if (_targetPort != null) config.setProperty("targetPort", _targetPort); for (String p : _booleanServerOpts) @@ -940,9 +964,7 @@ public class IndexBean { if ("httpbidirserver".equals(_type)) { if (_port != null) config.setProperty("listenPort", _port); - if (_reachableByOther != null) - config.setProperty("interface", _reachableByOther); - else if (_reachableBy != null) + if (_reachableBy != null) config.setProperty("interface", _reachableBy); else if (_targetHost != null) config.setProperty("interface", _targetHost); diff --git a/apps/i2ptunnel/jsp/editClient.jsp b/apps/i2ptunnel/jsp/editClient.jsp index f2b427542ba1c87d60310e99174a8692fb3634b3..cabfb2946479df5f7aba8cd4862c856e7d96cf7d 100644 --- a/apps/i2ptunnel/jsp/editClient.jsp +++ b/apps/i2ptunnel/jsp/editClient.jsp @@ -80,7 +80,7 @@ <label><%=intl._("Target")%>:</label> <% } else { %> <label><%=intl._("Access Point")%>:</label> - <% } %> + <% } /* streamrclient */ %> </div> <div id="portField" class="rowItem"> <label for="port" accesskey="P"> @@ -95,46 +95,41 @@ </label> <input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" /> </div> - <% String otherInterface = ""; - String clientInterface = editBean.getClientInterface(curTunnel); - if ("streamrclient".equals(tunnelType)) { - otherInterface = clientInterface; - } else { %> <div id="reachField" class="rowItem"> <label for="reachableBy" accesskey="r"> - <%=intl._("Reachable by")%>(<span class="accessKey">R</span>): - </label> - <select id="reachableBy" name="reachableBy" title="Valid IP for Client Access" class="selectbox"> - <% if (!("127.0.0.1".equals(clientInterface)) && - !("0.0.0.0".equals(clientInterface)) && - (clientInterface != null) && - (clientInterface.trim().length() > 0)) { - otherInterface = clientInterface; - } - %><option value="127.0.0.1"<%=("127.0.0.1".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Locally (127.0.0.1)")%></option> - <option value="0.0.0.0"<%=("0.0.0.0".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Everyone (0.0.0.0)")%></option> - <option value="other"<%=(!("".equals(otherInterface)) ? " selected=\"selected\"" : "")%>><%=intl._("LAN Hosts (Please specify your LAN address)")%></option> - </select> - </div> - <% } // streamrclient %> - <div id="otherField" class="rowItem"> - <label for="reachableByOther" accesskey="O"> - <% if ("streamrclient".equals(tunnelType)) { %> - Host: - <% String vvv = otherInterface; - if (vvv == null || "".equals(vvv.trim())) { + <% + if ("streamrclient".equals(tunnelType)) { + out.write("Host:"); + String targetHost = editBean.getTargetHost(curTunnel); + if (targetHost == null || "".equals(targetHost.trim())) { out.write(" <font color=\"red\">("); out.write(intl._("required")); out.write(")</font>"); } - %> + %> + </label> + <input type="text" size="20" id="targetHost" name="targetHost" title="Target Hostname or IP" value="<%=targetHost%>" class="freetext" /> <% } else { %> - <%=intl._("Other")%>(<span class="accessKey">O</span>): - <% } %> + <%=intl._("Reachable by")%>(<span class="accessKey">R</span>): </label> - <input type="text" size="20" id="reachableByOther" name="reachableByOther" title="Alternative IP for Client Access" value="<%=otherInterface%>" class="freetext" /> - </div> - + <select id="reachableBy" name="reachableBy" title="IP for Client Access" class="selectbox"> + <% + String clientInterface = editBean.getClientInterface(curTunnel); + for (String ifc : editBean.interfaceSet()) { + out.write("<option value=\""); + out.write(ifc); + out.write('\"'); + if (ifc.equals(clientInterface)) + out.write(" selected=\"selected\""); + out.write('>'); + out.write(ifc); + out.write("</option>\n"); + } + %> + </select> + <% } /* streamrclient */ %> + </div> + <div class="subdivider"> <hr /> </div> diff --git a/apps/i2ptunnel/jsp/editServer.jsp b/apps/i2ptunnel/jsp/editServer.jsp index b0f870fb7aa5797730ea6a1bc6f38ff480b17ac2..4f45b86672c9f70d3d2c7ee8cd132175b713d92a 100644 --- a/apps/i2ptunnel/jsp/editServer.jsp +++ b/apps/i2ptunnel/jsp/editServer.jsp @@ -89,16 +89,14 @@ <label><%=intl._("Target")%>:</label> <% } %> </div> + <% if (!"streamrserver".equals(tunnelType)) { %> <div id="hostField" class="rowItem"> <label for="targetHost" accesskey="H"> - <% if ("streamrserver".equals(tunnelType)) { %> - <%=intl._("Reachable by")%>(<span class="accessKey">R</span>): - <% } else { %> <%=intl._("Host")%>(<span class="accessKey">H</span>): - <% } %> </label> <input type="text" size="20" id="targetHost" name="targetHost" title="Target Hostname or IP" value="<%=editBean.getTargetHost(curTunnel)%>" class="freetext" /> </div> + <% } /* !streamrserver */ %> <div id="portField" class="rowItem"> <label for="targetPort" accesskey="P"> <%=intl._("Port")%>(<span class="accessKey">P</span>): @@ -113,8 +111,7 @@ <input type="text" size="6" maxlength="5" id="targetPort" name="targetPort" title="Target Port Number" value="<%=editBean.getTargetPort(curTunnel)%>" class="freetext" /> </div> - <% if ("httpbidirserver".equals(tunnelType)) { - %> + <% if ("httpbidirserver".equals(tunnelType)) { %> <div class="subdivider"> <hr /> </div> @@ -134,32 +131,30 @@ </label> <input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" /> </div> - <% String otherInterface = ""; - String clientInterface = editBean.getClientInterface(curTunnel); - %> + <% } /* httpbidirserver */ %> + <% if ("httpbidirserver".equals(tunnelType) || "streamrserver".equals(tunnelType)) { %> <div id="reachField" class="rowItem"> <label for="reachableBy" accesskey="r"> <%=intl._("Reachable by")%>(<span class="accessKey">R</span>): </label> - <select id="reachableBy" name="reachableBy" title="Valid IP for Client Access" class="selectbox"> - <% if (!("127.0.0.1".equals(clientInterface)) && - !("0.0.0.0".equals(clientInterface)) && - (clientInterface != null) && - (clientInterface.trim().length() > 0)) { - otherInterface = clientInterface; - } - %><option value="127.0.0.1"<%=("127.0.0.1".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Locally (127.0.0.1)")%></option> - <option value="0.0.0.0"<%=("0.0.0.0".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Everyone (0.0.0.0)")%></option> - <option value="other"<%=(!("".equals(otherInterface)) ? " selected=\"selected\"" : "")%>><%=intl._("LAN Hosts (Please specify your LAN address)")%></option> + <select id="reachableBy" name="reachableBy" title="IP for Client Access" class="selectbox"> + <% + String clientInterface = editBean.getClientInterface(curTunnel); + for (String ifc : editBean.interfaceSet()) { + out.write("<option value=\""); + out.write(ifc); + out.write('\"'); + if (ifc.equals(clientInterface)) + out.write(" selected=\"selected\""); + out.write('>'); + out.write(ifc); + out.write("</option>\n"); + } + %> </select> - </div> - <div id="otherField" class="rowItem"> - <label for="reachableByOther" accesskey="O"> - <%=intl._("Other")%>(<span class="accessKey">O</span>): - </label> - <input type="text" size="20" id="reachableByOther" name="reachableByOther" title="Alternative IP for Client Access" value="<%=otherInterface%>" class="freetext" /> </div> - <% } %> + <% } /* httpbidirserver || streamrserver */ %> + <div class="subdivider"> <hr /> </div> @@ -302,7 +297,7 @@ <div class="subdivider"> <hr /> </div> - <% } // !streamrserver %> + <% } /* !streamrserver */ %> <div id="optionsField" class="rowItem"> <label><%=intl._("Router I2CP Address")%>:</label> diff --git a/apps/i2ptunnel/jsp/index.jsp b/apps/i2ptunnel/jsp/index.jsp index cf0d0067c39cf4551a8fe37a1dae821fa2cca46d..faf904de034f52e0ea2e26bd2e26291e9a754273 100644 --- a/apps/i2ptunnel/jsp/index.jsp +++ b/apps/i2ptunnel/jsp/index.jsp @@ -95,7 +95,7 @@ <label><%=intl._("Points at")%>:</label> <span class="text"> <% - if ("httpserver".equals(indexBean.getInternalType(curServer))) { + if (indexBean.isServerTargetLinkValid(curServer)) { %> <a href="http://<%=indexBean.getServerTarget(curServer)%>/" title="Test HTTP server, bypassing I2P"><%=indexBean.getServerTarget(curServer)%></a> <% @@ -213,7 +213,18 @@ </div> <div class="portField rowItem"> <label><%=intl._("Port")%>:</label> - <span class="text"><%=indexBean.getClientPort(curClient)%></span> + <span class="text"> + <% + String cPort= indexBean.getClientPort(curClient); + if ("".equals(cPort)) { + out.write("<font color=\"red\">"); + out.write(intl._("Port not set")); + out.write("</font>"); + } else { + out.write(cPort); + } + %> + </span> </div> <div class="typeField rowItem"> <label><%=intl._("Type")%>:</label> @@ -221,7 +232,19 @@ </div> <div class="interfaceField rowItem"> <label><%=intl._("Interface")%>:</label> - <span class="text"><%=indexBean.getClientInterface(curClient)%></span> + <span class="text"> + <% + /* should only happen for streamr client */ + String cHost= indexBean.getClientInterface(curClient); + if ("".equals(cHost)) { + out.write("<font color=\"red\">"); + out.write(intl._("Hort not set")); + out.write("</font>"); + } else { + out.write(cHost); + } + %> + </span> </div> <div class="statusField rowItem"> <label><%=intl._("Status")%>:</label>