The features described in this page require EZproxy 5.1a GA or later unless otherwise noted.
EZproxy 5.1 introduced the ability to perform more complex string and math manipulations to allow more advanced authorization decisions. The following information explains the constant, variables, and functions that are available to create complex expressions.
The EZproxy administration page provides a Test user.txt configuration option, which can be used to experiment with variables and functions.
From the Test user.txt configuration page, you can check the Force Debug option and then enter a test like this:
::Common
If login:user eq "test"; Msg user is test
If login:user =~ "/^(.)(.)(.)(.)$/" {
Set rev = re:4 . re:3 . re:2 . re:1
Msg 4-letter username reversed and stored in rev
}
/Common
If you past in this example, try entering the 4-letter usernames test and TEST, noting that only the lower-case test triggers the message "user is test" to appear since eq is case-sensitive.
Numeric constants are formed from digits and an optional decimal point.
String constants must be surrounded by either a single quote (') or a double quote (") characters. The use of a single quote (') or double quote character (") has identical meaning to EZproxy. Within a string, the backslash (\) can be used to escape the string quoting character (e.g. O'Grady can be specified as 'O\'Grady' or "O'Grady"). Since backslash acts as an escape character, \\ must be used within a string to specify a \ character.
Standard variables are case-sensitive and must start with a letter which can be followed by any combination of letters, digits, underscores (_), and at signs (@). Variables may also be followed by an opening square bracket, an expression that forms an associate index, and a closing square bracket to store values in an associative array.
There are several namespace prefixes that are used to access special variable sets. The standard namespace prefixes are auth:, db:, login:, re:, and session:
The auth: namespace is used to access variables from an authentication source. Examples of support authentication methods include Athens, CAS, HIP, III, LDAP, Shibboleth, SIP, and TLC. The auth: variables are only available during the processing of user.txt, so any value that needs to be retained should be stored in a session: variable. See the example below. If an authentication source can return more than one value for the same variable, access the first value by include [0] at the end of the variable names, [1], for the second, etc. When using auth:, the variable names can include any of these additional special characters: ! # $ % & * + - . / ^ | ~
The db: prefix provides access to database definition information within the ^B/^E loop of menu.htm. The variables available include db:title, db:description, and db:url.
The env: prefix was introduced in EZproxy 5.1b and provides access to operating system environment variables.
The login: prefix provides access to key variables that are come from login.htm and loginbu.htm during login, including login:auth, login:pass, login:pin, login:url, and login:user. If a value is assigned to login:loguser during login process, the assigned value is used as the username for the user. Starting in EZproxy 5.1c, a value may be assigned to login:user to override the username that is tested by authentication methods.
The re: namespace provides access to the last values that matches during a regular expression comparison, with re:0 holding the last value matched, and re:1 through re:9 holding any values captured by parentheses.
The session: namespace can be used to store values in variables that survive across the entire user session. These variables can be used in files such as menu.htm using the syntax ^{expression}. The special variable session:admin returns 1 if the logged in user is an administrator, 0 if not. The special variable session:user provides the current username if some function has activated username tracking (e.g., if auditing is enabled).
Expressions are formed by mixing constants and variables using any appropriate combination of the following comparisons, operations, and functions.
The most common uses for expressions occur in user.txt with an authentication method block using the If or Set directives. For example:
::SIP
Host sip.yourlib.org
SIP2
IfUnauthenticated; Stop
If auth:BV >= 10 || auth:AT > 5; Deny delinquent.htm
Set session:fullname = auth:AE
/SIP
can be used to deny access if someone's outstanding fines (BV in SIP) are $10 or higher, or if the user has five or more items overdue (AT in SIP), and to store away the person's name (AE in SIP) in a session variable called fullname that can then be referenced in menu.htm with ^{session:fullname}.
For Boolean operations, empty strings and 0 are considered to be false, all other values are considered true. The result of a Boolean operation is 1 if the value is true or 0 if the value is false.
These comparisons are based on the numeric values of the values being compared (e.g., 2 is less than 10).
Unless otherwise noted, these comparisons are case-sensitive based on the sequences of characters in the string values being compared (e.g., "10" is less than "2" since the character "1" comes before the character "2", and "B" is less than "a" since internally"B" comes before the character "a"). To perform a case-insensitive comparison, use either the Upper or Lower function (e.g., Upper("B") is greater than Upper("a") since "B" is comes after "A", and likewise Lower("B") is greater than Lower("a") since "b" comes after "a").
This function parses a name to extract specified components into individual variables. Extracted name components are placed in variables named title, forename, middleName, surname, and nameSuffix. These variable names are case-sensitive. If namespacestr is specified, then the variable names are prefixed with the value of namespacestr and a colon (:).
The formatstr may contain the letters T (title), F (forename), M (middleName), S (surname), X (nameSuffix), K (keep existing variable values), and the comma character (,).
Sample uses include:
# Example 1: name in surname, forename middleName, nameSuffix format
# store results to surname, title, forename, middleName, nameSuffix
Set ParseName(name, "S,TFM,X", "")
# Example 2: name in title forename middleName surname nameSuffix
# store results to session:title, session:forename, session:middleName,
# session:surname, session:nameSuffix,
Set ParseName(name, "TFMSX", "session")
By default, ParseName erases the values of all possible destination variables before it parses the name. To prevent the clearing of existing variables, add K anywhere in formatstr.
This Boolean function directs EZproxy to try to open a file of the specified str and evaluate it based on the rules normally applied to user.txt and then returns 1 if the current user credentials are considered valid or 0 if not.
During user authentication, if the Admin directive has been used to declare a user as an administrator and then UserFile is called, the earlier Admin directive will be cancelled out. To avoid this, insure that any use of the Admin directive occurs either within the file invoked by UserFile or appears somewhere in the main file after UserFile is invoked.
The file specified does not need to include authentication directives, and may instead contain a simple ::Common /Common block of commands that manipulate variables. An advanced application of this concept to incorporate a time-of-day based greeting into login.htm might involve adding:
^{UserFile("greeting.txt"), greeting} to login.htm and creating greeting.txt in the directory where EZproxy is installed with this content:
::Common
Set now = DateTime()
Set hour = FormatDateTime("%H", now)
Set timeOfDay = "afternoon"
If hour < 12; Set timeOfDay = "morning"
If hour >= 18; Set timeOfDay = "evening"
Set greeting = "Good " . timeOfDay
/Common
This product includes GeoLite data created by MaxMind, available from www.maxmind.com .