Debian Codegraph @

src/modules/geoip2/README

raw
1 geoip2 Module
2
3 Sergey Okhapkin
4
5 callwithus.com
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Henning Westerholt
14
15 gilawa.com
16
17 Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
18 __________________________________________________________________
19
20 Table of Contents
21
22 1. Admin Guide
23
24 1. Overview
25 2. Dependencies
26
27 2.1. Kamailio Modules
28 2.2. External Libraries or Applications
29
30 3. Parameters
31
32 3.1. path (string)
33 3.2. resid (str)
34
35 4. Functions
36
37 4.1. geoip2_match(ipaddr, pvc)
38 4.2. geoip2_distance(ip_addr, latitude, longitude)
39
40 5. RPC Commands
41
42 5.1. geoip2.reload
43
44 6. Exported pseudo-variables
45
46 List of Examples
47
48 1.1. Set path parameter
49 1.2. Set resid parameter
50 1.3. geoip2_match usage
51 1.4. geoip2_distance usage
52 1.5. geoip2.reload usage
53
54 Chapter 1. Admin Guide
55
56 Table of Contents
57
58 1. Overview
59 2. Dependencies
60
61 2.1. Kamailio Modules
62 2.2. External Libraries or Applications
63
64 3. Parameters
65
66 3.1. path (string)
67 3.2. resid (str)
68
69 4. Functions
70
71 4.1. geoip2_match(ipaddr, pvc)
72 4.2. geoip2_distance(ip_addr, latitude, longitude)
73
74 5. RPC Commands
75
76 5.1. geoip2.reload
77
78 6. Exported pseudo-variables
79
80 1. Overview
81
82 This module allows real-time queries against the Max Mind GeoIP2
83 database to be performed from the config script.
84
85 The Max Mind GeoIP2 database is a map of IP network address assignments
86 to geographical locales that can be useful -- though approximate -- in
87 identifying the physical location with which an IP host address is
88 associated on a relatively granular level.
89
90 This database itself can be obtained on a free or commercial basis from
91 http://dev.maxmind.com/geoip/. The library libmaxminddb that interfaces
92 with the Max Mind API, as well as scripts to automate downloading of
93 the on-disk version are available at
94 http://dev.maxmind.com/geoip/geoip2/downloadable/.
95
96 This module exports a new class of pseudo-variables - $gip2(pvc=>key) -
97 to enable access to the results of a query to the database.
98
99 Many queries can be done and store results in different containers to
100 be able to use in parallel. Database is loaded at startup in cache. The
101 cache can be reloaded with an RPC command. In this case make sure that
102 you do not overwrite the file in place, but replace it, e.g. with a
103 “move” command.
104
105 2. Dependencies
106
107 2.1. Kamailio Modules
108 2.2. External Libraries or Applications
109
110 2.1. Kamailio Modules
111
112 The following modules must be loaded before this module:
113 * none.
114
115 2.2. External Libraries or Applications
116
117 The following libraries or applications must be installed before
118 running Kamailio with this module loaded:
119 * libmaxminddb - the GeoIP2 library.
120
121 3. Parameters
122
123 3.1. path (string)
124 3.2. resid (str)
125
126 3.1. path (string)
127
128 Path to the GeoIP2 database file.
129
130 Default value is “null”.
131
132 Example 1.1. Set path parameter
133 ...
134 modparam("geoip2", "path", "/usr/local/share/GeoIP/GeoLite2-City.mmdb")
135 ...
136
137 3.2. resid (str)
138
139 Preregister result container id during initialization, enabling the use
140 of the module in KEMI scripts. In native kamailio.cfg file,
141 registration is done when parsing config and finding variables.
142
143 Default value is “” (empty).
144
145 Example 1.2. Set resid parameter
146 ...
147 modparam("geoip2", "resid", "src")
148 ...
149 if(geoip2_match("$si", "src")) {
150 ...
151 }
152 ...
153
154 4. Functions
155
156 4.1. geoip2_match(ipaddr, pvc)
157 4.2. geoip2_distance(ip_addr, latitude, longitude)
158
159 4.1. geoip2_match(ipaddr, pvc)
160
161 Match ipaddr against the GeoIP database and set the pvc container. The
162 function has to be called before accessing a key via: $gip2(pvc=>key).
163 At least one function needs to be present that access the pvc
164 container, otherwise this function will not work.
165
166 Example 1.3. geoip2_match usage
167 ...
168 if(geoip2_match("$si", "src"))
169 xlog("SIP message from: $gip2(src=>cc)\n");
170 ...
171
172 4.2. geoip2_distance(ip_addr, latitude, longitude)
173
174 The function calculates the distance in miles between the
175 geocoordinates of the IP address passed as parameter (the coordinates
176 are calculated inside the function) and the geocoordinates latitude and
177 longitude
178
179 Example 1.4. geoip2_distance usage
180 ...
181 $var(client_ip) = "109.184.18.64";
182 $var(lat_pos) = "53.200660";
183 $var(lon_pos) = "45.004640";
184 $var(dist) = geoip2_distance($var(client_ip), $var(lat_pos), $var(lon_po
185 s));
186
187 xlog("distance is $var(dist)\n");
188 ...
189
190 5. RPC Commands
191
192 5.1. geoip2.reload
193
194 5.1. geoip2.reload
195
196 Reload the internal GeoIP database. This is necessary after the
197 database file has been changed on the disk.
198
199 Example 1.5. geoip2.reload usage
200 ...
201 kamctl rpc geoip2.reload
202 ...
203
204 6. Exported pseudo-variables
205
206 * $gip2(pvc=>key) - pvc is an identifier for this query result; it is
207 designated by the second parameter of geoip2_match(). The key can
208 be one of the following:
209 + cc - country code
210 + tz - time zone
211 + zip - postal code
212 + lat - latitude
213 + lon - longitude
214 + nmask - network mask (CIDR format)
215 + city - city
216 + regc - region
217 + regn - region name
218 + metro - metro code
219 + contc - continent code
220
221 Exported pseudo-variables are documented at
222 https://www.kamailio.org/wikidocs/.