Taiga 1274 (24976) Updated guided reports process
[kohadocs.git] / source / apis_protocols.rst
1 .. include:: images.rst
2
3 .. _other-apis-protocols-label:
4
5 Other APIs and protocols
6 =============================
7
8 .. _sip2-label:
9
10 SIP2
11 -----------------------------
12
13 SIP2 (Session Initiation Protocol) is a protocol for communication between devices.
14
15 In the context of Koha SIP2 is used for communication between Self Check (SC) machines i.e. self checkout machines, and the Automated Circulation System (also known as ACS which in this case is the server running Koha).
16
17 SIP2 communications consist of requests and responses.
18
19 The self checkout machines are ‘dumb’ and so they send requests to the Koha server which runs logic which determines a particular outcome which is sent as a response message back to the client self checkout machine, and this is then conveyed to the user.
20
21 .. warning:: Security notice regarding using SIP2 service:
22              To ensure that your SIP2 traffic is secure as it passes over the internet you need to make sure that you are using a VPN or stunnel.
23
24 .. _setting-up-sip2-label:
25
26 Setting up SIP2
27 ~~~~~~~~~~~~~~~
28
29 If you installed Koha using Debian packages then SIP2 setup is easy, simply follow these steps:
30
31 1. In your terminal (in the root Koha directory) write in:
32 *sudo koha-enable-sip <instancename>*
33
34 2. Now you need to configure the SIP2 settings, to do this you need to edit the SIPconfig.xml file which exists in the /etc/koha/sites/<instancename>/ directory.
35 You will need to edit this file as root because it contains passwords (to do so write ‘sudo’  at the start of your command).
36
37 e.g.
38 *sudo vi /etc/koha/sites/<instancename>/SIPconfig.xml*
39
40 .. note:: Important note: There are three areas of interest in the SIPconfig.xml file that you need to change. These are: service, account and institution.
41
42 **Service**
43
44         2.1 Change the port value near the top of the SIPconfig.xml file (identified by the number 1 in the below screen shot), so it has the same IP address as set further down the SIPconfig.xml file identified by 2.
45
46         .. note:: Make sure the two port values don’t have the same port number as you cannot have the same port being listened to by two different services. When deciding upon the port number make sure it is a high number (i.e. above 1000) because all ports below 1000 require root permissions.
47
48 |image1122|
49
50 **Account**
51
52 The account(s) you define in the SIPconfig.xml file are simply account(s) permitted to use the SIP2 service i.e. you're defining who can send and receive SIP2 commands.
53
54         .. warning:: Account information that you write here must also exist in the Koha database i.e. you need to create a patron in the Koha staff interface with the same username, password (making sure to assign them circulate permissions) as the user account you write into the SIPconfig.xml file.
55
56         .. note:: It is highly recommended that you only write in Koha user accounts with circulate permissions.
57
58                                 The reason we want SIP2 users to only have circulate permissions rather than superlibrarian permissions is to reduce the access SIP2 users have to confidential patron data in case the system was compromised.
59
60                                 If the ACS or the SC were compromised then having all SIP2 users only having circulation permissions means that an intruder would only be able to access patron data via the terminal rather than the web interface as well (which would be available with superlibrarian permissions). So it is simply a matter of protecting your users.
61
62 |image1119|
63
64 **Account value definitions:**
65
66 1. Login id: This is the account username. - Modify this accordingly
67 2. Password: Account password - Modify this accordingly
68 3. Delimiter: The type of delimiter for account information - Leave as default
69 4. error-detect -  Leave as default
70 5. Institution: This is the branchcode for the library that the user belongs to. NOTE: This institution needs to be defined further down in the institution area of the SIPconfig.xml file and it must also exist in the Koha database. i.e. you need to create a library with the same branchcode in Koha staff interface.
71 6. encoding: This is the standard used to encode the account data
72 7.  Terminator: This needs to match the terminator value of the SIP2 server. - Modify this if you know the terminator value of the SIP2 server.
73
74 It is also possible to add custom patron attributes to SIP2 profiles using the format such as:
75
76     <patron_attribute field="XX" code="CODE1" />
77     <patron_attribute field="XY" code="CODE2" />
78     <patron_attribute field="XZ" code="CODE3" />
79
80 **Institution**
81
82         The institution information you define here must match a library created in the Koha staff interface.
83
84         .. warning:: You need to make sure all the institutions that accounts are assigned to further up in the SIPconfig.xml file are also defined in the institution area of the same file.
85
86 |image1120|
87
88 **Institution value definitions:**
89
90         1. Institution id: The branchcode of the library. - Modify this accordingly.
91         Must be the same as created in Koha and the account area.
92
93 2. Implementation: Defines the code that will be run. - Leave as default
94
95  3. Policy: Policy defines the permitted SIP2 commands allowed from SC’s in this institution.
96  For example: renewal=”true” means that SC’s at that institution have permission to send renewal item SIP2 commands.
97
98  4. Starting SIP2
99  Simply write in the command:
100  *sudo koha-start-sip <instancename>*
101
102 .. note:: Now you have a running SIP2 server.
103
104 .. _using-sip2-label:
105
106 Using SIP2
107 ~~~~~~~~~~
108
109 SIP2 is a communication protocol. The messages sent in SIP2 are either requests or responses. The SC’s send request messages to the ACS which will run some logic and send back the resulting value to the SC as a response message.
110
111 The request messages contain arguments, which are data values used by the ACS in its functions to perform the required task such as renewing items.
112
113 **SIP2 commands**
114
115 If you want to manually use/test SIP2 then you will be writing and receiving messages via the Linux terminal.
116
117 To be able to send and receive messages with the SIP2 server you need to use telnet to open a SIP2 connection. You need to specify the port number you want telnet to use.
118
119 To find this information look at the service area at the top of the SIPconfig.xml file (look for the port number as pointed out by the arrow in the below screenshot).
120
121 |image1121|
122
123 1. Write into the terminal
124
125    *telnet localhost <portnumber>*
126
127    e.g. *telnet localhost 8023*
128
129 2. Now write in the username and password set in one of the accounts in the     SIPconfig.xml file.
130
131 3. Now you are connected to the SIP2 server you can start writing and sending request commands. The connection to the SIP2 server does time out fast so if haven’t finished writing and receiving commands simply write in:
132
133    *telnet localhost <portnumber>*
134
135    to restart the SIP2 connection.
136
137 **SIP2 command syntax**
138
139 Every SIP2 command has a 2 digit numerical prefix which defines what the command is doing.
140
141 e.g. To get information about a patron you start your command with the prefix: 63. The response from the server also has a corresponding numerical prefix.
142
143 Below is an example of a SIP2 request message to request patron information (in this example a Koha patron account with the user name ‘joe’, password ‘joes’, and card number ‘y76t5r43’ has been created in the Koha staff interface).
144
145 Additionally a library with the branchcode of ‘WEL’ has been created in the Koha staff interface and is also defined in the institution area of the SIPconfig.xml file):
146
147 |image1123|
148
149 So the format of this SIP2 request message is:
150
151 |image1124|
152
153 .. note:: The summary value is a 10 character value. If a Y is written in for the summary value then you will be able to get both a summary and more detailed informational output.
154
155 The value in the <YYYYMMDD> <HHMMSS> is the current datetime, by leaving a 4 space gap between the YYYYMMDD and HHMMSS this indicates you want to use local time rather than UTC.
156
157 .. note:: In this manual letter codes for the various fields are used where possible in describing the SIP2 message fields e.g. AO<institutionid>.
158
159                                         These letter codes can be written in the SIP2 commands into the Linux terminal, but make sure when substituting values in for the fields (values inside the <>) that you do not write in the <> brackets.
160
161 **SIP2 messages:**
162
163 **Block patron**
164
165 This uses the prefix 01 for request messages and 24 for response messages.
166
167 Request message:
168
169 |image1125|
170
171 .. note:: Card retained is a single character field of either ‘Y’ or ‘N’  which tells the ACS that a card has been retained by the self checkout machine.
172
173 Response message:
174
175 |image1126|
176
177 .. note:: <patronstatus> is a 14 character long value. The value Y in the string means true. Each position in this string (starting at 0) has a single corresponding value (Y or N) in the string.
178
179                                         e.g. a Y at position 1 (the second value in the string) means that the patrons renewal privileges are denied.
180
181 **Check-in items**
182
183 This uses the request message (messages sent to the ACS) prefix of 09 and the response prefix of 10 (sent to the SC).
184
185 Request message:
186
187 |image1127|
188
189 .. note:: * <no block (Offline)> is a single character field of either ‘Y’ or ‘N’ which indicates if the transaction is being performed offline. As offline transactions are not supported you need to write ‘N’ if you are testing this message out manually.
190
191                                         * <transactiondate> this is a 18 character field with the date is the format: YYYYMMDDZZZZHHMMSS.
192
193                                         ZZZZ is the timezone, if you want to set it to local you need to leave 4 blank spaces, but if you want to set it to the UTC (Coordinated Universal Time) then you need to write in 3 blank spaces and a Z.
194
195 Response message:
196
197 |image1128|
198
199 .. note:: Alert type could have one of several values:
200         00 : Unknown
201         01: local hold
202         02: remote hold
203         03: ILL Transfer
204         04: transfer
205         99: Other
206
207 If an item is resensitized then the value of <resentitize> should be Y otherwise it should be N. Rensensitizing items is done to ensure that if someone tries to steal the item they are detected.
208
209 **Checkout items**
210
211 This uses the request message prefix of 11 and the response message prefix of 12.
212 It has similar syntax to the check-in command, outlined above except the prefixes are different.
213
214 **Hold** – May not yet be supported on some systems. This has a request message numerical prefix of 15 and a response message prefix of 16.
215
216 Request message:
217
218 |image1129|
219
220 .. note:: <holdmode> is a single character value. + means add a hold, - means delete a hold and * means change a hold.
221
222 Response message:
223
224 |image1130|
225
226 .. note:: * <ok> is a single length value which is either 0 (for hold is not permitted or was not successful) or 1 (for hold is permitted and was successful).
227
228                                         * <available> is a single length value which is either Y or N. Y means the item is currently in the library, whilst N means the item is currently on loan/someone else has created a hold on the item.
229
230 **Item information: This uses the request command prefix of 17, and the response command prefix of 18**
231
232 Request message:
233
234 |image1131|
235
236 .. note:: See the check-in items command (described above) to find out what the <xact_date> value is.
237
238                                         The terminal password is optional.
239
240 Response message:
241
242 |image1132|
243
244 **Item status update  This uses the request message prefix of 19 and the response message prefix of 20**
245
246 Request message:
247
248 |image1133|
249
250 .. note:: <itemproperties> is not a fixed length value, and you can optionally write in values such as item size and these values will be stored in the Koha database for the item.
251
252 Response message:
253
254 |image1134|
255
256 .. note:: <itempropertiesok> is a single length character value which is either 0 or 1. 1 identifies that the <itemproperties> value defined in the item status update request message was successfully stored in the Koha database.
257
258 **Patron status**
259
260 This uses the request message prefix 23 and the response message prefix of 24.
261
262 Request message:
263
264 |image1135|
265
266 Response message:
267
268 |image1136|
269
270 .. note:: The value displayed for <patronvalidity> is Y (valid) and N (invalid)
271                                         The value in the <YYYYMMDD>    < HHMMSS> is the current date/time.
272
273                                         The reason for the gap between the two values is to define that you want to use localtime rather than UTC.
274
275 **Patron enable - This is not yet supported. This uses the request message prefix of 25 and the response message prefix of 26**
276
277 .. note:: This command undoes the block patron command.
278
279 Request message:
280
281 |image1137|
282
283 Response message:
284
285 |image1138|
286
287 **Renew This uses the request message prefix of 29 and the response message prefix of 30**
288
289 Request message:
290
291 |image1139|
292
293 .. note:: * <thirdpartyallowed> is  a single character value which is either Y or N. If it is Y then third parties can renew items.
294
295                                         * <noblock> is a single character value which is either Y or N. If it is Y then this means that the item was checkin/out when the ACS was offline.
296
297                                         * <nbduedate> is the transaction date of checkin/checkout when the ACS was offline.
298
299                                         * <feeacknowledged> is a single character value which is either Y or N. This indicates if the user accepts the fee associated with the item they are renewing.
300
301 Response message:
302
303 |image1140|
304
305 .. note:: * <ok> is a single character value which is either 0 or 1. A value of 1 means the item was successfully renewed, 0 means item was not successfully renewed.
306
307                                         * <renewalok> is a single character value which is either Y or N. The logic for the setting of the value of <renewalok> is Y is set when the item is already checkout by the user and so it should be desensitized thereby renewing it, whereas N is set if the item is not already checkout to the patron and so it should not be renewed.
308
309                                         In other words don’t let patrons renew books when they are not currently checked out to them.
310
311                                         * <magneticmedia> is a single character value which is either Y (for yes), N ( for no), or U (for unknown).
312
313                                         * <mediatype> is a three numerical character long value. For a list of the values go to: http://multimedia.3m.com/mws/media/355361O/sip2-protocol.pdf
314
315 **End session**
316
317 This uses the request message prefix of 35 and the response message prefix of 36
318
319 Request message:
320
321 |image1141|
322
323 Response message:
324
325 |image1142|
326
327 .. note:: <success_or_failure> is either Y for success or N for failure.
328
329 **Fee Paid – May not be implemented yet. This uses a request message prefix of 37 and a response message prefix of 38**
330
331 Request message:
332
333 |image1143|
334
335 .. note:: * <feetype> is a two numerical character value which is between 01 and 99. To see a list of fee type values go to http://multimedia.3m.com/mws/media/355361O/sip2-protocol.pdf
336
337                                         * <paymenttype> is a two character numerical value between 00 and 99. 00 is cash, 01 is Visa, and 02 is credit card.
338
339                                         * <currencytype> is a 3 alphanumeric character long value identifying the currency the fee paid was in.
340
341 Response message:
342
343 |image1144|
344
345 .. note:: <paymentaccepted> is a single alphanumeric character long value which is either Y (payment has been accepted) or N (payment has not been accepted).
346
347 **Patron information**
348
349 This uses the request message prefix of 63 and the response message prefix of 64
350
351 Request message:
352
353 |image1145|
354
355 Response message:
356
357 |image1146|
358
359 .. note::  <valid patron> is Y for valid and N for not valid.
360
361 .. note::  <hold itemcount><overdueitemcount><chargeditemscount><fienitemscount><recallitemscount><unavaliableholdscount> are all 4 numerical character long values.
362
363 **Renew all**
364
365 This uses the request message prefix of 65 and the  response message prefix of 66.
366
367 Request message:
368
369 |image1147|
370
371 Response message:
372
373 |image1148|
374
375 .. note:: * <renewedcount> is a 4 numerical character long value denoting the number of items that were renewed.
376
377                                         * <unrenewedcount>, has the same format as the <renewedcount> but it denotes the number of items not renewed.
378
379 **Login**
380
381 This uses the request message prefix of 93, and the response message prefix of 94.
382
383 Request message:
384
385 |image1149|
386
387 .. note:: <UIDalgorithm> and <PWDalgorithm> are one character long values indicating the type of algorithm to use to encrypt the loginuserid and loginpassword respectively.
388
389                                         Writing in the value of 0 means these values will not be encrypted.
390
391 Response message:
392 *941* is a successful login.
393 *940* is an unsuccessful login
394 *[connection closed by foreign host.]* is a unsuccessful login
395
396 **Resend**
397
398 This requests the receiving device to resend its last message.
399
400 SC -> ACS resend request is *97*
401
402 ACS -> SC resend request is *96*
403
404 **Status of the ACS and SC**
405
406 This has the request message prefix of 99 and the response message prefix of 98.
407
408 Request message:
409
410 |image1150|
411
412 .. note:: The status code is one of 3 values.
413                                         * 0: SC is ok
414                                         * 1: SC is out of paper
415                                         * 2: SC is shutting down
416                                         max print width is a 3 character long value which is the integer number of characters the client can print
417                                         Protocol version is a 4 character value in the format x.xx
418
419 Response message:
420
421 |image1151|
422
423 .. note:: If you get the response message ‘96’ this means that the request message is not valid/understood.
424
425 **Troubleshooting SIP2**
426
427 Can’t connect to remote host when writing in the command telnet localhost <portnumber>
428
429 3 solutions for this issue to try are:
430
431         1. Check the portnumber your writing in the above command is the port number written in the SIPconfig.xml file at the location indicated by the number 1. i.e. in the below example because the portnumber is 6001 the correct command would be: telnet localhost 6001.
432
433         2. Check if any userid is written more than once in the SIPconfig.xml file. The userid (which is simply the username of the Koha user) needs to be unique within the SIPconfig.xml file. If you have the same userid multiple times in your SIPconfig.xml file this will cause the connection to SIP2 to fail before you get a chance to authenticate.
434
435         3. Check the account defined in the SIPconfig.xml file also exists in the Koha database with the same username, password and has circulate permissions. If you have dropped and recreated the Koha database after creating the patron account in the Koha staff interface and the SIPconfig.xml file then that patron account will not exist in the Koha database and so you will need to recreate them in the Koha staff interface.
436
437 To access the SIP2 logs in your Koha home directory navigate to the following directory:
438 /var/log/koha/<instancename>
439
440 Then view the output of the sip-error.log and the sip-output.log files which give more detailed information about the SIP2 error.
441
442 * cat sip-error.log
443 * cat sip-output.log
444
445 **Useful links on SIP2 commands:**
446
447 http://multimedia.3m.com/mws/media/355361O/sip2-protocol.pdf
448
449 .. _ldap-label:
450
451 LDAP
452 -----------------------------
453
454 Setting up LDAP (Lightweight Directory Access Protocol) for Koha allows you to store all user information in a central database which is accessed both by your organisations Koha instance and for users to authenticate on other existing systems.
455
456 LDAP is a protocol used for file discovery over networks and network authentication.
457
458 LDAP configurations are powerful allowing you to customise how Koha and LDAP interact. LDAP  can be configured so that new accounts created in LDAP can be synced down into the Koha database, additionally updates to the LDAP user account are synced down to the Koha database.
459
460 However Koha cannot sync data up to the LDAP server, thus the data traffic when using LDAP is only one directional.
461
462 Auth_By_Bind is set to 1 where a Microsoft Windows Active Directory system is in use in the LDAP database.
463
464 **Before going through the steps to configure LDAP you will need the following
465 information/actions from the organisation**
466
467 * The organisation will need to open a port to allow access to their AD from the server.
468
469 * Information on the access to the AD server (IP address/hostname, port, SSL info)
470
471 * Information on the configuration of the AD server (relevant OUs, DCs, CN formats relative to usernames)
472
473 * Mapping between AD fields and Koha fields, including defaults
474
475 * Default values for things not provided by AD (categorycode, branchcode for example)
476
477 * To authenticate a user do we bind as them (seems to be common for AD) or do we use an account and login with that and then check? If the latter, we'll need details of how to log in
478
479 * Do the existing usernames in Koha match the usernames that we'll be using to look them up in AD? If so, good. If not, how will we deal with duplicate users?
480
481 **Steps to set up LDAP with your Koha instance**
482
483 1 In Linux terminal navigate to the directory containing the koha-conf.xml file which will either be in:
484 * /etc/koha/sites/<instance-name>/
485 OR
486 *  /etc/koha/
487
488 2 Open the koha-conf.xml file with root permissions:
489 sudo vi koha-conf.xml
490
491 3 Scroll down to the line containing ‘<useldapserver>0</useldapserver>’ and change it to:
492 <useldapserver>1</useldapserver>
493
494 4 Then in the next line below write in the LDAP configurations below: Note all fields highlighted in yellow need to be replaced with the appropriate values for your organisations LDAP server.
495
496 ::
497
498         <ldapserver id="<ldapserverid>">
499
500         <hostname><hostname></hostname>
501
502         <base>dc=<domaincontroller>,dc=<domaincontroller></base>
503
504         <user>cn=<nameofuser>, dc=<domaincontroller>,dc=<domaincontroller></user> <!--This is the username of user account with permissions to query the LDAP server -->
505
506         <pass><password></pass> <!-- This is password of the user account with permissions  to query the LDAP server-->
507
508         <replicate><either0or1></replicate> <!-- add new users from LDAP to Koha database -->
509
510         <update><either0or1></update> <!-- update existing users in Koha database -->
511
512         <auth_by_bind><either0or1></auth_by_bind> <!-- set to 1 to authenticate by binding instead of password comparison, e.g., to use Active Directory -->
513
514         <principal_name><principalname></principal_name> <!-- optional, for     auth_by_bind: a printf format to make userPrincipalName from koha userid        -->
515
516         <mapping> <!-- match koha SQL field names to your LDAP record field names-->
517
518         <firstname is="givenname"></firstname>
519
520         <surname is="sn"></surname>
521
522         <address is="postaladdress"></address>
523
524         <city is="l">Athens, OH</city>    <!-- Athens,OH is the default value for
525         city of all users logging into Koha -->
526
527         <zipcode is="postalcode"></zipcode>
528
529         <branchcode is="branch">Central</branchcode>
530
531         <userid is="uid"></userid>
532
533         <password is="userpassword"></password>
534
535         <email is="mail"></email>
536
537         <categorycode is="employeetype">EM</categorycode>
538
539         <phone is="telephonenumber"></phone>
540
541         </mapping>
542
543         </ldapserver>
544
545 5 Save and exit the koha-conf.xml file
546
547 6 Check the LDAP connection works by writing in:
548
549 ldapsearch -H ldaps://host.name  -s base -x  -w "" -d 1
550
551 .. note:: Note about hostname
552                                         Hostname can either be a alphanumerical name or it can be the LDAP server IP address (its optional to write port number). By default the ldaps default port number is 636, whilst ldap default port number is 389
553
554 .. note:: Note about the replicate and update fields
555                                         The replicate  LDAP config field for LDAP in the koha-conf.xml file allow the Koha database to be added to with a new borrower account whenever a user logs into Koha (either the staff client or OPAC) with their LDAP username and password (assuming the same username and password does not already exist in the Koha database).
556
557                                         Whereas the update LDAP config field (in the same file allows) allows for user information in the LDAP database to be synced down to the Koha database.
558                                         e.g. if someone gets married and their surname changes then the new surname only needs to       be updated in the existing LDAP database and that will be synced down to the Koha       database automatically if the update configuration is set to 1.
559
560 About the mapping fields (the fields highlighted green)
561 <city is="l">Athens, OH</city>
562
563 The left hand column name (highlighted yellow) is the name of the column in the LDAP database.
564
565 The column name inside quote marks (highlighted pink) is the name of the column in the Koha database. NOTE: This can be filled with any value if there is no equivalent column name in the Koha database as exists in the LDAP database.
566
567 The value highlighted cyan is the default value for the specified Koha and LDAP columns. So in the above example all user records in the Koha and LDAP databases  will by default have the city value of ‘Athens, OH’.
568
569 Example of the LDAP configurations:
570
571 ::
572
573  <useldapserver>1</useldapserver><!-- see C4::Auth_with_ldap for extra configs you must add if you want to turn this on -->
574
575  <ldapserver id="ldapserver" listenref="ldapserver">
576
577  <hostname>ldaps://example.co.au</hostname>
578
579  <base>ou=employees,dc=companya,dc=com,dc=au</base>
580
581  <user></user> <!-- DN, if not anonymous -->
582
583  <pass></pass> <!-- password, if not anonymous -->
584
585  <auth_by_bind>1</auth_by_bind>
586
587  <replicate>1</replicate> <!-- add new users from LDAP to Koha database -->
588
589  <update>0</update> <!-- update existing users in Koha database -->
590
591  <principal_name>ou=employees,dc=companya,dc=com,dc=au</principal_name>
592
593  <mapping>
594
595  <userid       is="uid"            ></userid>
596
597  <cardnumber   is="uid"            ></cardnumber>
598
599  <email        is="mail"           ></email>
600
601  <surname      is="sn"             ></surname>
602
603  <firstname    is="givenname"      ></firstname>
604
605  <categorycode is="1">EM</categorycode>
606
607  <branchcode   is="1">SYD</branchcode>
608
609  </mapping>
610
611  </ldapserver>
612
613 The values in the mapping area are not always the same, and it depends on what is in your organisations LDAP database. For example some organisations do not use <userid> instead each user is only identified by the <email> field and so no <userid> is written.
614
615 **Troubleshooting LDAP**
616
617 The log that LDAP errors are printed to depends on several factors:
618
619 If plack is not disabled then LDAP errors are displayed in the plack-error.log file
620 If plack is disabled then the location that LDAP errors are printed to is either the opac-error.log file (if the user is logging into the OPAC) or the intranet-error.log file (if the user is logging into the staff client)
621 All of these three log files are accessible in the following directory:
622
623 /var/log/koha/<instance>/