This section presents and overview of all the "input" variables that come preset when your scripts are run. They are shown together as many variables are available in several different contexts under the same name. A general rule of thumb is that a given variable is available everywhere that it makes sense. E.g.
In the following table, the Avail. column contains letters indicating the contexts in which a given variable is available:
Entries are sorted in a very rough order of importance.
Variable | Avail. | Description |
---|---|---|
(module persistent globals) | PR | Any variables set with setModuleVar(). See its description under Functions. |
Request Variables | ||
$PATH | P | The filename requested by the phone, including full path. Normalized: starts with a /, double slashes removed, /./ and /../ components resolved and removed. |
$PROTO | P | The protocol using which the request was received. One of the strings 'tftp', 'http' and 'ftp'. |
$OPERATOR_IP | P | IP address of the Operator machine. In case of multiple network interfaces, the IP on which the request was receieved (i.e., the one that the phone "can see"). This is the "right" address to be set as SIP proxy, NTP server, etc. in the phone configuration). |
$PHONE_IP | P | The IP adress from which the provisioning request came, i.e., of the phone. Not available in resync scripts, use $LAST_IP there. Neither is probably of much use, offered merely for completeness. |
(markers) | P | Any variables set with setMarker(). See the Two-stage configuration; markers section in the tutorial. |
$HTTP_* | P | HTTP headers, available under the same names as in CGI, i.e. converted to uppercase, with dashes replaced by underlines and prefixed by 'HTTP_'. E.g. $HTTP_USER_AGENT, $HTTP_ACCEPT, etc. |
$OPT_* | P | TFTP Options (RFC 2347) E.g. $OPT_blksize, etc. |
Global Operator Configuration | ||
$TIMEZONE | PR | Current Operator timezone as a POSIX/tzdata timezone name. E.g. Europe/Prague or America/New_York. See Wikipedia for a complete list. In most cases (unless your phone already understands these strings) it's easier to use $TIMEZONE_OFFSET. |
$TIMEZONE_OFFSET | PR | Current Operator UTC offset in seconds. If DST is currently in effect, this value already includes the DST offset. This is usually the easiest way to configure phone's timezones -- most Kerio's built-in provisioning modules use it. |
$TIMEZONE_OFFSET_BASE | PR | Same as above, only doesn't include any DST offset. |
$VOICEMAIL_EXT | PR | The voicemail access extension (usually 50). Can be used to make the "envelope" button present on many phones dial this number for faster voicemail access. |
$DISPLAY_LOGO | PR | Boolean indicating whether phones should display configured logos. See the chapter on logos in the tutorial. |
$AUTODIAL_TIMEOUT | PR | Auto dial timeout in seconds, sometimes also known as inter-digit timer. Defines time before a number is automatically dialed. |
$HOSTNAME | PR | Operator hostname |
Module Variables | ||
$PHONE_TYPES | PRF | Array of all the phone types defined in phone_types. Keys are type identifiers (first column in phone_types), values are arrays containing keys corresponding to variables in the Phone type variables section below. Usually used only to test phone type existence (isset($PHONE_TYPES[$sometype])), see Efficiently handling larger number of phone types in the tutorial. Example: array( 'spa504g' => array( 'IDENT' => 'spa504g', 'MAX_LINES' => 4, 'SECURE_SUPPORT' => false, // ... ), // ... ) |
$FIRMWARE_TYPES | PRF | Array of all the firmware slots defined in firmware types. Keys are the slot identifiers (first column), values are associative arrays with the following keys:
Plus any extra NAME=VALUE assignments from ``firmware_types``. |
$MODULE_ID | PRF | ID under which the module is internally stored. Useful for constructing module-private filenames for auxiliary provisioning files (firmwares, logos, additional configuration files, etc.) for which a name can be chosen arbitrarily. See Arbitrary Filenames under Firmwares and Logos in the tutorial. |
$MODULE_UUID | PRF | The UUID set in the info file. |
$MODULE_VERSION | PRF | Module version set in the info file. |
$DIALPLAN_(name) | PRF | The dialplan string generated by the dialplans/(name).php script. See Dialplans in the tutorial. |
Phone Type Variables | ||
$IDENT | ART | The phone type identifier (first column in phone_types). |
$MAX_LINES | ART | The phone type's maximum number of lines as set in phone_types. |
(phone type options) | ART | Any name=value options set in phone_types. E.g. $RESYNC, $REVIEW, ... Usually uppercase. See the Phone Type Options section for a list. |
(custom phone type variables) | ART | Any name=value definitions from phone_types that have no special meaning for Operator are available as-is. Customarily named lowercase. See Efficiently Handling Larger Number of Phone Types in the tutorial. |
Phone Configuration | ||
$MAC | AR | The phone's MAC address in normalized format (lowercase, without colons). |
$LINES | AR | An array of phone's assigned lines. Each item is an array with the following keys:
|
$ADMIN_PASSWORD | AR | The password that should be used to protect the phone's web administration. If master password is enabled, this is the master phone password, otherwise the password set in provisioned phone properties (generated by default). |
$PHONE_LABEL | AR | The label for the phone as a whole as opposed to its individual lines. Also known as station name. Should be displayed on the phone's screen if possible. |
$PHONE_DESCRIPTION | AR | Admin's description of the phone. For internal use, should NOT be displayed anywhere. Available only for completeness, probably useless. |
$DIALPLAN | AR | The dialplan for this phone, based on $DIALPLAN_TYPE set in phone_types. E.g. when $DIALPLAN_TYPE == 'spa', this variable has identical content to DIALPLAN_spa, i.e., whatever string was generated by the dialplans/spa.php script. See Dialplans in the tutorial. |
Last Read Phone Configuration (useful mainly in resync) | ||
$LAST_IP | AR | Phone's last know IP address. Our "best shot" when trying to resync the phone. |
$LAST_CONFIG | AR | The values of variables from the Phone configuration section at the last time that the phone has read the configuration. These should be the configuration that the phone "has seen" and currently uses. See Implementing custom resync mechanisms in the tutorial for usage example. Contains e.g. $LAST_CONFIG['LINES'], $LAST_CONFIG['ADMIN_PASSWORD'], etc. |
Firmware Script Variables | ||
$FW_IDENT | F | Identifier (first column from firmware_types) of the slot the file is uploaded to. Useful when one script handles several similar slots. |
$FW_ORIGNAME | F | The original name (without path) of the file uploaded by the user. E.g. 'spa942-6-1-5a.bin'. |
$FW_INFILE | F | The physical path of a temporary file to which the uploaded file was saved. This is the file that you can read, copy, convert, unzip or otherwise. Do not inspect its filename, it will be some random gibberish. Use $FW_ORIGNAME for that purpose. |
$FW_OUTDIR | F | The physical path of a freshly-created directory to which the firmware script should put the preprocessed output. The directory will be preserved as-is (until the firmware is delete or replaced) and made available to the provider script, which can access its files using getFirmwareFile(). |
$FW_VERIFY | F | If 1, the script should perform usual verification of the uploaded file. If false, it should fail only if it's physically impossible to preprocess the uploaded file (e.g. trying to unzip a file that's not a zip archive). |
On several occasions the provisioning modules need to describe lists of things (currently phone types and firmware slots). For this purpose, so-called tabular files are used. Their syntax is described throughout the tutorial, the advanced parts especially in Efficiently Handling Larger Number of Phone Types. Everything described there (variable expansions, @set, etc.) applies all the tabular files.
In the table below, options that are written in a fixed column without specifying a name have the column number in the Pos. column. Those written as NAME=value have the name in the Name column. Positional options can also be written as named (e.g. IDENT=spa504g) but this is discouraged.
Pos. | Name | Default | Description |
---|---|---|---|
1 | (IDENT) | (none) | A module-unique identifier for the phone type. Preferrably lowercase, may contain underscores (e.g. spa504g). |
2 | (MAX_LINES) | (none) | Maximum number of lines that can be assigned to a phone of this type. |
3 | (DESC) | (none) | A human-readable name for the phone type, including manufacturer. E.g. Cisco SPA504G. Show on the Provisioned Phones screen in Administration. |
RESYNC | (none) | The method used to resync the phone. Either a built-in one (named uppercase, see Built-In Resync Methods ) or the name of a resync script (customarily lowercase), which should then be located in "resync/$RESYNC.php" inside your module. | |
(resync options) | (none) | Resync methods may take additional options. For SIPNOTIFY, they are named SIPNOTIFY_something, see Butilt-In Resync Methods . | |
REVIEW | '' | A whitespace-separated list of configuration files that belong to phones of this type. Use variable expansion to put things like MAC address ($MAC) or phone type ($IDENT) in the filenames. Refer to the The Download Configuration feature and Variable expansion in phone_types sections in the tutorial for details. | |
SECURE_SUPPORT | 0 | Set to 1 when the phone supports Secure SIP and SRTP. If you indicate security support, your module MUST honor the SECURE flag for phone lines and MUST ensure secure connection is actually used (the users will count on it). | |
FW | (empty) | A comma-separated list of identifiers of firmware slots associated with this phone. This serves two purposes:
|
|
(custom options) | (none) | You can add arbitrary custom options to phone_types (customarily named lowercase to avoid clashes with future Operator options). Any name=value pair you include in phone_types will be available as a variable in the A, R, T contexts as explained in Variables. See the Efficiently handling larger number of phone types for usage of this feature. |
Pos. | Name | Default | Description |
---|---|---|---|
1 | (FW_IDENT) | (none) | A module-unique identifier for this slot. |
2 | (DESC) | (none) | A humand-readable name for the slot, shown in the Firmwares and Logos dialog in Administration. |
3 | (ROLE) | (none) | The role of the slot. Can be one of firmware, logo or other. It is used to display the slot on the correct tab of the firmwares dialog, it can be used as a filter in phoneFirmwares() and moduleFirmwares() but otherwise has no special significance. You could use a logo slot for firmwares if you really wanted to. |
SCRIPT | $FW_IDENT | The name of the script used to preprocess files uploaded to this slot, without path or extensions. Operators tries to run the files firmware/$SCRIPT.sh and firmware/$SCRIPT.php from the module directory, in this order. | |
LONGDESC | (empty) | A long textual description (several lines) of what the user is supposed to upload to the slot. For firmware it's good to directly include download links. Any URL is automatically converted into a clickable hyperlink. The description is displayed in the upload dialog (i.e., when one clicks on Edit on the slot). | |
(custom options) | (none) | You can add any arbitrary name=value options (preferrably named lowercase to avoid clashes with future Operator names). They will be in the preprocessing script (as global variables) and in the $FIRMWARE_TYPES entry for this slot, accessible from the provider. |
Functions marked * are "use only when you know what you are doing" functions.
A provider script can end two ways: successfully and unsuccessfully.
A successful exit means that the module generates a configuration file and sends it to the phone. It can write its output to STDOUT as usual (with echo and friends), however, using one of the provided output functions, escpecially sendTemplate(), is strongly recommended as it allows end users to override the templates with custom configuration modifications.
An unsuccessful exit consists of returning an error status (NotFound, PassNext) to the provisioning engine by calling one of the corresponding functions below. A module that exists unsucessfully MUST NOT write anything to STDOUT (i.e., with echo).
If your script reaches its end or raises an exception, passNext() is called implicitly. In case your module has already written anything to STDOUT, this partial output will get mixed with output of the following modules. Another reason why manual output is discouraged.
Each of these functions returns the corresponding exit status to the provisioning engine and terminates the script.
Each of the following functions sends some output and/or returns some status and terminates the script.
These functions send output but do not terminate the script. Manual output is error-prone. Use only when you have a good reason to!
Open the URL "$scheme://$LAST_IP/$pathAndQuery" (where $LAST_IP is the last known IP of the phone) and return a file handle for reading the contents.
$opts may contain the following options:
Name | Default | Description |
---|---|---|
user | (none) | Username for HTTP authentication. |
password | (none) | Password for HTTP authentication. |
auth | 'auto' | HTTP authentication type: 'basic', 'digest' or 'auto'. It's recommended to set this to the right type instead if auto. In case of basic auth, it will save you one extra request (that would end with 401). In case of digest auth, it will increase security. |
body | (none) | The request body. When present, a POST request is sent instead of the default GET. |
referer | (none) | Set the Referer header. |
verifySSlCert | true | Set to false to disable SSL certificate verification. Almost always needed when using HTTPS. The default is true only for "formal correctness", otherwise useless. |
Uses CURL as backend. Cookies are automagically preserved between requests.
Return a socket connected to the phone using protocol $proto ('tcp' or 'udp') on port $port.
Equivalent to:
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // for tcp $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); // for udp socket_connect($sock, $LAST_IP, $port);
You shouldn't use socket_create or socket_connect in your scripts directly. Always use connectPhone().
Send a SIP NOTIFY request to the phone. This does exactly the same as the SIPNOTIFY built-in resync method. It may be used when you need to compute the SIP NOTIFY options in some more complex way than RESYNC=SIPNOTIFY allows. It may also be used to combine resync methods: e.g. the Kerio's built-in SPA module does resync using both HTTP (urlopenPhone) and SIP NOTIFY (sendSipNotify) as each of these methods has its own unreliabilities.
The individual options availables:
Name | Default | Description |
---|---|---|
auth | 'none' | Whether and how to authenticate the request. Allowed values: 'none', 'auto', 'basic' and 'digest'. Setting a specific type is preferred to 'auto' for the same reasons as outlined in urlopenPhone(). |
username | $LAST_CONFIG ['LINES'][0] ['SIP_USERNAME'] | The To: username used in the resync request. |
authUser | (same as username) | The authentication username for the resync request. |
password | $LAST_CONFIG ['LINES'][0] ['SIP_PASSWORD'] | The password used to authenticate the resync request. |
event | 'check-sync' | The Event: header. |
arg | (none) | Additional arguments for the event. They will be appended after the event name separated by a semicolon. E.g. when arg is 'reboot=true', the request will contain: Event: check-sync;reboot=true |
addHeaders | array() | Additional headers as a list of array($name, $value) pairs. |
body | '' | The request body. Usually empty. |
port | 5060 | Port to send the packets to. |
callId | (random) | The Call-Id for the request. Some phones may require setting it to getRegCallId(0). Most don't. Don't touch unless you need to. |
cseq | 1 | You probably shouldn't change this either. |
The resulting packet will look like this:
NOTIFY sip:{$username}@{$LAST_IP} SIP/2.0" Via: SIP/2.0/UDP {$OPERATOR_IP}:{/*source port*/};branch=1 From: <sip:admin@{$OPERATOR_IP}> To: <sip:{$username}@{$LAST_IP}> Event: {$event}{$arg ? "; $arg" : ""} Call-ID: {$callId} CSeq: {$cseq} NOTIFY Contact: <sip:admin@{$OPERATOR_IP}> [Authorization: ...] Content-Length: {strlen($body)} {$body}