2004-08-23 07:33:14 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2004-08-31 21:25:23 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2004-08-23 07:33:14 +00:00
|
|
|
import net.i2p.router.ClientTunnelSettings;
|
2004-08-23 21:32:24 +00:00
|
|
|
import net.i2p.router.Router;
|
2004-08-24 06:58:05 +00:00
|
|
|
import net.i2p.apps.systray.SysTray;
|
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 {
|
2004-08-23 17:11:38 +00:00
|
|
|
public void ConfigNetHandler() {}
|
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)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
WrapperManager.signalStopped(Router.EXIT_GRACEFUL);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
addFormError("Warning: unable to contact the service manager - " + t.getMessage());
|
|
|
|
}
|
2004-08-23 07:33:14 +00:00
|
|
|
_context.router().shutdownGracefully();
|
|
|
|
addFormNotice("Graceful shutdown initiated");
|
|
|
|
} else if ("Shutdown immediately".equals(_action)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
WrapperManager.signalStopped(Router.EXIT_HARD);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
addFormError("Warning: unable to contact the service manager - " + t.getMessage());
|
|
|
|
}
|
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-08-24 18:02:48 +00:00
|
|
|
} else if ("Hard restart".equals(_action)) {
|
|
|
|
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
|
|
|
addFormNotice("Hard restart requested");
|
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-08-23 21:32:24 +00:00
|
|
|
addFormNotice("Threads dumped to logs/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-08-23 07:33:14 +00:00
|
|
|
} else {
|
|
|
|
addFormNotice("Blah blah blah. whatever. I'm not going to " + _action);
|
|
|
|
}
|
|
|
|
}
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|