lemonldap-ng/doc/pages/documentation/current/customfunctions.html
Xavier Guimard ce59789747 Update doc
2019-06-28 16:53:45 +02:00

216 lines
9.1 KiB
HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>documentation:2.0:customfunctions</title>
<meta name="generator" content="DokuWiki"/>
<meta name="robots" content="index,follow"/>
<meta name="keywords" content="documentation,2.0,customfunctions"/>
<link rel="search" type="application/opensearchdescription+xml" href="lib/exe/opensearch.html" title="LemonLDAP::NG"/>
<link rel="start" href="customfunctions.html"/>
<link rel="contents" href="customfunctions.html" title="Sitemap"/>
<link rel="stylesheet" type="text/css" href="lib/exe/css.php.t.bootstrap3.css"/>
<!-- //if:usedebianlibs
<link rel="stylesheet" type="text/css" href="/javascript/bootstrap/css/bootstrap.min.css" />
//elsif:useexternallibs
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
//elsif:cssminified
<link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.min.css" />
//else -->
<link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.css" />
<!-- //endif -->
<script type="text/javascript">/*<![CDATA[*/var NS='documentation:2.0';var JSINFO = {"id":"documentation:2.0:customfunctions","namespace":"documentation:2.0"};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="lib/exe/js.php.t.bootstrap3.js"></script>
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
//elsif:useexternallibs
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
//elsif:jsminified
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.min.js"></script>
//else -->
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.js"></script>
<!-- //endif -->
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery-ui/jquery-ui.min.js"></script>
//elsif:useexternallibs
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
//elsif:jsminified
<script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.min.js"></script>
//else -->
<script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.js"></script>
<!-- //endif -->
</head>
<body>
<div class="dokuwiki export container">
<!-- TOC START -->
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>
<ul class="toc">
<li class="level1"><div class="li"><a href="#implementation">Implementation</a></div></li>
<li class="level1"><div class="li"><a href="#write_custom_functions_library">Write custom functions library</a></div></li>
<li class="level1"><div class="li"><a href="#import_custom_functions_in_lemonldapng">Import custom functions in LemonLDAP::NG</a></div>
<ul class="toc">
<li class="level2"><div class="li"><a href="#load_relevant_code_in_handler_server">Load relevant code in handler server</a></div>
<ul class="toc">
<li class="level3"><div class="li"><a href="#new_method">New method</a></div></li>
<li class="level3"><div class="li"><a href="#old_method">Old method</a></div></li>
</ul>
</li>
<li class="level2"><div class="li"><a href="#declare_custom_functions">Declare custom functions</a></div></li>
</ul>
</li>
<li class="level1"><div class="li"><a href="#use_it">Use it</a></div></li>
</ul>
</div>
</div>
<!-- TOC END -->
<h1 class="sectionedit1" id="custom_functions">Custom functions</h1>
<div class="level1">
<p>
Custom functions allow one to extend <abbr title="LemonLDAP::NG">LL::NG</abbr>, they can be used in <a href="writingrulesand_headers.html#headers" class="wikilink1" title="documentation:2.0:writingrulesand_headers">headers</a>, <a href="writingrulesand_headers.html#rules" class="wikilink1" title="documentation:2.0:writingrulesand_headers">rules</a> or <a href="formreplay.html" class="wikilink1" title="documentation:2.0:formreplay">form replay data</a>. Two actions are needed:
</p>
<ul>
<li class="level1"><div class="li"> declare them in LLNG configuration</div>
</li>
<li class="level1"><div class="li"> load the relevant code</div>
</li>
</ul>
</div>
<!-- EDIT1 SECTION "Custom functions" [1-309] -->
<h2 class="sectionedit2" id="implementation">Implementation</h2>
<div class="level2">
<p>
Your perl custom function must be declared on appropriate server when separating :
</p>
<p>
portal type : declare custom function here when using it in rules, macros, menu
</p>
<p>
reverse-proxy type : declare custom function here when using it in headers
</p>
</div>
<!-- EDIT2 SECTION "Implementation" [310-578] -->
<h2 class="sectionedit3" id="write_custom_functions_library">Write custom functions library</h2>
<div class="level2">
<p>
Create your Perl module with custom functions. You can name your module as you want, for example <code>SSOExtensions.pm</code>:
</p>
<pre class="code">vi /path/to/SSOExtensions.pm</pre>
<pre class="code file perl"><a href="http://perldoc.perl.org/functions/package.html"><span class="kw3">package</span></a> SSOExtensions<span class="sy0">;</span>
&nbsp;
<span class="kw2">sub</span> function1 <span class="br0">&#123;</span>
<span class="kw1">my</span> <span class="br0">&#40;</span><span class="re0">@args</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="co5">@_</span><span class="sy0">;</span>
&nbsp;
<span class="co1"># Your nice code here</span>
<a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="re0">$result</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw2">sub</span> function2 <span class="br0">&#123;</span>
<a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="co5">$_</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="nu0">1</span><span class="sy0">;</span></pre>
</div>
<!-- EDIT3 SECTION "Write custom functions library" [579-951] -->
<h2 class="sectionedit4" id="import_custom_functions_in_lemonldapng">Import custom functions in LemonLDAP::NG</h2>
<div class="level2">
</div>
<!-- EDIT4 SECTION "Import custom functions in LemonLDAP::NG" [952-1005] -->
<h3 class="sectionedit5" id="load_relevant_code_in_handler_server">Load relevant code in handler server</h3>
<div class="level3">
</div>
<h4 id="new_method">New method</h4>
<div class="level4">
<p>
Just declare files or Perl module that must be loaded:
</p>
<pre class="code file :ini"><span class="re0"><span class="br0">&#91;</span>all<span class="br0">&#93;</span></span>
<span class="re1">require</span> <span class="sy0">=</span><span class="re2"> /path/to/functions.pl, /path/to/SSOExtensions.pm</span>
# OR
<span class="re1">require</span> <span class="sy0">=</span><span class="re2"> SSOExtensions::function1, SSOExtensions::function2</span></pre>
</div>
<h4 id="old_method">Old method</h4>
<div class="level4">
<div class="notewarning">This method is available but unusable by Portal under Apache. So if your rule may be used by the menu, use the new method.
</div>
</div>
<h5 id="apache">Apache</h5>
<div class="level5">
<p>
Your module has to be loaded by Apache (for example after Handler load):
</p>
<pre class="code file apache"><span class="co1"># Perl environment</span>
PerlRequire Lemonldap::NG::Handler
PerlRequire /path/to/SSOExtensions.pm
PerlOptions +GlobalRequest</pre>
</div>
<h5 id="fastcgi_server_nginx">FastCGI server (Nginx)</h5>
<div class="level5">
<p>
You&#039;ve just to incicate to <a href="fastcgiserver.html" class="wikilink1" title="documentation:2.0:fastcgiserver">LLNG FastCGI server</a> the file to read using either <code>-f</code> option or <code>CUSTOM_FUNCTIONS_FILE</code> environment variable. Using packages, you just have to modify your <code>/etc/default/llng-fastcgi-server</code> (or <code>/etc/default/lemonldap-ng-fastcgi-server</code>) file:
</p>
<pre class="code file sh"># Number of process (default: 7)
#NPROC = 7
&nbsp;
# Unix socket to listen to
SOCKET=/var/run/llng-fastcgi-server/llng-fastcgi.sock
&nbsp;
# Pid file
PID=/var/run/llng-fastcgi-server/llng-fastcgi-server.pid
&nbsp;
# User and GROUP
USER=www-data
GROUP=www-data
&nbsp;
# Custom functions file
CUSTOM_FUNCTIONS_FILE=/path/to/SSOExtensions.pm</pre>
</div>
<!-- EDIT5 SECTION "Load relevant code in handler server" [1006-2337] -->
<h3 class="sectionedit6" id="declare_custom_functions">Declare custom functions</h3>
<div class="level3">
<p>
Go in Manager, <code>General Parameters</code> » <code>Advanced Parameters</code> » <code>Custom functions</code> and set:
</p>
<pre class="code">SSOExtensions::function1 SSOExtensions::function2</pre>
<div class="noteimportant">If your function is not compliant with <a href="safejail.html" class="wikilink1" title="documentation:2.0:safejail">Safe jail</a>, you will need to disable the jail.
</div>
</div>
<!-- EDIT6 SECTION "Declare custom functions" [2338-2659] -->
<h2 class="sectionedit7" id="use_it">Use it</h2>
<div class="level2">
<p>
You can now use your function in a macro, an header or an access rule, for example:
</p>
<pre class="code">Custom-Header =&gt; function1( $uid, $ENV{REMOTE_ADDR} )</pre>
</div>
<!-- EDIT7 SECTION "Use it" [2660-] --></div>
</body>
</html>