New command to get JSON of all tunnels

pull/6/head
knaccc 5 years ago
parent 35e68db438
commit ea77448002

@ -123,6 +123,10 @@ specified host and port. Note that the base 32 I2P destination address determini
`tunnel-control.sh all.destroy`
#### List all tunnels. Returns JSON string containing information about all tunnels currently in existence
`tunnel-control.sh all.list`
#### Start a SAM listener on port 7656. Returns "OK"
`tunnel-control.sh sam.create`

@ -98,7 +98,7 @@ public class TunnelControl implements Runnable {
throw new RuntimeException(e);
}
}
public void save() {
public String getJSON(boolean includeKeyPairs) {
try {
JSONObject root = new JSONObject();
JSONArray tunnelsArray = new JSONArray();
@ -112,7 +112,7 @@ public class TunnelControl implements Runnable {
entry.put("host", t.getHost());
entry.put("port", t.getPort());
entry.put("dest", t.getI2P());
entry.put("keypair", ((ServerTunnel) t).keyPair.toString());
if(includeKeyPairs) entry.put("keypair", ((ServerTunnel) t).keyPair.toString());
break;
case "client":
@ -125,7 +125,15 @@ public class TunnelControl implements Runnable {
break;
}
}
Files.writeString(new File(tunnelControlConfigDir, "tunnels.json").toPath(), root.toJSONString());
return root.toJSONString();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public void save() {
try {
Files.writeString(new File(tunnelControlConfigDir, "tunnels.json").toPath(), getJSON(true));
}
catch (Exception e) {
throw new RuntimeException(e);
@ -389,6 +397,11 @@ public class TunnelControl implements Runnable {
break;
}
case "all.list": {
out.println(tunnelList.getJSON(false));
break;
}
case "sam.create": {
String[] samArgs = new String[]{"sam.keys", "127.0.0.1", "7656", "i2cp.tcp.host=127.0.0.1", "i2cp.tcp.port=7654"};
I2PAppContext context = router.getContext();

Loading…
Cancel
Save