Compare commits

...

3 Commits

4 changed files with 71 additions and 3 deletions

View File

@ -112,6 +112,7 @@ public class JSONRPC2Servlet extends HttpServlet {
disp.register(new RouterManagerHandler(_context, _helper));
disp.register(new I2PControlHandler(_context, _helper, _secMan));
disp.register(new AdvancedSettingsHandler(_context, _helper));
disp.register(new LogHandler(_context, _helper));
if (_isWebapp) {
PortMapper pm = _context.portMapper();
int port = pm.getPort(PortMapper.SVC_CONSOLE);

View File

@ -0,0 +1,64 @@
package net.i2p.i2pcontrol.servlets.jsonrpc2handlers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.thetransactioncompany.jsonrpc2.JSONRPC2Error;
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;
import com.thetransactioncompany.jsonrpc2.server.MessageContext;
import com.thetransactioncompany.jsonrpc2.server.RequestHandler;
import net.i2p.I2PAppContext;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
import net.i2p.util.LogManager;
public class LogHandler implements RequestHandler {
private final RouterContext _context;
private final Log _log;
private static final String[] requiredArgs = { "Info" };
private final JSONRPC2Helper _helper;
public LogHandler(RouterContext ctx, JSONRPC2Helper helper) {
_helper = helper;
_context = ctx;
if (ctx != null)
_log = ctx.logManager().getLog(I2PControlHandler.class);
else
_log = I2PAppContext.getGlobalContext().logManager().getLog(I2PControlHandler.class);
}
// Reports the method names of the handled requests
public String[] handledRequests() {
return new String[] { "Info" };
}
// Processes the requests
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals("Info")) {
JSONRPC2Error err = _helper.validateParams(requiredArgs, req);
if (err != null)
return new JSONRPC2Response(err, req.getID());
Map<String, Object> inParams = req.getNamedParams();
String selector = (String) inParams.get("Info");
Map<String, Object> outParams = new HashMap<String, Object>(4);
LogManager logManager = _context.logManager();
if (selector != null && !selector.isEmpty()) {
String echo = logManager.getLog(selector).toString();
outParams.put("Result", echo);
return new JSONRPC2Response(outParams, req.getID());
} else {
List<String> echoArray = logManager.getBuffer().getMostRecentMessages();
String echo = String.join("\n", echoArray);
outParams.put("Result", echo);
return new JSONRPC2Response(outParams, req.getID());
}
} else {
// Method name not supported
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}
}
}

View File

@ -97,6 +97,8 @@ public class HomeHelper extends HelperBase {
//"sponge.i2p" + S + _x("Seedless and the Robert BitTorrent applications") + S + "http://sponge.i2p/" + S + I + "user_astronaut.png" + S +
"notbob.i2p" + S + _x("Not Bob's Address Services") + S + "http://notbob.i2p/" + S + I + "notblob.png" + S +
"[Ramble]" + S + _x("Ramble user-moderated forum aggregator") + S + "http://ramble.i2p/" + S + I + "ramble.png" + S +
"Metrics" + S + _x("I2P Network Statistics") + S + "http://metrics.i2p/" + S + I + "plugin.png" + S +
"StormyCloud" + S + _x("StormyCloud Outproxy Services") + S + "http://stormycloud.i2p/" + S + I + "plugin.png" + S +
"";
// No commas allowed in text strings!

View File

@ -18,11 +18,12 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Git";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 0;
/** for example: "beta", "alpha", "rc" */
public final static String STATUS = "";
public final static long BUILD = 1;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
public final static String FULL_VERSION = VERSION + "-" + STATUS + BUILD + EXTRA;
public static void main(String args[]) {
System.out.println("I2P Router version: " + FULL_VERSION);
System.out.println("Router ID: " + RouterVersion.ID);