package net.i2p.router.web; import java.util.StringTokenizer; 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 { 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".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".equals(action)) { ctx.router().cancelGracefulShutdown(); } else if ("restartImmediate".equals(action) || "Restart immediately".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".equalsIgnoreCase(action)) { ctx.addShutdownTask(new ConfigServiceHandler.UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART)); ctx.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART); } else if ("shutdown".equalsIgnoreCase(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(); if (shuttingDown) { if (timeRemaining <= 0) { return "