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 Require ip 192.168.2.0/24
439 </LocationMatch>
440
441 XML notifications through SOAP
442 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
443
444 If you use old XML format, new notifications can be inserted or deleted
445 by using SOAP request, once SOAP is activated:
446
447 \* Insertion example in Perl
448 ''''''''''''''''''''''''''''
449
450 .. code-block:: perl
451
452 #!/usr/bin/perl
453
454 use SOAP::Lite;
455 use utf8;
456
457 my $lite = SOAP::Lite
458 ->uri('urn:Lemonldap::NG::Common::PSGI::SOAPService')
459 ->proxy('http://auth.example.com/notifications');
460
461
462 $r = $lite->newNotification(
463 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
464 <root>
465 <notification uid="foo.bar" date="2009-01-27" reference="ABC">
466 <text> You have been granted to access to appli-1 </text>
467 <text> You have been granted to access to appli-2 </text>
468 <check> I know that I can access to appli-1 </check>
469 <check> I know that I can access to appli-2 </check>
470 </notification>
471 </root>
472 ');
473
474 if ( $r->fault ) {
475 print STDERR "SOAP Error: " . $r->fault->{faultstring};
476 }
477 else {
478 my $res = $r->result();
479 print "$res notification(s) have been inserted\n";
480 }
481
482 \* Deletion example in Perl
483 '''''''''''''''''''''''''''
484
485 .. code-block:: perl
486
487 #!/usr/bin/perl
488
489 use SOAP::Lite;
490 use utf8;
491
492 my $lite = SOAP::Lite
493 ->uri('urn:Lemonldap::NG::Common::CGI::SOAPService')
494 ->proxy('http://auth.example.com/index.pl/notification');
495
496
497 $r = $lite->deleteNotification('foo.bar', 'ABC');
498
499 if ( $r->fault ) {
500 print STDERR "SOAP Error: " . $r->fault->{faultstring};
501 }
502 else {
503 my $res = $r->result();
504 print "$res notification(s) have been deleted\n";
505 }
506
507 JSON notifications through REST
508 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
509
510 Insertion example with REST API
511 '''''''''''''''''''''''''''''''
512
513 Using JSON, you just have to POST json files.
514
515 For example with curl:
516
517 ::
518
519 curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d @notif.json http://auth.example.com/notifications
520
521 Deletion example with REST API
522 ''''''''''''''''''''''''''''''
523
524 DELETE API is available with LLNG ≥ 2.0.6
525
526 For example with curl:
527
528 ::
529
530 curl -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>/<reference>
531
532 List example with REST API
533 ''''''''''''''''''''''''''
534
535 GET API is available with LLNG ≥ 2.0.6
536
537 For example with curl:
538
539 ::
540
541 # Retrieve 'wildcard' notifications
542 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications
543
544 # Retrieve all pending notifications
545 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/_allPending_
546
547 # Retrieve all existing notifications
548 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/_allExisting_
549
550 # Retrieve all <uid>'s notifications
551 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>
552
553 # Retrieve <uid>/<reference> notification parameters
554 curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" http://auth.example.com/notifications/<uid>/<reference>
555
556 Test notification
557 ~~~~~~~~~~~~~~~~~
558
559 You've just to insert a notification and connect to the portal using the
560 same UID. You will be prompted.
561
562 |image1|
563
564 Try also to create a global notification (to the uid "allusers"), and
565 connect with any user, the message will be prompted.
566
567 .. |image0| image:: /documentation/manager-notification.png
568 :class: align-center
569 .. |image1| image:: /documentation/portal-notification.png
570 :class: align-center
571
572
573 JSON response
574 ~~~~~~~~~~~~~
575
576 If a notification is pending, JSON response fields are:
577
578 - ``result``: ``0``
579 - ``error``: ``36``
580 - ``ciphered_id``: a ciphered session id is returned in this field.
581 This id can be used to forward and continue the notification process if you call the REST ``/notifback`` endpoint
582 with a LL::NG cookie built with this id.