/
README
141 lines (99 loc) · 3.59 KB
/
README
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
mmgeoip Module
Kobi Eshun
SightSpeed, Inc.
Edited by
Kobi Eshun
Copyright © 2008 SightSpeed, Inc.
Revision History
Revision $Revision: 5901 $ $Date$
__________________________________________________________
Table of Contents
1. Admin Guide
1.1. Overview
1.2. Dependencies
1.2.1. OpenSIPS Modules
1.2.2. External Libraries or Applications
1.3. Exported Parameters
1.3.1. mmgeoip_city_db_path (string)
1.3.2. cache_type (string)
1.4. Exported Functions
1.4.1. mmg_lookup([fields,]src,dst)
1.5. Known Issues
List of Examples
1.1. Set “mmgeoip_city_db_path” parameter
1.2. Set “cache_type” parameter
1.3. mmg_lookup usage
Chapter 1. Admin Guide
1.1. Overview
This module is a lightweight wrapper for the MaxMind GeoIP API.
It adds IP address-to-location lookup capability to OpenSIPS
scripts.
Lookups are executed against the freely-available GeoLite City
database; and the non-free GeoIP City database is drop-in
compatible. All lookup fields provided by the API are
accessible by the script. Visit the MaxMind website for more
information on the location databases.
1.2. Dependencies
1.2.1. OpenSIPS Modules
The following modules must be loaded before this module:
* No dependencies on other OpenSIPS modules.
1.2.2. External Libraries or Applications
The following libraries or applications must be installed
before running OpenSIPS with this module loaded:
* libGeoIP.
1.3. Exported Parameters
1.3.1. mmgeoip_city_db_path (string)
Path to either a GeoLite or GeoIP City database file.
Mandatory parameter.
Example 1.1. Set “mmgeoip_city_db_path” parameter
...
modparam("mmgeoip", "mmgeoip_city_db_path",
"/usr/share/GeoIP/GeoLiteCity.dat")
...
1.3.2. cache_type (string)
Databse memory caching options. The following options are
available:
* STANDARD - Read database from file system; least memory
used;
* MMAP_CACHE - Load database into mmap allocated memory;
WARNING: this option will cause a segmentation fault if
database file is changed at runtime!
* MEM_CACHE_CHECK - Load database into memory; this mode
checks for database updates; if database was modified, the
file will be reloaded after 60 seconds; it will be slower
than MMAP_CACHE but it will allow reloads;
Default value for this parameter is MMAP_CACHE.
Example 1.2. Set “cache_type” parameter
...
modparam("mmgeoip", "cache_type","MEM_CACHE_CHECK")
...
1.4. Exported Functions
1.4.1. mmg_lookup([fields,]src,dst)
Looks up specified fields associated with IP address specified
by the src. The resulting data are loaded in reverse order into
the dst AVP.
src can be a pseudo-variable or AVP; and dst must be an AVP.
fields defaults to "lon:lat," and is a colon-delimited list of
these elements:
* lat Latitude
* lon Longitude
* cont Continent
* cc Country Code
* reg Region
* city City
* pc Postal Code
* dma DMA Code
* ac Area Code
* TZ Time Zone
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
ONREPLY_ROUTE, BRANCH_ROUTE,ERROR_ROUTE, and LOCAL_ROUTE.
Example 1.3. mmg_lookup usage
...
if(mmg_lookup("lon:lat","$si","$avp(lat_lon)")) {
xlog("L_INFO","Source IP latitude:$(avp(lat_lon)[0])\n");
xlog("L_INFO","Source IP longitude:$(avp(lat_lon)[1])\n");
};
...
1.5. Known Issues
It is not currently possible to load an updated location
database without first stalling the server.