forked from I2P_Developers/i2p.i2p
change UI to allow same filter definition to be used in multiple tunnels
This commit is contained in:
@@ -48,7 +48,6 @@ public class GeneralHelper {
|
|||||||
|
|
||||||
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
||||||
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
||||||
protected static final String PROP_FILTER_DEFINITION = "filterDefinition";
|
|
||||||
|
|
||||||
private static final String OPT = TunnelController.PFX_OPTION;
|
private static final String OPT = TunnelController.PFX_OPTION;
|
||||||
|
|
||||||
@@ -616,21 +615,17 @@ public class GeneralHelper {
|
|||||||
return 1;
|
return 1;
|
||||||
if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
|
if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
|
||||||
return 2;
|
return 2;
|
||||||
TunnelController tun = getController(tunnel);
|
|
||||||
if (tun.getFilter() != null)
|
|
||||||
return 3;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessList(int tunnel) {
|
public String getAccessList(int tunnel) {
|
||||||
switch(getAccessMode(tunnel)) {
|
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
||||||
case 0:
|
}
|
||||||
case 1:
|
|
||||||
case 2:
|
public String getFilterDefinition(int tunnel) {
|
||||||
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
TunnelController tunnelController = getController(tunnel);
|
||||||
}
|
String filter = tunnelController.getFilter();
|
||||||
TunnelController tun = getController(tunnel);
|
return filter == null ? "" : filter;
|
||||||
return FileUtil.readTextFile(tun.getFilter(), -1, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJumpList(int tunnel) {
|
public String getJumpList(int tunnel) {
|
||||||
|
@@ -9,10 +9,6 @@ import java.util.Set;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
import net.i2p.client.I2PClient;
|
||||||
import net.i2p.crypto.KeyGenerator;
|
import net.i2p.crypto.KeyGenerator;
|
||||||
@@ -30,7 +26,6 @@ import net.i2p.i2ptunnel.I2PTunnelServer;
|
|||||||
import net.i2p.i2ptunnel.TunnelController;
|
import net.i2p.i2ptunnel.TunnelController;
|
||||||
import net.i2p.util.ConcurrentHashSet;
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.PasswordManager;
|
import net.i2p.util.PasswordManager;
|
||||||
import net.i2p.util.SecureFileOutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to generate a valid TunnelController configuration from provided
|
* Helper class to generate a valid TunnelController configuration from provided
|
||||||
@@ -80,7 +75,6 @@ public class TunnelConfig {
|
|||||||
private String _newProxyUser;
|
private String _newProxyUser;
|
||||||
private String _newProxyPW;
|
private String _newProxyPW;
|
||||||
private Destination _dest;
|
private Destination _dest;
|
||||||
private boolean _filter;
|
|
||||||
private String _filterDefinition;
|
private String _filterDefinition;
|
||||||
|
|
||||||
public TunnelConfig() {
|
public TunnelConfig() {
|
||||||
@@ -311,7 +305,6 @@ public class TunnelConfig {
|
|||||||
|
|
||||||
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
||||||
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
||||||
protected static final String PROP_FILTER = "filterDefinition";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls how other tunnels are checked for access.
|
* Controls how other tunnels are checked for access.
|
||||||
@@ -331,15 +324,20 @@ public class TunnelConfig {
|
|||||||
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
||||||
_booleanOptions.add(PROP_ENABLE_BLACKLIST);
|
_booleanOptions.add(PROP_ENABLE_BLACKLIST);
|
||||||
break;
|
break;
|
||||||
case 3:
|
|
||||||
_filter = true;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
||||||
_booleanOptions.remove(PROP_ENABLE_BLACKLIST);
|
_booleanOptions.remove(PROP_ENABLE_BLACKLIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFilterDefinition(String filterDefinition) {
|
||||||
|
if (filterDefinition != null) {
|
||||||
|
filterDefinition = filterDefinition.trim();
|
||||||
|
if (!filterDefinition.isEmpty())
|
||||||
|
_filterDefinition = filterDefinition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setDelayOpen(boolean val) {
|
public void setDelayOpen(boolean val) {
|
||||||
if (val)
|
if (val)
|
||||||
_booleanOptions.add("i2cp.delayOpen");
|
_booleanOptions.add("i2cp.delayOpen");
|
||||||
@@ -382,9 +380,8 @@ public class TunnelConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessList(String val) {
|
public void setAccessList(String val) {
|
||||||
if (val == null)
|
if (val != null)
|
||||||
return;
|
_otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
|
||||||
_filterDefinition = val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJumpList(String val) {
|
public void setJumpList(String val) {
|
||||||
@@ -625,25 +622,14 @@ public class TunnelConfig {
|
|||||||
// generic server stuff
|
// generic server stuff
|
||||||
if (_targetPort >= 0)
|
if (_targetPort >= 0)
|
||||||
config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
|
config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
|
||||||
|
|
||||||
|
if (_filterDefinition != null)
|
||||||
|
config.setProperty(TunnelController.PROP_FILTER, _filterDefinition);
|
||||||
|
|
||||||
// see TunnelController.setConfig()
|
// see TunnelController.setConfig()
|
||||||
_booleanOptions.add(TunnelController.PROP_LIMITS_SET);
|
_booleanOptions.add(TunnelController.PROP_LIMITS_SET);
|
||||||
for (String p : _booleanServerOpts)
|
for (String p : _booleanServerOpts)
|
||||||
config.setProperty(OPT + p, Boolean.toString(_booleanOptions.contains(p)));
|
config.setProperty(OPT + p, Boolean.toString(_booleanOptions.contains(p)));
|
||||||
if (_filter) {
|
|
||||||
String dslFile = _context.getConfigDir() + File.separator + _name+".accessrules";
|
|
||||||
config.setProperty(TunnelController.PROP_FILTER, dslFile);
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
try {
|
|
||||||
fos = new SecureFileOutputStream(dslFile);
|
|
||||||
fos.write(_filterDefinition.getBytes());
|
|
||||||
} catch (IOException bad) {
|
|
||||||
throw new RuntimeException("failed to save access rules", bad);
|
|
||||||
} finally {
|
|
||||||
if (fos != null) try { fos.close(); } catch (IOException ignored) {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_otherOptions.put("i2cp.accessList", _filterDefinition.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
|
|
||||||
}
|
|
||||||
for (String p : _otherServerOpts) {
|
for (String p : _otherServerOpts) {
|
||||||
if (_otherOptions.containsKey(p))
|
if (_otherOptions.containsKey(p))
|
||||||
config.setProperty(OPT + p, _otherOptions.get(p));
|
config.setProperty(OPT + p, _otherOptions.get(p));
|
||||||
|
@@ -270,6 +270,10 @@ public class EditBean extends IndexBean {
|
|||||||
public String getAccessList(int tunnel) {
|
public String getAccessList(int tunnel) {
|
||||||
return _helper.getAccessList(tunnel);
|
return _helper.getAccessList(tunnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFilterDefinition(int tunnel) {
|
||||||
|
return _helper.getFilterDefinition(tunnel);
|
||||||
|
}
|
||||||
|
|
||||||
public String getJumpList(int tunnel) {
|
public String getJumpList(int tunnel) {
|
||||||
return _helper.getJumpList(tunnel);
|
return _helper.getJumpList(tunnel);
|
||||||
|
@@ -888,6 +888,11 @@ public class IndexBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFilterDefinition(String val) {
|
||||||
|
if (val != null)
|
||||||
|
_config.setFilterDefinition(val);
|
||||||
|
}
|
||||||
|
|
||||||
public void setDelayOpen(String moo) {
|
public void setDelayOpen(String moo) {
|
||||||
_config.setDelayOpen(true);
|
_config.setDelayOpen(true);
|
||||||
}
|
}
|
||||||
|
@@ -533,9 +533,6 @@
|
|||||||
<%=intl._t("Blacklist")%></label></span>
|
<%=intl._t("Blacklist")%></label></span>
|
||||||
<span class="multiOption"><label title="<%=intl._t("Only allow listed clients to connect to this service")%>"><input value="1" type="radio" name="accessMode"<%=(editBean.getAccessMode(curTunnel).equals("1") ? " checked=\"checked\"" : "")%> class="tickbox" />
|
<span class="multiOption"><label title="<%=intl._t("Only allow listed clients to connect to this service")%>"><input value="1" type="radio" name="accessMode"<%=(editBean.getAccessMode(curTunnel).equals("1") ? " checked=\"checked\"" : "")%> class="tickbox" />
|
||||||
<%=intl._t("Whitelist")%></label></span>
|
<%=intl._t("Whitelist")%></label></span>
|
||||||
<span class="multiOption"><label title="<%=intl._t("Advanced access list configuration")%>"><input value="3" type="radio" name="accessMode"<%=(editBean.getAccessMode(curTunnel).equals("3") ? " checked=\"checked\"" : "")%> class="tickbox" />
|
|
||||||
<%=intl._t("Advanced")%></label></span>
|
|
||||||
<span><a href="http://i2p-projekt.i2p/spec/filter-format">(<%=intl._t("format")%>)</a></span>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -551,6 +548,25 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<b><%=intl._t("Filter Definition File")%></b>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<%=intl._t("You can define an advanced filter for this tunnel.")%> (<a href="http://i2p-projekt.i2p/spec/filter-format" target="_blank"><%=intl._t("Format Specification")%></a>)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<label for="filterDefinition"><%=intl._t("File containing filter definition")%></label>
|
||||||
|
<input type="text" id="filterDefinition" name="filterDefinition" value="<%=editBean.getFilterDefinition(curTunnel)%>" size="30"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">
|
<th colspan="2">
|
||||||
<%=intl._t("Server Access Options")%>
|
<%=intl._t("Server Access Options")%>
|
||||||
|
Reference in New Issue
Block a user