support shutting down the router from the web console:

specify a "router.shutdownPassword" value in the router.config (or in the environment [ala -D]),
  then specify that password on the shutdown form in the web console and hit submit.  after 30 seconds, it'll kill the router (and unless you're running the sim, it'll kill the JVM too, including clientApp.* started tunnels / etc)
if we had some sort of ACL for accessing the web console, we could avoid the password field altogether, but we dont, so we cant.
This commit is contained in:
jrandom
2004-05-19 22:00:32 +00:00
committed by zzz
parent 7293a8d3c0
commit 0e5d164a8a
2 changed files with 32 additions and 0 deletions

View File

@ -232,6 +232,11 @@ public class Router {
buf.append("</select>"); buf.append("</select>");
buf.append("</form>"); buf.append("</form>");
buf.append("<form action=\"/shutdown\" method=\"GET\">");
buf.append("<b>Shut down the router:</b>");
buf.append("<input type=\"password\" name=\"password\" size=\"8\" />");
buf.append("<input type=\"submit\" value=\"shutdown!\" />");
buf.append("</form>");
buf.append("<hr />\n"); buf.append("<hr />\n");
if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) ) if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )

View File

@ -15,6 +15,7 @@ import java.util.Set;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.I2PThread;
class AdminRunner implements Runnable { class AdminRunner implements Runnable {
private Log _log; private Log _log;
@ -52,6 +53,8 @@ class AdminRunner implements Runnable {
} else if (command.indexOf("setTime") >= 0) { } else if (command.indexOf("setTime") >= 0) {
setTime(command); setTime(command);
reply(out, "<html><body>Time updated</body></html>"); reply(out, "<html><body>Time updated</body></html>");
} else if (command.indexOf("/shutdown") >= 0) {
reply(out, shutdown(command));
} else if (true || command.indexOf("routerConsole.html") > 0) { } else if (true || command.indexOf("routerConsole.html") > 0) {
reply(out, _context.router().renderStatusHTML()); reply(out, _context.router().renderStatusHTML());
} }
@ -135,4 +138,28 @@ class AdminRunner implements Runnable {
private void setTime(long now) { private void setTime(long now) {
_context.clock().setNow(now); _context.clock().setNow(now);
} }
private static final String SHUTDOWN_PASSWORD_PROP = "router.shutdownPassword";
private String shutdown(String cmd) {
String password = _context.router().getConfigSetting(SHUTDOWN_PASSWORD_PROP);
if (password == null)
password = _context.getProperty(SHUTDOWN_PASSWORD_PROP);
if (password == null)
return "No shutdown password specified in the config or context - <b>REFUSING SHUTDOWN</b>." +
"<a href=\"/routerConsole.html\">back</a>";
if (cmd.indexOf(password) > 0) {
I2PThread t = new I2PThread(new Runnable() {
public void run() {
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
_context.router().shutdown();
}
});
t.start();
return "Shutdown request accepted. Killing the router in 30 seconds";
} else {
return "Incorrect shutdown password specified. Please edit your router.config appropriately." +
"<a href=\"/routerConsole.html\">back</a>";
}
}
} }