FusionDirectory
Functions
functions.inc File Reference

Go to the source code of this file.

Functions

 fusiondirectory_autoload ($class_name)
 Does autoloading for classes used in FusionDirectory. More...
 
 class_available ($name)
 Checks if a class is available. More...
 
 plugin_available ($plugin)
 Check if plugin is available. More...
 
 DEBUG ($level, $line, $function, $file, $data, $info='')
 Debug level action. More...
 
 copynotice ()
 Return HTML safe copyright notice.
 
 get_template_path ($filename='', $plugin=FALSE, $path='')
 Return themed path for specified base file. More...
 
 array_remove_entries (array $needles, array $haystack)
 
 array_remove_entries_ics (array $needles, array $haystack)
 
 array_merge_unique (array $ar1, array $ar2)
 
 fusiondirectory_log ($message)
 Generate a system log info. More...
 
get_userinfo ()
 Return the current userinfo object. More...
 
get_smarty ()
 Get global smarty object. More...
 
 convert_department_dn ($dn, $base=NULL)
 Convert a department DN to a sub-directory style list. More...
 
 get_ou ($name)
 Get the OU of a certain RDN. More...
 
 get_people_ou ()
 Get the OU for users. More...
 
 get_base_from_people ($dn)
 Return a base from a given user DN. More...
 
 strict_uid_mode ()
 Check if strict naming rules are configured. More...
 
 to_string ($value)
 Return a string/HTML representation of an array. More...
 
 rewrite ($s)
 Function to rewrite some problematic characters. More...
 
 dn2base ($dn, $ou=NULL)
 Return the base of a given DN. More...
 
 check_command ($cmdline)
 Check if a given command exists and is executable. More...
 
 normalize_netmask ($netmask)
 Put netmask in n.n.n.n format. More...
 
 netmask_to_bits ($netmask)
 Return the number of set bits in the netmask. More...
 
 to_byte ($value)
 Convert various data sizes to bytes. More...
 
 humanReadableSize ($bytes, $precision=2)
 Convert a size in bytes to a human readable version. More...
 
 in_array_ics ($value, array $items)
 Check if a value exists in an array (case-insensitive) More...
 
 validate ($string)
 Removes malicious characters from a (POST) string. More...
 
 rmdirRecursive ($path, $followLinks=FALSE)
 Recursively delete a path in the file system. More...
 
 scan_directory ($path, $sort_desc=FALSE)
 Get directory content information. More...
 
 clean_smarty_compile_dir ($directory)
 Clean the smarty compile dir. More...
 
 create_revision ($revision_file, $revision)
 Create the revision file. More...
 
 compare_revision ($revision_file, $revision)
 Compare the revision file. More...
 
 array_key_ics ($ikey, array $items)
 Lookup a key in an array case-insensitive. More...
 
 array_differs (array $src, array $dst)
 
 array_differs_recursive ($src, $dst)
 
 array_cmp_recursive ($src, $dst)
 
 normalizeLdap ($input)
 Escape all LDAP filter relevant characters. More...
 
 check_schema (array $cfg)
 Check if LDAP schema matches the requirements. More...
 
 get_post ($name)
 Returns contents of the given POST variable and check magic quotes settings. More...
 
 get_correct_class_name ($cls)
 Return class name in correct case.
 
 change_password ($dn, $password, $hash="")
 Change the password of a given DN. More...
 
 getEntryCSN (string $dn)
 Get the Change Sequence Number of a certain DN. More...
 
 send_binary_content ($data, $name, $type="application/octet-stream")
 Initialize a file download with given content, name and data type. More...
 
 xmlentities ($str)
 Encode special string characters. More...
 
 get_random_char ()
 Returns a random char.
 
 cred_decrypt ($input, $password)
 Decrypt a string with RIJNDAEL_128. More...
 
 isIpInNet ($ip, $net, $mask)
 Test if an ip is the network range. More...
 
 expandIPv6 ($ip)
 Expands an IP v6.
 

Detailed Description

Common functions and named definitions.

Definition in file functions.inc.

Function Documentation

◆ array_cmp_recursive()

array_cmp_recursive (   $src,
  $dst 
)

Determine if two arrays are different using recursion for sublevels

Parameters
mixed$srcThe source
mixed$dstThe destination
Returns
int negative, 0 or positive if $src is <, = or > $dst

Definition at line 1099 of file functions.inc.

Referenced by array_differs_recursive().

◆ array_differs()

array_differs ( array  $src,
array  $dst 
)

Determine if two arrays are different

Parameters
array<int|string|bool|null|float|double|object>$src The source
array<int|string|bool|null|float|double|object>$dst The destination
Returns
bool TRUE or FALSE

Definition at line 1066 of file functions.inc.

Referenced by simplePlugin\cleanup().

◆ array_differs_recursive()

array_differs_recursive (   $src,
  $dst 
)

Determine if two arrays are different using recursion for sublevels

Parameters
mixed$srcThe source
mixed$dstThe destination
Returns
bool TRUE or FALSE

Definition at line 1085 of file functions.inc.

References array_cmp_recursive().

◆ array_key_ics()

array_key_ics (   $ikey,
array  $items 
)

Lookup a key in an array case-insensitive.

Given an associative array this can lookup the value of a certain key, regardless of the case.

$items = array ('FOO' => 'blub', 'bar' => 'blub');
array_key_ics('foo', $items); # Returns 'blub'
array_key_ics('BAR', $items); # Returns 'blub'
Parameters
string$ikeyneedle
array$itemshaystack
Returns
return key or empty result

Definition at line 1045 of file functions.inc.

◆ array_merge_unique()

array_merge_unique ( array  $ar1,
array  $ar2 
)

Merge to array but remove duplicate entries (case-insensitive)

Merges two arrays and removes duplicate entries. Triggers an error if first or second parametre is not an array.

Parameters
array<int|string|bool|null|float|double|object>$ar1 first array
array<int|string|bool|null|float|double|object>$ar2 second array
Returns
array<int,int|string|bool|null|float|double|object>

Definition at line 275 of file functions.inc.

Referenced by ObjectClassBooleanAttribute\__construct(), and simplePlugin\mergeObjectClasses().

◆ array_remove_entries()

array_remove_entries ( array  $needles,
array  $haystack 
)

Remove multiple entries from an array

Removes every element that is in $needles from the array given as $haystack

Parameters
array$needlesarray of the entries to remove
array$haystackoriginal array to remove the entries from
Returns
array<int,mixed>

Definition at line 239 of file functions.inc.

Referenced by ObjectClassBooleanAttribute\__construct().

◆ array_remove_entries_ics()

array_remove_entries_ics ( array  $needles,
array  $haystack 
)

Remove multiple entries from an array (case-insensitive)

Removes every element that is in $needles from the array given as $haystack but case insensitive

Parameters
array<int|string|bool|null|float|double|object>$needles array of the entries to remove
array<int|string|bool|null|float|double|object>$haystack original array to remove the entries from
Returns
array<int,int|string|bool|null|float|double|object>

Definition at line 257 of file functions.inc.

Referenced by simplePlugin\remove().

◆ change_password()

change_password (   $dn,
  $password,
  $hash = "" 
)

Change the password of a given DN.

Change the password of a given DN with the specified hash.

Parameters
string$dnthe DN whose password shall be changed
string$passwordthe password
string$hashwhich hash to use to encrypt it, default is empty for reusing existing hash method for this password (or use the default one).
Returns
boolean TRUE on success and an error strings array on failure.

Definition at line 1302 of file functions.inc.

References objects\open().

◆ check_command()

check_command (   $cmdline)

Check if a given command exists and is executable.

Test if a given cmdline contains an executable command. Strips arguments from the given cmdline.

Parameters
string$cmdlinethe cmdline to check
Returns
TRUE if command exists and is executable, otherwise FALSE.

Definition at line 640 of file functions.inc.

◆ check_schema()

check_schema ( array  $cfg)

Check if LDAP schema matches the requirements.

Parameters
string$cfgA config object

Definition at line 1138 of file functions.inc.

References class_available(), and htmlescape().

Referenced by LoginMethod\runSchemaCheck().

◆ class_available()

class_available (   $name)

Checks if a class is available.

Parameters
string$nameThe subject of the test
Returns
boolean Return TRUE if successfull FALSE otherwise

Definition at line 92 of file functions.inc.

Referenced by check_schema(), LDAP\connect(), LDAP\get_objectclasses(), simplePlugin\getAuditAttributesListFromConf(), LoginPost\getLabel(), templateHandling\parseString(), and config\snapshotEnabled().

◆ clean_smarty_compile_dir()

clean_smarty_compile_dir (   $directory)

Clean the smarty compile dir.

Parameters
string$directorysmarty compile dir

Definition at line 905 of file functions.inc.

References compare_revision(), create_revision(), FD_VERSION, htmlescape(), and scan_directory().

◆ compare_revision()

compare_revision (   $revision_file,
  $revision 
)

Compare the revision file.

Create the revision file in FusionDirectory spool dir

Parameters
string$revision_filethe name of the revision file
string$revisionthe version of FusionDirectory
Returns
TRUE if revision match FALSE otherwise

Definition at line 996 of file functions.inc.

Referenced by clean_smarty_compile_dir().

◆ convert_department_dn()

convert_department_dn (   $dn,
  $base = NULL 
)

Convert a department DN to a sub-directory style list.

This function returns a DN in a sub-directory style list. Examples:

  • ou=1.1.1,ou=limux becomes limux/1.1.1
  • cn=bla,ou=foo,dc=local becomes foo/bla or foo/bla/local, depending on the value for $base.

If the specified DN contains a basedn which either matches the specified base or $config->current['BASE'] it is stripped.

Parameters
string$dnthe subject for the conversion
string$basethe base dn, default: $config->current['BASE']
Returns
a string in the form as described above

Definition at line 349 of file functions.inc.

Referenced by config\storeDepartmentList().

◆ create_revision()

create_revision (   $revision_file,
  $revision 
)

Create the revision file.

Create the revision file in FusionDirectory spool dir

Parameters
string$revision_filethe name of the revision file
string$revisionthe version of FusionDirectory
Returns
TRUE if successfully created FALSE otherwise

Definition at line 954 of file functions.inc.

Referenced by clean_smarty_compile_dir().

◆ cred_decrypt()

cred_decrypt (   $input,
  $password 
)

Decrypt a string with RIJNDAEL_128.

Parameters
string$inputThe string to decrypt.
String$passwordThe password used

Definition at line 1431 of file functions.inc.

Referenced by config\get_credentials().

◆ DEBUG()

DEBUG (   $level,
  $line,
  $function,
  $file,
  $data,
  $info = '' 
)

Debug level action.

Print a DEBUG level if specified debug level of the level matches the the configured debug level.

Parameters
int$levelThe log level of the message (should use the constants, defined in functions.in (DEBUG_TRACE, DEBUG_LDAP, etc.)
int$lineDefine the line of the logged action (using LINE is common)
string$functionDefine the function where the logged action happened in (using FUNCTION is common)
string$fileDefine the file where the logged action happend in (using FILE is common)
mixed$dataThe data to log. Can be a message or an array, which is printed with print_a
string$infoOptional: Additional information

Definition at line 141 of file functions.inc.

References logging\debug().

◆ dn2base()

dn2base (   $dn,
  $ou = NULL 
)

Return the base of a given DN.

Parameters
string$dna DN
string$ouan ou to remove from the base
Returns
base of the given DN

Definition at line 614 of file functions.inc.

References get_ou(), and get_people_ou().

Referenced by BaseSelectorAttribute\__construct(), Attribute\check(), and template\reset().

◆ fusiondirectory_autoload()

fusiondirectory_autoload (   $class_name)

Does autoloading for classes used in FusionDirectory.

Takes the list generated by 'fusiondirectory-configuration-manager' and loads the file containing the requested class.

Parameters
array$class_namelist of class name

Definition at line 44 of file functions.inc.

◆ fusiondirectory_log()

fusiondirectory_log (   $message)

Generate a system log info.

Creates a syslog message, containing user information.

Parameters
string$messagethe message to log

Definition at line 288 of file functions.inc.

Referenced by logging\check().

◆ get_base_from_people()

get_base_from_people (   $dn)

Return a base from a given user DN.

get_base_from_people('cn=Max Muster,dc=local')
# Result is 'dc=local'
Parameters
string$dn
Returns
the base from the dn

Definition at line 500 of file functions.inc.

References get_people_ou().

◆ get_ou()

get_ou (   $name)

Get the OU of a certain RDN.

Given a certain RDN name (ogroupRDN, applicationRDN etc.) this function returns either a configured OU or the default for the given RDN.

Example:

# Determine LDAP base where systems are stored
$base = get_ou('systemRDN') . $config->current['BASE'];
$ldap->cd($base);
Parameters
$namethe rdn of the ou you are trying to find
Returns
the ou associated the the RDN or nothing

Definition at line 391 of file functions.inc.

Referenced by Lock\add(), LoginMethod\checkForLockingBranch(), Lock\deleteByObject(), Lock\deleteByUser(), dn2base(), Lock\get(), and get_people_ou().

◆ get_people_ou()

get_people_ou ( )

Get the OU for users.

Function for getting the userRDN

Returns
the ou of the userRDN

Definition at line 484 of file functions.inc.

References get_ou().

Referenced by dn2base(), and get_base_from_people().

◆ get_post()

get_post (   $name)

Returns contents of the given POST variable and check magic quotes settings.

Depending on the magic quotes settings this returns a stripclashed'ed version of a certain POST variable.

Parameters
string$namethe POST var to return ($_POST[$name])
Returns
string

Definition at line 1261 of file functions.inc.

References validate().

◆ get_smarty()

& get_smarty ( )

Get global smarty object.

Returns
return the global smarty object

Definition at line 324 of file functions.inc.

◆ get_template_path()

get_template_path (   $filename = '',
  $plugin = FALSE,
  $path = '' 
)

Return themed path for specified base file.

Depending on its parameters, this function returns the full path of a template file. First match wins while searching in this order:

  • load theme depending file
  • load global theme depending file
  • load default theme file
  • load global default theme file
Parameters
string$filenameThe base file name
boolean$pluginFlag to take the plugin directory as search base
string$pathUser specified path to take as search base
Returns
string Full path to the template file

Definition at line 174 of file functions.inc.

Referenced by pluglist\show_iconmenu().

◆ get_userinfo()

& get_userinfo ( )

◆ getEntryCSN()

getEntryCSN ( string  $dn)

Get the Change Sequence Number of a certain DN.

To verify if a given object has been changed outside of FusionDirectory in the meanwhile, this function can be used to get the entryCSN from the LDAP directory. It uses the attribute as configured in modificationDetectionAttribute

Parameters
string$dnThe dn you want to check
Returns
either the result or "" in any other case

Definition at line 1334 of file functions.inc.

Referenced by simplePlugin\__construct().

◆ humanReadableSize()

humanReadableSize (   $bytes,
  $precision = 2 
)

Convert a size in bytes to a human readable version.

Parameters
float$bytessize in bytes
int$precisionnumber of digits after comma, default is 2
Returns
Returns something like '9.77KiB' for arguments (10000, 2)

Definition at line 780 of file functions.inc.

◆ in_array_ics()

in_array_ics (   $value,
array  $items 
)

Check if a value exists in an array (case-insensitive)

This is just as http://php.net/in_array except that the comparison is case-insensitive.

Parameters
string$valueneedle
array$itemshaystack
Returns
Return TRUE is value is found, FALSE if not.

Definition at line 814 of file functions.inc.

Referenced by simplePlugin\__construct(), acl\extractMembers(), managementListing\getBase(), tests\is_email(), and managementListing\refreshBasesList().

◆ isIpInNet()

isIpInNet (   $ip,
  $net,
  $mask 
)

Test if an ip is the network range.

Parameters
string$ipThe ip address to test.
string$netThe network to test
string$maskThe netmask of the network

Definition at line 1465 of file functions.inc.

◆ netmask_to_bits()

netmask_to_bits (   $netmask)

Return the number of set bits in the netmask.

For a given subnetmask (for example 255.255.255.0) this returns the number of set bits.

Example:

$bits = netmask_to_bits('255.255.255.0') # Returns 24
$bits = netmask_to_bits('255.255.254.0') # Returns 23

Be aware of the fact that the function does not check if the given subnet mask is actually valid. For example: Bad examples:

$bits = netmask_to_bits('255.0.0.255') # Returns 16
$bits = netmask_to_bits('255.255.0.255') # Returns 24
Parameters
$netmaskgiven netmask
Returns
the number of bits in the netmask

Definition at line 714 of file functions.inc.

◆ normalize_netmask()

normalize_netmask (   $netmask)

Put netmask in n.n.n.n format.

Parameters
string$netmaskThe netmask
Returns
string Converted netmask

Definition at line 664 of file functions.inc.

◆ normalizeLdap()

normalizeLdap (   $input)

Escape all LDAP filter relevant characters.

Parameters
string$inputstring where we should add \ before special caracters

Definition at line 1127 of file functions.inc.

◆ plugin_available()

plugin_available (   $plugin)

Check if plugin is available.

Checks if a given plugin is available and readable.

Parameters
string$pluginthe subject of the check
Returns
boolean Return TRUE if successfull FALSE otherwise

Definition at line 108 of file functions.inc.

Referenced by simpleTabs\__construct(), simpleTabs\addSpecialTabs(), pluglist\gen_menu(), and pluglist\show_iconmenu().

◆ rewrite()

rewrite (   $s)

Function to rewrite some problematic characters.

This function takes a string and replaces all possibly characters in it with less problematic characters, as defined in $REWRITE.

Parameters
string$sthe string to rewrite
Returns
string $s the result of the rewrite

Definition at line 572 of file functions.inc.

◆ rmdirRecursive()

rmdirRecursive (   $path,
  $followLinks = FALSE 
)

Recursively delete a path in the file system.

Will delete the given path and all its files recursively. Can also follow links if told so.

Parameters
string$path
boolean$followLinksTRUE to follow links, FALSE (default) for not following links

Definition at line 842 of file functions.inc.

◆ scan_directory()

scan_directory (   $path,
  $sort_desc = FALSE 
)

Get directory content information.

Returns the content of a directory as an array in an ascending sorted manner.

Parameters
string$path
boolean$sort_descweither to sort the content descending.
Returns
array content of directory in ascending sorted manner.

Definition at line 869 of file functions.inc.

Referenced by clean_smarty_compile_dir().

◆ send_binary_content()

send_binary_content (   $data,
  $name,
  $type = "application/octet-stream" 
)

Initialize a file download with given content, name and data type.

Parameters
string$dataThe content to send.
string$nameThe name of the file.
string$typeThe content identifier, default value is "application/octet-stream";

Definition at line 1363 of file functions.inc.

◆ strict_uid_mode()

strict_uid_mode ( )

Check if strict naming rules are configured.

Return TRUE or FALSE depending on weither strictNamingRules are configured or not.

Returns
Returns TRUE if strictNamingRules is set to TRUE or if the config object is not available, otherwise FALSE.

Definition at line 526 of file functions.inc.

Referenced by tests\is_uid(), and templateHandling\listFields().

◆ to_byte()

to_byte (   $value)

Convert various data sizes to bytes.

Given a certain value in the format n(g|m|k), where n is a value and (g|m|k) stands for Gigabyte, Megabyte and Kilobyte this function returns the byte value.

Parameters
string$valuea value in the above specified format
Returns
a byte value or the original value if specified string is simply a numeric value

Definition at line 746 of file functions.inc.

◆ to_string()

to_string (   $value)

Return a string/HTML representation of an array.

This returns a string representation of a given value. It can be used to dump arrays, where every value is printed on its own line. The output is targetted at HTML output, it uses '
' for line breaks. If the value is already a string its returned unchanged.

Parameters
mixed$valueWhatever needs to be printed.
Returns
string $value in html form.

Definition at line 549 of file functions.inc.

◆ validate()

validate (   $string)

Removes malicious characters from a (POST) string.

Parameters
string$stringthe string to check for malicious caracters
Returns
string with caracters removed

Definition at line 826 of file functions.inc.

Referenced by get_post(), managementListing\getAction(), and managementListing\updateBase().

◆ xmlentities()

xmlentities (   $str)

Encode special string characters.

Encode the special caracters so we can use the string in HTML output, without breaking quotes.

Parameters
string$strThe String we want to encode.
Returns
string The encoded String

Definition at line 1394 of file functions.inc.