package net.i2p.router.web; import net.i2p.data.DataHelper; import net.i2p.router.Router; import net.i2p.router.RouterContext; /** * simple helper to control restarts/shutdowns in the left hand nav * */ public class ConfigRestartBean { /** all these are tagged below so no need to _x them here */ static final String[] SET1 = {"shutdownImmediate", "Shutdown immediately", "cancelShutdown", "Cancel shutdown"}; static final String[] SET2 = {"restartImmediate", "Restart immediately", "cancelShutdown", "Cancel restart"}; static final String[] SET3 = {"restart", "Restart", "shutdown", "Shutdown"}; static final String[] SET4 = {"shutdown", "Shutdown"}; public static String getNonce() { RouterContext ctx = ContextHelper.getContext(null); String nonce = System.getProperty("console.nonce"); if (nonce == null) { nonce = ""+ctx.random().nextLong(); System.setProperty("console.nonce", nonce); } return nonce; } public static String renderStatus(String urlBase, String action, String nonce) { RouterContext ctx = ContextHelper.getContext(null); String systemNonce = getNonce(); if ( (nonce != null) && (systemNonce.equals(nonce)) && (action != null) ) { // Normal browsers send value, IE sends button label if ("shutdownImmediate".equals(action) || _("Shutdown immediately", ctx).equals(action)) { ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_HARD)); //ctx.router().shutdown(Router.EXIT_HARD); // never returns ctx.router().shutdownGracefully(Router.EXIT_HARD); // give the UI time to respond } else if ("cancelShutdown".equals(action) || _("Cancel shutdown", ctx).equals(action)) { ctx.router().cancelGracefulShutdown(); } else if ("restartImmediate".equals(action) || _("Restart immediately", ctx).equals(action)) { ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART)); //ctx.router().shutdown(Router.EXIT_HARD_RESTART); // never returns ctx.router().shutdownGracefully(Router.EXIT_HARD_RESTART); // give the UI time to respond } else if ("restart".equals(action) || _("Restart", ctx).equals(action)) { ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART)); ctx.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART); } else if ("shutdown".equals(action) || _("Shutdown", ctx).equals(action)) { ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL)); ctx.router().shutdownGracefully(); } } boolean shuttingDown = isShuttingDown(ctx); boolean restarting = isRestarting(ctx); long timeRemaining = ctx.router().getShutdownTimeRemaining(); StringBuilder buf = new StringBuilder(128); if ((shuttingDown || restarting) && timeRemaining <= 0) { buf.append("