| 1 |
Portal customization |
| 2 |
==================== |
| 3 |
|
| 4 |
|
| 5 |
.. note:: |
| 6 |
|
| 7 |
The portal is the visible part of LemonLDAP::NG, all user |
| 8 |
interactions are displayed on it. |
| 9 |
|
| 10 |
A lot of customization can be done through configuration parameters (logo, background, ...), this is the advocated method |
| 11 |
as it requires no effort when upgrading the software. |
| 12 |
|
| 13 |
If you need deeper changes in the user interface, then you should create your own skin. In this case, you need to |
| 14 |
read :doc:`template upgrade notes<upgrade_templates>` at each version update. |
| 15 |
|
| 16 |
Customization parameters |
| 17 |
------------------------ |
| 18 |
|
| 19 |
Main Logo |
| 20 |
~~~~~~~~~ |
| 21 |
|
| 22 |
You can change the default Main Logo in Manager: General Parameters > |
| 23 |
Portal > Customization > Main logo. |
| 24 |
|
| 25 |
A blank value disables Main logo display. |
| 26 |
|
| 27 |
.. tip:: |
| 28 |
|
| 29 |
- Logo files must be stored in lemonldap-ng-portal/site/htdocs/static/my/path directory |
| 30 |
- Logo file path must be like my/path/logo.png |
| 31 |
- Main logo is included in Portal templates AND mail body |
| 32 |
|
| 33 |
Skin background |
| 34 |
~~~~~~~~~~~~~~~ |
| 35 |
|
| 36 |
Go in ``General Parameters`` > ``Portal`` > ``Customization`` > |
| 37 |
``Skin background``. You can define a background by selecting one of the |
| 38 |
available image. Select ``None`` to use the default skin background configuration. |
| 39 |
|
| 40 |
|image0| |
| 41 |
|
| 42 |
To set your own background, copy your file in |
| 43 |
``/usr/share/lemonldap-ng/portal/htdocs/static/common/backgrounds/`` and |
| 44 |
register it in ``/etc/lemonldap-ng/lemonldap-ng.ini``: |
| 45 |
|
| 46 |
.. code-block:: ini |
| 47 |
|
| 48 |
[portal] |
| 49 |
portalSkinBackground = file.png |
| 50 |
|
| 51 |
You can also use ``lemonldap-ng-cli``: |
| 52 |
|
| 53 |
:: |
| 54 |
|
| 55 |
/usr/share/lemonldap-ng/bin/lemonldap-ng-cli set portalSkinBackground file.png |
| 56 |
|
| 57 |
|
| 58 |
Favicon |
| 59 |
~~~~~~~ |
| 60 |
|
| 61 |
You can change the default favicon in Manager: General Parameters > |
| 62 |
Portal > Customization > Favicon. |
| 63 |
|
| 64 |
A blank value displays default favicon ``common/favicon.ico``. |
| 65 |
|
| 66 |
.. tip:: |
| 67 |
|
| 68 |
- Logo files must be stored in lemonldap-ng-portal/site/htdocs/static/my/path directory |
| 69 |
- Logo file path must be like my/path/logo.ico |
| 70 |
|
| 71 |
Show languages choice |
| 72 |
~~~~~~~~~~~~~~~~~~~~~ |
| 73 |
|
| 74 |
You can disabled languages choice in Manager: General Parameters > |
| 75 |
Portal > Customization > Show languages choice. |
| 76 |
|
| 77 |
Option enabled by default. |
| 78 |
|
| 79 |
|
| 80 |
.. tip:: |
| 81 |
|
| 82 |
If languages choice is disabled, Portal displays accepted languages by |
| 83 |
your browser (EN by default). |
| 84 |
|
| 85 |
|
| 86 |
Scroll to top button |
| 87 |
~~~~~~~~~~~~~~~~~~~~ |
| 88 |
|
| 89 |
You can display a button to go to back to the top after <value> pixels scrolling. |
| 90 |
|
| 91 |
.. tip:: |
| 92 |
|
| 93 |
A blank or null value disable this feature. |
| 94 |
|
| 95 |
Floating category name |
| 96 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 97 |
|
| 98 |
You can display an applications category as a floating menu by specifying its category ``name``. |
| 99 |
Example: ``Sample applications``. |
| 100 |
|
| 101 |
.. tip:: |
| 102 |
|
| 103 |
A blank or an inexisting value disable this feature. |
| 104 |
|
| 105 |
Custom CSS file |
| 106 |
~~~~~~~~~~~~~~~ |
| 107 |
|
| 108 |
You can define a custom CSS file, for example ``custom.css``, which will |
| 109 |
be loaded after default CSS files. This file must be created in the static repository |
| 110 |
(By default: ``/usr/share/lemonldap-ng/portal/htdocs/static/``). |
| 111 |
|
| 112 |
Then set this value in Custom CSS parameter: |
| 113 |
``bootstrap/css/custom.css``. |
| 114 |
|
| 115 |
CSS file example to remove white background of main logo: |
| 116 |
|
| 117 |
.. code-block:: css |
| 118 |
|
| 119 |
#header img { |
| 120 |
background-color: transparent; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
Custom JS file |
| 125 |
~~~~~~~~~~~~~~ |
| 126 |
|
| 127 |
Similarly, you can define a custom JS file, for example ``custom.js``, which will |
| 128 |
be loaded after default JS files. This file must be created in the static repository |
| 129 |
(By default: ``/usr/share/lemonldap-ng/portal/htdocs/static/``). |
| 130 |
|
| 131 |
Then set this value in Custom JS parameter: |
| 132 |
``bootstrap/js/custom.js``. |
| 133 |
|
| 134 |
Check out the :doc:`jqueryevents` page for available integrations |
| 135 |
|
| 136 |
Some javascript functions are exported by LemonLDAP: |
| 137 |
|
| 138 |
* ``translate(msg)``: lookup the value of the translation label ``msg`` in the current language |
| 139 |
|
| 140 |
.. versionadded:: 2.21.0 |
| 141 |
|
| 142 |
* ``translatePage(lang)``: translate the page into ``lang``, if ommitted, retranslate the whole page into the current language |
| 143 |
* ``webauthn_start``: start WebAuthn authentication flow. This only works on login page and 2FA pages |
| 144 |
* ``ssl_start``: start SSL authentication. This only works the login page |
| 145 |
|
| 146 |
.. _portalcustom-skin-customization: |
| 147 |
|
| 148 |
.. _intlmessages: |
| 149 |
|
| 150 |
Messages |
| 151 |
~~~~~~~~ |
| 152 |
|
| 153 |
Messages are defined in source code. If they really do not suit you, |
| 154 |
override them! You just need to know the ID of the message (look at |
| 155 |
Portal/Main/Constants.pm). |
| 156 |
|
| 157 |
There are two methods to do this: |
| 158 |
|
| 159 |
- Use ``lemonldap-ng.ini``: |
| 160 |
|
| 161 |
.. code-block:: ini |
| 162 |
|
| 163 |
[portal] |
| 164 |
|
| 165 |
# Custom error messages |
| 166 |
error_0 = Big brother is watching you, authenticated user |
| 167 |
|
| 168 |
# Custom standard messages |
| 169 |
msg_lastLogins = Your last connections |
| 170 |
|
| 171 |
You can also define messages in several languages or disable message |
| 172 |
boxes by using the bareword ``_hide_`` : |
| 173 |
|
| 174 |
.. code-block:: ini |
| 175 |
|
| 176 |
error_en_0 = Big brother is watching you, authenticated user |
| 177 |
error_fr_0 = Souriez, vous êtes surveillés ! |
| 178 |
msg_fr_lastLogins = Dernières connexions |
| 179 |
error_9 = _hide_ |
| 180 |
|
| 181 |
- Create a lang file in skin: |
| 182 |
|
| 183 |
You can create a lang file in |
| 184 |
``templates/bootstrap`` similar to the default lang files provided in |
| 185 |
``htdocs/static/languages/``. |
| 186 |
|
| 187 |
For example ``templates/bootstrap/en.json``: |
| 188 |
|
| 189 |
.. code-block:: javascript |
| 190 |
|
| 191 |
{ |
| 192 |
"PE9":"Please authenticate!", |
| 193 |
"lastLogins": "Previous authentications", |
| 194 |
"myMessage": "My custom message, in english" |
| 195 |
} |
| 196 |
|
| 197 |
You can also create a file called ``all.json`` to override messages in |
| 198 |
all languages. |
| 199 |
|
| 200 |
.. versionchanged:: 2.0.15 |
| 201 |
Translations in lemonldap-ng.ini now take priority over translations from skin files |
| 202 |
|
| 203 |
Buttons on login page |
| 204 |
~~~~~~~~~~~~~~~~~~~~~ |
| 205 |
|
| 206 |
This node allows one to enable/disable buttons on the login page: |
| 207 |
|
| 208 |
- **Check last logins**: display a checkbox on login form, allowing |
| 209 |
user to check his login history right after opening session |
| 210 |
- **Register new account**: display a link to :doc:`register page<register>` (for |
| 211 |
password based authentication backends) |
| 212 |
- **Reset your certificate**: display a link to :doc:`reset certificate page<resetcertificate>` (for |
| 213 |
password based authentication backends) |
| 214 |
- **Reset password**: display a link to |
| 215 |
:doc:`reset your password page<resetpassword>` (for password based |
| 216 |
authentication backends). Number of allowed retries can be set (3 |
| 217 |
times by default) |
| 218 |
|
| 219 |
Password management |
| 220 |
~~~~~~~~~~~~~~~~~~~ |
| 221 |
|
| 222 |
- **Require old password**: used only in the password changing module |
| 223 |
of the menu, will check the old password before updating it |
| 224 |
- **Allow to display password**: if enabled, a small icon in the password |
| 225 |
field is added and when users click on it, the password value is |
| 226 |
revealed. Disabled by default. |
| 227 |
- **Hide old password**: used only if the password need to be reset by |
| 228 |
the user (LDAP password policy), will hide the old password input |
| 229 |
- **Send mail on password change**: send a mail if the password is |
| 230 |
changed from the Menu, or from forced password reset (LDAP password |
| 231 |
policy) |
| 232 |
|
| 233 |
Password Policy |
| 234 |
~~~~~~~~~~~~~~~ |
| 235 |
|
| 236 |
.. tip:: |
| 237 |
|
| 238 |
Available since version 2.0.6 |
| 239 |
|
| 240 |
- **Activation**: enable/disable password policy. You can set a rule |
| 241 |
to enable policy for specific users only |
| 242 |
- **Display policy in password form**: enable this option to display an |
| 243 |
information message about password policy constraints |
| 244 |
- **Minimal size**: leave 0 to bypass the check |
| 245 |
- **Maximal size**: leave 0 to bypass the check |
| 246 |
- **Minimal lower characters**: leave 0 to bypass the check |
| 247 |
- **Minimal upper characters**: leave 0 to bypass the check |
| 248 |
- **Minimal digit characters**: leave 0 to bypass the check |
| 249 |
- **Minimal special characters**: leave 0 to bypass the check |
| 250 |
- **Allowed special characters**: list of allowed special characters. Set the ``__ALL__`` value to allow ALL special characters. |
| 251 |
A blank value forbids ALL special characters. The ``space`` character can not be |
| 252 |
specified at the begin or at the end of the list to prevent trimming. |
| 253 |
|
| 254 |
.. _portalcustom-other-parameters: |
| 255 |
|
| 256 |
Other |
| 257 |
~~~~~ |
| 258 |
|
| 259 |
- **User attribute**: which session attribute will be used to display |
| 260 |
``Connected as`` in the menu |
| 261 |
- **New window**: open menu links in new window |
| 262 |
- **Anti iframe protection**: Set ``X-Frame-Options`` and CSP |
| 263 |
``frame-ancestors`` headers (see `Browser |
| 264 |
compatibility <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options#Browser_compatibility>`__) |
| 265 |
- **Ping interval**: number of milliseconds between each ping (Ajax |
| 266 |
request) on the portal menu. Set to 0 to dismiss checks. |
| 267 |
- **Show error on expired session**: display the error "Session |
| 268 |
expired", which stops the authentication process. This is enabled by |
| 269 |
default but can be disabled to prevent transparent authentication |
| 270 |
(like SSL or Kerberos) to be stopped. |
| 271 |
- **Show error on mail not found**: display error if provided mail is |
| 272 |
not found in password reset by mail process. Disabled by default to |
| 273 |
prevent mail enumeration from this page. |
| 274 |
- **Display rights refresh link**: enable/disable link in Portal menu to allow users to refresh their rights |
| 275 |
- **Cache-busting salt**: change this value any time you update a static file |
| 276 |
on the server to force your users to reload their browser cache |
| 277 |
|
| 278 |
Create your own skin |
| 279 |
-------------------- |
| 280 |
|
| 281 |
Default skin |
| 282 |
~~~~~~~~~~~~ |
| 283 |
|
| 284 |
You can change the default skin in Manager: ``General Parameters`` > |
| 285 |
``Portal`` > ``Customization`` > ``Default skin``. |
| 286 |
|
| 287 |
Select the ``Custom`` skin, then set the name of the skin you want to |
| 288 |
use in the input below. |
| 289 |
|
| 290 |
Skin rules |
| 291 |
~~~~~~~~~~ |
| 292 |
|
| 293 |
You might want to display different skin depending on the URL that was |
| 294 |
called before being redirected to the portal, or the IP address of the |
| 295 |
user. |
| 296 |
|
| 297 |
To achieve this, you can create a rule in the Manager: select |
| 298 |
``General Parameters`` > ``Portal`` > ``Customization`` > |
| 299 |
``Skin display rules`` and click on "New entry". Then fill the two fields; |
| 300 |
|
| 301 |
- **Key**: a Perl expression (you can use ``%ENV`` hash to get environment |
| 302 |
variables, or ``$_url`` to get URL called before redirection, or ``$ipAddr`` |
| 303 |
to use user IP address). If the rule evaluation is true, the corresponding |
| 304 |
skin is applied. |
| 305 |
- **Value**: the name of the skin to use. |
| 306 |
|
| 307 |
Example:: |
| 308 |
|
| 309 |
$_url =~ m#^http://test1.example.com# |
| 310 |
|
| 311 |
Skin files |
| 312 |
~~~~~~~~~~ |
| 313 |
|
| 314 |
A skin is composed of different files: |
| 315 |
|
| 316 |
- **.tpl**: Perl `HTML::Template <https://metacpan.org/pod/HTML::Template>`__ files, for HTML content |
| 317 |
- **.css**: CSS (styles) |
| 318 |
- **.js**: Javascript |
| 319 |
- images and other media files |
| 320 |
|
| 321 |
A skin will often refer to the ``common`` skin, which is not a real |
| 322 |
skin, but shared skin objects (like scripts, images and CSS). |
| 323 |
|
| 324 |
Skin customization |
| 325 |
~~~~~~~~~~~~~~~~~~ |
| 326 |
|
| 327 |
.. attention:: |
| 328 |
|
| 329 |
If you modify directly the skin files, your |
| 330 |
modifications will certainly be erased on the next upgrade. The best is |
| 331 |
to create your own skin, based on an existing skin. |
| 332 |
|
| 333 |
Here we explain how to create a new skin, named ``myskin``, from the |
| 334 |
``bootstrap`` skin. |
| 335 |
|
| 336 |
First copy static content: |
| 337 |
|
| 338 |
:: |
| 339 |
|
| 340 |
cd /usr/share/lemonldap-ng/portal/htdocs/static |
| 341 |
mkdir myskin |
| 342 |
cd myskin/ |
| 343 |
cp -a ../bootstrap/js/ . |
| 344 |
cp -a ../bootstrap/css/ . |
| 345 |
mkdir images |
| 346 |
|
| 347 |
Then create a folder for template overrides |
| 348 |
|
| 349 |
:: |
| 350 |
|
| 351 |
cd /usr/share/lemonldap-ng/portal/templates/ |
| 352 |
mkdir myskin |
| 353 |
cd myskin/ |
| 354 |
|
| 355 |
LemonLDAP::NG contains templates that are made for common customization, these |
| 356 |
particular templates do not need any modification when you upgrade |
| 357 |
LemonLDAP::NG: |
| 358 |
|
| 359 |
- ``customhead.tpl`` : HTML header markups (like CSS, js inclusion) |
| 360 |
- ``customheader.tpl`` : HTML code in the header |
| 361 |
- ``customfooter.tpl`` : HTML code in the footer |
| 362 |
- ``customLoginHeader.tpl`` : HTML code in the login header |
| 363 |
- ``customLoginFooter.tpl`` : HTML code in the login footer |
| 364 |
|
| 365 |
To use override these files, copy them into your skin folder: |
| 366 |
|
| 367 |
:: |
| 368 |
|
| 369 |
cp ../bootstrap/custom* . |
| 370 |
|
| 371 |
Then you can add your media to ``myskin/images``, you will be able to |
| 372 |
use them in HTML template with this code: |
| 373 |
|
| 374 |
:: |
| 375 |
|
| 376 |
<img src="<TMPL_VAR NAME="STATIC_PREFIX">myskin/images/logo.png" class="mx-auto d-block" /> |
| 377 |
|
| 378 |
To change CSS, two options: |
| 379 |
|
| 380 |
- Edit myksin/css/styles.css and myskin/css/styles.min.css |
| 381 |
- Create a new CSS file, for example myskin/css/myskin.css and load it |
| 382 |
in customhead.tpl: |
| 383 |
|
| 384 |
:: |
| 385 |
|
| 386 |
<link href="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/css/myskin.css" rel="stylesheet" type="text/css" /> |
| 387 |
|
| 388 |
To add custom JS, create a new file in myskin/js/custom.js and load it in customhead.tpl :: |
| 389 |
|
| 390 |
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/js/custom.js"></script> |
| 391 |
|
| 392 |
In this file, you can access JQuery functions, and hook your code to :doc:`JQuery events <jqueryevents>` |
| 393 |
|
| 394 |
Put then all custom HTML code in the custom template files. |
| 395 |
|
| 396 |
To configure your new skin in Manager, select the custom skin, and enter |
| 397 |
your skin name in the configuration field. For example with |
| 398 |
lemonldap-ng-cli: |
| 399 |
|
| 400 |
:: |
| 401 |
|
| 402 |
/usr/share/lemonldap-ng/bin/lemonldap-ng-cli -yes 1 set portalSkin 'myskin' portalSkinBackground '' |
| 403 |
|
| 404 |
You can find additional documentation on the syntax of template files in the |
| 405 |
`official documentation of the HTML::Template module |
| 406 |
<https://metacpan.org/pod/HTML::Template>`__ |
| 407 |
|
| 408 |
.. note:: |
| 409 |
|
| 410 |
If you modify the static files of your theme often, you should use the |
| 411 |
*Cache-busting salt* configuration parameters to force web browsers to |
| 412 |
reload your static resources by changing the special ``?v=`` parameter in static resource URLs. |
| 413 |
Be sure that you include ``?v=<TMPL_VAR CACHE_TAG>`` in the URL of your static resources |
| 414 |
|
| 415 |
Additional error details |
| 416 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 417 |
|
| 418 |
When a particular error happens, it can be useful to display some detailed |
| 419 |
instructions to the user, you can do this using the ``TMPL_ERROR_NNN`` variable:: |
| 420 |
|
| 421 |
<!-- Account has been locked: PE21 --> |
| 422 |
<TMPL_IF NAME="AUTH_ERROR_21"> |
| 423 |
<div trspan="custom_error_message_for_locked_account"></div> |
| 424 |
</TMPL_IF> |
| 425 |
|
| 426 |
Adding messages in your templates |
| 427 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 428 |
|
| 429 |
You can use the ``trspan`` HTML attribute to replace the content of a tag by an internationalized string :: |
| 430 |
|
| 431 |
<span trspan="myMessage">This will be replaced by the translation of myMessage</span> |
| 432 |
|
| 433 |
|
| 434 |
.. versionadded:: 2.0.16 |
| 435 |
|
| 436 |
You can now also replace HTML attributes with translated messages |
| 437 |
|
| 438 |
.. code :: |
| 439 |
|
| 440 |
<img src="http://xxx" trattribute="alt:myMessage data-description:myMessage"></img> |
| 441 |
|
| 442 |
In this example, the ``alt=`` and ``data-description=`` attributes will be replaced by the translation of ``myMessage`` |
| 443 |
|
| 444 |
Menu tabs |
| 445 |
~~~~~~~~~ |
| 446 |
|
| 447 |
If you modify the menu template to add some tabs, you should add the new |
| 448 |
tabs in \`customMenuTabs\` parameter in lemonldap-ng.ini: |
| 449 |
|
| 450 |
.. code-block:: ini |
| 451 |
|
| 452 |
[portal] |
| 453 |
|
| 454 |
customMenuTabs = test, test2 |
| 455 |
|
| 456 |
This will allow one to display the tab directly with this URL: |
| 457 |
http://auth.example.com/?tab=test |
| 458 |
|
| 459 |
Template parameters |
| 460 |
~~~~~~~~~~~~~~~~~~~ |
| 461 |
|
| 462 |
Template parameters are defined in source code. If you need to add a |
| 463 |
template parameter for your customization, then add to |
| 464 |
``lemonldap-ng.ini``: |
| 465 |
|
| 466 |
.. code-block:: ini |
| 467 |
|
| 468 |
[portal] |
| 469 |
|
| 470 |
# Custom template parameters |
| 471 |
tpl_myparam = world |
| 472 |
|
| 473 |
You can also define them directly in configuration, in ``portalCustomTplParams`` key: |
| 474 |
|
| 475 |
:: |
| 476 |
|
| 477 |
/usr/share/lemonldap-ng/bin/lemonldap-ng-cli -yes 1 \ |
| 478 |
addKey \ |
| 479 |
portalCustomTplParams myparam "world" |
| 480 |
|
| 481 |
Then you will be able to use it in your template like this: |
| 482 |
|
| 483 |
.. code-block:: html |
| 484 |
|
| 485 |
Hello <TMPL_VAR NAME="myparam">! |
| 486 |
|
| 487 |
All session variables are also available in templates, with the prefix |
| 488 |
``session_``: |
| 489 |
|
| 490 |
.. code-block:: html |
| 491 |
|
| 492 |
Hello <TMPL_VAR NAME="session_cn">! |
| 493 |
|
| 494 |
You can also display environment variables, with the prefix ``env_``: |
| 495 |
|
| 496 |
.. code-block:: html |
| 497 |
|
| 498 |
Your IP is <TMPL_VAR NAME="env_REMOTE_ADDR"> |
| 499 |
|
| 500 |
.. |image0| image:: /documentation/manager-skin-background.png |
| 501 |
:class: align-center |