Procedural File: functions.php
Source Location: /templates/3rdParty/pla/lib/functions.php
Page Details:
A collection of common generic functions used throughout the application.
Tags:
CONFDIR [line 18]
DOCDIR [line 21]
HOOKSDIR [line 22]
HTDOCDIR [line 16]
JSDIR [line 23]
LANGDIR [line 17]
QUERYDIR [line 19]
TMPLDIR [line 20]
app_error_handler [line 122]
void app_error_handler(
int $errno, string $errstr, string $file, int $lineno)
|
|
Custom error handling function. When a PHP error occurs, PHP will call this function rather than printing the typical PHP error string. This provides the application the ability to format an error message so that it looks better. Optionally, it can present a link so that a user can search/submit bugs. This function is not to be called directly. It is exclusively for the use of PHP internally. If this function is called by PHP from within a context where error handling has been disabled (ie, from within a function called with "@" prepended), then this function does nothing.
Tags:
Parameters
int |
$errno |
The PHP error number that occurred (ie, E_ERROR, E_WARNING, E_PARSE, etc). |
string |
$errstr |
The PHP error string provided (ie, "Warning index "foo" is undefined) |
string |
$file |
The file in which the PHP error ocurred. |
int |
$lineno |
The line number on which the PHP error ocurred |
app_name [line 167]
Returns the application name.
app_version [line 177]
Returns the application version currently running. The version is read from the file named VERSION.
Tags:
arrayLower [line 2548]
array arrayLower(
array $array)
|
|
Reads an array and returns the array values back in lower case
Tags:
Parameters
array |
$array |
The array to convert the values to lowercase. |
array_stripslashes [line 74]
void array_stripslashes(
Array &$array)
|
|
Strips all slashes from the specified array in place (pass by ref).
Parameters
Array |
&$array |
The array to strip slashes from, typically one of $_GET, $_POST, or $_COOKIE. |
array_to_query_string [line 2478]
string array_to_query_string(
array $array, [array $exclude_vars = array()])
|
|
Converts an array to a query-string with the option to exclude certain variables from the returned query string. This is convenient if callers want to convert the current GET query string or POST array into a string and replace certain variables with their own.
Tags:
Parameters
array |
$array |
The associate array to convert whose form is such that the keys are the names of the variables and the values are said variables' values like this: Array (
[server_id] = 0,
[dn] = "dc=example,dc=com",
[attr] = "sn"
)
This will produce a string like this: "server_id=0&dn=dc=example,dc=com&attr=sn" |
array |
$exclude_vars |
(optional) An array of variables to exclude in the resulting string |
auto_lang [line 186]
This function will convert the browser two character language into the default 5 character language, where the country portion should NOT be assumed to be upper case characters of the first two characters.
Parameters
a_array_rand [line 2835]
string a_array_rand(
array $input, integer $num_req)
|
|
This function returns an array of $num_req values randomly picked from the $input array
Tags:
Parameters
array |
$input |
Array of values |
integer |
$num_req |
Number of values in returned array |
binSIDtoText [line 2673]
void binSIDtoText(
$binsid)
|
|
Parameters
blowfish_decrypt [line 710]
string blowfish_decrypt(
string $encdata, [string $secret = null])
|
|
Decryption using blowfish algorithm
Tags:
Parameters
string |
$encdata |
Encrypted data |
string |
$secret |
The secret |
blowfish_encrypt [line 661]
string blowfish_encrypt(
string $data, [string $secret = null])
|
|
Encryption using blowfish algorithm
Tags:
Parameters
string |
$data |
Original data |
string |
$secret |
The secret |
check_config [line 197]
void check_config(
$config_file)
|
|
Makes sure that the config file is properly setup.
Parameters
cmd_control_pane [line 286]
array cmd_control_pane(
$type)
|
|
Commands available in the control_panel of the page
Parameters
debug_dump [line 359]
void debug_dump(
string|array $variable, [boolean $die = false], [ $onlydebugaddr = false])
|
|
This function dumps the $variable for debugging purposes
Parameters
string|array |
$variable |
Variable to dump |
boolean |
$die |
Whether to stop execution or not. |
|
$onlydebugaddr |
|
debug_dump_backtrace [line 368]
void debug_dump_backtrace(
[boolean $msg = 'Calling BackTrace'], [ $die = false])
|
|
This function generates a backtrace
Parameters
boolean |
$msg |
Whether to stop execution or not. |
|
$die |
|
debug_log [line 410]
void debug_log(
string $msg, int $level, $indent)
|
|
Debug Logging The global debug level is turned on in your configuration file by setting: $config->custom->debug['level'] = 255;
together with atleast one output direction (currently file and syslog are supported). $config->custom->debug['file'] = '/tmp/app_debug.log';
$config->custom->debug['syslog'] = true;
The debug level is turned into binary, then if the message levels bit is on the message will be sent to the debug log. (Thus setting your debug level to 255, all bits on, will results in all messages being printed.) The message level bits are defined here. 0( 1) = Entry/Return results from function calls. 1( 2) = Configuration Processing 2( 4) = Template Processing 3( 8) = Schema Processing 4( 16) = LDAP Server Communication 5( 32) = Tree Processing 7( 64) = Other non generic messages 8(128) = Page Processing 9(256) = Hooks Processing
Tags:
Parameters
string |
$msg |
Message to send to syslog |
int |
$level |
Log bit number for this message. |
|
$indent |
|
debug_sysmsg [line 375]
Send a debug as a sys message
Parameters
del_cached_item [line 841]
void del_cached_item(
$index, $item, [ $subitem = 'null'])
|
|
Deletes the cache for a specified $item for the specified $index
Parameters
dn_escape [line 2364]
Parse a DN and escape any special characters
Parameters
dn_unescape [line 2385]
Parse a DN and unescape any special characters
Parameters
draw_chooser_link [line 2285]
void draw_chooser_link(
string $form, boolean $element, [ $include_choose_text = true], [ $rdn = 'none'])
|
|
Draws an HTML browse button which, when clicked, pops up a DN chooser dialog.
Parameters
string |
$form |
The name of the form element to which this chooser dialog will publish the user's choice. The form element must be a member of a form with the "name" or "id" attribute set in the form tag, and the element must also define "name" or "id" for JavaScript to uniquely identify it. Example $form_element values may include "creation_form.container" or "edit_form.member_uid". See /templates/modification/default.php for example usage. |
boolean |
$element |
(optional) If true, the function draws the localized text "choose" to the right of the button. |
|
$include_choose_text |
|
|
$rdn |
|
draw_formatted_dn [line 2565]
void draw_formatted_dn(
$server, $entry)
|
|
Gets a DN string using the user-configured tree_display_format string to format it.
Parameters
draw_jpeg_photo [line 1927]
void draw_jpeg_photo(
object The $server, string $dn, [string $attr_name = 'jpegphoto'], int $index, [boolean $draw_delete_buttons = false], [array $options = array()])
|
|
Draw the jpegPhoto image(s) for an entry wrapped in HTML. Many options are available to specify how the images are to be displayed. Usage Examples: draw_jpeg_photo(0,'cn=Bob,ou=People,dc=example,dc=com',"jpegPhoto",0,true,array('img_opts'=> "border: 1px; width: 150px"));
Parameters
object The |
$server |
Server to get the image from. |
string |
$dn |
The DN of the entry that contains the jpeg attribute you want to draw. |
string |
$attr_name |
The name of the attribute containing the jpeg data (usually 'jpegPhoto'). |
int |
$index |
Index of the attribute to draw |
boolean |
$draw_delete_buttons |
If true, draws a button beneath the image titled 'Delete' allowing the user to delete the jpeg attribute by calling JavaScript function deleteAttribute() provided in the default modification template. |
array |
$options |
Specifies optional image and CSS style attributes for the table tag. Supported keys are fixed_width, fixed_height, img_opts. |
error [line 498]
void error(
$msg, [ $type = 'note'], [ $redirect = null], [ $fatal = false], [ $backtrace = false])
|
|
Display an error message in the system message panel of the page.
Parameters
|
$msg |
|
|
$type |
|
|
$redirect |
|
|
$fatal |
|
|
$backtrace |
|
expand_dn_with_base [line 1673]
string|null expand_dn_with_base(
string $base, string $sub_dn)
|
|
Appends a servers base to a "sub" dn or returns the base.
Tags:
Parameters
string |
$base |
The baseDN to be added if the DN is relative |
string |
$sub_dn |
The DN to be made absolute |
full_str_pad [line 764]
string full_str_pad(
string $input, integer $pad_length, [string $pad_string = ''], [integer $pad_type = 0])
|
|
String padding
Tags:
Parameters
string |
$input |
Input string |
integer |
$pad_length |
Length of the result |
string |
$pad_string |
The filling string |
integer |
$pad_type |
Padding mode |
get_cached_item [line 799]
Returns get_cached_item(
$index, $item, [ $subitem = 'null'])
|
|
Returns the cached array of LDAP resources. Note that internally, this function utilizes a two-layer cache, one in memory using a static variable for multiple calls within the same page load, and one in a session for multiple calls within the same user session (spanning multiple page loads).
Tags:
Parameters
get_custom_file [line 901]
string get_custom_file(
int $index, string $filename, $path)
|
|
Get a customized file for a server We don't need any caching, because it's done by PHP
Tags:
Parameters
int |
$index |
The ID of the server |
string |
$filename |
The requested filename |
|
$path |
|
get_enc_type [line 2246]
string get_enc_type(
string $user_password)
|
|
Detects password encryption type Returns crypto string listed in braces. If it is 'crypt' password, returns crypto detected in password hash. Function should detect md5crypt, blowfish and extended DES crypt. If function fails to detect encryption type, it returns NULL.
Parameters
string |
$user_password |
Hashed password |
get_href [line 2410]
string get_href(
string $type, [ $extra_info = ''])
|
|
Fetches the URL for the specified item. This is a convenience function for fetching project HREFs (like bugs)
Tags:
Parameters
string |
$type |
One of "open_bugs", "add_bug", "donate", or "add_rfe" (rfe = request for enhancement) |
|
$extra_info |
|
get_icon [line 1492]
string get_icon(
string $server_id, $dn, [ $object_classes = array()])
|
|
Given a DN and server ID, this function reads the DN's objectClasses and determines which icon best represents the entry. The results of this query are cached in a session variable so it is not run every time the tree browser changes, just when exposing new DNs that were not displayed previously. That means we can afford a little bit of inefficiency here in favor of coolness. :) This function returns a string like "country.png". All icon files are assumed to be contained in the /images/ directory of phpLDAPadmin. Developers are encouraged to add new icons to the images directory and modify this function as needed to suit their types of LDAP entries. If the modifications are general to an LDAP audience, the phpLDAPadmin team will gladly accept them as a patch.
Parameters
string |
$server_id |
The DN of the entry whose icon you wish to fetch. |
|
$dn |
|
|
$object_classes |
|
get_next_number [line 1300]
int get_next_number(
string $base, string $attr, [boolean $increment = false], [string $filter = false], [ $startmin = null])
|
|
For LDAP servers with auto_number enabled, this function will get the next available number using the host's preferred mechanism (pool or search). This is configured in config.php by server: $servers->setValue('auto_number','enable',true|false);
The available mechanisms are: pool: The pool mechanism uses a user-configured entry in the LDAP server to store the last used "number". This mechanism simply fetches and increments and returns that value. search: The search mechanism will search the LDAP server that has the attribute set. It will then find the smallest value and "fills in the gaps" by incrementing the smallest attribute until an unused value is found. NOTE: Both mechanisms do NOT prevent race conditions or toe-stomping, so care must be taken when actually creating the entry to check that the number returned here has not been used in the mean time. Note that the two different mechanisms may (will!) return different values as they use different algorithms to arrive at their result. Do not be alarmed if (when!) this is the case. See config.php.example for more notes on the two mechanisms.
Parameters
string |
$base |
Base to start the search from |
string |
$attr |
Attribute to query |
boolean |
$increment |
Increment the result (for pool searches) |
string |
$filter |
LDAP filter to use (for pool searches) |
|
$startmin |
|
get_rdn [line 1725]
string get_rdn(
string $dn, [boolean $include_attrs = 0], [ $decode = false])
|
|
Given a DN string, this returns the 'RDN' portion of the string. For example. given 'cn=Manager,dc=example,dc=com', this function returns 'cn=Manager' (it is really the exact opposite of ds_ldap::getContainer()).
Tags:
Parameters
string |
$dn |
The DN whose RDN to return. |
boolean |
$include_attrs |
If true, include attributes in the RDN string. See http://php.net/ldap_explode_dn for details |
|
$decode |
|
get_request [line 573]
The get_request(
$attr, [ $type = 'POST'], [ $die = false], [ $default = null])
|
|
Return the result of a form variable, with optional default
Tags:
Parameters
|
$attr |
|
|
$type |
|
|
$die |
|
|
$default |
|
htmlid [line 2883]
string htmlid(
string $sid, $dn)
|
|
Returns a HTML id that can be used in the URL after the #.
Parameters
string |
$sid |
The DN to pretty-print. |
|
$dn |
|
isAjaxEnabled [line 2890]
Is PLA configured for AJAX display
isCompress [line 1014]
Is compression enabled for output
is_dn_string [line 1103]
boolean is_dn_string(
string $str)
|
|
Given a string, this function returns true if the string has the format of a DN (ie, looks like "cn=Foo,dc=example,dc=com"). Returns false otherwise. The purpose of this function is so that developers can examine a string and know if it looks like a DN, and draw a hyperlink as needed. (See unit_test.php for test cases)
Parameters
string |
$str |
The attribute to examine for "DNness" |
is_mail_string [line 1140]
boolean is_mail_string(
string $str)
|
|
Get whether a string looks like an email address (user@example.com).
Tags:
Parameters
string |
$str |
The string to analyze. |
is_url_string [line 1158]
boolean is_url_string(
string $str)
|
|
Get whether a string looks like a web URL (http://www.example.com/)
Tags:
Parameters
string |
$str |
The string to analyze. |
ldap_error_msg [line 1882]
void ldap_error_msg(
$msg, $errnum)
|
|
Print an LDAP error message
Parameters
littleEndian [line 2661]
Converts a little-endian hex-number to one, that 'hexdec' can convert
Parameters
masort [line 927]
array masort(
array &$data, string $sortby, [boolean $rev = 0])
|
|
Sort a multi dimensional array.
Tags:
Parameters
array |
&$data |
Multi demension array passed by reference |
string |
$sortby |
Comma delimited string of sort keys. |
boolean |
$rev |
Whether to reverse sort. |
obfuscate_password_display [line 1041]
boolean obfuscate_password_display(
[string $enc = null])
|
|
Fetches whether the user has configured phpLDAPadmin to obfuscate passwords with "*********" when displaying them. This is configured in config.php thus: $config->custom->appearance['obfuscate_password_display'] = true;
Or if it is OK to show encrypted passwords but not clear text passwords $config->custom->appearance['show_clear_password'] = false;
Parameters
string |
$enc |
Password encoding type |
password_check [line 2092]
Boolean password_check(
String $cryptedpassword, String $plainpassword, [ $attribute = 'userpassword'])
|
|
Given a clear-text password and a hash, this function determines if the clear-text password is the password that was used to generate the hash. This is handy to verify a user's password when all that is given is the hash and a "guess".
Tags:
Parameters
String |
$cryptedpassword |
The hash. |
String |
$plainpassword |
The password in clear text to test. |
|
$attribute |
|
password_generate [line 2753]
void password_generate(
)
|
|
This function returns a string automatically generated based on the criteria defined in the array $criteria in config.php
password_hash [line 2041]
string password_hash(
string $password_clear, string $enc_type)
|
|
Hashes a password and returns the hash based on the specified enc_type.
Tags:
Parameters
string |
$password_clear |
The password to hash in clear text. |
string |
$enc_type |
Standard LDAP encryption type which must be one of crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear. |
password_types [line 2019]
Return the list of available password types
Tags:
pla_compare_dns [line 1201]
int pla_compare_dns(
string $dn1, string $dn2)
|
|
Compares 2 DNs. If they are equivelant, returns 0, otherwise, returns their sorting order (similar to strcmp()): Returns < 0 if dn1 is less than dn2. Returns > 0 if dn1 is greater than dn2. The comparison is performed starting with the top-most element of the DN. Thus, the following list: ou=people,dc=example,dc=com
cn=Admin,ou=People,dc=example,dc=com
cn=Joe,ou=people,dc=example,dc=com
dc=example,dc=com
cn=Fred,ou=people,dc=example,dc=org
cn=Dave,ou=people,dc=example,dc=org
Will be sorted thus using usort( $list, "pla_compare_dns" ): dc=com
dc=example,dc=com
ou=people,dc=example,dc=com
cn=Admin,ou=People,dc=example,dc=com
cn=Joe,ou=people,dc=example,dc=com
cn=Dave,ou=people,dc=example,dc=org
cn=Fred,ou=people,dc=example,dc=org
Parameters
string |
$dn1 |
The first of two DNs to compare |
string |
$dn2 |
The second of two DNs to compare |
pla_explode_dn [line 2316]
array pla_explode_dn(
string $dn, [int $with_attributes = 0])
|
|
Explode a DN into an array of its RDN parts. NOTE: When a multivalue RDN is passed to ldap_explode_dn, the results returns with 'value + value'; Array (
[0] => uid=ppratt
[1] => ou=People
[2] => dc=example
[3] => dc=com
)
Tags:
Parameters
string |
$dn |
The DN to explode. |
int |
$with_attributes |
(optional) Whether to include attribute names (see http://php.net/ldap_explode_dn for details) |
pla_reverse_dn [line 2525]
string pla_reverse_dn(
string $dn)
|
|
Reverses a DN such that the top-level RDN is first and the bottom-level RDN is last For example: cn=Brigham,ou=People,dc=example,dc=com
Becomes: dc=com,dc=example,ou=People,cn=Brigham
This makes it possible to sort lists of DNs such that they are grouped by container.
Tags:
Parameters
string |
$dn |
The DN to reverse |
pla_verbose_error [line 1783]
array pla_verbose_error(
string $key)
|
|
Given an LDAP error number, returns a verbose description of the error. This function parses ldap_error_codes.txt and looks up the specified ldap error number, and returns the verbose message defined in that file. Array (
[title] => "Invalid Credentials"
[description] => "An invalid username and/or password was supplied to the LDAP server."
)
Tags:
Parameters
string |
$key |
The hex error number (ie, "0x42") of the LDAP error of interest. |
pretty_print_dn [line 1070]
string pretty_print_dn(
string $dn)
|
|
Returns an HTML-beautified version of a DN. Internally, this function makes use of pla_explode_dn() to break the the DN into its components. It then glues them back together with "pretty" HTML. The returned HTML is NOT to be used as a real DN, but simply displayed.
Parameters
string |
$dn |
The DN to pretty-print. |
random_junk [line 2872]
This is for Opera. By putting "random junk" in the query string, it thinks that it does not have a cached version of the page, and will thus fetch the page rather than display the cached version
random_salt [line 1699]
string random_salt(
int $length)
|
|
Used to generate a random salt for crypt-style passwords. Salt strings are used to make pre-built hash cracking dictionaries difficult to use as the hash algorithm uses not only the user's password but also a randomly generated string. The string is stored as the first N characters of the hash for reference of hashing algorithms later.
Tags:
Parameters
int |
$length |
The length of the salt string to generate. |
rdn_explode [line 1747]
Split an RDN into its attributes
Parameters
return_ldap_hash [line 2704]
array return_ldap_hash(
string $base, string $filter, string $key, array $attrs, [boolean $sort = true])
|
|
Query LDAP and return a hash.
Tags:
Parameters
string |
$base |
The base DN to use. |
string |
$filter |
LDAP Query filter. |
string |
$key |
LDAP attribute to use as key. |
array |
$attrs |
Attributes to use as values. |
boolean |
$sort |
Specify false to not sort results by DN or true to have the returned array sorted by DN (uses ksort) or an array of attribute names to sort by attribute values |
server_select_list [line 2623]
void server_select_list(
[ $selected = null], [ $logged_on = false], [ $name = 'index'], [ $isVisible = true], [ $js = null])
|
|
Server html select list
Parameters
|
$selected |
|
|
$logged_on |
|
|
$name |
|
|
$isVisible |
|
|
$js |
|
set_cached_item [line 821]
void set_cached_item(
$index, $item, [ $subitem = 'null'], $data)
|
|
Caches the specified $item for the specified $index. Returns true on success of false on failure.
Parameters
|
$index |
|
|
$item |
|
|
$subitem |
|
|
$data |
|
set_cookie [line 866]
boolean set_cookie(
string $name, string $val, [int $expire = null], [string $dir = null])
|
|
Utility wrapper for setting cookies, which takes into consideration application configuration values. On success, true is returned. On failure, false is returned.
Parameters
string |
$name |
The name of the cookie to set. |
string |
$val |
The value of the cookie to set. |
int |
$expire |
(optional) The duration in seconds of this cookie. If unspecified, $cookie_time is used from config.php |
string |
$dir |
(optional) The directory value of this cookie (see php.net/setcookie) |
sortAttrs [line 2535]
Attribute sorting
Parameters
support_oid_to_text [line 1835]
array support_oid_to_text(
string $key)
|
|
Given an LDAP OID number, returns a verbose description of the OID. This function parses ldap_supported_oids.txt and looks up the specified OID, and returns the verbose message defined in that file. Array (
[ref] => RFC 3673
[desc] => An LDAP extension which clients may use to request the return of all operational attributes.
)
Tags:
Parameters
string |
$key |
The OID number (ie, "1.3.6.1.4.1.4203.1.5.1") of the OID of interest. |
system_message [line 608]
void system_message(
$msg, [ $redirect = null])
|
|
Record a system message. This function can be used as an alternative to generate a system message, if page hasnt yet been defined.
Parameters
utime [line 2452]
Returns the current time as a double (including micro-seconds).
Tags:
_ [line 96]
If gettext is not available in PHP, then this will provide compatibility for it.
Parameters
__autoload [line 54]
void __autoload(
$className)
|
|
Loads class definition
Parameters
|
|