java.lang.Object
net.i2p.router.web.FormHandler
net.i2p.router.web.ConfigServiceHandler
Handler to deal with form submissions from the service config form and act upon the values.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classTell the wrapper we are stopped.private static classRekey and/or tell the wrapper we are stopping.Nested classes/interfaces inherited from class FormHandler
FormHandler.Message, FormHandler.RateLimitEntryModifier and TypeClassDescriptionstatic classMessage class to encapsulate the message text and the canClose flag.(package private) static classOne window's POST count.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringWrapper version with the listener API.private static final StringWrapper version with the location command.private static final StringWrapper version with the properties command.private static WrapperListenerListener for the wrapper service commands.Fields inherited from class FormHandler
_action, _context, _log, _method, _out, _requestWrapper, _session, _settings, RATE_LIMIT_GLOBAL_KEY, RATE_LIMIT_MAP, RATE_LIMIT_MAX_POSTS, RATE_LIMIT_WINDOW_MSModifier and TypeFieldDescriptionprotected StringForm action.protected RouterContextRouter context.protected LogClass logger.protected StringRequest method.protected WriterOutput writer.protected RequestWrapperOnly for multipart/form-data.protected HttpSessionHTTP session for nonce validation.protected MapNot for multipart/form-data, will be null.(package private) static final StringThe single budget key the console charges POSTs to.(package private) static final ConcurrentHashMap<String, FormHandler.RateLimitEntry> Live budgets, keyed by the value passed to checkRateLimit().(package private) static final intPOSTs admitted per window per key before further ones are refused.(package private) static final intLength of one rate-limit window, in ms.Constructor Summary
ConstructorsConstructorDescriptionCreates a handler; the container calls it with no arguments before each submission.Method Summary
Modifier and TypeMethodDescriptionprivate voidbrowseOnStartup(boolean shouldLaunchBrowser) Sets whether the browser opens at startup.private voidchangeSystray(boolean enable) Enable/disable and start/stop systray.private voidDisables the router as a system service.private voidEnables the router as a system service.private voidexecServiceAction(String action) Run the consolidated service management script (service.ps1).Get the console URL.booleanIs the systray enabled?protected voidImplement this to perform the final processing (in turn, adding formNotice and formError messages, etc)(package private) static voidRegister a handler for signals, so we can handle HUP from the wrapper (wrapper 3.2.0 or higher).private voidregisterWrapperNotifier(int code, boolean rekey) Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping, and a final one to tell the wrapper we are stopped.static voidregisterWrapperNotifier(RouterContext ctx, int code, boolean rekey) Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping, and a final one to tell the wrapper we are stopped.booleanShould we show the cancel button?booleanShould we show the systray controls?static voidUnregister the handler for signals.static FileDoes not necessarily exist.Methods inherited from class FormHandler
_t, _t, _t, _x, addFormError, addFormError, addFormErrorNoEscape, addFormErrorNoEscape, addFormNotice, addFormNotice, addFormNoticeNoEscape, addFormNoticeNoEscape, checkRateLimit, cleanupRateLimits, getAllMessages, getErrors, getJettyString, getNotices, isAdvanced, resolveEffectiveAction, setAction, setContextId, setNonce, setRequestWrapper, setSettings, storeMethod, storeSession, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected voidaddFormError(String errorMsg) Add an error message to display Use if it does not include a link.protected voidaddFormError(String errorMsg, boolean canClose) Add an error message to display Use if it does not include a link.protected voidAdd an error message to display Use if it includes a link or other formatting.protected voidaddFormErrorNoEscape(String msg, boolean canClose) Add an error message to display Use if it includes a link or other formatting.protected voidaddFormNotice(String msg) Add a non-error message to display Use if it does not include a link.protected voidaddFormNotice(String msg, boolean canClose) Add a non-error message to display Use if it does not include a link.protected voidAdd a non-error message to display Use if it includes a link or other formatting.protected voidaddFormNoticeNoEscape(String msg, boolean canClose) Add a non-error message to display Use if it includes a link or other formatting.(package private) static booleancheckRateLimit(String key, long now) Check and record one form submission against the budget for key.(package private) static voidcleanupRateLimits(long now) Remove budgets that have seen no POST for two full windows.Display everything, wrap it in a div for consistent presentation.Display any error messages (processing the form if it hasn't been yet).protected StringgetJettyString(String key) FormHandler.setSettings(Map)must have been called previously Curses Jetty for returning arrays.Display any non-error messages (processing the form if it hasn't been yet).booleanSame as HelperBase.static StringresolveEffectiveAction(String action, Map<?, ?> settings) Resolve which operation the user actually requested.voidAction value.voidsetContextId(String contextId) Configure this bean to query a particular router context.voidNonce value.voidOnly set by formhandler.jsi for multipart/form-data.voidsetSettings(Map settings) For many forms, it's easiest just to put all the parameters here.voidstoreMethod(String val) Call this to prevent changes using GET.voidstoreSession(HttpSession session) For nonce validation.voidstoreWriter(Writer out) Store the output writer for inline form processing.
Field Details
wrapperListener
Listener for the wrapper service commands.LISTENER_AVAILABLE
Wrapper version with the listener API.- See Also:
PROPERTIES_AVAILABLE
Wrapper version with the properties command.- See Also:
LOCATION_AVAILABLE
Wrapper version with the location command.- See Also:
Constructor Details
ConfigServiceHandler
public ConfigServiceHandler()Creates a handler; the container calls it with no arguments before each submission.
Method Details
registerWrapperNotifier
private void registerWrapperNotifier(int code, boolean rekey) Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping, and a final one to tell the wrapper we are stopped.- Parameters:
code- the exit coderekey- true to kill the router's keys on shutdown
registerWrapperNotifier
Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping, and a final one to tell the wrapper we are stopped.- Parameters:
ctx- the router contextcode- the exit coderekey- whether to rekey
registerSignalHandler
Register a handler for signals, so we can handle HUP from the wrapper (wrapper 3.2.0 or higher).- Parameters:
ctx- the router context
unregisterSignalHandler
public static void unregisterSignalHandler()Unregister the handler for signals.shouldShowCancelGraceful
public boolean shouldShowCancelGraceful()Should we show the cancel button?- Returns:
- true if graceful shutdown is in progress
shouldShowSystray
public boolean shouldShowSystray()Should we show the systray controls?- Returns:
- true if the systray should be shown
isSystrayEnabled
public boolean isSystrayEnabled()Is the systray enabled?- Returns:
- true if the systray is enabled
getConsoleURL
Get the console URL.- Returns:
- the full http://host:port URL of the console
processForm
protected void processForm()Description copied from class:FormHandlerImplement this to perform the final processing (in turn, adding formNotice and formError messages, etc)Will only be called if _action is non-null and the nonce is valid.
- Specified by:
processFormin classFormHandler
wrapperLogFile
Does not necessarily exist.- Parameters:
ctx- the I2P app context- Returns:
- non-null, doesn't necessarily exist
enableService
private void enableService()Enables the router as a system service.disableService
private void disableService()Disables the router as a system service.execServiceAction
Run the consolidated service management script (service.ps1). The legacy EnableI2P+Service.bat / DisableI2P+Service.bat shims were removed; the Enable/Disable actions now live in service.ps1.- Parameters:
action- the action to pass to the script, "Enable" or "Disable"- Throws:
IOException- if powershell.exe cannot be started
browseOnStartup
private void browseOnStartup(boolean shouldLaunchBrowser) Sets whether the browser opens at startup.- Parameters:
shouldLaunchBrowser- true to open the browser on startup
changeSystray
private void changeSystray(boolean enable) Enable/disable and start/stop systray.- Parameters:
enable- true to start the systray app, false to shut it down