use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.
the class IndexBean method start.
private String start() {
if (_tunnel < 0)
return "Invalid tunnel";
List<TunnelController> controllers = _group.getControllers();
if (_tunnel >= controllers.size())
return "Invalid tunnel";
TunnelController controller = controllers.get(_tunnel);
controller.startTunnelBackground();
// give the messages a chance to make it to the window
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
}
// FIXME name will be HTML escaped twice
return _t("Starting tunnel") + ' ' + getTunnelName(_tunnel) + "...";
}
use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.
the class IndexBean method stop.
private String stop() {
if (_tunnel < 0)
return "Invalid tunnel";
List<TunnelController> controllers = _group.getControllers();
if (_tunnel >= controllers.size())
return "Invalid tunnel";
TunnelController controller = controllers.get(_tunnel);
controller.stopTunnel();
// give the messages a chance to make it to the window
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
}
// FIXME name will be HTML escaped twice
return _t("Stopping tunnel") + ' ' + getTunnelName(_tunnel) + "...";
}
use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.
the class IndexBean method modifyDestination.
/**
* Modify or create a destination
*/
private String modifyDestination() {
String privKeyFile = _config.getPrivKeyFile();
if (privKeyFile == null)
return "Private Key File not specified";
TunnelController tun = getController(_tunnel);
Properties config = getConfig();
if (tun == null) {
// creating new
tun = new TunnelController(config, "", true);
_group.addController(tun);
saveChanges();
} else if (tun.getIsRunning() || tun.getIsStarting()) {
return "Tunnel must be stopped before modifying destination";
}
File keyFile = new File(privKeyFile);
if (!keyFile.isAbsolute())
keyFile = new File(_context.getConfigDir(), privKeyFile);
PrivateKeyFile pkf = new PrivateKeyFile(keyFile);
try {
pkf.createIfAbsent();
} catch (I2PException e) {
return "Create private key file failed: " + e;
} catch (IOException e) {
return "Create private key file failed: " + e;
}
switch(_certType) {
case Certificate.CERTIFICATE_TYPE_NULL:
case Certificate.CERTIFICATE_TYPE_HIDDEN:
pkf.setCertType(_certType);
break;
case Certificate.CERTIFICATE_TYPE_HASHCASH:
pkf.setHashCashCert(_hashCashValue);
break;
case Certificate.CERTIFICATE_TYPE_SIGNED:
if (_certSigner == null || _certSigner.trim().length() <= 0)
return "No signing destination specified";
// find the signer's key file...
String signerPKF = null;
for (int i = 0; i < getTunnelCount(); i++) {
TunnelController c = getController(i);
if (_certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_NAME)) || _certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_SPOOFED_HOST))) {
signerPKF = c.getConfig("").getProperty(TunnelController.PROP_FILE);
break;
}
}
if (signerPKF == null || signerPKF.length() <= 0)
return "Signing destination " + _certSigner + " not found";
if (privKeyFile.equals(signerPKF))
return "Self-signed destinations not allowed";
Certificate c = pkf.setSignedCert(new PrivateKeyFile(signerPKF));
if (c == null)
return "Signing failed - does signer destination exist?";
break;
default:
return "Unknown certificate type";
}
Destination newdest;
try {
pkf.write();
newdest = pkf.getDestination();
} catch (I2PException e) {
return "Modification failed: " + e;
} catch (IOException e) {
return "Modification failed: " + e;
}
return "Destination modified - " + "New Base32 is " + newdest.toBase32() + "New Destination is " + newdest.toBase64();
}
use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.
the class GeneralHelper method getCustomOptionsString.
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;
// 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 "";
}
}
use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.
the class GeneralHelper method getPrivateKeyFile.
/**
* @return path, non-null, non-empty
*/
public String getPrivateKeyFile(TunnelControllerGroup tcg, int tunnel) {
TunnelController tun = getController(tcg, tunnel);
if (tun != null) {
String rv = tun.getPrivKeyFile();
if (rv != null)
return rv;
}
if (tunnel < 0)
tunnel = tcg == null ? 999 : tcg.getControllers().size();
String rv = "i2ptunnel" + tunnel + "-privKeys.dat";
// Don't default to a file that already exists,
// which could happen after other tunnels are deleted.
int i = 0;
while ((new File(_context.getConfigDir(), rv)).exists()) {
rv = "i2ptunnel" + tunnel + '.' + (++i) + "-privKeys.dat";
}
return rv;
}
Aggregations