public class CSSHelperextends HelperBase
Copied and modded from I2PTunnel IndexBean (GPL).
  • Field Details

    • _log

      private static final Log _log
      The log for the CSS helper.
    • LANG_PATTERN

      private static final Pattern LANG_PATTERN
      Pattern of characters allowed in language names.
    • SPACE_SPLIT

      private static final Pattern SPACE_SPLIT
      Pattern that splits text on whitespace.
    • MAX_UA_CACHE

      static final int MAX_UA_CACHE
      Max User-Agent strings retained by _UACache before LRU eviction.
      See Also:
    • _UACache

      private static final Map<String,Boolean> _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; LHMCache caps it. Wrapped in Collections.synchronizedMap(Map) because LHMCache is unsynchronized and the console serves concurrent requests.
    • PROP_UNIVERSAL_THEMING

      public static final String PROP_UNIVERSAL_THEMING
      Property key selecting the universal (theme-independent) colour scheme.
      See Also:
    • PROP_THEME_NAME

      public static final String PROP_THEME_NAME
      Property key naming the console theme in use.
      See Also:
    • PROP_THEME_PFX

      public static final String PROP_THEME_PFX
      Prefix for the per-theme properties mapping a theme name to its directory.
      See Also:
    • DEFAULT_THEME

      public static final String DEFAULT_THEME
      Theme applied when none is configured.
      See Also:
    • BASE_THEME_PATH

      public static final String BASE_THEME_PATH
      Console-relative path each theme's directory is served under.
      See Also:
    • FORCE

      private static final String FORCE
      Theme name that forces the classic console.
      See Also:
    • PROP_REFRESH

      public static final String PROP_REFRESH
      Property key holding the summary page refresh interval in seconds.
      See Also:
    • DEFAULT_REFRESH

      public static final String DEFAULT_REFRESH
      Refresh interval in seconds used when none is configured.
      See Also:
    • MIN_REFRESH

      public static final int MIN_REFRESH
      Lowest refresh interval accepted, disabling automatic refresh when zero.
      See Also:
    • PROP_DISABLE_REFRESH

      public static final String PROP_DISABLE_REFRESH
      Property key that suppresses the summary page's automatic refresh.
      See Also:
    • PROP_XFRAME

      private static final String PROP_XFRAME
      Config key for disabling the X-Frame protection.
      See Also:
    • PROP_FORCE_MOBILE_CONSOLE

      public static final String PROP_FORCE_MOBILE_CONSOLE
      Property key forcing the narrow mobile console on wide screens.
      See Also:
    • PROP_EMBED_APPS

      public static final String PROP_EMBED_APPS
      Whether apps open inside a console IFrame instead of replacing the console.
      See Also:
    • PROP_ENABLE_SORA_FONT

      public static final String 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_FONT
      Whether the Sora display font is used when no preference is configured.
      See Also:
    • currentNonce

      private static String currentNonce
      Rotating nonce for CSRF protection, rotates every 5 minutes.
    • _recentNonces

      private static final String[] _recentNonces
      The nonces accepted for the current and previous rotation.
    • lastRotation

      private static long lastRotation
      When the content nonces were last rotated.
    • NONCE_ROTATION_MS

      private static final long NONCE_ROTATION_MS
      Interval between the nonce rotations.
      See Also:
    • PROP_UNIFIED_SIDEBAR

      public static final String PROP_UNIFIED_SIDEBAR
      Whether the sidebar is unified with the main content column.
      See Also:
    • DEFAULT_UNIFIED_SIDEBAR

      public static final boolean DEFAULT_UNIFIED_SIDEBAR
      Whether the sidebar is merged into the main content column by default.
      See Also:
    • PROP_STICKY_SIDEBAR

      public static final String 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_SIDEBAR
      Whether a short sidebar sticks to the top while the page scrolls.
      See Also:
    • PROP_SIDEBAR_GRAPH_LEGACY

      public static final String 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_LEGACY
      Default true for legacy RRD4J; set false for dual-baseline canvas.
      See Also:
    • PROP_SIDEBAR_GRAPH_MINUTES

      public static final String PROP_SIDEBAR_GRAPH_MINUTES
      Sidebar graph time period in minutes (2–30, default 20).
      See Also:
    • PROP_SIDEBAR_GRAPH_SPLIT

      public static final String PROP_SIDEBAR_GRAPH_SPLIT
      True to split the display (inbound top, outbound bottom), false to overlay.
      See Also:
    • PROP_SIDEBAR_GRAPH_DIRECTION

      public static final String PROP_SIDEBAR_GRAPH_DIRECTION
      Sidebar graph render direction: "ltr" or "rtl".
      See Also:
    • PROP_SIDEBAR_GRAPH_CONTINUOUS

      public static final String PROP_SIDEBAR_GRAPH_CONTINUOUS
      True for a continuous scrolling graph, false for a full-buffer redraw (default).
      See Also:
    • SESSION_CONSOLE_NONCE

      private static final String 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_SIZE
      Number 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

      public static String getNonce(HttpSession session)
      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

      public static boolean validateNonce(HttpSession session, String nonce)
      Session-bound nonce validation - replaces static nonce validation.
      Parameters:
      session - returns false if null
      nonce - returns false if null
      Returns:
      true if valid
    • validateNonce

      public static boolean validateNonce(HttpSession session, String nonce, boolean preserve)
      Session-bound nonce validation with preserve option.
      Parameters:
      session - returns false if null
      nonce - returns false if null
      preserve - if true, do not delete the nonce. Use for early checks in jsps.
      Returns:
      true if valid
    • getNonce

      public static String 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

      public static String getRecentNonce(int index)
      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

      public String getTheme(String userAgent)
      Theme directory prefix, forced to classic for pre-Trident/6 IE.
      Parameters:
      userAgent - the request User-Agent header, null for a normal browser
      Returns:
      the theme path to prepend to console CSS and image references
    • 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

      public String 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

      public void setLang(String lang)
      Change default language for the router AND save it.
      Parameters:
      lang - xx OR xx_XX OR xxx OR xxx_XX
    • getLang

      public String getLang()
      Needed for conditional css loads for zh.
      Returns:
      two-letter only, lower-case
    • setNews

      public void setNews(String val)
      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

      public void setRefresh(String r)
      Change refresh and save it, "0" also disables the refresh entirely.
      Parameters:
      r - the new refresh period in seconds
    • getRefresh

      public String 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

      public void setDisableRefresh(String r)
      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

      public String title(String s)
      Translate the title and display consistently.
      Parameters:
      s - the raw page title
      Returns:
      a complete title element, prefixed by routerconsole.pageTitlePrefix if set
    • allowIFrame

      public boolean allowIFrame(String ua)
      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

      static boolean cachedAllowIFrame(String ua)
      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

      private static boolean shouldAllowIFrame(String ua)
      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