forked from I2P_Developers/i2p.i2p
Migrate accessors to GeneralHelper, fix broken outproxyAuth boolean
This commit is contained in:
@@ -4,10 +4,22 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.PrivateKeyFile;
|
||||
import net.i2p.i2ptunnel.I2PTunnelClientBase;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPClient;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPServer;
|
||||
import net.i2p.i2ptunnel.I2PTunnelIRCClient;
|
||||
import net.i2p.i2ptunnel.I2PTunnelServer;
|
||||
import net.i2p.i2ptunnel.SSLClientUtil;
|
||||
import net.i2p.i2ptunnel.TunnelController;
|
||||
import net.i2p.i2ptunnel.TunnelControllerGroup;
|
||||
@@ -22,8 +34,31 @@ import net.i2p.util.SecureFile;
|
||||
* @since 0.9.19
|
||||
*/
|
||||
public class GeneralHelper {
|
||||
public static final int RUNNING = 1;
|
||||
public static final int STARTING = 2;
|
||||
public static final int NOT_RUNNING = 3;
|
||||
public static final int STANDBY = 4;
|
||||
|
||||
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
||||
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
||||
|
||||
private static final String OPT = TunnelController.PFX_OPTION;
|
||||
|
||||
private I2PAppContext _context;
|
||||
protected TunnelControllerGroup _group;
|
||||
|
||||
public GeneralHelper(TunnelControllerGroup tcg) {
|
||||
this(I2PAppContext.getGlobalContext(), tcg);
|
||||
}
|
||||
|
||||
public GeneralHelper(I2PAppContext context, TunnelControllerGroup tcg) {
|
||||
_context = context;
|
||||
_group = tcg;
|
||||
}
|
||||
|
||||
public TunnelController getController(int tunnel) {
|
||||
return getController(_group, tunnel);
|
||||
}
|
||||
public static TunnelController getController(TunnelControllerGroup tcg, int tunnel) {
|
||||
if (tunnel < 0) return null;
|
||||
if (tcg == null) return null;
|
||||
@@ -34,6 +69,9 @@ public class GeneralHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> saveTunnel(int tunnel, TunnelConfig config) {
|
||||
return saveTunnel(_context, _group, tunnel, config);
|
||||
}
|
||||
public static List<String> saveTunnel(
|
||||
I2PAppContext context, TunnelControllerGroup tcg, int tunnel, TunnelConfig config) {
|
||||
List<String> msgs = updateTunnelConfig(tcg, tunnel, config);
|
||||
@@ -117,16 +155,22 @@ public class GeneralHelper {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public List<String> deleteTunnel(int tunnel, String privKeyFile) {
|
||||
return deleteTunnel(_context, _group, tunnel, privKeyFile);
|
||||
}
|
||||
/**
|
||||
* Stop the tunnel, delete from config,
|
||||
* rename the private key file if in the default directory
|
||||
*
|
||||
* @param privKeyFile The priv key file name from the tunnel edit form. Can
|
||||
* be null if not known.
|
||||
*/
|
||||
public static List<String> deleteTunnel(
|
||||
I2PAppContext context, TunnelControllerGroup tcg,int tunnel, TunnelConfig config) {
|
||||
I2PAppContext context, TunnelControllerGroup tcg, int tunnel, String privKeyFile) {
|
||||
List<String> msgs;
|
||||
TunnelController cur = getController(tcg, tunnel);
|
||||
if (cur == null) {
|
||||
msgs = new ArrayList<>();
|
||||
msgs = new ArrayList<String>();
|
||||
msgs.add("Invalid tunnel number");
|
||||
return msgs;
|
||||
}
|
||||
@@ -140,7 +184,7 @@ public class GeneralHelper {
|
||||
// Use configured file name if available, not the one from the form.
|
||||
String pk = cur.getPrivKeyFile();
|
||||
if (pk == null)
|
||||
pk = config.getPrivKeyFile();
|
||||
pk = privKeyFile;
|
||||
if (pk != null && pk.startsWith("i2ptunnel") && pk.endsWith("-privKeys.dat") &&
|
||||
((!TunnelController.isClient(cur.getType())) || cur.getPersistentClientKey())) {
|
||||
File pkf = new File(context.getConfigDir(), pk);
|
||||
@@ -171,14 +215,485 @@ public class GeneralHelper {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
public String getTunnelType(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return (tun != null && tun.getType() != null) ? tun.getType() : "";
|
||||
}
|
||||
|
||||
public String getTunnelName(int tunnel) {
|
||||
return getTunnelName(_group, tunnel);
|
||||
}
|
||||
public static String getTunnelName(TunnelControllerGroup tcg, int tunnel) {
|
||||
TunnelController tun = getController(tcg, tunnel);
|
||||
if (tun != null)
|
||||
return tun.getName();
|
||||
return tun != null ? tun.getName() : null;
|
||||
}
|
||||
|
||||
public String getTunnelDescription(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return (tun != null && tun.getDescription() != null) ? tun.getDescription() : "";
|
||||
}
|
||||
|
||||
public String getTargetHost(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return (tun != null && tun.getTargetHost() != null) ? tun.getTargetHost() : "127.0.0.1";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tunnel
|
||||
* @return -1 if unset or invalid
|
||||
*/
|
||||
public int getTargetPort(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null && tun.getTargetPort() != null) {
|
||||
try {
|
||||
return Integer.parseInt(tun.getTargetPort());
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getSpoofedHost(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return (tun != null && tun.getSpoofedHost() != null) ? tun.getSpoofedHost() :"";
|
||||
}
|
||||
|
||||
public String getPrivateKeyFile(int tunnel) {
|
||||
return getPrivateKeyFile(_group, tunnel);
|
||||
}
|
||||
public static String getPrivateKeyFile(TunnelControllerGroup tcg, int tunnel) {
|
||||
TunnelController tun = getController(tcg, tunnel);
|
||||
if (tun != null && tun.getPrivKeyFile() != null)
|
||||
return tun.getPrivKeyFile();
|
||||
if (tunnel < 0)
|
||||
tunnel = tcg == null ? 999 : tcg.getControllers().size();
|
||||
return "i2ptunnel" + tunnel + "-privKeys.dat";
|
||||
}
|
||||
|
||||
public String getClientInterface(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
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) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun == null) return NOT_RUNNING;
|
||||
if (tun.getIsRunning()) {
|
||||
if (tun.isClient() && tun.getIsStandby())
|
||||
return STANDBY;
|
||||
else
|
||||
return RUNNING;
|
||||
} else if (tun.getIsStarting()) return STARTING;
|
||||
else return NOT_RUNNING;
|
||||
}
|
||||
|
||||
public String getClientDestination(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun == null) return "";
|
||||
String rv;
|
||||
if (TunnelController.TYPE_STD_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_IRC_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_STREAMR_CLIENT.equals(tun.getType()))
|
||||
rv = tun.getTargetDestination();
|
||||
else
|
||||
rv = tun.getProxyList();
|
||||
return rv != null ? rv : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Works even if tunnel is not running.
|
||||
* @return Destination or null
|
||||
*/
|
||||
public Destination getDestination(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Destination rv = tun.getDestination();
|
||||
if (rv != null)
|
||||
return rv;
|
||||
// if not running, do this the hard way
|
||||
File keyFile = tun.getPrivateKeyFile();
|
||||
if (keyFile != null) {
|
||||
PrivateKeyFile pkf = new PrivateKeyFile(keyFile);
|
||||
try {
|
||||
rv = pkf.getDestination();
|
||||
if (rv != null)
|
||||
return rv;
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean shouldStartAutomatically(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return tun != null ? tun.getStartOnLoad() : false;
|
||||
}
|
||||
|
||||
public boolean isSharedClient(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
return tun != null ? Boolean.parseBoolean(tun.getSharedClient()) : false;
|
||||
}
|
||||
|
||||
public boolean shouldDelayConnect(int tunnel) {
|
||||
return getProperty(tunnel, "i2p.streaming.connectDelay", 0) > 0;
|
||||
}
|
||||
|
||||
public boolean isInteractive(int tunnel) {
|
||||
return getProperty(tunnel, "i2p.streaming.maxWindowSize", 128) == 16;
|
||||
}
|
||||
|
||||
public int getTunnelDepth(int tunnel, int defaultLength) {
|
||||
return getProperty(tunnel, "inbound.length", defaultLength);
|
||||
}
|
||||
|
||||
public int getTunnelQuantity(int tunnel, int defaultQuantity) {
|
||||
return getProperty(tunnel, "inbound.quantity", defaultQuantity);
|
||||
}
|
||||
|
||||
public int getTunnelBackupQuantity(int tunnel, int defaultBackupQuantity) {
|
||||
return getProperty(tunnel, "inbound.backupQuantity", defaultBackupQuantity);
|
||||
}
|
||||
|
||||
public int getTunnelVariance(int tunnel, int defaultVariance) {
|
||||
return getProperty(tunnel, "inbound.lengthVariance", defaultVariance);
|
||||
}
|
||||
|
||||
public boolean getReduceOnIdle(int tunnel, boolean def) {
|
||||
return getBooleanProperty(tunnel, "i2cp.reduceOnIdle", def);
|
||||
}
|
||||
|
||||
public int getReduceCount(int tunnel, int def) {
|
||||
return getProperty(tunnel, "i2cp.reduceQuantity", def);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tunnel
|
||||
* @param def in minutes
|
||||
* @return time in minutes
|
||||
*/
|
||||
public int getReduceTime(int tunnel, int def) {
|
||||
return getProperty(tunnel, "i2cp.reduceIdleTime", def*60*1000) / (60*1000);
|
||||
}
|
||||
|
||||
public int getCert(int tunnel) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getEffort(int tunnel) {
|
||||
return 23;
|
||||
}
|
||||
|
||||
public String getSigner(int tunnel) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean getEncrypt(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.encryptLeaseSet");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newTunnelType used if tunnel < 0
|
||||
*/
|
||||
public int getSigType(int tunnel, String newTunnelType) {
|
||||
SigType type;
|
||||
String ttype;
|
||||
boolean isShared;
|
||||
if (tunnel >= 0) {
|
||||
Destination d = getDestination(tunnel);
|
||||
if (d != null) {
|
||||
type = d.getSigType();
|
||||
if (type != null)
|
||||
return type.getCode();
|
||||
}
|
||||
String stype = getProperty(tunnel, I2PClient.PROP_SIGTYPE, null);
|
||||
type = stype != null ? SigType.parseSigType(stype) : null;
|
||||
ttype = getTunnelType(tunnel);
|
||||
isShared = isSharedClient(tunnel);
|
||||
} else {
|
||||
type = null;
|
||||
ttype = newTunnelType;
|
||||
isShared = false;
|
||||
}
|
||||
if (type == null) {
|
||||
// same default logic as in TunnelController.setConfig()
|
||||
if ((!TunnelController.isClient(ttype) ||
|
||||
((TunnelController.TYPE_IRC_CLIENT.equals(ttype) ||
|
||||
TunnelController.TYPE_SOCKS_IRC.equals(ttype) ||
|
||||
TunnelController.TYPE_STREAMR_CLIENT.equals(ttype) ||
|
||||
TunnelController.TYPE_STD_CLIENT.equals(ttype)) &&
|
||||
!isShared)))
|
||||
type = TunnelController.PREFERRED_SIGTYPE;
|
||||
else
|
||||
type = SigType.DSA_SHA1;
|
||||
}
|
||||
return type.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Random keys
|
||||
*/
|
||||
public String getInboundRandomKey(int tunnel) {
|
||||
return getProperty(tunnel, "inbound.randomKey", "");
|
||||
}
|
||||
|
||||
public String getOutboundRandomKey(int tunnel) {
|
||||
return getProperty(tunnel, "outbound.randomKey", "");
|
||||
}
|
||||
|
||||
public String getLeaseSetSigningPrivateKey(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetSigningPrivateKey", "");
|
||||
}
|
||||
|
||||
public String getLeaseSetPrivateKey(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetPrivateKey", "");
|
||||
}
|
||||
|
||||
public boolean getDCC(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelIRCClient.PROP_DCC);
|
||||
}
|
||||
|
||||
public String getEncryptKey(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetKey", "");
|
||||
}
|
||||
|
||||
public int getAccessMode(int tunnel) {
|
||||
if (getBooleanProperty(tunnel, PROP_ENABLE_ACCESS_LIST))
|
||||
return 1;
|
||||
if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getAccessList(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
||||
}
|
||||
|
||||
public String getJumpList(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClient.PROP_JUMP_SERVERS,
|
||||
I2PTunnelHTTPClient.DEFAULT_JUMP_SERVERS).replace(",", "\n");
|
||||
}
|
||||
|
||||
public boolean getCloseOnIdle(int tunnel, boolean def) {
|
||||
return getBooleanProperty(tunnel, "i2cp.closeOnIdle", def);
|
||||
}
|
||||
|
||||
public int getCloseTime(int tunnel, int def) {
|
||||
return getProperty(tunnel, "i2cp.closeIdleTime", def*60*1000) / (60*1000);
|
||||
}
|
||||
|
||||
public boolean getNewDest(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.newDestOnResume") &&
|
||||
getBooleanProperty(tunnel, "i2cp.closeOnIdle") &&
|
||||
!getBooleanProperty(tunnel, "persistentClientKey");
|
||||
}
|
||||
|
||||
public boolean getPersistentClientKey(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "persistentClientKey");
|
||||
}
|
||||
|
||||
public boolean getDelayOpen(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.delayOpen");
|
||||
}
|
||||
|
||||
public boolean getAllowUserAgent(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_USER_AGENT);
|
||||
}
|
||||
|
||||
public boolean getAllowReferer(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_REFERER);
|
||||
}
|
||||
|
||||
public boolean getAllowAccept(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_ACCEPT);
|
||||
}
|
||||
|
||||
public boolean getAllowInternalSSL(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_INTERNAL_SSL);
|
||||
}
|
||||
|
||||
public boolean getMultihome(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "shouldBundleReplyInfo");
|
||||
}
|
||||
|
||||
public String getProxyAuth(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_AUTH, "false");
|
||||
}
|
||||
|
||||
public boolean getOutproxyAuth(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH);
|
||||
}
|
||||
|
||||
public String getOutproxyUsername(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER, "");
|
||||
}
|
||||
|
||||
public String getOutproxyPassword(int tunnel) {
|
||||
if (getOutproxyUsername(tunnel).length() <= 0)
|
||||
return "";
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW, "");
|
||||
}
|
||||
|
||||
public String getSslProxies(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClient.PROP_SSL_OUTPROXIES, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Default true
|
||||
*/
|
||||
public boolean getUseOutproxyPlugin(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_USE_OUTPROXY_PLUGIN, true);
|
||||
}
|
||||
|
||||
/** all of these are @since 0.8.3 */
|
||||
public int getLimitMinute(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_MIN, 0);
|
||||
}
|
||||
|
||||
public int getLimitHour(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_HOUR, 0);
|
||||
}
|
||||
|
||||
public int getLimitDay(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_DAY, 0);
|
||||
}
|
||||
|
||||
public int getTotalMinute(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_MIN, 0);
|
||||
}
|
||||
|
||||
public int getTotalHour(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_HOUR, 0);
|
||||
}
|
||||
|
||||
public int getTotalDay(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_DAY, 0);
|
||||
}
|
||||
|
||||
public int getMaxStreams(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_STREAMS, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST limits
|
||||
* @since 0.9.9
|
||||
*/
|
||||
public int getPostMax(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_MAX, 0);
|
||||
}
|
||||
|
||||
public int getPostTotalMax(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_MAX, 0);
|
||||
}
|
||||
|
||||
public int getPostCheckTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_WINDOW, I2PTunnelHTTPServer.DEFAULT_POST_WINDOW) / 60;
|
||||
}
|
||||
|
||||
public int getPostBanTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_BAN_TIME, I2PTunnelHTTPServer.DEFAULT_POST_BAN_TIME) / 60;
|
||||
}
|
||||
|
||||
public int getPostTotalBanTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_BAN_TIME, I2PTunnelHTTPServer.DEFAULT_POST_TOTAL_BAN_TIME) / 60;
|
||||
}
|
||||
|
||||
public boolean getUniqueLocal(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelServer.PROP_UNIQUE_LOCAL);
|
||||
}
|
||||
|
||||
public String getCustomOptionsString(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = tun.getClientOptionProps();
|
||||
if (opts == null) return "";
|
||||
boolean isMD5Proxy = TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_CONNECT.equals(tun.getType());
|
||||
Map<String, String> sorted = new TreeMap<String, String>();
|
||||
for (Map.Entry<Object, Object> e : opts.entrySet()) {
|
||||
String key = (String)e.getKey();
|
||||
if (TunnelConfig._noShowSet.contains(key))
|
||||
continue;
|
||||
// leave in for HTTP and Connect so it can get migrated to MD5
|
||||
// hide for SOCKS until migrated to MD5
|
||||
if ((!isMD5Proxy) &&
|
||||
TunnelConfig._nonProxyNoShowSet.contains(key))
|
||||
continue;
|
||||
sorted.put(key, (String)e.getValue());
|
||||
}
|
||||
if (sorted.isEmpty())
|
||||
return "";
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
boolean space = false;
|
||||
for (Map.Entry<String, String> e : sorted.entrySet()) {
|
||||
if (space)
|
||||
buf.append(' ');
|
||||
else
|
||||
space = true;
|
||||
buf.append(e.getKey()).append('=').append(e.getValue());
|
||||
}
|
||||
return DataHelper.escapeHTML(buf.toString());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Internal helpers
|
||||
//
|
||||
|
||||
private int getProperty(int tunnel, String prop, int def) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = tun.getClientOptionProps();
|
||||
if (opts != null) {
|
||||
String s = opts.getProperty(prop);
|
||||
if (s == null) return def;
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private String getProperty(int tunnel, String prop, String def) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = tun.getClientOptionProps();
|
||||
if (opts != null) {
|
||||
String rv = opts.getProperty(prop);
|
||||
if (rv != null)
|
||||
return DataHelper.escapeHTML(rv);
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
/** default is false */
|
||||
private boolean getBooleanProperty(int tunnel, String prop) {
|
||||
return getBooleanProperty(tunnel, prop, false);
|
||||
}
|
||||
private boolean getBooleanProperty(int tunnel, String prop, boolean def) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = tun.getClientOptionProps();
|
||||
if (opts != null)
|
||||
return Boolean.parseBoolean(opts.getProperty(prop));
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
protected static String _(String key, I2PAppContext context) {
|
||||
return Messages._(key, context);
|
||||
}
|
||||
|
@@ -257,7 +257,7 @@ public class TunnelConfig {
|
||||
/**
|
||||
* Controls how ephemeral the I2P Destination of a client tunnel is.
|
||||
* <p/>
|
||||
* If {@link #setClose(boolean)} is set to true then mode 1 == mode 0.
|
||||
* If {@link #setClose(boolean)} is set to false then mode 1 == mode 0.
|
||||
*
|
||||
* @param mode 0 for new dest on restart, 1 for new dest on resume from idle, 2 for persistent key
|
||||
*/
|
||||
@@ -356,15 +356,16 @@ public class TunnelConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authentication type required for configured outproxies. The
|
||||
* same authentication type is assumed for all configured outproxies.
|
||||
* Supported authentication types: "basic", "digest".
|
||||
* Sets whether authentication is required for any of the configured
|
||||
* outproxies.
|
||||
*
|
||||
* @param authType the authentication type, or "false" for no authentication
|
||||
* @param val true if authentication is required, false otherwise
|
||||
*/
|
||||
public void setOutproxyAuth(String authType) {
|
||||
if (authType != null)
|
||||
_otherOptions.put(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH, authType.trim());
|
||||
public void setOutproxyAuth(boolean val) {
|
||||
if (val)
|
||||
_booleanOptions.add(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH);
|
||||
else
|
||||
_booleanOptions.remove(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH);
|
||||
}
|
||||
|
||||
public void setOutproxyUsername(String s) {
|
||||
|
@@ -9,12 +9,7 @@ package net.i2p.i2ptunnel.web;
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
@@ -22,14 +17,8 @@ import net.i2p.data.Destination;
|
||||
import net.i2p.data.PrivateKeyFile;
|
||||
import net.i2p.data.Signature;
|
||||
import net.i2p.data.SigningPrivateKey;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPClient;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase;
|
||||
import net.i2p.i2ptunnel.I2PTunnelHTTPServer;
|
||||
import net.i2p.i2ptunnel.I2PTunnelIRCClient;
|
||||
import net.i2p.i2ptunnel.I2PTunnelServer;
|
||||
import net.i2p.i2ptunnel.TunnelController;
|
||||
import net.i2p.i2ptunnel.TunnelControllerGroup;
|
||||
import net.i2p.i2ptunnel.ui.TunnelConfig;
|
||||
import net.i2p.util.Addresses;
|
||||
|
||||
/**
|
||||
@@ -62,19 +51,12 @@ public class EditBean extends IndexBean {
|
||||
}
|
||||
|
||||
public String getTargetHost(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null && tun.getTargetHost() != null)
|
||||
return DataHelper.escapeHTML(tun.getTargetHost());
|
||||
else
|
||||
return "127.0.0.1";
|
||||
return DataHelper.escapeHTML(_helper.getTargetHost(tunnel));
|
||||
}
|
||||
|
||||
public String getTargetPort(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null && tun.getTargetPort() != null)
|
||||
return DataHelper.escapeHTML(tun.getTargetPort());
|
||||
else
|
||||
return "";
|
||||
int port = _helper.getTargetPort(tunnel);
|
||||
return port > 0 ? "" + port : "";
|
||||
}
|
||||
|
||||
public String getSpoofedHost(int tunnel) {
|
||||
@@ -86,12 +68,7 @@ public class EditBean extends IndexBean {
|
||||
}
|
||||
|
||||
public String getPrivateKeyFile(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null && tun.getPrivKeyFile() != null)
|
||||
return tun.getPrivKeyFile();
|
||||
if (tunnel < 0)
|
||||
tunnel = _group == null ? 999 : _group.getControllers().size();
|
||||
return "i2ptunnel" + tunnel + "-privKeys.dat";
|
||||
return _helper.getPrivateKeyFile(tunnel);
|
||||
}
|
||||
|
||||
public String getNameSignature(int tunnel) {
|
||||
@@ -136,55 +113,55 @@ public class EditBean extends IndexBean {
|
||||
}
|
||||
|
||||
public boolean shouldDelay(int tunnel) {
|
||||
return getProperty(tunnel, "i2p.streaming.connectDelay", 0) > 0;
|
||||
return _helper.shouldDelayConnect(tunnel);
|
||||
}
|
||||
|
||||
public boolean isInteractive(int tunnel) {
|
||||
return getProperty(tunnel, "i2p.streaming.maxWindowSize", 128) == 16;
|
||||
return _helper.isInteractive(tunnel);
|
||||
}
|
||||
|
||||
public int getTunnelDepth(int tunnel, int defaultLength) {
|
||||
return getProperty(tunnel, "inbound.length", defaultLength);
|
||||
return _helper.getTunnelDepth(tunnel, defaultLength);
|
||||
}
|
||||
|
||||
public int getTunnelQuantity(int tunnel, int defaultQuantity) {
|
||||
return getProperty(tunnel, "inbound.quantity", defaultQuantity);
|
||||
return _helper.getTunnelQuantity(tunnel, defaultQuantity);
|
||||
}
|
||||
|
||||
public int getTunnelBackupQuantity(int tunnel, int defaultBackupQuantity) {
|
||||
return getProperty(tunnel, "inbound.backupQuantity", defaultBackupQuantity);
|
||||
return _helper.getTunnelBackupQuantity(tunnel, defaultBackupQuantity);
|
||||
}
|
||||
|
||||
public int getTunnelVariance(int tunnel, int defaultVariance) {
|
||||
return getProperty(tunnel, "inbound.lengthVariance", defaultVariance);
|
||||
return _helper.getTunnelVariance(tunnel, defaultVariance);
|
||||
}
|
||||
|
||||
public boolean getReduce(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.reduceOnIdle");
|
||||
return _helper.getReduceOnIdle(tunnel, false);
|
||||
}
|
||||
|
||||
public int getReduceCount(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.reduceQuantity", 1);
|
||||
return _helper.getReduceCount(tunnel, 1);
|
||||
}
|
||||
|
||||
public int getReduceTime(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.reduceIdleTime", 20*60*1000) / (60*1000);
|
||||
return _helper.getReduceTime(tunnel, 20);
|
||||
}
|
||||
|
||||
public int getCert(int tunnel) {
|
||||
return 0;
|
||||
return _helper.getCert(tunnel);
|
||||
}
|
||||
|
||||
public int getEffort(int tunnel) {
|
||||
return 23;
|
||||
return _helper.getEffort(tunnel);
|
||||
}
|
||||
|
||||
public String getSigner(int tunnel) {
|
||||
return "";
|
||||
return _helper.getSigner(tunnel);
|
||||
}
|
||||
|
||||
public boolean getEncrypt(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.encryptLeaseSet");
|
||||
return _helper.getEncrypt(tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,38 +169,7 @@ public class EditBean extends IndexBean {
|
||||
* @since 0.9.12
|
||||
*/
|
||||
public int getSigType(int tunnel, String newTunnelType) {
|
||||
SigType type;
|
||||
String ttype;
|
||||
boolean isShared;
|
||||
if (tunnel >= 0) {
|
||||
Destination d = getDestination(tunnel);
|
||||
if (d != null) {
|
||||
type = d.getSigType();
|
||||
if (type != null)
|
||||
return type.getCode();
|
||||
}
|
||||
String stype = getProperty(tunnel, I2PClient.PROP_SIGTYPE, null);
|
||||
type = stype != null ? SigType.parseSigType(stype) : null;
|
||||
ttype = getTunnelType(tunnel);
|
||||
isShared = isSharedClient(tunnel);
|
||||
} else {
|
||||
type = null;
|
||||
ttype = newTunnelType;
|
||||
isShared = false;
|
||||
}
|
||||
if (type == null) {
|
||||
// same default logic as in TunnelController.setConfig()
|
||||
if ((!TunnelController.isClient(ttype) ||
|
||||
((TunnelController.TYPE_IRC_CLIENT.equals(ttype) ||
|
||||
TunnelController.TYPE_SOCKS_IRC.equals(ttype) ||
|
||||
TunnelController.TYPE_STREAMR_CLIENT.equals(ttype) ||
|
||||
TunnelController.TYPE_STD_CLIENT.equals(ttype)) &&
|
||||
!isShared)))
|
||||
type = TunnelController.PREFERRED_SIGTYPE;
|
||||
else
|
||||
type = SigType.DSA_SHA1;
|
||||
}
|
||||
return type.getCode();
|
||||
return _helper.getSigType(tunnel, newTunnelType);
|
||||
}
|
||||
|
||||
/** @since 0.9.12 */
|
||||
@@ -236,118 +182,109 @@ public class EditBean extends IndexBean {
|
||||
* @since 0.9.18
|
||||
*/
|
||||
public String getKey1(int tunnel) {
|
||||
return getProperty(tunnel, "inbound.randomKey", "");
|
||||
return _helper.getInboundRandomKey(tunnel);
|
||||
}
|
||||
|
||||
public String getKey2(int tunnel) {
|
||||
return getProperty(tunnel, "outbound.randomKey", "");
|
||||
return _helper.getOutboundRandomKey(tunnel);
|
||||
}
|
||||
|
||||
public String getKey3(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetSigningPrivateKey", "");
|
||||
return _helper.getLeaseSetSigningPrivateKey(tunnel);
|
||||
}
|
||||
|
||||
public String getKey4(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetPrivateKey", "");
|
||||
return _helper.getLeaseSetPrivateKey(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.8.9 */
|
||||
public boolean getDCC(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelIRCClient.PROP_DCC);
|
||||
return _helper.getDCC(tunnel);
|
||||
}
|
||||
|
||||
public String getEncryptKey(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.leaseSetKey", "");
|
||||
return _helper.getEncryptKey(tunnel);
|
||||
}
|
||||
|
||||
public String getAccessMode(int tunnel) {
|
||||
if (getBooleanProperty(tunnel, PROP_ENABLE_ACCESS_LIST))
|
||||
return "1";
|
||||
if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
|
||||
return "2";
|
||||
return "0";
|
||||
return Integer.toString(_helper.getAccessMode(tunnel));
|
||||
}
|
||||
|
||||
public String getAccessList(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
|
||||
return _helper.getAccessList(tunnel);
|
||||
}
|
||||
|
||||
public String getJumpList(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClient.PROP_JUMP_SERVERS,
|
||||
I2PTunnelHTTPClient.DEFAULT_JUMP_SERVERS).replace(",", "\n");
|
||||
return _helper.getJumpList(tunnel);
|
||||
}
|
||||
|
||||
public boolean getClose(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.closeOnIdle");
|
||||
return _helper.getCloseOnIdle(tunnel, false);
|
||||
}
|
||||
|
||||
public int getCloseTime(int tunnel) {
|
||||
return getProperty(tunnel, "i2cp.closeIdleTime", 30*60*1000) / (60*1000);
|
||||
return _helper.getCloseTime(tunnel, 30);
|
||||
}
|
||||
|
||||
public boolean getNewDest(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.newDestOnResume") &&
|
||||
getBooleanProperty(tunnel, "i2cp.closeOnIdle") &&
|
||||
!getBooleanProperty(tunnel, "persistentClientKey");
|
||||
return _helper.getNewDest(tunnel);
|
||||
}
|
||||
|
||||
public boolean getPersistentClientKey(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "persistentClientKey");
|
||||
return _helper.getPersistentClientKey(tunnel);
|
||||
}
|
||||
|
||||
public boolean getDelayOpen(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "i2cp.delayOpen");
|
||||
return _helper.getDelayOpen(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.14 */
|
||||
public boolean getAllowUserAgent(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_USER_AGENT);
|
||||
return _helper.getAllowUserAgent(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.14 */
|
||||
public boolean getAllowReferer(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_REFERER);
|
||||
return _helper.getAllowReferer(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.14 */
|
||||
public boolean getAllowAccept(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_ACCEPT);
|
||||
return _helper.getAllowAccept(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.14 */
|
||||
public boolean getAllowInternalSSL(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClient.PROP_INTERNAL_SSL);
|
||||
return _helper.getAllowInternalSSL(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.18 */
|
||||
public boolean getMultihome(int tunnel) {
|
||||
return getBooleanProperty(tunnel, "shouldBundleReplyInfo");
|
||||
return _helper.getMultihome(tunnel);
|
||||
}
|
||||
|
||||
/** all proxy auth @since 0.8.2 */
|
||||
public boolean getProxyAuth(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_AUTH, "false") != "false";
|
||||
return _helper.getProxyAuth(tunnel) != "false";
|
||||
}
|
||||
|
||||
// TODO think
|
||||
public boolean getOutproxyAuth(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH) &&
|
||||
return _helper.getOutproxyAuth(tunnel) &&
|
||||
getOutproxyUsername(tunnel).length() > 0 &&
|
||||
getOutproxyPassword(tunnel).length() > 0;
|
||||
}
|
||||
|
||||
public String getOutproxyUsername(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER, "");
|
||||
return _helper.getOutproxyUsername(tunnel);
|
||||
}
|
||||
|
||||
public String getOutproxyPassword(int tunnel) {
|
||||
if (getOutproxyUsername(tunnel).length() <= 0)
|
||||
return "";
|
||||
return getProperty(tunnel, I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW, "");
|
||||
return _helper.getOutproxyPassword(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.11 */
|
||||
public String getSslProxies(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPClient.PROP_SSL_OUTPROXIES, "");
|
||||
return _helper.getSslProxies(tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,36 +292,36 @@ public class EditBean extends IndexBean {
|
||||
* @since 0.9.11
|
||||
*/
|
||||
public boolean getUseOutproxyPlugin(int tunnel) {
|
||||
return Boolean.parseBoolean(getProperty(tunnel, I2PTunnelHTTPClient.PROP_USE_OUTPROXY_PLUGIN, "true"));
|
||||
return _helper.getUseOutproxyPlugin(tunnel);
|
||||
}
|
||||
|
||||
/** all of these are @since 0.8.3 */
|
||||
public int getLimitMinute(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_MIN, 0);
|
||||
return _helper.getLimitMinute(tunnel);
|
||||
}
|
||||
|
||||
public int getLimitHour(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_HOUR, 0);
|
||||
return _helper.getLimitHour(tunnel);
|
||||
}
|
||||
|
||||
public int getLimitDay(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_DAY, 0);
|
||||
return _helper.getLimitDay(tunnel);
|
||||
}
|
||||
|
||||
public int getTotalMinute(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_MIN, 0);
|
||||
return _helper.getTotalMinute(tunnel);
|
||||
}
|
||||
|
||||
public int getTotalHour(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_HOUR, 0);
|
||||
return _helper.getTotalHour(tunnel);
|
||||
}
|
||||
|
||||
public int getTotalDay(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_DAY, 0);
|
||||
return _helper.getTotalDay(tunnel);
|
||||
}
|
||||
|
||||
public int getMaxStreams(int tunnel) {
|
||||
return getProperty(tunnel, TunnelConfig.PROP_MAX_STREAMS, 0);
|
||||
return _helper.getMaxStreams(tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,67 +329,28 @@ public class EditBean extends IndexBean {
|
||||
* @since 0.9.9
|
||||
*/
|
||||
public int getPostMax(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_MAX, 0);
|
||||
return _helper.getPostMax(tunnel);
|
||||
}
|
||||
|
||||
public int getPostTotalMax(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_MAX, 0);
|
||||
return _helper.getPostTotalMax(tunnel);
|
||||
}
|
||||
|
||||
public int getPostCheckTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_WINDOW, I2PTunnelHTTPServer.DEFAULT_POST_WINDOW) / 60;
|
||||
return _helper.getPostCheckTime(tunnel);
|
||||
}
|
||||
|
||||
public int getPostBanTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_BAN_TIME, I2PTunnelHTTPServer.DEFAULT_POST_BAN_TIME) / 60;
|
||||
return _helper.getPostBanTime(tunnel);
|
||||
}
|
||||
|
||||
public int getPostTotalBanTime(int tunnel) {
|
||||
return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_BAN_TIME, I2PTunnelHTTPServer.DEFAULT_POST_TOTAL_BAN_TIME) / 60;
|
||||
return _helper.getPostTotalBanTime(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.9.13 */
|
||||
public boolean getUniqueLocal(int tunnel) {
|
||||
return getBooleanProperty(tunnel, I2PTunnelServer.PROP_UNIQUE_LOCAL);
|
||||
}
|
||||
|
||||
private int getProperty(int tunnel, String prop, int def) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = getOptions(tun);
|
||||
if (opts != null) {
|
||||
String s = opts.getProperty(prop);
|
||||
if (s == null) return def;
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
private String getProperty(int tunnel, String prop, String def) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = getOptions(tun);
|
||||
if (opts != null) {
|
||||
String rv = opts.getProperty(prop);
|
||||
if (rv != null)
|
||||
return DataHelper.escapeHTML(rv);
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
/** default is false */
|
||||
private boolean getBooleanProperty(int tunnel, String prop) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = getOptions(tun);
|
||||
if (opts != null)
|
||||
return Boolean.parseBoolean(opts.getProperty(prop));
|
||||
}
|
||||
return false;
|
||||
return _helper.getUniqueLocal(tunnel);
|
||||
}
|
||||
|
||||
/** @since 0.8.3 */
|
||||
@@ -491,49 +389,7 @@ public class EditBean extends IndexBean {
|
||||
}
|
||||
|
||||
public String getCustomOptions(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Properties opts = getOptions(tun);
|
||||
if (opts == null) return "";
|
||||
boolean isMD5Proxy = TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_CONNECT.equals(tun.getType());
|
||||
Map<String, String> sorted = new TreeMap<String, String>();
|
||||
for (Map.Entry<Object, Object> e : opts.entrySet()) {
|
||||
String key = (String)e.getKey();
|
||||
if (TunnelConfig._noShowSet.contains(key))
|
||||
continue;
|
||||
// leave in for HTTP and Connect so it can get migrated to MD5
|
||||
// hide for SOCKS until migrated to MD5
|
||||
if ((!isMD5Proxy) &&
|
||||
TunnelConfig._nonProxyNoShowSet.contains(key))
|
||||
continue;
|
||||
sorted.put(key, (String)e.getValue());
|
||||
}
|
||||
if (sorted.isEmpty())
|
||||
return "";
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
boolean space = false;
|
||||
for (Map.Entry<String, String> e : sorted.entrySet()) {
|
||||
if (space)
|
||||
buf.append(' ');
|
||||
else
|
||||
space = true;
|
||||
buf.append(e.getKey()).append('=').append(e.getValue());
|
||||
}
|
||||
return DataHelper.escapeHTML(buf.toString());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the client options from the tunnel
|
||||
*
|
||||
* @return map of name=val to be used as I2P session options
|
||||
*/
|
||||
private static Properties getOptions(TunnelController controller) {
|
||||
if (controller == null) return null;
|
||||
return controller.getClientOptionProps();
|
||||
return _helper.getCustomOptionsString(tunnel);
|
||||
}
|
||||
|
||||
private static final String PROP_ADVANCED = "routerconsole.advanced";
|
||||
|
@@ -44,6 +44,7 @@ public class IndexBean {
|
||||
protected final I2PAppContext _context;
|
||||
protected final Log _log;
|
||||
protected final TunnelControllerGroup _group;
|
||||
protected final GeneralHelper _helper;
|
||||
private final String _fatalError;
|
||||
private String _action;
|
||||
private int _tunnel;
|
||||
@@ -58,10 +59,10 @@ public class IndexBean {
|
||||
private int _certType;
|
||||
private String _certSigner;
|
||||
|
||||
public static final int RUNNING = 1;
|
||||
public static final int STARTING = 2;
|
||||
public static final int NOT_RUNNING = 3;
|
||||
public static final int STANDBY = 4;
|
||||
public static final int RUNNING = GeneralHelper.RUNNING;
|
||||
public static final int STARTING = GeneralHelper.STARTING;
|
||||
public static final int NOT_RUNNING = GeneralHelper.NOT_RUNNING;
|
||||
public static final int STANDBY = GeneralHelper.STANDBY;
|
||||
|
||||
//static final String PROP_NONCE = IndexBean.class.getName() + ".nonce";
|
||||
//static final String PROP_NONCE_OLD = PROP_NONCE + '2';
|
||||
@@ -90,6 +91,7 @@ public class IndexBean {
|
||||
error = iae.toString();
|
||||
}
|
||||
_group = tcg;
|
||||
_helper = new GeneralHelper(_context, _group);
|
||||
_fatalError = error;
|
||||
_tunnel = -1;
|
||||
_curNonce = "-1";
|
||||
@@ -236,7 +238,7 @@ public class IndexBean {
|
||||
|
||||
private String saveChanges() {
|
||||
// FIXME name will be HTML escaped twice
|
||||
return getMessages(GeneralHelper.saveTunnel(_context, _group, _tunnel, _config));
|
||||
return getMessages(_helper.saveTunnel(_tunnel, _config));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +249,7 @@ public class IndexBean {
|
||||
if (!_removeConfirmed)
|
||||
return "Please confirm removal";
|
||||
|
||||
return getMessages(GeneralHelper.deleteTunnel(_context, _group, _tunnel, _config));
|
||||
return getMessages(_helper.deleteTunnel(_tunnel, _config.getPrivKeyFile()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +318,7 @@ public class IndexBean {
|
||||
}
|
||||
|
||||
public String getTunnelName(int tunnel) {
|
||||
String name = GeneralHelper.getTunnelName(_group, tunnel);
|
||||
String name = _helper.getTunnelName(tunnel);
|
||||
if (name != null)
|
||||
return DataHelper.escapeHTML(name);
|
||||
else
|
||||
@@ -391,42 +393,19 @@ public class IndexBean {
|
||||
}
|
||||
|
||||
public String getInternalType(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null)
|
||||
return tun.getType();
|
||||
else
|
||||
return "";
|
||||
return _helper.getTunnelType(tunnel);
|
||||
}
|
||||
|
||||
public String getClientInterface(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
if ("streamrclient".equals(tun.getType()))
|
||||
return tun.getTargetHost();
|
||||
else
|
||||
return tun.getListenOnInterface();
|
||||
} else
|
||||
return "127.0.0.1";
|
||||
return _helper.getClientInterface(tunnel);
|
||||
}
|
||||
|
||||
public int getTunnelStatus(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun == null) return NOT_RUNNING;
|
||||
if (tun.getIsRunning()) {
|
||||
if (isClient(tunnel) && tun.getIsStandby())
|
||||
return STANDBY;
|
||||
else
|
||||
return RUNNING;
|
||||
} else if (tun.getIsStarting()) return STARTING;
|
||||
else return NOT_RUNNING;
|
||||
return _helper.getTunnelStatus(tunnel);
|
||||
}
|
||||
|
||||
public String getTunnelDescription(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null && tun.getDescription() != null)
|
||||
return DataHelper.escapeHTML(tun.getDescription());
|
||||
else
|
||||
return "";
|
||||
return DataHelper.escapeHTML(_helper.getTunnelDescription(tunnel));
|
||||
}
|
||||
|
||||
public String getSharedClient(int tunnel) {
|
||||
@@ -438,16 +417,7 @@ public class IndexBean {
|
||||
}
|
||||
|
||||
public String getClientDestination(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun == null) return "";
|
||||
String rv;
|
||||
if (TunnelController.TYPE_STD_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_IRC_CLIENT.equals(tun.getType()) ||
|
||||
TunnelController.TYPE_STREAMR_CLIENT.equals(tun.getType()))
|
||||
rv = tun.getTargetDestination();
|
||||
else
|
||||
rv = tun.getProxyList();
|
||||
return rv != null ? rv : "";
|
||||
return _helper.getClientDestination(tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,23 +465,7 @@ public class IndexBean {
|
||||
* @since 0.9.17
|
||||
*/
|
||||
protected Destination getDestination(int tunnel) {
|
||||
TunnelController tun = getController(tunnel);
|
||||
if (tun != null) {
|
||||
Destination rv = tun.getDestination();
|
||||
if (rv != null)
|
||||
return rv;
|
||||
// if not running, do this the hard way
|
||||
File keyFile = tun.getPrivateKeyFile();
|
||||
if (keyFile != null) {
|
||||
PrivateKeyFile pkf = new PrivateKeyFile(keyFile);
|
||||
try {
|
||||
rv = pkf.getDestination();
|
||||
if (rv != null)
|
||||
return rv;
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return _helper.getDestination(tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -741,9 +695,6 @@ public class IndexBean {
|
||||
_config.setUniqueLocal(true);
|
||||
}
|
||||
|
||||
protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
|
||||
protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
|
||||
|
||||
public void setAccessMode(String val) {
|
||||
if (val != null) {
|
||||
try {
|
||||
@@ -836,7 +787,7 @@ public class IndexBean {
|
||||
}
|
||||
|
||||
public void setOutproxyAuth(String s) {
|
||||
_config.setOutproxyAuth(I2PTunnelHTTPClientBase.DIGEST_AUTH);
|
||||
_config.setOutproxyAuth(true);
|
||||
}
|
||||
|
||||
public void setOutproxyUsername(String s) {
|
||||
@@ -1120,7 +1071,7 @@ public class IndexBean {
|
||||
///
|
||||
|
||||
protected TunnelController getController(int tunnel) {
|
||||
return GeneralHelper.getController(_group, tunnel);
|
||||
return _helper.getController(tunnel);
|
||||
}
|
||||
|
||||
private static String getMessages(List<String> msgs) {
|
||||
|
Reference in New Issue
Block a user