java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.CSSHelper
Copied and modded from I2PTunnel IndexBean (GPL).
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCapitalize first letter of each word of stringField Summary
Modifier and TypeFieldDescriptionprivate static final LogThe log for the CSS helper.private static final String[]The nonces accepted for the current and previous rotation.Bounded LRU memo of the "is this a small browser?" decision, keyed on the request User-Agent.static final StringConsole-relative path each theme's directory is served under.private static StringRotating nonce for CSRF protection, rotates every 5 minutes.static final booleanWhether the Sora display font is used when no preference is configured.static final StringRefresh interval in seconds used when none is configured.static final booleanDefault true for legacy RRD4J; set false for dual-baseline canvas.static final booleanWhether a short sidebar sticks to the top while the page scrolls.static final StringTheme applied when none is configured.static final booleanWhether the sidebar is merged into the main content column by default.private static final StringTheme name that forces the classic console.private static final PatternPattern of characters allowed in language names.private static longWhen the content nonces were last rotated.(package private) static final intMax User-Agent strings retained by_UACachebefore LRU eviction.static final intLowest refresh interval accepted, disabling automatic refresh when zero.private static final intNumber of issued nonces kept for checking.private static final longInterval between the nonce rotations.static final StringProperty key that suppresses the summary page's automatic refresh.static final StringWhether apps open inside a console IFrame instead of replacing the console.static final StringWhether the console uses the Sora display font instead of Open Sans.static final StringProperty key forcing the narrow mobile console on wide screens.static final StringProperty key holding the summary page refresh interval in seconds.static final StringTrue for a continuous scrolling graph, false for a full-buffer redraw (default).static final StringSidebar graph render direction: "ltr" or "rtl".static final StringTrue for the legacy RRD4J minigraph renderer, false for the dual-baseline canvas.static final StringSidebar graph time period in minutes (2–30, default 20).static final StringTrue to split the display (inbound top, outbound bottom), false to overlay.static final StringWhether a sidebar shorter than the viewport sticks to the top while scrolling.static final StringProperty key naming the console theme in use.static final StringPrefix for the per-theme properties mapping a theme name to its directory.static final StringWhether the sidebar is unified with the main content column.static final StringProperty key selecting the universal (theme-independent) colour scheme.private static final StringConfig key for disabling the X-Frame protection.private static final StringSession-bound nonce for CSRF protection, replaces static nonces @since 0.9.69.private static final PatternPattern that splits text on whitespace.Fields inherited from class HelperBase
_context, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.protected WriterThe writer for output.static final StringChecked attribute for HTML checkboxes.static final StringProperty key for advanced mode.static final StringSelected attribute for HTML select options.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionbooleanallowIFrame(String ua) Should we allow a refreshing IFrame?(package private) static booleanMemoise the small-browser decision for a User-Agent in the bounded_UACache.booleanReturns whether app embedding is enabled or disabled.booleanReturns whether we should use a sticky sidebar when the sidebar height is less than the height of the viewport.booleanWhether the unified sidebar is in use, defaulting to true.booleanIs the summary page refresh turned off?getLang()Needed for conditional css loads for zh.static StringgetNonce()Get current CSRF nonce, rotating every 5 minutes.static StringgetNonce(HttpSession session) Session-bound nonce generation - replaces static consoleNonce, updateNonce, reseedNonce, systemNonce.static StringgetRecentNonce(int index) Get recent nonce for backward compatibility.The summary page refresh period, floored at 5s under heavy CPU load.Returns the sidebar graph render direction ("ltr" or "rtl").intReturns the sidebar graph time period in minutes (2–30).Theme directory prefix, forced to classic for pre-Trident/6 IE.booleanAre the advanced console settings pages shown?voidChange disable refresh boolean and save it.voidChange default language for the router AND save it.voidShow / hide news on home page.voidsetRefresh(String r) Change refresh and save it, "0" also disables the refresh entirely.voidSave the configuration to enable the Sora display font, if the property is set.private static booleanWhether the user agent may embed the console in a frame.booleanShould we send X_Frame_Options=SAMEORIGIN Default true.Translate the title and display consistently.(package private) static intNumber of User-Agent strings currently memoised in_UACache.booleanReturns whether to use the legacy RRD4J minigraph renderer.booleanReturns whether the sidebar graph uses continuous scroll mode.booleanReturns whether the sidebar graph uses split mode (inbound top, outbound bottom).booleanWhether the Sora display font is enabled.booleanReturns whether we should use a sticky sidebar when the sidebar height is less than the height of the viewport.booleanWhether the unified sidebar is enabled, defaulting to false.static booleanvalidateNonce(HttpSession session, String nonce) Session-bound nonce validation - replaces static nonce validation.static booleanvalidateNonce(HttpSession session, String nonce, boolean preserve) Session-bound nonce validation with preserve option.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, isAdvanced, ngettext, setContextId, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected StringgetChecked(String prop) Get the checked attribute for a boolean property.booleanCheck if advanced mode is enabled.Translate a string with plural forms (ngettext).voidsetContextId(String contextId) Configure this bean to query a particular router context.voidstoreWriter(Writer out) Store the writer for output.
Field Details
_log
The log for the CSS helper.LANG_PATTERN
Pattern of characters allowed in language names.SPACE_SPLIT
Pattern that splits text on whitespace.MAX_UA_CACHE
static final int MAX_UA_CACHEMax User-Agent strings retained by_UACachebefore LRU eviction.- See Also:
_UACache
Bounded LRU memo of the "is this a small browser?" decision, keyed on the request User-Agent. The key is a client-supplied string, so an unbounded map would grow with every unique UA ever seen;LHMCachecaps it. Wrapped inCollections.synchronizedMap(Map)becauseLHMCacheis unsynchronized and the console serves concurrent requests.PROP_UNIVERSAL_THEMING
Property key selecting the universal (theme-independent) colour scheme.- See Also:
PROP_THEME_NAME
Property key naming the console theme in use.- See Also:
PROP_THEME_PFX
Prefix for the per-theme properties mapping a theme name to its directory.- See Also:
DEFAULT_THEME
Theme applied when none is configured.- See Also:
BASE_THEME_PATH
Console-relative path each theme's directory is served under.- See Also:
FORCE
Theme name that forces the classic console.- See Also:
PROP_REFRESH
Property key holding the summary page refresh interval in seconds.- See Also:
DEFAULT_REFRESH
Refresh interval in seconds used when none is configured.- See Also:
MIN_REFRESH
public static final int MIN_REFRESHLowest refresh interval accepted, disabling automatic refresh when zero.- See Also:
PROP_DISABLE_REFRESH
Property key that suppresses the summary page's automatic refresh.- See Also:
PROP_XFRAME
Config key for disabling the X-Frame protection.- See Also:
PROP_FORCE_MOBILE_CONSOLE
Property key forcing the narrow mobile console on wide screens.- See Also:
PROP_EMBED_APPS
Whether apps open inside a console IFrame instead of replacing the console.- See Also:
PROP_ENABLE_SORA_FONT
Whether the console uses the Sora display font instead of Open Sans.- See Also:
DEFAULT_ENABLE_SORA_FONT
public static final boolean DEFAULT_ENABLE_SORA_FONTWhether the Sora display font is used when no preference is configured.- See Also:
currentNonce
Rotating nonce for CSRF protection, rotates every 5 minutes._recentNonces
The nonces accepted for the current and previous rotation.lastRotation
private static long lastRotationWhen the content nonces were last rotated.NONCE_ROTATION_MS
private static final long NONCE_ROTATION_MSInterval between the nonce rotations.- See Also:
PROP_UNIFIED_SIDEBAR
Whether the sidebar is unified with the main content column.- See Also:
DEFAULT_UNIFIED_SIDEBAR
public static final boolean DEFAULT_UNIFIED_SIDEBARWhether the sidebar is merged into the main content column by default.- See Also:
PROP_STICKY_SIDEBAR
Whether a sidebar shorter than the viewport sticks to the top while scrolling.- See Also:
DEFAULT_STICKY_SIDEBAR
public static final boolean DEFAULT_STICKY_SIDEBARWhether a short sidebar sticks to the top while the page scrolls.- See Also:
PROP_SIDEBAR_GRAPH_LEGACY
True for the legacy RRD4J minigraph renderer, false for the dual-baseline canvas.- See Also:
DEFAULT_SIDEBAR_GRAPH_LEGACY
public static final boolean DEFAULT_SIDEBAR_GRAPH_LEGACYDefault true for legacy RRD4J; set false for dual-baseline canvas.- See Also:
PROP_SIDEBAR_GRAPH_MINUTES
Sidebar graph time period in minutes (2–30, default 20).- See Also:
PROP_SIDEBAR_GRAPH_SPLIT
True to split the display (inbound top, outbound bottom), false to overlay.- See Also:
PROP_SIDEBAR_GRAPH_DIRECTION
Sidebar graph render direction: "ltr" or "rtl".- See Also:
PROP_SIDEBAR_GRAPH_CONTINUOUS
True for a continuous scrolling graph, false for a full-buffer redraw (default).- See Also:
SESSION_CONSOLE_NONCE
Session-bound nonce for CSRF protection, replaces static nonces @since 0.9.69.- See Also:
NONCE_QUEUE_SIZE
private static final int NONCE_QUEUE_SIZENumber of issued nonces kept for checking.- See Also:
Constructor Details
CSSHelper
public CSSHelper()The context is injected by setContextId(), not by the ctor.
Method Details
getNonce
Session-bound nonce generation - replaces static consoleNonce, updateNonce, reseedNonce, systemNonce.- Parameters:
session- returns an invalid nonce if null- Returns:
- a new nonce for each call
validateNonce
Session-bound nonce validation - replaces static nonce validation.- Parameters:
session- returns false if nullnonce- returns false if null- Returns:
- true if valid
validateNonce
Session-bound nonce validation with preserve option.- Parameters:
session- returns false if nullnonce- returns false if nullpreserve- if true, do not delete the nonce. Use for early checks in jsps.- Returns:
- true if valid
getNonce
Get current CSRF nonce, rotating every 5 minutes. Keeps 2 previous nonces for backward compatibility (multi-tab, slow clients).- Returns:
- the current CSRF token, replaced with a fresh one once the rotation interval has elapsed
getRecentNonce
Get recent nonce for backward compatibility.- Parameters:
index- 0 for most recent, 1 for second most recent- Returns:
- nonce or null if not available
getTheme
embedApps
public boolean embedApps()Returns whether app embedding is enabled or disabled.- Returns:
- true to open apps in a console IFrame, false to replace the console
useSoraDisplayFont
public boolean useSoraDisplayFont()Whether the Sora display font is enabled.- Returns:
- true to use Sora, false for Open Sans
setSoraDisplayFont
public void setSoraDisplayFont()Save the configuration to enable the Sora display font, if the property is set.useUnifiedSidebar
public boolean useUnifiedSidebar()Whether the unified sidebar is enabled, defaulting to false.- Returns:
- true if explicitly enabled, false otherwise
enableUnifiedSidebar
public boolean enableUnifiedSidebar()Whether the unified sidebar is in use, defaulting to true.- Returns:
- true unless the user has explicitly turned the unified sidebar off
useStickySidebar
public boolean useStickySidebar()Returns whether we should use a sticky sidebar when the sidebar height is less than the height of the viewport.- Returns:
- true if explicitly enabled, false otherwise
useLegacySidebarGraph
public boolean useLegacySidebarGraph()Returns whether to use the legacy RRD4J minigraph renderer. When false, the new dual-baseline canvas renderer is used with inbound spiking upward (top half) and outbound downward (bottom half).- Returns:
- true for RRD4J, false for the canvas renderer
getSidebarGraphMinutes
public int getSidebarGraphMinutes()Returns the sidebar graph time period in minutes (2–30).- Returns:
- the sidebar graph minutes
useSidebarGraphSplit
public boolean useSidebarGraphSplit()Returns whether the sidebar graph uses split mode (inbound top, outbound bottom). When false, overlay mode is used (both lines from top).- Returns:
- true unless the user has explicitly turned split mode off
useSidebarGraphContinuous
public boolean useSidebarGraphContinuous()Returns whether the sidebar graph uses continuous scroll mode. When enabled, the graph scrolls left as new data arrives.- Returns:
- true for continuous scrolling, false to redraw the whole buffer
getSidebarGraphDirection
Returns the sidebar graph render direction ("ltr" or "rtl").- Returns:
- the sidebar graph direction
enableStickySidebar
public boolean enableStickySidebar()Returns whether we should use a sticky sidebar when the sidebar height is less than the height of the viewport.- Returns:
- true unless the user has explicitly turned the sticky sidebar off
setLang
Change default language for the router AND save it.- Parameters:
lang- xx OR xx_XX OR xxx OR xxx_XX
getLang
setNews
Show / hide news on home page.- Parameters:
val- if non-null, "1" to show, else hide
shouldSendXFrame
public boolean shouldSendXFrame()Should we send X_Frame_Options=SAMEORIGIN Default true.- Returns:
- whether send x frame
setRefresh
Change refresh and save it, "0" also disables the refresh entirely.- Parameters:
r- the new refresh period in seconds
getRefresh
The summary page refresh period, floored at 5s under heavy CPU load.- Returns:
- refresh time in seconds, as a string, or "3600" when refresh is disabled
setDisableRefresh
Change disable refresh boolean and save it.- Parameters:
r- "0" to disable the refresh, anything else to re-enable it
getDisableRefresh
public boolean getDisableRefresh()Is the summary page refresh turned off?- Returns:
- true if refresh is disabled
title
allowIFrame
Should we allow a refreshing IFrame?- Parameters:
ua- the request User-Agent header, null to allow the IFrame- Returns:
- false if the mobile console is forced or the browser is too small
cachedAllowIFrame
Memoise the small-browser decision for a User-Agent in the bounded_UACache. Package-visible and static so the eviction behaviour is testable without a router context.- Parameters:
ua- the request User-Agent header, non-null- Returns:
- whether an IFrame is allowed for this UA
uaCacheSize
static int uaCacheSize()Number of User-Agent strings currently memoised in_UACache.- Returns:
- the cache size, for tests and diagnostics
shouldAllowIFrame
Whether the user agent may embed the console in a frame.- Parameters:
ua- the user agent string- Returns:
- true to allow the frame
isAdvancedMode
public boolean isAdvancedMode()Are the advanced console settings pages shown?- Returns:
- whether advanced mode