2004-08-23 07:33:14 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2004-11-25 21:57:19 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
2004-08-31 21:25:23 +00:00
|
|
|
import java.io.IOException;
|
2009-01-02 20:09:20 +00:00
|
|
|
import java.util.List;
|
2004-08-31 21:25:23 +00:00
|
|
|
|
2004-08-24 06:58:05 +00:00
|
|
|
import net.i2p.apps.systray.SysTray;
|
2004-11-25 21:57:19 +00:00
|
|
|
import net.i2p.apps.systray.UrlLauncher;
|
2008-07-16 13:42:54 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
|
|
|
import net.i2p.router.Router;
|
2009-01-02 20:09:20 +00:00
|
|
|
import net.i2p.router.startup.ClientAppConfig;
|
2008-07-16 13:42:54 +00:00
|
|
|
|
2004-08-23 21:32:24 +00:00
|
|
|
import org.tanukisoftware.wrapper.WrapperManager;
|
2004-08-23 07:33:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to deal with form submissions from the service config form and act
|
|
|
|
* upon the values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ConfigServiceHandler extends FormHandler {
|
|
|
|
|
2005-03-23 21:13:03 +00:00
|
|
|
public static class UpdateWrapperManagerTask implements Runnable {
|
2004-09-07 07:17:02 +00:00
|
|
|
private int _exitCode;
|
|
|
|
public UpdateWrapperManagerTask(int exitCode) {
|
|
|
|
_exitCode = exitCode;
|
|
|
|
}
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
WrapperManager.signalStopped(_exitCode);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-26 09:16:11 +00:00
|
|
|
|
|
|
|
public static class UpdateWrapperManagerAndRekeyTask implements Runnable {
|
|
|
|
private int _exitCode;
|
|
|
|
public UpdateWrapperManagerAndRekeyTask(int exitCode) {
|
|
|
|
_exitCode = exitCode;
|
|
|
|
}
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Router.killKeys();
|
|
|
|
WrapperManager.signalStopped(_exitCode);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 07:17:02 +00:00
|
|
|
|
2004-08-23 07:33:14 +00:00
|
|
|
protected void processForm() {
|
|
|
|
if (_action == null) return;
|
2004-08-23 17:11:38 +00:00
|
|
|
|
2004-08-23 07:33:14 +00:00
|
|
|
if ("Shutdown gracefully".equals(_action)) {
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL));
|
2004-08-23 07:33:14 +00:00
|
|
|
_context.router().shutdownGracefully();
|
|
|
|
addFormNotice("Graceful shutdown initiated");
|
|
|
|
} else if ("Shutdown immediately".equals(_action)) {
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD));
|
2004-08-23 21:32:24 +00:00
|
|
|
_context.router().shutdown(Router.EXIT_HARD);
|
2004-08-23 07:33:14 +00:00
|
|
|
addFormNotice("Shutdown immediately! boom bye bye bad bwoy");
|
|
|
|
} else if ("Cancel graceful shutdown".equals(_action)) {
|
|
|
|
_context.router().cancelGracefulShutdown();
|
|
|
|
addFormNotice("Graceful shutdown cancelled");
|
2004-09-06 05:20:40 +00:00
|
|
|
} else if ("Graceful restart".equals(_action)) {
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
|
2004-09-06 05:20:40 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
|
|
|
addFormNotice("Graceful restart requested");
|
2004-08-24 18:02:48 +00:00
|
|
|
} else if ("Hard restart".equals(_action)) {
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART));
|
2004-08-24 18:02:48 +00:00
|
|
|
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
|
|
|
addFormNotice("Hard restart requested");
|
2005-11-26 09:16:11 +00:00
|
|
|
} else if ("Rekey and Restart".equals(_action)) {
|
|
|
|
addFormNotice("Rekeying after graceful restart");
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL_RESTART));
|
2005-11-26 09:16:11 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
|
|
|
} else if ("Rekey and Shutdown".equals(_action)) {
|
|
|
|
addFormNotice("Rekeying after graceful shutdown");
|
2009-02-25 00:05:30 +00:00
|
|
|
_context.addShutdownTask(new UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL));
|
2005-11-26 09:16:11 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL);
|
2004-08-31 21:25:23 +00:00
|
|
|
} else if ("Run I2P on startup".equals(_action)) {
|
|
|
|
installService();
|
|
|
|
} else if ("Don't run I2P on startup".equals(_action)) {
|
|
|
|
uninstallService();
|
2004-08-23 21:32:24 +00:00
|
|
|
} else if ("Dump threads".equals(_action)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
WrapperManager.requestThreadDump();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
addFormError("Warning: unable to contact the service manager - " + t.getMessage());
|
|
|
|
}
|
2004-09-03 19:46:07 +00:00
|
|
|
addFormNotice("Threads dumped to wrapper.log");
|
2004-08-24 06:58:05 +00:00
|
|
|
} else if ("Show systray icon".equals(_action)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
SysTray tray = SysTray.getInstance();
|
|
|
|
if (tray != null) {
|
|
|
|
tray.show();
|
|
|
|
addFormNotice("Systray enabled");
|
|
|
|
} else {
|
|
|
|
addFormNotice("Systray not supported on this platform");
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
addFormError("Warning: unable to contact the systray manager - " + t.getMessage());
|
2004-08-24 18:02:48 +00:00
|
|
|
}
|
2004-08-24 06:58:05 +00:00
|
|
|
} else if ("Hide systray icon".equals(_action)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
SysTray tray = SysTray.getInstance();
|
|
|
|
if (tray != null) {
|
|
|
|
tray.hide();
|
|
|
|
addFormNotice("Systray disabled");
|
|
|
|
} else {
|
|
|
|
addFormNotice("Systray not supported on this platform");
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
addFormError("Warning: unable to contact the systray manager - " + t.getMessage());
|
2004-08-24 18:02:48 +00:00
|
|
|
}
|
2004-11-25 21:57:19 +00:00
|
|
|
} else if ("View console on startup".equals(_action)) {
|
|
|
|
browseOnStartup(true);
|
|
|
|
addFormNotice("Console is to be shown on startup");
|
|
|
|
} else if ("Do not view console on startup".equals(_action)) {
|
|
|
|
browseOnStartup(false);
|
|
|
|
addFormNotice("Console is not to be shown on startup");
|
2004-08-23 07:33:14 +00:00
|
|
|
} else {
|
2006-02-15 05:33:17 +00:00
|
|
|
//addFormNotice("Blah blah blah. whatever. I'm not going to " + _action);
|
2004-08-23 07:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-31 21:25:23 +00:00
|
|
|
|
|
|
|
private void installService() {
|
|
|
|
try {
|
|
|
|
Runtime.getRuntime().exec("install_i2p_service_winnt.bat");
|
|
|
|
addFormNotice("Service installed");
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
addFormError("Warning: unable to install the service - " + ioe.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void uninstallService() {
|
|
|
|
try {
|
|
|
|
Runtime.getRuntime().exec("uninstall_i2p_service_winnt.bat");
|
|
|
|
addFormNotice("Service removed");
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
addFormError("Warning: unable to remove the service - " + ioe.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2004-11-25 21:57:19 +00:00
|
|
|
|
|
|
|
private void browseOnStartup(boolean shouldLaunchBrowser) {
|
2009-01-02 20:09:20 +00:00
|
|
|
List clients = ClientAppConfig.getClientApps(_context);
|
|
|
|
boolean found = false;
|
|
|
|
for (int cur = 0; cur < clients.size(); cur++) {
|
|
|
|
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
|
|
|
|
if (UrlLauncher.class.getName().equals(ca.className)) {
|
|
|
|
ca.disabled = !shouldLaunchBrowser;
|
|
|
|
found = true;
|
|
|
|
break;
|
2004-11-25 21:57:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-02 20:09:20 +00:00
|
|
|
// releases <= 0.6.5 deleted the entry completely
|
|
|
|
if (shouldLaunchBrowser && !found) {
|
2009-04-08 01:34:12 +00:00
|
|
|
ClientAppConfig ca = new ClientAppConfig(UrlLauncher.class.getName(), "consoleBrowser", "http://127.0.0.1:7657", 5, false);
|
2009-01-02 20:09:20 +00:00
|
|
|
clients.add(ca);
|
|
|
|
}
|
|
|
|
ClientAppConfig.writeClientAppConfig(_context, clients);
|
2004-11-25 21:57:19 +00:00
|
|
|
}
|
2005-11-26 09:16:11 +00:00
|
|
|
}
|