java.lang.Object
net.i2p.router.web.RouterConsoleRunner
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classFor logging authentication failures.private static classPut IPv4 first.private classStops the web server when the router shuts down.private static classFilter selecting the war files to deploy.Field Summary
Modifier and TypeFieldDescriptionprivate final RouterContextThe router context.private static ScheduledExecutorSchedulerShared Jetty timer thread.private StringHost addresses the console listens on.private StringHTTP port the console listens on.private final LogLogger for the console.private final ClientAppManagerManager starting and stopping the app.private final NavHelperHelper building the navigation menu.private ServerThe Jetty server, null until started.private StringHost addresses the HTTPS listener uses.private StringHTTPS port the console listens on.private ClientAppStateCurrent state of the console app.private StringDirectory holding the webapps to deploy.private static final DigestAuthenticatorJetty authenticator for the console login.static final intDefault HTTP listen port for the console.private static final StringFile listing the webapps to deploy.private static final StringDefault webapps directory.static final StringProperty suffix for webapp enable flags.static final StringRealm name for console authentication.private static final StringJetty role required by the protected pages.private static final intIdle time before Jetty closes a connection.private static final intHandler thread counts, adjusted for connectors and acceptors in startConsole().private static final StringFrom Jetty Credential.java.private static final intHandler thread counts, adjusted for connectors and acceptors instartConsole().private static final StringName of this client app.static final StringProperty prefix for webapp enable flags.(package private) static final StringProperty name for hosts allowed to access the console.static final StringProperty name for the console authentication password.static final StringProperty name for the desktop GUI enable flag.static final StringProperty name for the console SSL key password.static final StringProperty name for the console keystore password.static final StringProperty name for enabling console authentication.static final StringName of the root console webapp.private static final StringName of the console's app thread.private static final StringText shown for bad console arguments.(package private) static final FileFilterAccepts every .war file in the webapps directory exceptrouterconsole.war, which is the root context rather than a plugin webapp.Constructor Summary
ConstructorsConstructorDescriptionRouterConsoleRunner(RouterContext ctx, ClientAppManager mgr, String[] args) Construct and start the console, parsing command-line arguments.Method Summary
Modifier and TypeMethodDescriptionprivate intaddListeners(List<Connector> connectors, Set<String> listenHosts, boolean hasIPV4, boolean hasIPV6) Add the HTTP listeners for the configured hosts, testing each bind before the connector is added, and register the console service with the port mapper.private intaddSSLListeners(List<Connector> connectors, Set<String> listenHosts, boolean hasIPV4, boolean hasIPV6) Add the HTTPS listeners for the configured hosts, creating the self-signed keystore if needed and testing each bind before the connector is added, and register the HTTPS console service with the port mapper.private voidchangeState(ClientAppState state) Records the new app state and notifies the app manager.private voidWarn if the JVM is too old.private booleancreateKeyStore(File ks, Set<String> altNames) Create a new keystore with a keypair in it.private voidfixUpListenHosts(Set<String> listenHosts, HostCheckHandler chCollWrapper) Expand the listen-host set with the local addresses and the allowed-hosts property, unless a wildcard address was configured, and hand it to the host check handler.(package private) ServerThe Jetty server backing the console.(package private) static ServerTo get to Jetty.The console's display name.getName()The console's internal name.getState()Current console state.(package private) static voidinitialize(RouterContext ctx, WebAppContext context) Set up basic security constraints for the webapp.(package private) static booleanisSystrayEnabled(I2PAppContext context) Package private for ConfigServiceHandler.static StringThe version string of the Jetty server library the console runs on.static voidStart the console against the first running router context.private voidmapNotStartedWebApps(ServletHandler rootServletHandler, List<String> notStarted) Map each not-started webapp to the no-webapp error page.voidStop the console web server.private voidStart the graph generator, update manager, news manager, and plugin starter threads, and register the shutdown and signal handlers.private voidstartConnectors(List<Connector> connectors) Start the server, then add and start each connector one at a time so a failing bind does not take down the console.voidHandler tree:private voidStarts the system tray icon if enabled.voidstartup()Start the console web server.startWebApps(ContextHandlerCollection chColl, Properties props) Start the other webapps in the webapps directory once the server is up, since Jetty starts the connector before the router console is ready; this makes startup faster and keeps one bad webapp from breaking the console.private voidStops all but the root webapp (routerconsole.war) In Jetty 9, stopping the server doesn't stop the non-root webapps, so we must do it here.static voidstoreWebAppProperties(RouterContext ctx, Properties props) Persist the webapp enable properties to the config directory.private booleanverifyKeyStore(File ks, Set<String> altNames) Check the console keystore, creating one with a self-signed keypair if needed.private PropertiesLoads the webapps config file.static PropertieswebAppProperties(String dir) Webapp enable properties from the given directory.static PropertiesWebapp enable properties from the router config directory.
Field Details
_context
The router context._mgr
Manager starting and stopping the app._log
Logger for the console._state
Current state of the console app._server
The Jetty server, null until started._jettyTimer
Shared Jetty timer thread._listenPort
HTTP port the console listens on._listenHost
Host addresses the console listens on._sslListenPort
HTTPS port the console listens on._sslListenHost
Host addresses the HTTPS listener uses._webAppsDir
Directory holding the webapps to deploy.DEFAULT_WEBAPP_CONFIG_FILENAME
File listing the webapps to deploy.- See Also:
authenticator
Jetty authenticator for the console login.NAME
JETTY_REALM
Realm name for console authentication.- See Also:
JETTY_ROLE
Jetty role required by the protected pages.- See Also:
PROP_CONSOLE_PW
Property name for the console authentication password.- See Also:
PROP_PW_ENABLE
Property name for enabling console authentication.- See Also:
MD5_CREDENTIAL_TYPE
From Jetty Credential.java.- See Also:
ROUTERCONSOLE
Name of the root console webapp.- See Also:
PREFIX
Property prefix for webapp enable flags.- See Also:
ENABLED
Property suffix for webapp enable flags.- See Also:
PROP_KEYSTORE_PASSWORD
Property name for the console keystore password.- See Also:
PROP_KEY_PASSWORD
Property name for the console SSL key password.- See Also:
DEFAULT_LISTEN_PORT
public static final int DEFAULT_LISTEN_PORTDefault HTTP listen port for the console.- See Also:
DEFAULT_WEBAPPS_DIR
Default webapps directory.- See Also:
USAGE
Text shown for bad console arguments.- See Also:
MIN_THREADS
private static final int MIN_THREADSHandler thread counts, adjusted for connectors and acceptors instartConsole().- See Also:
MAX_THREADS
private static final int MAX_THREADSHandler thread counts, adjusted for connectors and acceptors in startConsole().- See Also:
MAX_IDLE_TIME
private static final int MAX_IDLE_TIMEIdle time before Jetty closes a connection.- See Also:
THREAD_NAME
Name of the console's app thread.- See Also:
PROP_DTG_ENABLED
Property name for the desktop GUI enable flag.- See Also:
PROP_ALLOWED_HOSTS
Property name for hosts allowed to access the console.- See Also:
WAR_FILTER
Accepts every .war file in the webapps directory exceptrouterconsole.war, which is the root context rather than a plugin webapp.
Constructor Details
RouterConsoleRunner
Construct and start the console, parsing command-line arguments. Usage:non-SSL: RouterConsoleRunner RouterConsoleRunner 7657 RouterConsoleRunner 7657 127.0.0.1 RouterConsoleRunner 7657 127.0.0.1,::1 RouterConsoleRunner 7657 127.0.0.1,::1 ./webapps/. SSL: RouterConsoleRunner -s 7657 RouterConsoleRunner -s 7657 127.0.0.1 RouterConsoleRunner -s 7657 127.0.0.1,::1 RouterConsoleRunner -s 7657 127.0.0.1,::1 ./webapps/ If using both, non-SSL must be first: RouterConsoleRunner 7657 127.0.0.1 -s 7667 RouterConsoleRunner 7657 127.0.0.1 -s 7667 127.0.0.1 RouterConsoleRunner 7657 127.0.0.1,::1 -s 7667 127.0.0.1,::1 RouterConsoleRunner 7657 127.0.0.1,::1 -s 7667 127.0.0.1,::1 ./webapps/
- Parameters:
ctx- the router contextmgr- the client app manager to register with, or null for a standalone runargs- second arg may be a comma-separated list of bind addresses, for example ::1,127.0.0.1 On XP, the other order (127.0.0.1,::1) fails the IPV6 bind, because 127.0.0.1 will bind ::1 also. But even though it's bound to both, we can't connect to [::1]:7657 for some reason. So the wise choice is ::1,127.0.0.1
Method Details
main
Start the console against the first running router context.- Parameters:
args- the console options, in the order documented on the constructor
startup
shutdown
getState
Current console state.getName
getDisplayName
The console's display name.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- non-null
changeState
Records the new app state and notifies the app manager.- Parameters:
state- the state to move to
getConsoleServer
Server getConsoleServer()The Jetty server backing the console.- Returns:
- the server, may be null or stopped
getConsoleServer
To get to Jetty. Warning, this will NOT work during shutdown, because changeState(STOPPING) will unregister us first.- Parameters:
ctx- the context whose registered console instance to look up- Returns:
- may be null or stopped perhaps
jettyVersion
The version string of the Jetty server library the console runs on.- Returns:
- the Jetty version, as reported by Jetty itself
isSystrayEnabled
Package private for ConfigServiceHandler.- Parameters:
context- the context to read the desktopgui.enabled property from- Returns:
- true if the desktop GUI tray icon is enabled, false if not or on a headless box
startTrayApp
private void startTrayApp()Starts the system tray icon if enabled.checkJavaVersion
private void checkJavaVersion()Warn if the JVM is too old.startConsole
public void startConsole()Handler tree:Server HandlerCollection HostCheckHandler ContextHandlerCollection LocaleWebAppHandler (routerconsole) SessionHandler SecurityHandler ServletHandler servlets... WebAppContext (i2psnark, i2ptunnel, imagegen, susidns, susimail, and each plugin with a .war) DefaultHandler RequestLogHandler (opt)addListeners
private int addListeners(List<Connector> connectors, Set<String> listenHosts, boolean hasIPV4, boolean hasIPV6) Add the HTTP listeners for the configured hosts, testing each bind before the connector is added, and register the console service with the port mapper.- Parameters:
connectors- the list to add the created connectors tolistenHosts- collects the hosts successfully boundhasIPV4- whether IPv4 is availablehasIPV6- whether IPv6 is available- Returns:
- the number of hosts bound
addSSLListeners
private int addSSLListeners(List<Connector> connectors, Set<String> listenHosts, boolean hasIPV4, boolean hasIPV6) Add the HTTPS listeners for the configured hosts, creating the self-signed keystore if needed and testing each bind before the connector is added, and register the HTTPS console service with the port mapper.- Parameters:
connectors- the list to add the created connectors tolistenHosts- collects the hosts successfully boundhasIPV4- whether IPv4 is availablehasIPV6- whether IPv6 is available- Returns:
- the number of hosts bound
fixUpListenHosts
Expand the listen-host set with the local addresses and the allowed-hosts property, unless a wildcard address was configured, and hand it to the host check handler.- Parameters:
listenHosts- the configured hosts, modified in placechCollWrapper- the handler that rejects requests with an unexpected Host header
startConnectors
startWebApps
Start the other webapps in the webapps directory once the server is up, since Jetty starts the connector before the router console is ready; this makes startup faster and keeps one bad webapp from breaking the console. Enable-property rewrites are persisted here.- Parameters:
chColl- the context collection to add the webapps toprops- the webapp properties, updated with the enable rewrites- Returns:
- the names of the webapps that were not started
mapNotStartedWebApps
Map each not-started webapp to the no-webapp error page.- Parameters:
rootServletHandler- the root servlet handler to add the mappings tonotStarted- the names of the webapps that did not start
startBackgroundServices
private void startBackgroundServices()Start the graph generator, update manager, news manager, and plugin starter threads, and register the shutdown and signal handlers.verifyKeyStore
Check the console keystore, creating one with a self-signed keypair if needed.- Parameters:
ks- the keystore file to checkaltNames- the Subject Alternative Names if a new keystore is created, may be null- Returns:
- true if the keystore exists with a password or was created successfully
createKeyStore
initialize
Set up basic security constraints for the webapp. Add all users and passwords.- Parameters:
ctx- the router context, supplying the config directory and password storecontext- the Jetty webapp context the constraints are attached to
webAppProperties
Loads the webapps config file.- Returns:
- the properties read, empty if missing
webAppProperties
Webapp enable properties from the router config directory.- Parameters:
ctx- the context whose config directory holds the webapp config file- Returns:
- the webapp enable properties, empty if the file does not exist yet
webAppProperties
Webapp enable properties from the given directory.- Parameters:
dir- the directory holding the webapp config file- Returns:
- the webapp enable properties, empty if the file does not exist or cannot be read
storeWebAppProperties
Persist the webapp enable properties to the config directory. A config directory that cannot be written is logged and otherwise ignored, so the flags are simply re-derived on the next start.- Parameters:
ctx- the router context, supplying the config directory to write toprops- the webapp enable properties to store
stopAllWebApps
private void stopAllWebApps()Stops all but the root webapp (routerconsole.war) In Jetty 9, stopping the server doesn't stop the non-root webapps, so we must do it here. There should be a better way to do this, possibly by making the webapps "managed".