web::match result listToBeSearched searchFor
In case searchFor exists in
listToBeSearched,
web::match returns
result, otherwise an empty string.
web::match treats listToBeSearched as a list. Thus, web::match "ok" {tv dvd vcr} dvd will return ok.
web::tempfile ?options?
Options are -path path,
-prefix prefix, and -remove.
web::tempfile ?-path
path
? ?-prefix
prefix
?
Returns a unique name of a temporary file in the default
temp directory or the directory given with
path.
The name can be prefixed with prefix.
The maximum of guaranteed unique names per application is system
dependent. This command just returns the name of a file. It is the
programmers job to handle the file, for example to open
it. Note that Websh keeps an internal list of all file
names generated with web::tempfile and will
attempt to delete all files when the interpreter dies.
web::tempfile -removeAttempts to clean up all temporary files previously created using web::tempfile and resets the internal list of these file names.
web::randombytes count
Returns count cryptographically
secure random bytes.
web::randombytes names
Lists the available random sources (e.g.
getrandom, random,
urandom, default;
platform dependent).
web::randombytes source nameSelects the random source.
web::ts ?ms?
Generates an ISO-8601 timestamp
(2025-02-19T12:34:56.789). If the optional
parameter ms (milliseconds) is not
a valid wide integer, the current system time (from
clock milliseconds) is used.
web::configSetup ?context?
Initializes the configuration context (default:
::config) by assigning the provided context
to the variable configContext and calling
web::context internally.
web::sessionSetup ?context?
Initializes the session context (default:
::session). Stores the provided context in
sessionContext, creates a UUID v4 based id generator via
web::filerandom, and calls
web::filecontext with the appropriate path,
id generator, and disabled encryption (crypt off). Requires
web::configSetup first.
web::loggingSetup level ?syslog?
Configures logging by adding the specified logging level via
web::loglevel add and adding a syslog log
destination with a custom format (including the session tag).
The optional syslog parameter sets
the priority (default: 10). Note that this only wires the
syslog destination; under mod_websh add the
apache destination separately if messages
should appear in the Apache error log.
web::sessionGet
Returns a dictionary containing the current session data. The
dictionary includes the keys iss (Issuer),
sub (Subject), aud
(Audience), exp (Expiration Time),
nbf (Not Before), iat
(Issued At), jti (JWT ID), and
mlt (Max Life Time).
web::sessionNew ?timeout? ?subject? ?audience? ?maxlifetime?
Creates a new session. It computes session validity based on
the current time and the provided timeout (default: 3600000
ms), sets parameters such as Issuer (from SERVER_NAME),
Subject, Audience, Expiration Time, Not Before, Issued At, and
JWT ID (via the session context id), and optionally maximum
lifetime (mlt). A JSON string with the session data is sent
via the response header X-Session. Returns
the session id, or an empty string on failure.
web::sessionInit ?uuid?
Initializes an existing session. The session id is taken from
the uuid argument if given,
otherwise from the AUTH_BEARER token obtained via
web::request. Returns false if no id is
found, if initialization fails, if the session is already
marked as closed, or if it has expired (exp/mlt); otherwise,
updates the session tag and logging and returns true.
web::sessionClose
Closes the current session by setting the sessionClosed flag
and committing the change. Also sets the response header
X-Status to
sessionClosed and returns the current
session data.
web::sessionRefresh ?timeout?
Refreshes the session by updating the expiration time based on
the provided timeout (default: 3600000 ms), commits the
change, updates the X-Session response
header, and returns the current session data.
web::uuidV4 Generates a UUID version 4 by obtaining 16 random bytes via web::randombytes, adjusting specific bits as specified by the UUIDv4 standard, and formatting the result as a string in the format 8-4-4-4-12.
web::getContent
Decodes the raw POST body (CONTENT_DATA) and returns it as a
string. The encoding is resolved in this order: the
charset= parameter of the Content-Type
header; for JSON content types without charset
(application/json,
*+json) UTF-8 as mandated by RFC 8259;
otherwise CONTENT_ENCODING; UTF-8 as final fallback. Always
use this instead of manually converting CONTENT_DATA.
web::mimeType tokenDetermines the MIME type based on a given token. Supported tokens include: bin, bz2, csv, docx, gz, ics, jpg, json, png, pdf, rtf, svg, txt, xlsx, xml, zip, 7z. If the token is not recognized, returns the original token.
web::returnJson jsonSends a JSON response. Configures the response channel with UTF-8 encoding, sets appropriate headers (Content-Type, Content-Length, Cache-Control, etc.), sends the JSON data via web::put, and resets the response.
web::returnText mimetype data ?encoding?Sends a text response. Sets the specified encoding (default: utf-8) and MIME type (via web::mimeType), calculates the content length, sets cache control headers, outputs the text via web::put, and resets the response.
web::returnBinary mimetype data filenameSends a binary response, typically used for file downloads. Sets the response channel to binary mode, configures headers (Content-Type, Content-Length, Content-Disposition with the specified filename), sets cache control headers, sends the binary data via web::put, and resets the response.
web::genPasswd create name ?len?
name generate
name configure ?key? ?value?
TclOO class (package genpasswd, compiled
in): random password generator backed by
web::randombytes (CSPRNG; indices are drawn
with rejection sampling, so there is no modulo bias) with a
Fisher-Yates shuffle, suitable for real secrets. Defaults:
length 10 (constructor argument or configure len
n; values below 4 fall back to 10) with at least one
character from each class
(lower/upper/numbers/punctuation); ambiguous characters
(l, I, O, 0) are excluded from the alphabets.
configure without arguments returns all
rules (len, lower,min,
upper,min, numbers,min,
punctuation,min), with a key returns that
rule, and with key and value sets it.