* i2ptunnel:

- Use dropdown box to select interface for clients
      - Warn on index page if required fields not set
This commit is contained in:
zzz
2010-12-30 00:36:41 +00:00
parent 6ee162002a
commit cc4158a7e1
6 changed files with 137 additions and 97 deletions

View File

@@ -259,10 +259,9 @@ public class TunnelController implements Logging {
/* /*
* Streamr client is a UDP server, use the listenPort field for targetPort * Streamr client is a UDP server, use the listenPort field for targetPort
* and the listenOnInterface field for the targetHost
*/ */
private void startStreamrClient() { private void startStreamrClient() {
String targetHost = getListenOnInterface(); String targetHost = getTargetHost();
String targetPort = getListenPort(); String targetPort = getListenPort();
String dest = getTargetDestination(); String dest = getTargetDestination();
_tunnel.runStreamrClient(new String[] { targetHost, targetPort, dest }, this); _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 * Streamr server is a UDP client, use the targetPort field for listenPort
* and the targetHost field for the listenOnInterface
*/ */
private void startStreamrServer() { private void startStreamrServer() {
String listenOn = getTargetHost(); String listenOn = getListenOnInterface();
if ( (listenOn != null) && (listenOn.length() > 0) ) { if ( (listenOn != null) && (listenOn.length() > 0) ) {
_tunnel.runListenOn(new String[] { listenOn }, this); _tunnel.runListenOn(new String[] { listenOn }, this);
} }

View File

@@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Set;
import net.i2p.data.Base64; import net.i2p.data.Base64;
import net.i2p.data.Destination; import net.i2p.data.Destination;
@@ -22,6 +23,7 @@ import net.i2p.i2ptunnel.I2PTunnelHTTPClient;
import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase; import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase;
import net.i2p.i2ptunnel.TunnelController; import net.i2p.i2ptunnel.TunnelController;
import net.i2p.i2ptunnel.TunnelControllerGroup; import net.i2p.i2ptunnel.TunnelControllerGroup;
import net.i2p.util.Addresses;
/** /**
* Ugly little accessor for the edit page * Ugly little accessor for the edit page
@@ -314,6 +316,11 @@ public class EditBean extends IndexBean {
return _context.isRouterContext(); return _context.isRouterContext();
} }
/** @since 0.8.3 */
public Set<String> interfaceSet() {
return Addresses.getAllAddresses();
}
public String getI2CPHost(int tunnel) { public String getI2CPHost(int tunnel) {
if (_context.isRouterContext()) if (_context.isRouterContext())
return _("internal"); return _("internal");

View File

@@ -63,7 +63,6 @@ public class IndexBean {
private String _proxyList; private String _proxyList;
private String _port; private String _port;
private String _reachableBy; private String _reachableBy;
private String _reachableByOther;
private String _targetDestination; private String _targetDestination;
private String _targetHost; private String _targetHost;
private String _targetPort; private String _targetPort;
@@ -432,10 +431,13 @@ public class IndexBean {
public String getClientInterface(int tunnel) { public String getClientInterface(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun != null) if (tun != null) {
return tun.getListenOnInterface(); if ("streamrclient".equals(tun.getType()))
else return tun.getTargetHost();
return ""; else
return tun.getListenOnInterface();
} else
return "127.0.0.1";
} }
public int getTunnelStatus(int tunnel) { public int getTunnelStatus(int tunnel) {
@@ -478,11 +480,38 @@ public class IndexBean {
return rv != null ? rv : ""; 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) { public String getServerTarget(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun != null) if (tun != null) {
return tun.getTargetHost() + ':' + tun.getTargetPort(); String host;
else 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 ""; return "";
} }
@@ -575,19 +604,11 @@ public class IndexBean {
_port = (port != null ? port.trim() : null); _port = (port != null ? port.trim() : null);
} }
/** /**
* what interface should this client/httpclient/ircclient listen on (unless * what interface should this client/httpclient/ircclient listen on
* overridden by the setReachableByOther() field)
*/ */
public void setReachableBy(String reachableBy) { public void setReachableBy(String reachableBy) {
_reachableBy = (reachableBy != null ? reachableBy.trim() : null); _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 */ /** What peer does this client tunnel point at */
public void setTargetDestination(String dest) { public void setTargetDestination(String dest) {
_targetDestination = (dest != null ? dest.trim() : null); _targetDestination = (dest != null ? dest.trim() : null);
@@ -891,17 +912,22 @@ public class IndexBean {
Properties config = new Properties(); Properties config = new Properties();
updateConfigGeneric(config); updateConfigGeneric(config);
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)) { if (isClient(_type)) {
// generic client stuff // generic client stuff
if (_port != null) if (_port != null)
config.setProperty("listenPort", _port); config.setProperty("listenPort", _port);
if (_reachableByOther != null)
config.setProperty("interface", _reachableByOther);
else if (_reachableBy != null)
config.setProperty("interface", _reachableBy);
else
config.setProperty("interface", "");
config.setProperty("sharedClient", _sharedClient + ""); config.setProperty("sharedClient", _sharedClient + "");
for (String p : _booleanClientOpts) for (String p : _booleanClientOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p)); config.setProperty("option." + p, "" + _booleanOptions.contains(p));
@@ -910,8 +936,6 @@ public class IndexBean {
config.setProperty("option." + p, _otherOptions.get(p)); config.setProperty("option." + p, _otherOptions.get(p));
} else { } else {
// generic server stuff // generic server stuff
if (_targetHost != null)
config.setProperty("targetHost", _targetHost);
if (_targetPort != null) if (_targetPort != null)
config.setProperty("targetPort", _targetPort); config.setProperty("targetPort", _targetPort);
for (String p : _booleanServerOpts) for (String p : _booleanServerOpts)
@@ -940,9 +964,7 @@ public class IndexBean {
if ("httpbidirserver".equals(_type)) { if ("httpbidirserver".equals(_type)) {
if (_port != null) if (_port != null)
config.setProperty("listenPort", _port); config.setProperty("listenPort", _port);
if (_reachableByOther != null) if (_reachableBy != null)
config.setProperty("interface", _reachableByOther);
else if (_reachableBy != null)
config.setProperty("interface", _reachableBy); config.setProperty("interface", _reachableBy);
else if (_targetHost != null) else if (_targetHost != null)
config.setProperty("interface", _targetHost); config.setProperty("interface", _targetHost);

View File

@@ -80,7 +80,7 @@
<label><%=intl._("Target")%>:</label> <label><%=intl._("Target")%>:</label>
<% } else { %> <% } else { %>
<label><%=intl._("Access Point")%>:</label> <label><%=intl._("Access Point")%>:</label>
<% } %> <% } /* streamrclient */ %>
</div> </div>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label for="port" accesskey="P"> <label for="port" accesskey="P">
@@ -95,46 +95,41 @@
</label> </label>
<input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" /> <input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" />
</div> </div>
<% String otherInterface = "";
String clientInterface = editBean.getClientInterface(curTunnel);
if ("streamrclient".equals(tunnelType)) {
otherInterface = clientInterface;
} else { %>
<div id="reachField" class="rowItem"> <div id="reachField" class="rowItem">
<label for="reachableBy" accesskey="r"> <label for="reachableBy" accesskey="r">
<%=intl._("Reachable by")%>(<span class="accessKey">R</span>): <%
</label> if ("streamrclient".equals(tunnelType)) {
<select id="reachableBy" name="reachableBy" title="Valid IP for Client Access" class="selectbox"> out.write("Host:");
<% if (!("127.0.0.1".equals(clientInterface)) && String targetHost = editBean.getTargetHost(curTunnel);
!("0.0.0.0".equals(clientInterface)) && if (targetHost == null || "".equals(targetHost.trim())) {
(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())) {
out.write(" <font color=\"red\">("); out.write(" <font color=\"red\">(");
out.write(intl._("required")); out.write(intl._("required"));
out.write(")</font>"); out.write(")</font>");
} }
%> %>
<% } else { %>
<%=intl._("Other")%>(<span class="accessKey">O</span>):
<% } %>
</label> </label>
<input type="text" size="20" id="reachableByOther" name="reachableByOther" title="Alternative IP for Client Access" value="<%=otherInterface%>" class="freetext" /> <input type="text" size="20" id="targetHost" name="targetHost" title="Target Hostname or IP" value="<%=targetHost%>" class="freetext" />
</div> <% } else { %>
<%=intl._("Reachable by")%>(<span class="accessKey">R</span>):
</label>
<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"> <div class="subdivider">
<hr /> <hr />
</div> </div>

View File

@@ -89,16 +89,14 @@
<label><%=intl._("Target")%>:</label> <label><%=intl._("Target")%>:</label>
<% } %> <% } %>
</div> </div>
<% if (!"streamrserver".equals(tunnelType)) { %>
<div id="hostField" class="rowItem"> <div id="hostField" class="rowItem">
<label for="targetHost" accesskey="H"> <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>): <%=intl._("Host")%>(<span class="accessKey">H</span>):
<% } %>
</label> </label>
<input type="text" size="20" id="targetHost" name="targetHost" title="Target Hostname or IP" value="<%=editBean.getTargetHost(curTunnel)%>" class="freetext" /> <input type="text" size="20" id="targetHost" name="targetHost" title="Target Hostname or IP" value="<%=editBean.getTargetHost(curTunnel)%>" class="freetext" />
</div> </div>
<% } /* !streamrserver */ %>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label for="targetPort" accesskey="P"> <label for="targetPort" accesskey="P">
<%=intl._("Port")%>(<span class="accessKey">P</span>): <%=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" /> <input type="text" size="6" maxlength="5" id="targetPort" name="targetPort" title="Target Port Number" value="<%=editBean.getTargetPort(curTunnel)%>" class="freetext" />
</div> </div>
<% if ("httpbidirserver".equals(tunnelType)) { <% if ("httpbidirserver".equals(tunnelType)) { %>
%>
<div class="subdivider"> <div class="subdivider">
<hr /> <hr />
</div> </div>
@@ -134,32 +131,30 @@
</label> </label>
<input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" /> <input type="text" size="6" maxlength="5" id="port" name="port" title="Access Port Number" value="<%=editBean.getClientPort(curTunnel)%>" class="freetext" />
</div> </div>
<% String otherInterface = ""; <% } /* httpbidirserver */ %>
String clientInterface = editBean.getClientInterface(curTunnel); <% if ("httpbidirserver".equals(tunnelType) || "streamrserver".equals(tunnelType)) { %>
%>
<div id="reachField" class="rowItem"> <div id="reachField" class="rowItem">
<label for="reachableBy" accesskey="r"> <label for="reachableBy" accesskey="r">
<%=intl._("Reachable by")%>(<span class="accessKey">R</span>): <%=intl._("Reachable by")%>(<span class="accessKey">R</span>):
</label> </label>
<select id="reachableBy" name="reachableBy" title="Valid IP for Client Access" class="selectbox"> <select id="reachableBy" name="reachableBy" title="IP for Client Access" class="selectbox">
<% if (!("127.0.0.1".equals(clientInterface)) && <%
!("0.0.0.0".equals(clientInterface)) && String clientInterface = editBean.getClientInterface(curTunnel);
(clientInterface != null) && for (String ifc : editBean.interfaceSet()) {
(clientInterface.trim().length() > 0)) { out.write("<option value=\"");
otherInterface = clientInterface; out.write(ifc);
} out.write('\"');
%><option value="127.0.0.1"<%=("127.0.0.1".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Locally (127.0.0.1)")%></option> if (ifc.equals(clientInterface))
<option value="0.0.0.0"<%=("0.0.0.0".equals(clientInterface) ? " selected=\"selected\"" : "")%>><%=intl._("Everyone (0.0.0.0)")%></option> out.write(" selected=\"selected\"");
<option value="other"<%=(!("".equals(otherInterface)) ? " selected=\"selected\"" : "")%>><%=intl._("LAN Hosts (Please specify your LAN address)")%></option> out.write('>');
out.write(ifc);
out.write("</option>\n");
}
%>
</select> </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> </div>
<% } %> <% } /* httpbidirserver || streamrserver */ %>
<div class="subdivider"> <div class="subdivider">
<hr /> <hr />
</div> </div>
@@ -302,7 +297,7 @@
<div class="subdivider"> <div class="subdivider">
<hr /> <hr />
</div> </div>
<% } // !streamrserver %> <% } /* !streamrserver */ %>
<div id="optionsField" class="rowItem"> <div id="optionsField" class="rowItem">
<label><%=intl._("Router I2CP Address")%>:</label> <label><%=intl._("Router I2CP Address")%>:</label>

View File

@@ -95,7 +95,7 @@
<label><%=intl._("Points at")%>:</label> <label><%=intl._("Points at")%>:</label>
<span class="text"> <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> <a href="http://<%=indexBean.getServerTarget(curServer)%>/" title="Test HTTP server, bypassing I2P"><%=indexBean.getServerTarget(curServer)%></a>
<% <%
@@ -213,7 +213,18 @@
</div> </div>
<div class="portField rowItem"> <div class="portField rowItem">
<label><%=intl._("Port")%>:</label> <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>
<div class="typeField rowItem"> <div class="typeField rowItem">
<label><%=intl._("Type")%>:</label> <label><%=intl._("Type")%>:</label>
@@ -221,7 +232,19 @@
</div> </div>
<div class="interfaceField rowItem"> <div class="interfaceField rowItem">
<label><%=intl._("Interface")%>:</label> <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>
<div class="statusField rowItem"> <div class="statusField rowItem">
<label><%=intl._("Status")%>:</label> <label><%=intl._("Status")%>:</label>