aboutsummaryrefslogtreecommitdiff
path: root/src/vmod_geoip.vcc
blob: 4500ad26c7d0754b79f2db45d23e616d0987910f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$Module geoip 3 "GeoIP support for Varnish Cache"

DESCRIPTION
===========

Provides interface for accessing geolocation information from
the MaxMind's GeoIP2 databases.

$Event geoip_event
$Function VOID init(PRIV_VCL, STRING)

Description
    By default, all functions operate on the database
    **/usr/share/GeoIP/GeoLite2-City.mmdb**.  This can be changed by
    calling **geoip.init** from with the full pathname to the database
    as its argument.  Normally, it is done in **vcl_init**.  The pathname
    must exist.  If the pathname refers to a directory, **/GeoLite2-City.mmdb**
    will be appended to it.

$Function STRING get(PRIV_VCL, IP ip, STRING path)

Description
    Look up in the database a value described by **path** corresponding to the
    IP address **ip**.  The lookup path must consist of one or more lookup
    keys separated by dots.  If the lookup path is found, the function returns
    the requested value converted to string.  Otherwise, **NULL** is returned.

    The following data types can be represented as string:
    
    - utf8_string
    - int32
    - uint16
    - uint32
    - boolean
      (**0** for *false*, **1** for *true*)
    - double
      (formatted using **%g**)
    - float        
      (formatted using **%g**)

    For types not listed above, the following string is returned:
    
    [*X.X.X.X*: can't format *A.B.C* of type *N*]

    where *X.X.X.X* stands for IP address, *A.B.C* for lookup path, and
    *N* for the data type in decimal.
    
Example
    ::

      set req.http.X-Country-Code = geoip.get(client.ip,
                                              "country.name.en");
    
$Function STRING country_code(PRIV_VCL, IP ip)

Description
    Returns the ISO 3166-1 alpha-2 country code corresponding to the **ip**.
    Equivalent to geoip.get(ip, "country.iso_code").

$Function STRING country_name(PRIV_VCL, IP ip)

Description
    Returns the English name of the country corresponding to **ip**.
    Equivalent to geoip.get(ip, "country.names.en"),
    
$Function STRING city_name(PRIV_VCL, IP ip)

Description
    Returns the name of the city where **ip** is located.
    Equivalent to geoip.get(ip, "city.names.en").

Return to:

Send suggestions and report system problems to the System administrator.