public class I2PSnarkServlet extends BasicServlet
This servlet provides the complete web-based user interface for I2PSnark, allowing users to manage their torrents through a browser. It handles:
The servlet has been refactored to eliminate Jetty-specific dependencies and works with standard servlet containers.
Security features include:
BasicServlet.HttpContent| Modifier and Type | Field and Description |
|---|---|
(package private) String | cspNonceCsp nonce |
(package private) static char | HELLIPEllipsis character used to truncate long names. |
(package private) static int | MAX_DISPLAYED_FILENAME_LENGTHLongest file name shown before truncation. |
static String | PROP_CONFIG_FILEConfig file path property. |
static String | WARBASEWebapp resource base path. |
_context, _log, _resourceBase| Constructor and Description |
|---|
I2PSnarkServlet() |
| Modifier and Type | Method and Description |
|---|---|
static boolean | browserApiAuthorized(boolean enabled,
boolean hostAllowed,
String providedKey,
String configuredKey)Pure decision function for browser API authorization (unit-testable):
requires the API to be enabled and the client to be an allowed host or
to present the configured API key. |
static String | buildBridgeMetaTag(String baseUrl)The meta element advertising the base URL of the I2PSnark webapp that
served this page, so the I2PSnark Bridge extension's content script can
discover the exact origin + context path (host, port, https) and route
subsequent magnet: handoffs to it. |
void | destroy()Destroy the servlet. |
void | doGet(HttpServletRequest request,
HttpServletResponse response)Handle what we can here, calling super.doGet() for the rest. |
void | doPost(HttpServletRequest request,
HttpServletResponse response)Handle what we can here, calling super.doPost() for the rest. |
File | getResource(String pathInContext)We override this to set the file relative to the storage directory
for the torrent. |
void | init(ServletConfig cfg)Initialize the servlet. |
boolean | isAdvanced()Returns whether advanced mode is enabled in the router console. |
static boolean | isFirefoxFamilyUserAgent(String ua)Whether the given User-Agent header indicates a Firefox-family browser
(Firefox, LibreWolf, Waterfox, Pale Moon, Tor Browser), which can install
the I2PSnark Bridge extension. |
static boolean | isValidBase32InfoHash(String s)Validates if a string is a valid 32-base32 character info hash. |
static boolean | isValidHexInfoHash(String s)Validates if a string is a valid 40-hex character info hash. |
static boolean | isValidV2InfoHash(String s)Validates if string is version 2 hex multihash (68 characters starting with "1220"). |
static boolean | isWindowsUserAgent(String ua)Whether the given User-Agent header indicates Windows, which gets the
PowerShell installer script instead of the shell one. |
(package private) boolean | multiDestSortEnabled()Whether pool badges and pool-based sorting apply: multi-dest mode
with more than one active destination. |
(package private) String | toIcon(String path)Returns the icon name representing the file type or mime type of the given file path. |
(package private) static String | urlify(String s)This is for a full URL. |
boolean | useSoraFont()Returns whether the Sora display font should be used. |
addMimeMapping, addPaths, decodePath, doDelete, doOptions, doTrace, encodePath, getContent, getMimeType, loadMimeMap, passConditionalHeaders, sendData, setResourceBase, setWarBase, writeHeadersdoHead, doPut, getLastModified, service, servicegetInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, logString cspNonce
static final char HELLIP
static final int MAX_DISPLAYED_FILENAME_LENGTH
public static final String PROP_CONFIG_FILE
public static final String WARBASE
public static boolean browserApiAuthorized(boolean enabled,
boolean hostAllowed,
String providedKey,
String configuredKey)enabled - the browser API enable flaghostAllowed - whether the client address is loopback or on the allowlistprovidedKey - the apiKey request parameter, may be nullconfiguredKey - the configured API key, may be null or emptypublic static String buildBridgeMetaTag(String baseUrl)
baseUrl - the webapp base URL, e.g. http://127.0.0.1:8002/i2psnarkpublic void destroy()
destroy in interface Servletdestroy in class GenericServletpublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doGet in class BasicServletServletExceptionIOExceptionpublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doPost in class BasicServletrequest - the HTTP requestresponse - the HTTP responseServletException - if a servlet error occursIOException - if an I/O error occurspublic File getResource(String pathInContext)
getResource in class BasicServletpathInContext - should always start with /public void init(ServletConfig cfg) throws ServletException
init in interface Servletinit in class BasicServletcfg - the servlet configServletException - if initialization failspublic boolean isAdvanced()
public static boolean isFirefoxFamilyUserAgent(String ua)
ua - the User-Agent header, may be nullpublic static boolean isValidBase32InfoHash(String s)
public static boolean isValidHexInfoHash(String s)
public static boolean isValidV2InfoHash(String s)
public static boolean isWindowsUserAgent(String ua)
ua - the User-Agent header, may be nullboolean multiDestSortEnabled()
String toIcon(String path)
path - the file path or file name to analyzepublic boolean useSoraFont()