Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 1 | DeviceAtlas Device Detection |
| 2 | ---------------------------- |
| 3 | |
| 4 | In order to add DeviceAtlas Device Detection support, you would need to download |
David Carlier | 019dbd7 | 2021-02-16 11:37:45 +0000 | [diff] [blame] | 5 | the API source code from https://deviceatlas.com/deviceatlas-haproxy-module. |
| 6 | The build supports the USE_PCRE and USE_PCRE2 options. Once extracted : |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 7 | |
David Carlier | e072458 | 2021-02-19 12:01:38 +0000 | [diff] [blame] | 8 | $ make TARGET=<target> USE_PCRE=1 (or USE_PCRE2=1) USE_DEVICEATLAS=1 DEVICEATLAS_SRC=<path to the API root folder> |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 9 | |
| 10 | Optionally DEVICEATLAS_INC and DEVICEATLAS_LIB may be set to override the path |
| 11 | to the include files and libraries respectively if they're not in the source |
David Carlier | b81483c | 2022-01-27 18:13:54 +0000 | [diff] [blame] | 12 | directory. However, if the API had been installed beforehand, DEVICEATLAS_SRC |
| 13 | can be omitted. Note that the DeviceAtlas C API version supported is the 2.4.0 |
| 14 | at minimum. |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 15 | |
Michael Prokop | 4438c60 | 2019-05-24 10:25:45 +0200 | [diff] [blame] | 16 | For HAProxy developers who need to verify that their changes didn't accidentally |
David Carlier | 0470d70 | 2019-04-26 12:02:28 +0000 | [diff] [blame] | 17 | break the DeviceAtlas code, it is possible to build a dummy library provided in |
Willy Tarreau | f8d9ec5 | 2021-04-02 16:19:39 +0200 | [diff] [blame] | 18 | the addons/deviceatlas/dummy directory and to use it as an alternative for the |
| 19 | full library. This will not provide the full functionalities, it will just allow |
David Carlier | 0470d70 | 2019-04-26 12:02:28 +0000 | [diff] [blame] | 20 | haproxy to start with a deviceatlas configuration, which generally is enough to |
| 21 | validate API changes : |
| 22 | |
Willy Tarreau | f8d9ec5 | 2021-04-02 16:19:39 +0200 | [diff] [blame] | 23 | $ make TARGET=<target> USE_PCRE=1 USE_DEVICEATLAS=1 DEVICEATLAS_SRC=$PWD/addons/deviceatlas/dummy |
David Carlier | 0470d70 | 2019-04-26 12:02:28 +0000 | [diff] [blame] | 24 | |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 25 | These are supported DeviceAtlas directives (see doc/configuration.txt) : |
| 26 | - deviceatlas-json-file <path to the DeviceAtlas JSON data file>. |
| 27 | - deviceatlas-log-level <number> (0 to 3, level of information returned by |
| 28 | the API, 0 by default). |
| 29 | - deviceatlas-property-separator <character> (character used to separate the |
| 30 | properties produced by the API, | by default). |
| 31 | |
| 32 | Sample configuration : |
| 33 | |
| 34 | global |
| 35 | deviceatlas-json-file <path to json file> |
| 36 | |
| 37 | ... |
| 38 | frontend |
| 39 | bind *:8881 |
| 40 | default_backend servers |
| 41 | |
| 42 | There are two distinct methods available, one which leverages all HTTP headers |
| 43 | and one which uses only a single HTTP header for the detection. The former |
| 44 | method is highly recommended and more accurate. There are several possible use |
| 45 | cases. |
| 46 | |
| 47 | # To transmit the DeviceAtlas data downstream to the target application |
| 48 | |
| 49 | All HTTP headers via the sample / fetch |
| 50 | |
| 51 | http-request set-header X-DeviceAtlas-Data %[da-csv-fetch(primaryHardwareType,osName,osVersion,browserName,browserVersion,browserRenderingEngine)] |
| 52 | |
Michael Prokop | 4438c60 | 2019-05-24 10:25:45 +0200 | [diff] [blame] | 53 | Single HTTP header (e.g. User-Agent) via the converter |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 54 | |
| 55 | http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv-conv(primaryHardwareType,osName,osVersion,browserName,browserVersion,browserRenderingEngine)] |
| 56 | |
| 57 | # Mobile content switching with ACL |
| 58 | |
| 59 | All HTTP headers |
| 60 | |
| 61 | acl is_mobile da-csv-fetch(mobileDevice) 1 |
| 62 | |
| 63 | Single HTTP header |
| 64 | |
| 65 | acl device_type_tablet req.fhdr(User-Agent),da-csv-conv(primaryHardwareType) "Tablet" |
| 66 | |
David Carlier | b81483c | 2022-01-27 18:13:54 +0000 | [diff] [blame] | 67 | Optionally a JSON download scheduler is provided to allow a data file being |
| 68 | fetched automatically in a daily basis without restarting HAProxy : |
| 69 | |
| 70 | $ cd addons/deviceatlas && make [DEVICEATLAS_SRC=<path to the API root folder>] |
| 71 | |
| 72 | Similarly, if the DeviceAtlas API is installed, DEVICEATLAS_SRC can be omitted. |
| 73 | |
| 74 | $ ./dadwsch -u JSON data file URL e.g. "https://deviceatlas.com/getJSON?licencekey=<your licence key>&format=zip&data=my&index=web" \ |
| 75 | [-p download directory path /tmp by default] \ |
| 76 | [-d scheduled hour of download, hour when the service is launched by default] |
| 77 | |
| 78 | Noted it needs to be started before HAProxy. |
| 79 | |
Willy Tarreau | 29b2531 | 2016-11-08 14:57:29 +0100 | [diff] [blame] | 80 | |
David Carlier | b81483c | 2022-01-27 18:13:54 +0000 | [diff] [blame] | 81 | Please find more information about DeviceAtlas and the detection methods at |
| 82 | https://deviceatlas.com/resources . |