Skip to content

Commit f3e7e7d

Browse files
committed
Added "fraud_score" field to support PX12 database.
1 parent 9ef0ee0 commit f3e7e7d

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 - 2024 IP2Location.com
3+
Copyright (c) 2017 - 2025 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ The IP2Proxy database can be downloaded from [https://lite.ip2location.com](http
2424
rm master.zip
2525
```
2626

27-
27+
2828

2929
4. Download the latest Nginx source code from https://nginx.org/en/download.html
3030

3131
```bash
3232
wget https://nginx.org/download/nginx-x.y.z.tar.gz
3333
```
3434

35-
35+
3636

3737
5. Decompress and go into Nginx source directory.
3838

@@ -41,7 +41,7 @@ The IP2Proxy database can be downloaded from [https://lite.ip2location.com](http
4141
cd nginx-x.y.z
4242
```
4343

44-
44+
4545

4646
6. Re-compile Nginx from source to include this module.
4747

@@ -102,7 +102,7 @@ Description : Set a list of proxies to translate x-forwarded-for headers for.
102102
```nginx
103103
http {
104104
...
105-
105+
106106
ip2proxy_database /usr/share/ip2location/PX3.BIN;
107107
ip2proxy_proxy_recursive on;
108108
ip2proxy_proxy 192.168.1.0/24;
@@ -130,6 +130,7 @@ $ip2proxy_proxy_as;
130130
$ip2proxy_last_seen;
131131
$ip2proxy_threat;
132132
$ip2proxy_provider;
133+
$ip2proxy_fraud_score;
133134
```
134135

135136

@@ -157,7 +158,7 @@ server {
157158
fastcgi_pass php-fpm-sock;
158159
fastcgi_index index.php;
159160
include fastcgi.conf;
160-
161+
161162
# Add custom header to view result in HTTP response
162163
add_header X-Country-Code $ip2proxy_country_short;
163164
add_header X-Country-Name $ip2proxy_country_long;
@@ -176,6 +177,7 @@ server {
176177
fastcgi_param IP2PROXY_LAST_SEEN $ip2proxy_last_seen;
177178
fastcgi_param IP2PROXY_THREAT $ip2proxy_threat;
178179
fastcgi_param IP2PROXY_PROVIDER $ip2proxy_provider;
180+
fastcgi_param IP2PROXY_FRAUD_SCORE $ip2proxy_fraud_score;
179181
}
180182
}
181183
```

ngx_http_ip2proxy.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ ngx_http_ip2proxy_vars[] = {
175175
offsetof(IP2ProxyRecord, provider),
176176
0, 0
177177
},
178-
178+
{
179+
ngx_string("ip2proxy_fraud_score"), NULL,
180+
ngx_http_ip2proxy_get_str_value,
181+
offsetof(IP2ProxyRecord, fraud_score),
182+
0, 0
183+
},
179184
ngx_http_null_variable
180185
};
181186

@@ -193,14 +198,14 @@ ngx_http_ip2proxy_get_str_value(ngx_http_request_t *r, ngx_http_variable_value_t
193198
}
194199

195200
val = *(char **) ((char *) record + data);
196-
201+
197202
if (val == NULL) {
198203
goto no_value;
199204
}
200205

201206
len = ngx_strlen(val);
202207
v->data = ngx_pnalloc(r->pool, len);
203-
208+
204209
if (v->data == NULL) {
205210
IP2Proxy_free_record(record);
206211
return NGX_ERROR;
@@ -237,7 +242,7 @@ ngx_http_ip2proxy_get_records(ngx_http_request_t *r)
237242

238243
if (gcf->handler) {
239244
ngx_addr_t addr;
240-
245+
241246
#if defined(nginx_version) && nginx_version >= 1023000
242247
ngx_table_elt_t *xfwd;
243248
#else
@@ -257,7 +262,7 @@ ngx_http_ip2proxy_get_records(ngx_http_request_t *r)
257262
xfwd = &r->headers_in.x_forwarded_for;
258263

259264
if (xfwd->nelts > 0 && gcf->proxies != NULL) {
260-
#endif
265+
#endif
261266
(void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL, gcf->proxies, gcf->proxy_recursive);
262267
}
263268

@@ -273,7 +278,7 @@ ngx_http_ip2proxy_get_records(ngx_http_request_t *r)
273278

274279
return IP2Proxy_get_all(gcf->handler, (char *)p);
275280
}
276-
281+
277282
return NULL;
278283
}
279284

@@ -285,7 +290,7 @@ ngx_http_ip2proxy_add_variables(ngx_conf_t *cf)
285290

286291
for (v = ngx_http_ip2proxy_vars; v->name.len; v++) {
287292
var = ngx_http_add_variable(cf, &v->name, v->flags);
288-
293+
289294
if (var == NULL) {
290295
return NGX_ERROR;
291296
}
@@ -305,15 +310,15 @@ ngx_http_ip2proxy_create_conf(ngx_conf_t *cf)
305310
ngx_http_ip2proxy_conf_t *conf;
306311

307312
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ip2proxy_conf_t));
308-
313+
309314
if (conf == NULL) {
310315
return NULL;
311316
}
312317

313318
conf->proxy_recursive = NGX_CONF_UNSET;
314319

315320
cln = ngx_pool_cleanup_add(cf->pool, 0);
316-
321+
317322
if (cln == NULL) {
318323
return NULL;
319324
}

0 commit comments

Comments
 (0)