| 1 |
Custom functions |
| 2 |
================ |
| 3 |
|
| 4 |
Custom functions allow one to extend LL::NG, they can be used in |
| 5 |
:ref:`headers`, |
| 6 |
:ref:`rules` or |
| 7 |
:doc:`form replay data<formreplay>`. Two actions are needed: |
| 8 |
|
| 9 |
- declare them in LLNG configuration |
| 10 |
- load the relevant code |
| 11 |
|
| 12 |
Implementation |
| 13 |
-------------- |
| 14 |
|
| 15 |
Your perl custom functions must be declared on appropriate server when |
| 16 |
separating: |
| 17 |
|
| 18 |
**Portal type**: declare custom functions here when using it in rules, |
| 19 |
macros or menu. |
| 20 |
|
| 21 |
**Reverse-proxy type**: declare custom functions here when using it in |
| 22 |
headers. |
| 23 |
|
| 24 |
Write custom functions library |
| 25 |
------------------------------ |
| 26 |
|
| 27 |
Create your Perl module with custom functions. You can name your module |
| 28 |
as you want, for example ``SSOExtensions.pm``: |
| 29 |
|
| 30 |
:: |
| 31 |
|
| 32 |
vi /path/to/SSOExtensions.pm |
| 33 |
|
| 34 |
.. code-block:: perl |
| 35 |
|
| 36 |
package SSOExtensions; |
| 37 |
|
| 38 |
sub function1 { |
| 39 |
my (@args) = @_; |
| 40 |
|
| 41 |
# Your nice code here |
| 42 |
return $result; |
| 43 |
} |
| 44 |
|
| 45 |
sub function2 { |
| 46 |
return $_[0]; |
| 47 |
} |
| 48 |
|
| 49 |
1; |
| 50 |
|
| 51 |
Import custom functions in LemonLDAP::NG |
| 52 |
---------------------------------------- |
| 53 |
|
| 54 |
LemonLDAP::NG Configuration |
| 55 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 56 |
|
| 57 |
Edit ``lemonldap-ng.ini`` to load the Perl module(s) |
| 58 |
|
| 59 |
:: |
| 60 |
|
| 61 |
[all] |
| 62 |
require = /path/to/SSOExtensions.pm |
| 63 |
; Prevent Portal to crash if Perl module is not found |
| 64 |
;requireDontDie = 1 |
| 65 |
|
| 66 |
|
| 67 |
.. tip:: |
| 68 |
|
| 69 |
You can declare multiple custom function files, separated by a , |
| 70 |
|
| 71 |
require = /path/to/SSOExtensions1.pm, /path/to/SSOExtensions2.pm |
| 72 |
|
| 73 |
|
| 74 |
Declare custom functions |
| 75 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 76 |
|
| 77 |
Go in Manager, ``General Parameters`` » ``Advanced Parameters`` » |
| 78 |
``Custom functions`` and declare your function names, separated by a space: |
| 79 |
|
| 80 |
:: |
| 81 |
|
| 82 |
SSOExtensions::function1 SSOExtensions::function2 |
| 83 |
|
| 84 |
|
| 85 |
.. attention:: |
| 86 |
|
| 87 |
If your function is not compliant with |
| 88 |
:doc:`Safe jail<safejail>`, you will need to disable the jail. |
| 89 |
|
| 90 |
Usage |
| 91 |
----- |
| 92 |
|
| 93 |
You can now use your function in a macro, an header or an access rule, |
| 94 |
for example: |
| 95 |
|
| 96 |
:: |
| 97 |
|
| 98 |
function1( $uid, $env->{REMOTE_ADDR} ) |
| 99 |
|