extendedfunctions.html 16.5 KB
Newer Older
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
1 2 3 4 5 6
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8" />
  <title>documentation:2.0:extendedfunctions</title>
<meta name="generator" content="DokuWiki"/>
Yadd's avatar
Yadd committed
7
<meta name="robots" content="index,follow"/>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
8 9 10 11 12
<meta name="keywords" content="documentation,2.0,extendedfunctions"/>
<link rel="search" type="application/opensearchdescription+xml" href="lib/exe/opensearch.html" title="LemonLDAP::NG"/>
<link rel="start" href="extendedfunctions.html"/>
<link rel="contents" href="extendedfunctions.html" title="Sitemap"/>
<link rel="stylesheet" type="text/css" href="lib/exe/css.php.t.bootstrap3.css"/>
Yadd's avatar
Yadd committed
13 14 15 16 17 18 19 20 21
<!-- //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 -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
22 23 24
<script type="text/javascript">/*<![CDATA[*/var NS='documentation:2.0';var JSINFO = {"id":"documentation:2.0:extendedfunctions","namespace":"documentation:2.0"};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="lib/exe/js.php.t.bootstrap3.js"></script>
Yadd's avatar
Yadd committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<!-- //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="/lib/scripts/jquery-ui.min.js"></script>
//else -->
  <script type="text/javascript" src="/lib/scripts/jquery-ui.js"></script>
<!-- //endif -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
43 44 45 46 47 48 49 50 51 52
</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="#presentation">Presentation</a></div></li>
Yadd's avatar
Yadd committed
53
<li class="level1"><div class="li"><a href="#request_information">Request information</a></div></li>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
54 55 56 57 58 59 60 61 62 63
<li class="level1"><div class="li"><a href="#extended_functions_list">Extended Functions List</a></div>
<ul class="toc">
<li class="level2"><div class="li"><a href="#date">date</a></div></li>
<li class="level2"><div class="li"><a href="#checklogonhours">checkLogonHours</a></div></li>
<li class="level2"><div class="li"><a href="#checkdate">checkDate</a></div></li>
<li class="level2"><div class="li"><a href="#basic">basic</a></div></li>
<li class="level2"><div class="li"><a href="#unicode2iso">unicode2iso</a></div></li>
<li class="level2"><div class="li"><a href="#iso2unicode">iso2unicode</a></div></li>
<li class="level2"><div class="li"><a href="#groupmatch">groupMatch</a></div></li>
<li class="level2"><div class="li"><a href="#encrypt">encrypt</a></div></li>
Yadd's avatar
Yadd committed
64
<li class="level2"><div class="li"><a href="#token">token</a></div></li>
Yadd's avatar
Yadd committed
65
<li class="level2"><div class="li"><a href="#isinnet6">isInNet6</a></div></li>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
</ul></li>
</ul>
</div>
</div>
<!-- TOC END -->

<h1 class="sectionedit1" id="extended_functions">Extended functions</h1>
<div class="level1">

</div>
<!-- EDIT1 SECTION "Extended functions" [1-34] -->
<h2 class="sectionedit2" id="presentation">Presentation</h2>
<div class="level2">

<p>
When <a href="writingrulesand_headers.html" class="wikilink1" title="documentation:2.0:writingrulesand_headers">writing rules and headers</a>, you can use Perl expressions that will be evaluated in a jail, to prevent bad code execution.
</p>

<p>
This is also true for:
</p>
<ul>
<li class="level1"><div class="li"> <a href="portalmenu.html#menu_modules" class="wikilink1" title="documentation:2.0:portalmenu">Menu modules activation rules</a></div>
</li>
<li class="level1"><div class="li"> <a href="formreplay.html" class="wikilink1" title="documentation:2.0:formreplay">Form replay data</a></div>
</li>
<li class="level1"><div class="li"> Macros</div>
</li>
<li class="level1"><div class="li"> Issuer databases use rules</div>
</li>
<li class="level1"><div class="li"> etc.</div>
</li>
</ul>

<p>
Inside this jail, you can access to:
</p>
<ul>
<li class="level1"><div class="li"> Core Perl subroutines (split, pop, map, etc.)</div>
</li>
<li class="level1"><div class="li"> <a href="customfunctions.html" class="wikilink1" title="documentation:2.0:customfunctions">Custom functions</a></div>
</li>
<li class="level1"><div class="li"> The <a href="http://perldoc.perl.org/MIME/Base64.html" class="urlextern" title="http://perldoc.perl.org/MIME/Base64.html"  rel="nofollow">encode_base64</a> subroutine</div>
</li>
Yadd's avatar
Yadd committed
110
<li class="level1"><div class="li"> Environment variables, in some cases (through %ENV). <em>(NB: with Apache handlers it is generally empty, so unusable for rules/headers)</em> </div>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
111
</li>
Yadd's avatar
Yadd committed
112
<li class="level1"><div class="li"> <a href="#request_information" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">Information about current request</a></div>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
</li>
<li class="level1"><div class="li"> <a href="#extended_functions_list" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">Extended functions</a>:</div>
<ul>
<li class="level2"><div class="li"> <a href="#date" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">date</a></div>
</li>
<li class="level2"><div class="li"> <a href="#checklogonhours" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">checkLogonHours</a></div>
</li>
<li class="level2"><div class="li"> <a href="#checkdate" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">checkDate</a></div>
</li>
<li class="level2"><div class="li"> <a href="#basic" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">basic</a></div>
</li>
<li class="level2"><div class="li"> <a href="#unicode2iso" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">unicode2iso</a></div>
</li>
<li class="level2"><div class="li"> <a href="#iso2unicode" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">iso2unicode</a></div>
</li>
<li class="level2"><div class="li"> <a href="#groupmatch" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">groupMatch</a></div>
</li>
Yadd's avatar
Yadd committed
130 131 132 133 134 135
<li class="level2"><div class="li"> <a href="#encrypt" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">encrypt</a></div>
</li>
<li class="level2"><div class="li"> <a href="#token" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">token</a></div>
</li>
<li class="level2"><div class="li"> <a href="#isinnet6" title="documentation:2.0:extendedfunctions ↵" class="wikilink1">isInNet6</a></div>
</li>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
136 137 138 139 140 141
</ul>
</li>
</ul>
<div class="notetip">To know more about the jail, check <a href="http://perldoc.perl.org/Safe.html" class="urlextern" title="http://perldoc.perl.org/Safe.html"  rel="nofollow">Safe module documentation</a>.
</div>
</div>
Yadd's avatar
Yadd committed
142
<!-- EDIT2 SECTION "Presentation" [35-1271] -->
Yadd's avatar
Yadd committed
143
<h2 class="sectionedit3" id="request_information">Request information</h2>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
<div class="level2">

<p>
The following data about the current request are available through functions :
</p>
<ul>
<li class="level1"><div class="li"> hostname</div>
</li>
<li class="level1"><div class="li"> remote_ip: the client <abbr title="Internet Protocol">IP</abbr> address</div>
</li>
<li class="level1"><div class="li"> uri: <abbr title="Uniform Resource Locator">URL</abbr> path</div>
</li>
<li class="level1"><div class="li"> uri_with_args: <abbr title="Uniform Resource Locator">URL</abbr> path with query string</div>
</li>
<li class="level1"><div class="li"> unparsed_uri: <abbr title="Uniform Resource Locator">URL</abbr> path, before <abbr title="Uniform Resource Locator">URL</abbr> decoding</div>
</li>
<li class="level1"><div class="li"> args: the query string</div>
</li>
<li class="level1"><div class="li"> method: the request method (GET, POST etc.)</div>
</li>
<li class="level1"><div class="li"> header_in(“Your-Request-Header”): any request header</div>
</li>
</ul>

</div>
Yadd's avatar
Yadd committed
169
<!-- EDIT3 SECTION "Request information" [1272-1677] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
170 171 172 173
<h2 class="sectionedit4" id="extended_functions_list">Extended Functions List</h2>
<div class="level2">

</div>
Yadd's avatar
Yadd committed
174
<!-- EDIT4 SECTION "Extended Functions List" [1678-1714] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
175 176 177 178 179 180 181 182 183
<h3 class="sectionedit5" id="date">date</h3>
<div class="level3">

<p>
Returns the date, in format YYYYMMDDHHMMSS, local time by default, GMT by calling 
</p>
<pre class="code">date(1)</pre>

</div>
Yadd's avatar
Yadd committed
184
<!-- EDIT5 SECTION "date" [1715-1834] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
<h3 class="sectionedit6" id="checklogonhours">checkLogonHours</h3>
<div class="level3">

<p>
This function will check the day and the hour of current request, and compare it to allowed days and hours. It returns 1 if this match, 0 else.
All e
By default, the allowed days and hours is an hexadecimal value, representing each hour of the week. A day has 24 hours, and a week 7 days, so the value contains 168 bits, converted into 42 hexadecimal characters. Sunday is the first day.
</p>

<p>
For example, for a full access, excepted week-end:
</p>
<pre class="code">000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000</pre>
<div class="notetip">The <a href="authldap.html#schema_extension" class="wikilink1" title="documentation:2.0:authldap">LDAP schema extension</a> can be used to store this value. You can also use the binary value from the logonHours attribute of Active Directory
</div>
<p>
Functions parameters:
</p>
<ul>
<li class="level1"><div class="li"> <strong>logon_hours</strong>: string representing allowed logon hours (GMT)</div>
</li>
<li class="level1"><div class="li"> <strong>syntax</strong> (optional): <code>hexadecimal</code> (default) or <code>octetstring</code></div>
</li>
<li class="level1"><div class="li"> <strong>time_correction</strong> (optional): hours to add or to subtract</div>
</li>
<li class="level1"><div class="li"> <strong>default_access</strong> (optional): what result to return if <strong>logon_hours</strong> is empty</div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">checkLogonHours($ssoLogonHours)</pre>

<p>
If you use the binary value (Active Directory), use this:
</p>
<pre class="code">All e
checkLogonHours($ssoLogonHours, &#039;octetstring&#039;)</pre>

<p>
You can also configure jetlag (if all of your users use the same timezone):
</p>
<pre class="code">checkLogonHours($ssoLogonHours, &#039;&#039;, &#039;+2&#039;)</pre>

<p>
If you manage different timezones, you have to take the jetlag into account in ssoLogonHours values, or use the $_timezone parameter. This parameter is set by the portal and use javascript to get the connected user timezone. It should works on every browser:
</p>
<pre class="code">checkLogonHours($ssoLogonHours, &#039;&#039;, $_timezone)</pre>

<p>
You can modify the default behavior for people without value in ssoLogonHours. Indeed, by default, users without logon hours values are rejected. You can allow these users instead of reject them:
</p>
<pre class="code">checkLogonHours($ssoLogonHours, &#039;&#039;, &#039;&#039;, &#039;1&#039;)</pre>

</div>
Yadd's avatar
Yadd committed
241
<!-- EDIT6 SECTION "checkLogonHours" [1835-3772] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
<h3 class="sectionedit7" id="checkdate">checkDate</h3>
<div class="level3">

<p>
This function will check the date of current request, and compare it to a start date and an end date. It returns 1 if this match, 0 else.
</p>
<div class="notetip">The <a href="authldap.html#schema_extension" class="wikilink1" title="documentation:2.0:authldap">LDAP schema extension</a> can be used to store these values
</div>
<p>
The date format is the LDAP date syntax, for example for the 1st March 2009:
</p>
<pre class="code">20090301000000Z</pre>

<p>
Functions parameters:
</p>
<ul>
<li class="level1"><div class="li"> <strong>start</strong>: Start date (GMT)</div>
</li>
<li class="level1"><div class="li"> <strong>end</strong>: End date (GMT)</div>
</li>
<li class="level1"><div class="li"> <strong>default_access</strong> (optional): what result to return if <strong>start</strong> and <strong>end</strong> are empty</div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">checkDate($ssoStartDate, $ssoEndDate)</pre>

</div>
Yadd's avatar
Yadd committed
273
<!-- EDIT7 SECTION "checkDate" [3773-4400] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
<h3 class="sectionedit8" id="basic">basic</h3>
<div class="level3">
<div class="noteimportant">This 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 to use it.
</div>
<p>
This function builds the <code>Authorization</code> HTTP header used in <a href="applications/authbasic.html" class="wikilink1" title="documentation:2.0:applications:authbasic">HTTP Basic authentication scheme</a>. It will force conversion from UTF-8 to ISO-8859-1 of user and password data.
</p>

<p>
Functions parameters:
</p>
<ul>
<li class="level1"><div class="li"> <strong>user</strong></div>
</li>
<li class="level1"><div class="li"> <strong>password</strong></div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">basic($uid,$_password)</pre>

</div>
Yadd's avatar
Yadd committed
298
<!-- EDIT8 SECTION "basic" [4401-4863] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
<h3 class="sectionedit9" id="unicode2iso">unicode2iso</h3>
<div class="level3">
<div class="noteimportant">This 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 to use it.
</div>
<p>
This function convert a string from UTF-8 to ISO-8859-1.
</p>

<p>
Functions parameters:
</p>
<ul>
<li class="level1"><div class="li"> <strong>string</strong></div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">unicode2iso($name)</pre>

</div>
Yadd's avatar
Yadd committed
321
<!-- EDIT9 SECTION "unicode2iso" [4864-5168] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
<h3 class="sectionedit10" id="iso2unicode">iso2unicode</h3>
<div class="level3">
<div class="noteimportant">This 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 to use it.
</div>
<p>
This function convert a string from ISO-8859-1 to UTF-8.
</p>

<p>
Functions parameters:
</p>
<ul>
<li class="level1"><div class="li"> <strong>string</strong></div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">iso2unicode($name)</pre>

</div>
Yadd's avatar
Yadd committed
344
<!-- EDIT10 SECTION "iso2unicode" [5169-5473] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
345 346 347 348
<h3 class="sectionedit11" id="groupmatch">groupMatch</h3>
<div class="level3">

<p>
Yadd's avatar
Yadd committed
349
this function allows one to parse the <code>$hGroups</code> variable to check if a value is present inside a group attribute.
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
</p>

<p>
Function parameter:
</p>
<ul>
<li class="level1"><div class="li"> <strong>groups</strong>: <code>$hGroups</code> variable</div>
</li>
<li class="level1"><div class="li"> <strong>attribute</strong>: Name of group attribute</div>
</li>
<li class="level1"><div class="li"> <strong>value</strong>: Value to check</div>
</li>
</ul>

<p>
Simple usage example:
</p>
<pre class="code">groupMatch($hGroups, &#039;description&#039;, &#039;Service 1&#039;)</pre>

</div>
Yadd's avatar
Yadd committed
370
<!-- EDIT11 SECTION "groupMatch" [5474-5832] -->
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
371 372
<h3 class="sectionedit12" id="encrypt">encrypt</h3>
<div class="level3">
Yadd's avatar
Yadd committed
373
<div class="notetip">Since version 2.0, this function is now compliant with <a href="safejail.html" class="wikilink1" title="documentation:2.0:safejail">Safe jail</a>.
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
374 375 376 377 378 379 380
</div>
<p>
This function uses the secret key of LLNG configuration to crypt a data. This can be used to anonymize identifier given to the protected application.
</p>
<pre class="code">encrypt($_whatToTrace)</pre>

</div>
Yadd's avatar
Yadd committed
381
<!-- EDIT12 SECTION "encrypt" [5833-6138] -->
Yadd's avatar
Yadd committed
382 383 384 385 386 387 388 389 390
<h3 class="sectionedit13" id="token">token</h3>
<div class="level3">

<p>
This function generates token used to <a href="servertoserver.html" class="wikilink1" title="documentation:2.0:servertoserver">handle server webservice calls</a>.
</p>
<pre class="code">token($_session_id,&#039;webapp1.example.com&#039;,&#039;webapp2.example.com&#039;)</pre>

</div>
Yadd's avatar
Yadd committed
391 392 393 394 395 396 397 398 399 400 401
<!-- EDIT13 SECTION "token" [6139-6343] -->
<h3 class="sectionedit14" id="isinnet6">isInNet6</h3>
<div class="level3">

<p>
Function to check if an IPv6 address is in a subnet. Example <em>check if <abbr title="Internet Protocol">IP</abbr> address is local</em>:
</p>
<pre class="code perl">isInNet6<span class="br0">&#40;</span><span class="re0">$ipAddr</span><span class="sy0">,</span> <span class="st_h">'fe80::/10'</span><span class="br0">&#41;</span></pre>

</div>
<!-- EDIT14 SECTION "isInNet6" [6344-] --></div>
Clément OUDOT's avatar
New doc  
Clément OUDOT committed
402 403
</body>
</html>