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_BLACKLIST = "i2cp.enableBlackList";
|
||||
protected static final String PROP_FILTER_DEFINITION = "filterDefinition";
|
||||
|
||||
private static final String OPT = TunnelController.PFX_OPTION;
|
||||
|
||||
@@ -616,21 +615,17 @@ public class GeneralHelper {
|
||||
return 1;
|
||||
if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
|
||||
return 2;
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun.getFilter() != null)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getAccessList(int tunnel) {
|
||||
switch(getAccessMode(tunnel)) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
||||
}
|
||||
TunnelController tun = getController(tunnel);
|
||||
return FileUtil.readTextFile(tun.getFilter(), -1, true);
|
||||
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
||||
}
|
||||
|
||||
public String getFilterDefinition(int tunnel) {
|
||||
TunnelController tunnelController = getController(tunnel);
|
||||
String filter = tunnelController.getFilter();
|
||||
return filter == null ? "" : filter;
|
||||
}
|
||||
|
||||
public String getJumpList(int tunnel) {
|
||||
|
@@ -9,10 +9,6 @@ import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.crypto.KeyGenerator;
|
||||
@@ -30,7 +26,6 @@ import net.i2p.i2ptunnel.I2PTunnelServer;
|
||||
import net.i2p.i2ptunnel.TunnelController;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.PasswordManager;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
|
||||
/**
|
||||
* Helper class to generate a valid TunnelController configuration from provided
|
||||
@@ -80,7 +75,6 @@ public class TunnelConfig {
|
||||
private String _newProxyUser;
|
||||
private String _newProxyPW;
|
||||
private Destination _dest;
|
||||
private boolean _filter;
|
||||
private String _filterDefinition;
|
||||
|
||||
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_BLACKLIST = "i2cp.enableBlackList";
|
||||
protected static final String PROP_FILTER = "filterDefinition";
|
||||
|
||||
/**
|
||||
* Controls how other tunnels are checked for access.
|
||||
@@ -331,15 +324,20 @@ public class TunnelConfig {
|
||||
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
||||
_booleanOptions.add(PROP_ENABLE_BLACKLIST);
|
||||
break;
|
||||
case 3:
|
||||
_filter = true;
|
||||
break;
|
||||
default:
|
||||
_booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
|
||||
_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) {
|
||||
if (val)
|
||||
_booleanOptions.add("i2cp.delayOpen");
|
||||
@@ -382,9 +380,8 @@ public class TunnelConfig {
|
||||
}
|
||||
|
||||
public void setAccessList(String val) {
|
||||
if (val == null)
|
||||
return;
|
||||
_filterDefinition = val;
|
||||
if (val != null)
|
||||
_otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
|
||||
}
|
||||
|
||||
public void setJumpList(String val) {
|
||||
@@ -625,25 +622,14 @@ public class TunnelConfig {
|
||||
// generic server stuff
|
||||
if (_targetPort >= 0)
|
||||
config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
|
||||
|
||||
if (_filterDefinition != null)
|
||||
config.setProperty(TunnelController.PROP_FILTER, _filterDefinition);
|
||||
|
||||
// see TunnelController.setConfig()
|
||||
_booleanOptions.add(TunnelController.PROP_LIMITS_SET);
|
||||
for (String p : _booleanServerOpts)
|
||||
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) {
|
||||
if (_otherOptions.containsKey(p))
|
||||
config.setProperty(OPT + p, _otherOptions.get(p));
|
||||
|
@@ -270,6 +270,10 @@ public class EditBean extends IndexBean {
|
||||
public String getAccessList(int tunnel) {
|
||||
return _helper.getAccessList(tunnel);
|
||||
}
|
||||
|
||||
public String getFilterDefinition(int tunnel) {
|
||||
return _helper.getFilterDefinition(tunnel);
|
||||
}
|
||||
|
||||
public String getJumpList(int 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) {
|
||||
_config.setDelayOpen(true);
|
||||
}
|
||||
|
@@ -533,9 +533,6 @@
|
||||
<%=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" />
|
||||
<%=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>
|
||||
</tr>
|
||||
|
||||
@@ -551,6 +548,25 @@
|
||||
</td>
|
||||
</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>
|
||||
<th colspan="2">
|
||||
<%=intl._t("Server Access Options")%>
|
||||
|
Reference in New Issue
Block a user