templates/3rdParty/pla/lib/functions.php

Properties

Description

A collection of common generic functions used throughout the application.

Functions

__autoload(   $className, ) : n/a

Description

Loads class definition

Arguments

Name Type Description Default
$className n/a

Return value

Type Description
n/a n/a

array_stripslashes(   $array, ) : n/a

Description

Strips all slashes from the specified array in place (pass by ref).

Arguments

Name Type Description Default
$array n/a

Return value

Type Description
n/a n/a

_(   $msg, ) : n/a

Arguments

Name Type Description Default
$msg n/a

Return value

Type Description
n/a n/a

app_error_handler(   $errno,   $errstr,   $file,   $lineno, ) : n/a

Description

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.

Arguments

Name Type Description Default
$errno n/a
$errstr n/a
$file n/a
$lineno n/a

Return value

Type Description
n/a n/a

Tags

Name Description
see

app_name( ) : n/a

Description

Returns the application name.

Return value

Type Description
n/a n/a

app_version( ) : string

Description

Returns the application version currently running. The version is read from the file named VERSION.

Return value

Type Description
string The current version as read from the VERSION file.

auto_lang(   $lang, ) : n/a

Description

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.

Arguments

Name Type Description Default
$lang n/a

Return value

Type Description
n/a n/a

check_config(   $config_file, ) : n/a

Description

Makes sure that the config file is properly setup.

Arguments

Name Type Description Default
$config_file n/a

Return value

Type Description
n/a n/a

cmd_control_pane(   $type, ) : array

Description

Commands available in the control_panel of the page

Arguments

Name Type Description Default
$type n/a

Return value

Type Description
array

debug_dump(   $variable,   $die = false,   $onlydebugaddr = false, ) : n/a

Description

This function dumps the $variable for debugging purposes

Arguments

Name Type Description Default
$variable n/a
$die n/a false
$onlydebugaddr n/a false

Return value

Type Description
n/a n/a

debug_dump_backtrace(   $msg = 'Calling BackTrace',   $die = false, ) : n/a

Description

This function generates a backtrace

Arguments

Name Type Description Default
$msg n/a 'Calling BackTrace'
$die n/a false

Return value

Type Description
n/a n/a

debug_sysmsg(   $msg, ) : n/a

Description

Send a debug as a sys message

Arguments

Name Type Description Default
$msg n/a

Return value

Type Description
n/a n/a

debug_log(   $msg,   $level,   $indent, ) : n/a

Description

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

Arguments

Name Type Description Default
$msg n/a
$level n/a
$indent n/a

Return value

Type Description
n/a n/a

Tags

Name Description
see

error(   $msg,   $type = 'note',   $redirect = null,   $fatal = false,   $backtrace = false, ) : n/a

Description

Display an error message in the system message panel of the page.

Arguments

Name Type Description Default
$msg n/a
$type n/a 'note'
$redirect n/a null
$fatal n/a false
$backtrace n/a false

Return value

Type Description
n/a n/a

get_request(   $attr,   $type = 'POST',   $die = false,   $default = null, ) : \The

Description

Return the result of a form variable, with optional default

Arguments

Name Type Description Default
$attr n/a
$type n/a 'POST'
$die n/a false
$default n/a null

Return value

Type Description
\The form GET/REQUEST/SESSION/POST variable value or its default

system_message(   $msg,   $redirect = null, ) : n/a

Description

Record a system message.
This function can be used as an alternative to generate a system message, if page hasnt yet been defined.

Arguments

Name Type Description Default
$msg n/a
$redirect n/a null

Return value

Type Description
n/a n/a

blowfish_encrypt(   $data,   $secret = null, ) : string

Description

Encryption using blowfish algorithm

Arguments

Name Type Description Default
$data n/a
$secret n/a null

Return value

Type Description
string The encrypted result

Tags

Name Description
author lem9 (taken from the phpMyAdmin source)

blowfish_decrypt(   $encdata,   $secret = null, ) : string

Description

Decryption using blowfish algorithm

Arguments

Name Type Description Default
$encdata n/a
$secret n/a null

Return value

Type Description
string Original data

Tags

Name Description
author lem9 (taken from the phpMyAdmin source)

full_str_pad(   $input,   $pad_length,   $pad_string = '',   $pad_type = 0, ) : string

Description

String padding

Arguments

Name Type Description Default
$input n/a
$pad_length n/a
$pad_string n/a ''
$pad_type n/a 0

Return value

Type Description
string The padded string

get_cached_item(   $index,   $item,   $subitem = 'null', ) : \Returns

Description

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).

Arguments

Name Type Description Default
$index n/a
$item n/a
$subitem n/a 'null'

Return value

Type Description
\Returns the cached attributed requested, or null if there is nothing cached..

set_cached_item(   $index,   $item,   $subitem = 'null',   $data, ) : n/a

Description

Caches the specified $item for the specified $index.
Returns true on success of false on failure.

Arguments

Name Type Description Default
$index n/a
$item n/a
$subitem n/a 'null'
$data n/a

Return value

Type Description
n/a n/a

del_cached_item(   $index,   $item,   $subitem = 'null', ) : n/a

Description

Deletes the cache for a specified $item for the specified $index

Arguments

Name Type Description Default
$index n/a
$item n/a
$subitem n/a 'null'

Return value

Type Description
n/a n/a

set_cookie(   $name,   $val,   $expire = null,   $dir = null, ) : boolean

Description

Utility wrapper for setting cookies, which takes into consideration application configuration values. On success, true is returned. On failure, false is returned.

Arguments

Name Type Description Default
$name n/a
$val n/a
$expire n/a null
$dir n/a null

Return value

Type Description
boolean

get_custom_file(   $index,   $filename,   $path, ) : string

Description

Get a customized file for a server We don't need any caching, because it's done by PHP

Arguments

Name Type Description Default
$index n/a
$filename n/a
$path n/a

Return value

Type Description
string The customized filename, if exists, or the standard one

masort(   $data,   $sortby,   $rev = 0, ) : array

Description

Sort a multi dimensional array.

Arguments

Name Type Description Default
$data n/a
$sortby n/a
$rev n/a 0

Return value

Type Description
array Sorted multi demension array.

isCompress( ) : n/a

Description

Is compression enabled for output

Return value

Type Description
n/a n/a

obfuscate_password_display(   $enc = null, ) : boolean

Description

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;

Arguments

Name Type Description Default
$enc n/a null

Return value

Type Description
boolean

pretty_print_dn(   $dn, ) : string

Description

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.

Arguments

Name Type Description Default
$dn n/a

Return value

Type Description
string

is_dn_string(   $str, ) : boolean

Description

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)

Arguments

Name Type Description Default
$str n/a

Return value

Type Description
boolean

is_mail_string(   $str, ) : boolean

Description

Get whether a string looks like an email address (user@example.com).

Arguments

Name Type Description Default
$str n/a

Return value

Type Description
boolean Returns true if the specified string looks like an email address or false otherwise.

is_url_string(   $str, ) : boolean

Description

Get whether a string looks like a web URL (http://www.example.com/)

Arguments

Name Type Description Default
$str n/a

Return value

Type Description
boolean Returns true if the specified string looks like a web URL or false otherwise.

pla_compare_dns(   $dn1,   $dn2, ) : int

Description

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

Arguments

Name Type Description Default
$dn1 n/a
$dn2 n/a

Return value

Type Description
int

get_next_number(   $base,   $attr,   $increment = false,   $filter = false,   $startmin = null, ) : int

Description

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.

Arguments

Name Type Description Default
$base n/a
$attr n/a
$increment n/a false
$filter n/a false
$startmin n/a null

Return value

Type Description
int

get_icon(   $server_id,   $dn,   $object_classes = array(), ) : string

Description

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.

Arguments

Name Type Description Default
$server_id n/a
$dn n/a
$object_classes n/a array()

Return value

Type Description
string

expand_dn_with_base(   $base,   $sub_dn, ) : string|null

Description

Appends a servers base to a "sub" dn or returns the base.

Arguments

Name Type Description Default
$base n/a
$sub_dn n/a

Return value

Type Description
string|null Returns null if both base is null and sub_dn is null or empty

random_salt(   $length, ) : string

Description

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.

Arguments

Name Type Description Default
$length n/a

Return value

Type Description
string The generated salt string.

get_rdn(   $dn,   $include_attrs = 0,   $decode = false, ) : string

Description

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()).

Arguments

Name Type Description Default
$dn n/a
$include_attrs n/a 0
$decode n/a false

Return value

Type Description
string The RDN

rdn_explode(   $rdn, ) : n/a

Description

Split an RDN into its attributes

Arguments

Name Type Description Default
$rdn n/a

Return value

Type Description
n/a n/a

pla_verbose_error(   $key, ) : array

Description

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." )

Arguments

Name Type Description Default
$key n/a

Return value

Type Description
array An associative array contianing the error title and description like so:

support_oid_to_text(   $key, ) : array

Description

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 ( [title] => All Operational Attribute [ref] => RFC 3673 [desc] => An LDAP extension which clients may use to request the return of all operational attributes. )

Arguments

Name Type Description Default
$key n/a

Return value

Type Description
array An associative array contianing the OID title and description like so:

ldap_error_msg(   $msg,   $errnum, ) : n/a

Description

Print an LDAP error message

Arguments

Name Type Description Default
$msg n/a
$errnum n/a

Return value

Type Description
n/a n/a

draw_jpeg_photo(   $server,   $dn,   $attr_name = 'jpegphoto',   $index,   $draw_delete_buttons = false,   $options = array(), ) : n/a

Description

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")); draw_jpeg_photo(1,'cn=Fred,ou=People,dc=example,dc=com',null,1);

Arguments

Name Type Description Default
$server n/a
$dn n/a
$attr_name n/a 'jpegphoto'
$index n/a
$draw_delete_buttons n/a false
$options n/a array()

Return value

Type Description
n/a n/a

password_types( ) : n/a

Description

Return the list of available password types

Return value

Type Description
n/a n/a

Tags

Name Description
todo Dynamically work this list out so we only present hashes that we can encrypt

pla_password_hash(   $password_clear,   $enc_type, ) : string

Description

Hashes a password and returns the hash based on the specified enc_type.

Arguments

Name Type Description Default
$password_clear n/a
$enc_type n/a

Return value

Type Description
string The hashed password.

password_check(   $cryptedpassword,   $plainpassword,   $attribute = 'userpassword', ) : Boolean

Description

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".

Arguments

Name Type Description Default
$cryptedpassword n/a
$plainpassword n/a
$attribute n/a 'userpassword'

Return value

Type Description
Boolean True if the clear password matches the hash, and false otherwise.

get_enc_type(   $user_password, ) : string

Description

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.

Arguments

Name Type Description Default
$user_password n/a

Return value

Type Description
string

draw_chooser_link(   $form,   $element,   $include_choose_text = true,   $rdn = 'none', ) : n/a

Description

Draws an HTML browse button which, when clicked, pops up a DN chooser dialog.

Arguments

Name Type Description Default
$form n/a
$element n/a
$include_choose_text n/a true
$rdn n/a 'none'

Return value

Type Description
n/a n/a

pla_explode_dn(   $dn,   $with_attributes = 0, ) : array

Description

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 )

Arguments

Name Type Description Default
$dn n/a
$with_attributes n/a 0

Return value

Type Description
array An array of RDN parts of this format:

dn_escape(   $dn, ) : n/a

Description

Parse a DN and escape any special characters

Arguments

Name Type Description Default
$dn n/a

Return value

Type Description
n/a n/a

dn_unescape(   $dn, ) : n/a

Description

Parse a DN and unescape any special characters

Arguments

Name Type Description Default
$dn n/a

Return value

Type Description
n/a n/a

convertHexStringToCharCallback( array   $hex, ) : String

Description

Converts a hex encoded string like \12 to the corresponding character.

Arguments

Name Type Description Default
$hex array

preg_replace_callback: matching hex string array

Return value

Type Description
String character

get_href(   $type,   $extra_info = '', ) : string

Description

Fetches the URL for the specified item. This is a convenience function for fetching project HREFs (like bugs)

Arguments

Name Type Description Default
$type n/a
$extra_info n/a ''

Return value

Type Description
string The URL to the requested item.

utime( ) : double

Description

Returns the current time as a double (including micro-seconds).

Return value

Type Description
double The current time in seconds since the beginning of the UNIX epoch (Midnight Jan. 1, 1970)

array_to_query_string(   $array,   $exclude_vars = array(), ) : string

Description

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.

Arguments

Name Type Description Default
$array n/a
$exclude_vars n/a array()

Return value

Type Description
string The string created from the array.

pla_reverse_dn(   $dn, ) : string

Description

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.

Arguments

Name Type Description Default
$dn n/a

Return value

Type Description
string The reversed DN

Tags

Name Description
see
see

sortAttrs(   $a,   $b, ) : n/a

Description

Attribute sorting

Arguments

Name Type Description Default
$a n/a
$b n/a

Return value

Type Description
n/a n/a

arrayLower( array   $array, ) : n/a

Description

Reads an array and returns the array values back in lower case

Arguments

Name Type Description Default
$array array

The array to convert the values to lowercase.

Return value

Type Description
n/a n/a

Tags

Name Description
returns array Array with values converted to lowercase.

draw_formatted_dn(   $server,   $entry, ) : n/a

Description

Gets a DN string using the user-configured tree_display_format string to format it.

Arguments

Name Type Description Default
$server n/a
$entry n/a

Return value

Type Description
n/a n/a

server_select_list(   $selected = null,   $logged_on = false,   $name = 'index',   $isVisible = true,   $js = null, ) : n/a

Description

Server html select list

Arguments

Name Type Description Default
$selected n/a null
$logged_on n/a false
$name n/a 'index'
$isVisible n/a true
$js n/a null

Return value

Type Description
n/a n/a

littleEndian(   $hex, ) : n/a

Description

Converts a little-endian hex-number to one, that 'hexdec' can convert

Arguments

Name Type Description Default
$hex n/a

Return value

Type Description
n/a n/a

binSIDtoText(   $binsid, ) : n/a

Arguments

Name Type Description Default
$binsid n/a

Return value

Type Description
n/a n/a

return_ldap_hash(   $base,   $filter,   $key,   $attrs,   $sort = true, ) : array

Description

Query LDAP and return a hash.

Arguments

Name Type Description Default
$base n/a
$filter n/a
$key n/a
$attrs n/a
$sort n/a true

Return value

Type Description
array Array of values keyed by $key.

password_generate( ) : n/a

Description

This function returns a string automatically generated based on the criteria defined in the array $criteria in config.php

Return value

Type Description
n/a n/a

a_array_rand(   $input,   $num_req, ) : string

Description

This function returns an array of $num_req values randomly picked from the $input array

Arguments

Name Type Description Default
$input n/a
$num_req n/a

Return value

Type Description
string The padded string

random_junk( ) : n/a

Description

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

Return value

Type Description
n/a n/a

htmlid(   $sid,   $dn, ) : string

Description

Returns a HTML id that can be used in the URL after the #.

Arguments

Name Type Description Default
$sid n/a
$dn n/a

Return value

Type Description
string

isAjaxEnabled( ) : n/a

Description

Is PLA configured for AJAX display

Return value

Type Description
n/a n/a

Constants

  HTDOCDIR = sprintf('%s/', realpath(LIBDIR . '../htdocs/'))




  LANGDIR = sprintf('%s/', realpath(LIBDIR . '../locale/'))




  CONFDIR = sprintf('%s/', realpath(LIBDIR . '../config'))




  QUERYDIR = sprintf('%s/', realpath(LIBDIR . '../queries/'))




  TMPLDIR = sprintf('%s/', realpath(LIBDIR . '../templates/'))




  DOCDIR = sprintf('%s/', realpath(LIBDIR . '../doc/'))




  HOOKSDIR = sprintf('%s/', realpath(LIBDIR . '../hooks/'))




  JSDIR = 'js/'




Documentation was generated by phpDocumentor 2.1.0 .

Namespaces

  • global

    Packages