Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
documentation:latest:customfunctions [2016/07/19 12:10]
127.0.0.1 external edit
documentation:latest:customfunctions [2019/05/29 10:07] (current)
Line 1: Line 1:
 ====== Custom functions ====== ====== Custom functions ======
  
-Custom functions allow to extend LL::NG, they can be used in [[writingrulesand_headers#​headers|headers]],​ [[writingrulesand_headers#​rules|rules]] or [[formreplay|form replay data]].+Custom functions allow one to extend LL::NG, they can be used in [[writingrulesand_headers#​headers|headers]],​ [[writingrulesand_headers#​rules|rules]] or [[formreplay|form replay data]]. ​Two actions are needed: 
 +  * declare them in LLNG configuration 
 +  * load the relevant code 
 + 
 +===== Implementation ===== 
 + 
 +Your perl custom function must be declared on appropriate server when separating : 
 + 
 +portal type : declare custom function here when using it in rules, macros, menu 
 + 
 +reverse-proxy type : declare custom function here when using it in headers
  
 ===== Write custom functions library ===== ===== Write custom functions library =====
Line 8: Line 18:
  
 <​code>​ <​code>​
-vi /root/​SSOExtensions.pm+vi /path/to/​SSOExtensions.pm
 </​code>​ </​code>​
  
Line 15: Line 25:
  
 sub function1 { sub function1 {
-  my $url shift; +  my (@args) ​@_;
-  my $param = shift;+
  
   # Your nice code here   # Your nice code here
 +  return $result;
 +}
  
-  ​return $param;+sub function2 { 
 +  ​return $_[0];
 } }
  
 1; 1;
 </​file>​ </​file>​
- 
-<note tip> 
-First parameter passed to the custom function is the requested URL, that is 
-  * **portal full URL** if custom function is run by portal (e.g. https://​auth.example.com/​) 
-  * **absolute URL** if it is run by handler (e.g. /​admin/​index.php?​param=foo). 
-</​note>​ 
  
 ===== Import custom functions in LemonLDAP::​NG ===== ===== Import custom functions in LemonLDAP::​NG =====
  
-==== Declare module ​in handler server ====+==== Load relevant code in handler server ==== 
 + 
 +=== New method === 
 + 
 +Just declare files or Perl module that must be loaded: 
 +<​file:​ini>​ 
 +[all] 
 +require = /​path/​to/​functions.pl,​ /​path/​to/​SSOExtensions.pm 
 +# OR 
 +require = SSOExtensions::​function1,​ SSOExtensions::​function2 
 +</​file>​ 
 + 
 +=== Old method === 
 + 
 +<note warning>​This method is available but unusable by Portal under Apache. So if your rule may be used by the menu, use the new method.</​note>​
  
-=== Apache ​===+== Apache ==
  
 Your module has to be loaded by Apache (for example after Handler load): Your module has to be loaded by Apache (for example after Handler load):
Line 43: Line 63:
 # Perl environment # Perl environment
 PerlRequire Lemonldap::​NG::​Handler PerlRequire Lemonldap::​NG::​Handler
-PerlRequire /root/​SSOExtensions.pm+PerlRequire /path/to/​SSOExtensions.pm
 PerlOptions +GlobalRequest PerlOptions +GlobalRequest
 </​file>​ </​file>​
  
-=== FastCGI server (Nginx) ​===+== FastCGI server (Nginx) ==
  
 You've just to incicate to [[fastcgiserver|LLNG FastCGI server]] the file to read using either ''​-f''​ option or ''​CUSTOM_FUNCTIONS_FILE''​ environment variable. Using packages, you just have to modify your ''/​etc/​default/​llng-fastcgi-server''​ (or ''/​etc/​default/​lemonldap-ng-fastcgi-server''​) file: You've just to incicate to [[fastcgiserver|LLNG FastCGI server]] the file to read using either ''​-f''​ option or ''​CUSTOM_FUNCTIONS_FILE''​ environment variable. Using packages, you just have to modify your ''/​etc/​default/​llng-fastcgi-server''​ (or ''/​etc/​default/​lemonldap-ng-fastcgi-server''​) file:
Line 66: Line 86:
  
 # Custom functions file # Custom functions file
-CUSTOM_FUNCTIONS_FILE=/​root/​SSOExtensions.pm+CUSTOM_FUNCTIONS_FILE=/​path/to/​SSOExtensions.pm
 </​file>​ </​file>​
  
Line 73: Line 93:
 Go in Manager, ''​General Parameters''​ » ''​Advanced Parameters''​ » ''​Custom functions''​ and set: Go in Manager, ''​General Parameters''​ » ''​Advanced Parameters''​ » ''​Custom functions''​ and set:
 <​code>​ <​code>​
-SSOExtensions::​function1+SSOExtensions::​function1 ​SSOExtensions::​function2
 </​code>​ </​code>​
  
Line 82: Line 102:
 You can now use your function in a macro, an header or an access rule, for example: You can now use your function in a macro, an header or an access rule, for example:
 <​code>​ <​code>​
-Custom-Header => function1($uid)+Custom-Header => function1( $uid, $ENV{REMOTE_ADDR} ​)
 </​code>​ </​code>​