lemonldap-ng/doc/pages/documentation/1.4/customfunctions.html
David COUTADEUR e9dd825518 - updating documentation accordingly with new handler call (My::Packages -> Lemonldap::NG::Handler) in branch 1.4
- regenerating documentation with make documentation
(references #630)
2014-05-22 10:51:39 +00:00

127 lines
5.1 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!-- metadata -->
<meta name="generator" content="Offline" />
<meta name="version" content="Offline 0.1" />
<!-- style sheet links -->
<link rel="stylesheet" media="all" type="text/css" href="../../../css/all.css" />
<link rel="stylesheet" media="screen" type="text/css" href="../../../css/screen.css" />
<link rel="stylesheet" media="print" type="text/css" href="../../../css/print.css" />
</head>
<body>
<div class="dokuwiki export">
<h1><a name="custom_functions" id="custom_functions">Custom functions</a></h1>
<div class="level1">
<p>
Custom functions allow to extend <acronym title="LemonLDAP::NG">LL::NG</acronym>, they can be used in <a href="../../documentation/1.4/writingrulesand_headers.html#headers" class="wikilink1" title="documentation:1.4:writingrulesand_headers">headers</a>, <a href="../../documentation/1.4/writingrulesand_headers.html#rules" class="wikilink1" title="documentation:1.4:writingrulesand_headers">rules</a> or <a href="../../documentation/1.4/formreplay.html" class="wikilink1" title="documentation:1.4:formreplay">form replay data</a>.
</p>
</div>
<!-- SECTION "Custom functions" [1-215] -->
<h2><a name="write_custom_functions_library" id="write_custom_functions_library">Write custom functions library</a></h2>
<div class="level2">
<p>
Create your <acronym title="Practical Extraction and Report Language">Perl</acronym> module with custom functions. You can name your module as you want, for example <code>SSOExtensions.pm</code>:
</p>
<pre class="code">
vi /root/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="re0">$url</span> <span class="sy0">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a><span class="sy0">;</span>
<span class="kw1">my</span> <span class="re0">$param</span> <span class="sy0">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span class="kw3">shift</span></a><span class="sy0">;</span>
&nbsp;
<span class="co1"># Your nice code here</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="re0">$param</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="nu0">1</span><span class="sy0">;</span></pre>
<p>
<p><div class="notetip">
First parameter passed to the custom function is the requested <acronym title="Uniform Resource Locator">URL</acronym>, that is
</p>
<ul>
<li class="level1"><div class="li"> <strong>portal full <acronym title="Uniform Resource Locator">URL</acronym></strong> if custom function is run by portal (e.g. <a href="https://auth.example.com/" class="urlextern" title="https://auth.example.com/" rel="nofollow">https://auth.example.com/</a>)</div>
</li>
<li class="level1"><div class="li"> <strong>absolute <acronym title="Uniform Resource Locator">URL</acronym></strong> if it is run by handler (e.g. /admin/index.php?param=foo).</div>
</li>
</ul>
<p>
</div></p>
</p>
</div>
<!-- SECTION "Write custom functions library" [216-839] -->
<h2><a name="import_custom_functions_in_lemonldapng" id="import_custom_functions_in_lemonldapng">Import custom functions in LemonLDAP::NG</a></h2>
<div class="level2">
</div>
<!-- SECTION "Import custom functions in LemonLDAP::NG" [840-893] -->
<h3><a name="declare_module_in_apache_configuration" id="declare_module_in_apache_configuration">Declare module in Apache configuration</a></h3>
<div class="level3">
<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 /root/SSOExtensions.pm
PerlOptions +GlobalRequest</pre>
</div>
<!-- SECTION "Declare module in Apache configuration" [894-1156] -->
<h3><a name="declare_custom_functions" id="declare_custom_functions">Declare custom functions</a></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
</pre>
<p>
<p><div class="noteimportant">If your function is not compliant with <a href="../../documentation/1.4/safejail.html" class="wikilink1" title="documentation:1.4:safejail">Safe jail</a>, you will need to disable the jail.
</div></p>
</p>
</div>
<!-- SECTION "Declare custom functions" [1157-1453] -->
<h2><a name="use_it" id="use_it">Use it</a></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)
</pre>
</div>
<!-- SECTION "Use it" [1454-] --></div><!-- closes <div class="dokuwiki export">-->