lemonldap-ng/doc/pages/documentation/1.9/customfunctions.html
2015-12-18 09:46:34 +00:00

112 lines
4.9 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 class="sectionedit1" id="custom_functions">Custom functions</h1>
<div class="level1">
<p>
Custom functions allow to extend <abbr title="LemonLDAP::NG">LL::NG</abbr>, they can be used in <a href="../../documentation/1.9/writingrulesand_headers.html#headers" class="wikilink1" title="documentation:1.9:writingrulesand_headers">headers</a>, <a href="../../documentation/1.9/writingrulesand_headers.html#rules" class="wikilink1" title="documentation:1.9:writingrulesand_headers">rules</a> or <a href="../../documentation/1.9/formreplay.html" class="wikilink1" title="documentation:1.9:formreplay">form replay data</a>.
</p>
</div>
<!-- EDIT1 SECTION "Custom functions" [1-215] -->
<h2 class="sectionedit2" 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 /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 <abbr title="Uniform Resource Locator">URL</abbr>, that is
</p>
<ul>
<li class="level1"><div class="li"> <strong>portal full <abbr title="Uniform Resource Locator">URL</abbr></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 <abbr title="Uniform Resource Locator">URL</abbr></strong> if it is run by handler (e.g. /admin/index.php?param=foo).</div>
</li>
</ul>
<p>
</div></p>
</p>
</div>
<!-- EDIT2 SECTION "Write custom functions library" [216-839] -->
<h2 class="sectionedit3" id="import_custom_functions_in_lemonldapng">Import custom functions in LemonLDAP::NG</h2>
<div class="level2">
</div>
<!-- EDIT3 SECTION "Import custom functions in LemonLDAP::NG" [840-893] -->
<h3 class="sectionedit4" id="declare_module_in_apache_configuration">Declare module in Apache configuration</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>
<!-- EDIT4 SECTION "Declare module in Apache configuration" [894-1156] -->
<h3 class="sectionedit5" 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</pre>
<p>
<p><div class="noteimportant">If your function is not compliant with <a href="../../documentation/1.9/safejail.html" class="wikilink1" title="documentation:1.9:safejail">Safe jail</a>, you will need to disable the jail.
</div></p>
</p>
</div>
<!-- EDIT5 SECTION "Declare custom functions" [1157-1453] -->
<h2 class="sectionedit6" 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)</pre>
</div>
</div><!-- closes <div class="dokuwiki export">-->