Debian Codegraph @

doc/sources/admin/notifications.rst

raw
1 Notifications system
2 ====================
3
4 LemonLDAP::NG can be used to notify some messages to users. If a user
5 has got some messages, they will be displayed when he access to the
6 portal. If a message contains some check boxes, the user has to check
7 all of them else he can not access to the portal and retrieves his
8 session cookie.
9
10 A notification explorer is available in Manager, and notifications can
11 be set for all users, with possibility to use display conditions. When
12 the user accept the notification, notification reference is stored in
13 his persistent session.
14
15 Installation
16 ------------
17
18 Activation
19 ~~~~~~~~~~
20
21 To activate notifications system:
22
23 Go to Manager ``General Parameters`` » ``Plugins`` » ``Notifications`` » ``Activation``
24
25 or in ``lemonldap-ng.ini`` [portal] section:
26
27 .. code-block:: ini
28
29 [portal]
30 notification = 1
31
32 Public notifications
33 ~~~~~~~~~~~~~~~~~~~~
34
35 Public notifications allows to display a carousel of messages to all users on the login page.
36 This plugin uses the Notification , they will be displayed when he access to the
37 portal.
38
39 Disabled by default, you just have to activate it in the
40 Manager (``General Parameters`` » ``Plugins`` » ``Notifications`` »
41 ``Public Notifications``)
42
43 or in ``lemonldap-ng.ini`` [portal] section:
44
45 .. code-block:: ini
46
47 [portal]
48 notificationsExplorer = 1
49 publicNotification = 1
50
51 Usage
52 ^^^^^
53
54 When enabled, create a notification for a "public" recipient. There are 3 types pf publibc recipients, "public-info", "public-warn", "public-error". Each will be displayed with a different color (respectively blue, yellow and red).
55
56 Examples
57 ^^^^^^^^
58
59 JSON
60 ''''
61
62 .. code::
63
64 [{
65 "uid": "public-info",
66 "date": "2009-01-27",
67 "reference": "ABC",
68 "title": "Application Maintenance",
69 "subtitle": "Application 1",
70 "text": "Application 1 is scheduled to be in maintenance from 9am to 10 am and won't be available",
71 },
72 {
73 "uid": "public-error",
74 "date": "2009-01-27",
75 "reference": "ABC",
76 "title": "Application Maintenance",
77 "subtitle": "Application 1",
78 "text": "Application 1 is scheduled to be in maintenance from 9am to 10 am and won't be available",
79 },
80 {
81 "uid": "public-warn",
82 "date": "2009-01-27",
83 "reference": "ABC",
84 "title": "Application Maintenance",
85 "subtitle": "Application 1",
86 "text": "Application 1 is scheduled to be in maintenance from 9am to 10 am and won't be available",
87 }] # No comma at the end
88
89
90 Explorer
91 ~~~~~~~~
92
93 Notifications explorer allows users to see and display theirs accepted
94 notifications. Disable by default, you just have to activate it in the
95 Manager (``General Parameters`` » ``Plugins`` » ``Notifications`` »
96 ``Explorer``)
97
98 or in ``lemonldap-ng.ini`` [portal] section:
99
100 .. code-block:: ini
101
102 [portal]
103 notificationsExplorer = 1
104
105 By default, just the three last notifications are displayed. You can
106 modify this by editing ``lemonldap-ng.ini`` [portal] section:
107
108 .. code-block:: ini
109
110 [portal]
111 notificationsMaxRetrieve = 3
112
113 Usage
114 ^^^^^
115
116 When enabled, ``/mynotifications`` URL path is handled by this plugin.
117
118 Known issue
119 ^^^^^^^^^^^
120
121 An XML document can contain several notifications messages. Just the
122 first one can be searched and displayed!
123
124
125 .. attention::
126
127 Listed notifications are extracted from users
128 persistent session (notification reference and accepted date). ONLY the
129 notifications explorer can found in notifications backend are available
130 to be displayed. Notifications content (title, subtitle and so on...) is
131 not stored into persistent session.
132
133 Storage
134 ~~~~~~~
135
136 By default, notifications will be stored in the same database as
137 configuration:
138
139 - if you use "File" system and your "dirName" is set to
140 /usr/local/lemonldap-ng/conf/, the notifications will be stored in
141 /usr/local/lemonldap-ng/notifications/
142 - if you use "CDBI" or "RDBI" system, the notifications will be stored
143 in the same database as configuration and in a table named
144 "notifications".
145 - if you use "LDAP" system, the notifications will be stored in the
146 same directory as configuration and in a branch named
147 "notifications".
148
149 You can change default parameters using the "notificationStorage" and
150 "notificationStorageOptions" parameters with the same syntax as
151 configuration storage parameters. To do this in Manager, go in General
152 Parameters > Plugins > Notifications.
153
154 File
155 ^^^^
156
157 Parameters for File backend are the same as
158 :doc:`File configuration backend<fileconfbackend>`.
159
160
161 .. attention::
162
163 You need to create yourself the directory and set write
164 access to Apache user. For example:
165
166 ::
167
168 mkdir /usr/local/lemonldap-ng/notifications/
169 chown www-data /usr/local/lemonldap-ng/notifications/
170
171
172
173
174 .. tip::
175
176 The file name default separator is ``_``, this can be a
177 problem if you register notifications for users having ``_`` in their
178 login. You can change the separator with the ``fileNameSeparator``
179 option, and set another value, for example ``@``.
180
181 To summary available options:
182
183 - **dirName**: directory where notifications are stored.
184 - **fileNameSeparator**: file name separator.
185
186 DBI
187 ^^^
188
189 Parameters for DBI backend are the same as
190 :doc:`DBI configuration backend<sqlconfbackend>`.
191
192 You can find the database schema in ``/usr/share/lemonldap-ng/ressources/notifications.*.sql``.
193
194 To summary available options:
195
196 - **dbiChain**: DBI connection.
197 - **dbiUser**: DBI user.
198 - **dbiPassword**: DBI password.
199 - **dbiTable**: Notifications table name.
200
201 .. note::
202
203 DBI configuration example:
204
205 ::
206
207 notificationStorage = DBI
208 notificationStorageOptions={ \
209 'dbiChain' => 'DBI:Pg:dbname=llng;host=mydb;port=5432', \
210 'dbiTable' => 'notifications', \
211 'dbiUser' => 'user', \
212 'dbiPassword' => 'qwerty', \
213 }
214
215 LDAP
216 ^^^^
217
218 Parameters for LDAP backend are the same as
219 :doc:`LDAP configuration backend<ldapconfbackend>`.
220
221
222 .. attention::
223
224 You have to create the branch by yourself
225
226 To summary available options:
227
228 - **ldapServer**: LDAP URL.
229 - **ldapBindDN**: LDAP user.
230 - **ldapBindPassword**: LDAP password.
231 - **ldapConfBase**: Notifications branch DN.
232
233 .. note::
234
235 LDAP configuration example:
236
237 ::
238
239 notificationStorage = LDAP
240 notificationStorageOptions={ \
241 'ldapServer' => 'ldap://localhost', \
242 'ldapBindDN' => 'cn=manager,dc=example,dc=com', \
243 'ldapBindPassword' => 'secret', \
244 'ldapConfBase' => 'ou=notifications,ou=applications,dc=example,dc=com', \
245 }
246
247
248 Wildcard
249 ~~~~~~~~
250
251 The notifications module uses a wildcard to manage notifications for all
252 users. The default value of this wildcard is ``allusers``, but you can
253 change it if ``allusers`` is a known identifier in your system.
254
255 To change it, go in General Parameters > Plugins >
256 Notifications > Wildcard for all users, and set for example
257 ``alluserscustom``.
258
259 Then creating a notification for ``alluserscustom`` will display the
260 notification for all users.
261
262 Using notification system
263 -------------------------
264
265
266 .. attention::
267
268 Since version 2.0, notifications are now stored in JSON
269 format. If you want to keep old format, select "use old format" in the
270 Manager. Note that notification server depends on chosen format: REST
271 for JSON and SOAP for XML.
272
273 Notification format
274 ~~~~~~~~~~~~~~~~~~~
275
276 Notifications are JSON (default) or XML files containing:
277
278 - <notification> element(s) :
279
280 - Required attributes:
281
282 - date: creation date (format YYYY-MM-DD WITHOUT time!)
283 - ref: a reference that can be used later to know what has been
284 notified and when (Avoid ``_`` character)
285 - uid: the user login (it must correspond to the attribute set in
286 whatToTrace parameter, uid by default), or the wildcard string
287 (by default: ``allusers``) if the notification should be
288 displayed for every user.
289
290 - Optional attributes:
291
292 - condition: condition to display the notification, can use all
293 session variables.
294
295 - Sub elements:
296
297 - <title>: title to display: will be inserted in HTML page
298 enclosed in <h2 class="notifText">...</h2>
299 - <subtitle>: subtitle to display: will be inserted in HTML page
300 enclosed in <h2 class="notifText">...</h2>
301 - <text>: paragraph to display: will be inserted in HTML page
302 enclosed in <p class="notifText">...</p>
303 - <check>: paragraph to display with a checkbox: will be inserted
304 in HTML page enclosed in <p class="notifCheck"><input
305 type="checkbox" />...</p>
306
307
308 .. attention::
309
310 All other elements will be removed including HTML
311 elements like <b>.
312
313
314 .. tip::
315
316 One notification XML document can contain several
317 notifications messages.
318
319 Several notifications can be inserted with a single request by using an
320 array of JSON (Tested with an array of 10,000 elements)
321
322 Variables
323 ^^^^^^^^^
324
325 .. versionadded:: 2.21.0
326 You can use session variables in notifications's ``text`` field by using the ``$varname`` syntax.
327 Note that complex Perl expressions are not allowed, only simple variable interpolation.
328 This feature is only available when using JSON notifications.
329
330
331 Examples
332 ^^^^^^^^
333
334 JSON
335 ''''
336
337 .. code::
338
339 [{
340 "uid": "foo",
341 "date": "2009-01-27",
342 "reference": "ABC",
343 "title": "You have new authorizations",
344 "subtitle": "Application 1",
345 "text": "You have been granted to access to appli-1",
346 # An array is required to set multi checkboxes
347 "check": [
348 "I agree",
349 "Yes, I'm sure"
350 ]
351 },
352 {
353 "uid": "bar",
354 "date": "2009-01-27",
355 "reference": "ABC",
356 "title": "You have new authorizations",
357 "subtitle": "Application 1",
358 "text": "You have been granted to access to appli-1",
359 "check": "I agree"
360 }] # No comma at the end
361
362
363 .. tip::
364
365 JSON format notifications are displayed sorted by date and
366 reference
367
368 XML
369 '''
370
371 .. code-block:: xml
372
373 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
374 <root>
375 <notification uid="foo.bar" date="2009-01-27" reference="ABC">
376 <title>You have new authorizations</title>
377 <subtitle>Application 1</subtitle>
378 <text>You have been granted to access to appli-1</text>
379 <subtitle>Application 2</subtitle>
380 <text>You have been granted to access to appli-2</text>
381 <subtitle>Acceptation</subtitle>
382 <check>I know that I can access to appli-1 </check>
383 <check>I know that I can access to appli-2 </check>
384 </notification>
385 <notification uid="allusers" date="2009-01-27" reference="disclaimer" condition="$ipAddr =~ /^192/">
386 <title>This is your first access on this system</title>
387 <text>Be a nice user and do not break it please.</text>
388 <check>Of course I am not evil!</check>
389 </notification>
390 </root>
391
392 Create new notifications with notifications explorer
393 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394
395 In Manager, click on ``Notifications`` and then on the ``Create``
396 button.
397
398 |image0|
399
400 Then fill all inputs to create the notification. Only the condition is
401 not mandatory.
402
403 When all is ok, click on ``Save``.
404
405 Notification server
406 ~~~~~~~~~~~~~~~~~~~
407
408 LemonLDAP::NG provides two notification servers : SOAP and REST
409 depending on format.
410
411 If enabled, the server URL is https://auth.your.domain/notifications.
412
413 Notification server provides three API to insert (POST), delete (DELETE)
414 or list (GET) notification(s).
415
416 Available options:
417
418 - **Server**: Enable/Disable notification server
419 - **Default condition**: Condition appended to ALL notifications
420 inserted by notification server (JSON format only)
421 - **Notification parameters to send**: Notifications parameters
422 returned by ``GET`` method
423 - **HTTP methods**: Enable/Disable HTTP methods
424
425
426 .. attention::
427
428 If notification server is enabled, you have to protect
429 this URL by using the web server because there is no authentication
430 required to use it.
431
432 Example:
433
434 .. code::
435
436 # REST/SOAP functions for insert/delete/list notifications (disabled by default)
437 <LocationMatch ^/(index\.fcgi/)?notifications>
438 <IfVersion >= 2.3>
439 Require ip 192.168.2.0/24
440 </IfVersion>
441 <IfVersion < 2.3>
442 Order Deny,Allow
443 Deny from all
444 Allow from 192.168.2.0/24
445 </IfVersion>
446 </LocationMatch>
447
448 XML notifications through SOAP
449 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
450
451 If you use old XML format, new notifications can be inserted or deleted
452 by using SOAP request, once SOAP is activated:
453
454 \* Insertion example in Perl
455 ''''''''''''''''''''''''''''
456
457 .. code-block:: perl
458
459 #!/usr/bin/perl
460
461 use SOAP::Lite;
462 use utf8;
463
464 my $lite = SOAP::Lite
465 ->uri('urn:Lemonldap::NG::Common::PSGI::SOAPService')
466 ->proxy('http://auth.example.com/notifications');
467
468
469 $r = $lite->newNotification(
470 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
471 <root>
472 <notification uid="foo.bar" date="2009-01-27" reference="ABC">
473 <text> You have been granted to access to appli-1 </text>
474 <text> You have been granted to access to appli-2 </text>
475 <check> I know that I can access to appli-1 </check>
476 <check> I know that I can access to appli-2 </check>
477 </notification>
478 </root>
479 ');
480
481 if ( $r->fault ) {
482 print STDERR "SOAP Error: " . $r->fault->{faultstring};
483 }
484 else {
485 my $res = $r->result();
486 print "$res notification(s) have been inserted\n";
487 }
488
489 \* Deletion example in Perl
490 '''''''''''''''''''''''''''
491
492 .. code-block:: perl
493
494 #!/usr/bin/perl
495
496 use SOAP::Lite;
497 use utf8;
498
499 my $lite = SOAP::Lite
500 ->uri('urn:Lemonldap::NG::Common::CGI::SOAPService')
501 ->proxy('http://auth.example.com/index.pl/notification');
502
503
504 $r = $lite->deleteNotification('foo.bar', 'ABC');
505
506 if ( $r->fault ) {
507 print STDERR "SOAP Error: " . $r->fault->{faultstring};
508 }
509 else {
510 my $res = $r->result();
511 print "$res notification(s) have been deleted\n";
512 }
513
514 JSON notifications through REST
515 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
516
517 Insertion example with REST API
518 '''''''''''''''''''''''''''''''
519
520 Using JSON, you just have to POST json files.
521
522 For example with curl:
523
524 ::
525
526 curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d @notif.json http://auth.example.com/notifications
527
528 Deletion example with REST API
529 ''''''''''''''''''''''''''''''
530
531 DELETE API is available with LLNG ≥ 2.0.6
532
533 For example with curl:
534
535 ::
536
537 curl -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>/<reference>
538
539 List example with REST API
540 ''''''''''''''''''''''''''
541
542 GET API is available with LLNG ≥ 2.0.6
543
544 For example with curl:
545
546 ::
547
548 # Retrieve 'wildcard' notifications
549 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications
550
551 # Retrieve all pending notifications
552 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/_allPending_
553
554 # Retrieve all existing notifications
555 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/_allExisting_
556
557 # Retrieve all <uid>'s notifications
558 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>
559
560 # Retrieve <uid>/<reference> notification parameters
561 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>/<reference>
562
563 Test notification
564 ~~~~~~~~~~~~~~~~~
565
566 You've just to insert a notification and connect to the portal using the
567 same UID. You will be prompted.
568
569 |image1|
570
571 Try also to create a global notification (to the uid "allusers"), and
572 connect with any user, the message will be prompted.
573
574 .. |image0| image:: /documentation/manager-notification.png
575 :class: align-center
576 .. |image1| image:: /documentation/portal-notification.png
577 :class: align-center
578
579
580 JSON response
581 ~~~~~~~~~~~~~
582
583 If a notification is pending, JSON response fields are:
584
585 - ``result``: ``0``
586 - ``error``: ``36``
587 - ``ciphered_id``: a ciphered session id is returned in this field.
588 This id can be used to forward and continue the notification process if you call the REST ``/notifback`` endpoint
589 with a LL::NG cookie built with this id.