Hook system specification for phpldapadmin Benjamin Drieu
Benjamin.Drieu@fr.alcove.com
Version 1.0 This document describes the hook system developed for phpldapadmin. 2005Alcôve
Implementation
run_hook
Synopsis run_hook hook_name, args, hook_name name of hook to run. args Array of optional arguments set by phpldapadmin. It is normally in a form known by call_user_func_array() : [ 'server_id' => 0, 'dn' => 'uid=epoussa,ou=tech,o=corp,o=fr' ]
Usage Runs procedures attached to a hook. This is normally called from the phpldapadmin code. But user can define hooks in her code if needed. The mechanism is quite simple : hooks are added via the add_hook() function, using a numeric priority to sort order or invocation. The run_hook() function will run them sequentially from the lowest priority to the highest priotiry untill a procedure returns a non true value. In that case, rollbacks procedures that are defined together with procedures are executed in reverse order. Rollbacks are mainly used to keep consistency and achieve failsafe systems. Example of invocation of run_hook. Phpldapadamin runs a hook that contains three procedures, a, b, c and d of priority 0, 10, 20 and 30. Procedure a is executed first and after that, b is executed if no error occurs. If b does not returns an error, c is executed. Now, let imagine that c returns false. In that case, c's rollback is executed, then b's rollback and finally a's rollback.
add_hook
Synopsis add_hook hook_name, priority, hook_function, rollback_function, hook_name name of hook to add a procedure to. priority Numeric priority. Lowest means procedure will be executed before. hook_function Name of the php procedure called upon hook trigger. Procedure will called via the call_user_func_array() php function with pre-set arguments that depends on hook type. rollback_function Name of the php procedure called upon hook trigger when a procedure failed. Procedure will called via the call_user_func_array() php function with pre-set arguments that depends on hook type.
Usage Pushes a procedure in the procedure lists of a hook for later execution.
remove_hook
Synopsis remove_hook hook_name, priority, hook_function, rollback_function, hook_name name of hook to remove procedures from. priority Numeric priority. If set, all procedures of that priority will be removed. hook_function Name of the php procedure called upon hook trigger. If set, all procedures that call this function will be removed. rollback_function Name of the php rollback function called upon failure. If set, all procedures that call this function as a rollback will be removed.
Usage Removes a procedure from a hook, based on a filter. All arguments passed after hook_name are optional and can be omited. If specified, they are used to as a filter: if a procedure for this hook matches at lease one of these parameters, it will be removed.
clear_hooks
Synopsis clear_hook hook_name hook_name name of hook to clear.
Usage Remove all procedures from a hook. If this hook is called after a call to clear_hook, no procedures will be called.
Hooks reference
post_attr_modify
Synopsis post_attr_modify server_id, dn, attr_name, new_val, server_id numeric id of the LDAP server. dn DN of modified entry. attr_name name of attribute modified. new_val value that has been set by user, normally a string.
Usage This hook is triggered for every attribute changed by phpldapadmin after by user interaction. Function return value is not used by phpldapadmin since this hooks comes AFTER attribute has been modified. Thought, return value may trigger rollbacks.
post_display_update_array
Synopsis post_display_update_array server_id, dn, server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ] index reference to position of entry in update table.
Usage This hook is triggered by phpldapadmin after user has modified attributes in the editing form and before she commits changes in the confirmation form. This hooks is run after an update array of changes is build and its content is displayed into the commit form. As a reference of this update array is passed to this hook, it is possible to add, remove or change entries from it, thus allowing some manual tweaking before data is passed to phpldapadmin. An additional reference to a the number of rows already displayed is passed, allowing hook to change its behaviour, like displaying different color for odd or even rows.
post_entry_create
Synopsis post_entry_create server_id, dn, attrs, server_id numeric id of the LDAP server. dn DN of modified entry. attrs an array containing all attributes of created entry, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000', ... ]
Usage This hook is triggered after an entry has been created. Its return value is not used by phpldapadmin but it can still trigger rollbacks.
post_entry_delete
Synopsis post_entry_delete server_id, dn, server_id numeric id of the LDAP server. dn DN of deleted entry.
Usage This hook is triggered after an entry has been deleted.
post_rename_entry
Synopsis post_rename_entry server_id, new_dn, old_dn, server_id numeric id of the LDAP server. old_dn Previous DN of modified entry. new_dn New DN of modified entry.
Usage This hook is triggered by phpldapadmin after an entry has been renamed. Both dn variables are string representation of old DN.
post_session_init
Synopsis post_session_init
Usage This hook is triggered just after an user has connected.
post_update
Synopsis post_update server_id, dn, update_array, server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ]
Usage This hook is triggered after an entry has been modified. It is run after all post_attr_modify hook.
post_update_array_processing
Synopsis post_update_array_processing server_id, dn, update_array, server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ]
Usage This hook is triggered by phpldapadmin after user has modified attributes in the editing form and before she commits changes in the confirmation form. This hooks is run BEFORE an update array of changes is build and its content is displayed into the commit form. As a reference of this update array is passed to this hook, it is possible to add, remove or change entries from it, thus allowing some manual tweaking before data is displayed in commit confirmation form.
pre_attr_add
Synopsis pre_attr_add server_id, dn, attr_name, new_value server_id numeric id of the LDAP server. dn DN of modified entry. attr_name name of modified attribute./para> new_value new value for attribute.
Usage This hook is triggered before an attribute is changed. If it returns something else than true, attribute change fails and nothing is changed for this attribute and phpldapadmin adds this attribute to the failed_attrs parameter. This parameter can be used later by modification templates to display attributes that failed.
pre_attr_modify
Synopsis pre_attr_modify server_id, dn, attr_name, new_val, server_id numeric id of the LDAP server. dn DN of modified entry. attr_name name of attribute modified. new_val value that has been set by user, normally a string.
Usage This hook is triggered for every attribute changed by phpldapadmin after by user interaction BEFORE it is changed. If this hook returns a value different from true, attribute is not changed and it is added to a failed_attr array that can be later processed by other hooks or by forms. Rollback can be triggered too.
pre_connect
Synopsis pre_connect server_id, anonymous, use_cache, server_id numeric id of the LDAP server. anonymous true if connection is anonymous. use_cache true if connection is cached and is not closed is reused.
Usage This hook is triggered by phpldapadmin every time it needs to make a connection to a LDAP server using pla_ldap_connect function.
pre_display_update_array
Synopsis pre_display_update_array server_id, dn, update_array, server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ]
Usage This hook is triggered by phpldapadmin after user has modified attributes in the editing form and before she commits changes in the confirmation form. This hooks is run after an update array of changes is build and BEFORE its content is displayed into the commit form. As a reference of this update array is passed to this hook, it is possible to add, remove or change entries from it, thus allowing some manual tweaking before data is displayed in commit confirmation form.
pre_entry_create
Synopsis pre_entry_create server_id, dn, attrs server_id numeric id of the LDAP server. dn DN of modified entry. attrs an array containing all attributes of requested entry, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000', ... ]
Usage This hook is triggered BEFORE an entry is created. Its return value determines whether phpldapadmin will create entry or not. If not true, entry will not be created and rollbacks will be triggered.
pre_entry_delete
Synopsis pre_entry_delete server_id, dn, server_id numeric id of the LDAP server. dn DN of modified entry.
Usage This hook is triggered BEFORE an entry is deleted. If it returns a false value, entry will not be deleted and an error will be displayed.
pre_rename_entry
Synopsis pre_rename_entry server_id, dn, server_id numeric id of the LDAP server. old_dn Previous DN of modified entry. new_dn New DN of modified entry.
Usage This hook is triggered by phpldapadmin BEFORE an entry is renamed. Both dn variables are string representation of old and new DN. If this hook returns a false value, entry is not renamed.
pre_update
Synopsis pre_update server_id, dn, update_array server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ]
Usage This hook is triggered by phpldapadmin BEFORE an entry is updated. Also, it is run before any pre_attr_modify hook is triggered.
pre_update_array_processing
Synopsis pre_update_array_processing server_id, dn, update_array server_id numeric id of the LDAP server. dn DN of modified entry. update_array reference to an array containing all entries that are to be modified, in the form: [ 'cn' => 'El Poussah Haroun', 'description' => 'Calife', 'diskQuota' => '10000' ]
Usage This hook is triggered by phpldapadmin after user has modified attributes in the editing form and before she commits changes in the confirmation form. This hooks is run BEFORE an update array of changes is build and its content is displayed into the commit form. As a reference of this update array is passed to this hook, it is possible to add, remove or change entries from it, thus allowing some manual tweaking before data is displayed in commit confirmation form.