lemonldap-ng/doc/sources/admin/customfunctions.rst

93 lines
1.8 KiB
ReStructuredText
Raw Normal View History

2020-05-14 23:29:41 +02:00
Custom functions
================
Custom functions allow one to extend LL::NG, they can be used in
2020-05-18 09:56:39 +02:00
:ref:`headers`,
:ref:`rules` or
2020-05-14 23:29:41 +02:00
:doc:`form replay data<formreplay>`. Two actions are needed:
- declare them in LLNG configuration
- load the relevant code
Implementation
--------------
2021-11-26 21:09:59 +01:00
Your perl custom functions must be declared on appropriate server when
separating:
2020-05-14 23:29:41 +02:00
2021-11-26 21:09:59 +01:00
**Portal type**: declare custom functions here when using it in rules,
macros or menu.
2020-05-14 23:29:41 +02:00
2021-11-26 21:09:59 +01:00
**Reverse-proxy type**: declare custom functions here when using it in
headers.
2020-05-14 23:29:41 +02:00
Write custom functions library
------------------------------
Create your Perl module with custom functions. You can name your module
as you want, for example ``SSOExtensions.pm``:
::
vi /path/to/SSOExtensions.pm
2020-05-21 15:13:24 +02:00
.. code-block:: perl
2020-05-14 23:29:41 +02:00
package SSOExtensions;
sub function1 {
my (@args) = @_;
# Your nice code here
return $result;
}
sub function2 {
return $_[0];
}
1;
Import custom functions in LemonLDAP::NG
----------------------------------------
LemonLDAP::NG Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-05-14 23:29:41 +02:00
Edit ``lemonldap-ng.ini`` to load the Perl module(s)
2020-05-14 23:29:41 +02:00
::
[all]
require = /path/to/SSOExtensions.pm
2020-05-14 23:29:41 +02:00
; Prevent Portal to crash if Perl module is not found
;requireDontDie = 1
Declare custom functions
~~~~~~~~~~~~~~~~~~~~~~~~
Go in Manager, ``General Parameters`` » ``Advanced Parameters`` »
``Custom functions`` and declare your function names, separated by a space:
2020-05-14 23:29:41 +02:00
::
SSOExtensions::function1 SSOExtensions::function2
2020-05-14 23:29:41 +02:00
2020-05-21 15:13:24 +02:00
.. attention::
2020-05-14 23:29:41 +02:00
If your function is not compliant with
:doc:`Safe jail<safejail>`, you will need to disable the jail.
Usage
-----
2020-05-14 23:29:41 +02:00
You can now use your function in a macro, an header or an access rule,
for example:
::
function1( $uid, $ENV{REMOTE_ADDR} )
2020-05-14 23:29:41 +02:00