Added GeoIP support
This commit is contained in:
parent
dee7ecfce7
commit
e58d20dc08
10
ChangeLog
10
ChangeLog
@ -3,6 +3,16 @@ $Id$
|
|||||||
|
|
||||||
v0.91.13 12-Oct-2007
|
v0.91.13 12-Oct-2007
|
||||||
|
|
||||||
|
mbcico:
|
||||||
|
Added GeoIP support.
|
||||||
|
|
||||||
|
mbsebbs:
|
||||||
|
Added GeoIP support.
|
||||||
|
|
||||||
|
mbnewusr:
|
||||||
|
Added GeoIP support.
|
||||||
|
|
||||||
|
|
||||||
v0.91.12 24-Sep-2007 - 12-Oct-2007
|
v0.91.12 24-Sep-2007 - 12-Oct-2007
|
||||||
|
|
||||||
libmsgbase:
|
libmsgbase:
|
||||||
|
@ -85,37 +85,22 @@ char *typestr(int tp)
|
|||||||
extern void _GeoIP_setup_dbfilename(void);
|
extern void _GeoIP_setup_dbfilename(void);
|
||||||
|
|
||||||
|
|
||||||
void geoiplookup(GeoIP* gi,char *hostname,int i)
|
void geoiplookup(GeoIP* gi, char *hostname, int i)
|
||||||
{
|
{
|
||||||
const char * country_code;
|
const char * country_code;
|
||||||
const char * country_name;
|
const char * country_name;
|
||||||
|
const char * country_continent;
|
||||||
int country_id;
|
int country_id;
|
||||||
GeoIPRecord * gir;
|
|
||||||
|
|
||||||
if (GEOIP_COUNTRY_EDITION == i) {
|
if (GEOIP_COUNTRY_EDITION == i) {
|
||||||
country_id = GeoIP_id_by_name(gi, hostname);
|
country_id = GeoIP_id_by_name(gi, hostname);
|
||||||
country_code = GeoIP_country_code[country_id];
|
country_code = GeoIP_country_code[country_id];
|
||||||
country_name = GeoIP_country_name[country_id];
|
country_name = GeoIP_country_name[country_id];
|
||||||
|
country_continent = GeoIP_country_continent[country_id];
|
||||||
if (country_code == NULL) {
|
if (country_code == NULL) {
|
||||||
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
|
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
|
||||||
} else {
|
} else {
|
||||||
Syslog('+', "%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name);
|
Syslog('+', "GeoIP location: %s, %s %s\n", country_name, country_code, country_continent);
|
||||||
}
|
|
||||||
} else if (GEOIP_CITY_EDITION_REV0 == i) {
|
|
||||||
gir = GeoIP_record_by_name(gi, hostname);
|
|
||||||
if (NULL == gir) {
|
|
||||||
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
|
|
||||||
} else {
|
|
||||||
Syslog('+', "%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, gir->region,
|
|
||||||
gir->city, gir->postal_code,gir->latitude, gir->longitude);
|
|
||||||
}
|
|
||||||
} else if (GEOIP_CITY_EDITION_REV1 == i) {
|
|
||||||
gir = GeoIP_record_by_name(gi, hostname);
|
|
||||||
if (NULL == gir) {
|
|
||||||
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
|
|
||||||
} else {
|
|
||||||
Syslog('+', "%s: %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, gir->region, gir->city,
|
|
||||||
gir->postal_code, gir->latitude, gir->longitude, gir->dma_code, gir->area_code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +117,6 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
|
|||||||
pid_t ipid, opid;
|
pid_t ipid, opid;
|
||||||
#ifdef HAVE_GEOIP_H
|
#ifdef HAVE_GEOIP_H
|
||||||
char *hostname;
|
char *hostname;
|
||||||
int i;
|
|
||||||
GeoIP *gi;
|
GeoIP *gi;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -163,19 +147,12 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
|
|||||||
#ifdef HAVE_GEOIP_H
|
#ifdef HAVE_GEOIP_H
|
||||||
hostname = inet_ntoa(peeraddr.sin_addr);
|
hostname = inet_ntoa(peeraddr.sin_addr);
|
||||||
_GeoIP_setup_dbfilename();
|
_GeoIP_setup_dbfilename();
|
||||||
Syslog('-', "Start GeoIP %s", hostname);
|
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
|
||||||
for (i = 0; i < NUM_DB_TYPES; ++i) {
|
if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
|
||||||
if (GeoIP_db_avail(i)) {
|
geoiplookup(gi, hostname, GEOIP_COUNTRY_EDITION);
|
||||||
Syslog('-', "Doing %s", GeoIPDBDescription[i]);
|
|
||||||
gi = GeoIP_open_type(i, GEOIP_STANDARD);
|
|
||||||
if (NULL == gi) {
|
|
||||||
// Syslog('+', "%s not available, skipping", GeoIPDBDescription[i]);
|
|
||||||
} else {
|
|
||||||
geoiplookup(gi,hostname,i);
|
|
||||||
}
|
}
|
||||||
GeoIP_delete(gi);
|
GeoIP_delete(gi);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tcp_mode == TCPMODE_ITN) {
|
if (tcp_mode == TCPMODE_ITN) {
|
||||||
|
@ -50,6 +50,32 @@ char *StartTime;
|
|||||||
int cols = 80; /* Screen columns */
|
int cols = 80; /* Screen columns */
|
||||||
int rows = 80; /* Screen rows */
|
int rows = 80; /* Screen rows */
|
||||||
|
|
||||||
|
#ifdef HAVE_GEOIP_H
|
||||||
|
|
||||||
|
extern void _GeoIP_setup_dbfilename(void);
|
||||||
|
|
||||||
|
void geoiplookup(GeoIP* gi, char *hostname, int i)
|
||||||
|
{
|
||||||
|
const char * country_code;
|
||||||
|
const char * country_name;
|
||||||
|
const char * country_continent;
|
||||||
|
int country_id;
|
||||||
|
|
||||||
|
if (GEOIP_COUNTRY_EDITION == i) {
|
||||||
|
country_id = GeoIP_id_by_name(gi, hostname);
|
||||||
|
Syslog('b', "geoiplookup '%s', id=%d", hostname, country_id);
|
||||||
|
country_code = GeoIP_country_code[country_id];
|
||||||
|
country_name = GeoIP_country_name[country_id];
|
||||||
|
country_continent = GeoIP_country_continent[country_id];
|
||||||
|
if (country_code == NULL) {
|
||||||
|
Syslog('+', "%s: IP Address not found\n", GeoIPDBDescription[i]);
|
||||||
|
} else {
|
||||||
|
Syslog('+', "GeoIP location: %s, %s %s\n", country_name, country_code, country_continent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -58,6 +84,10 @@ int main(int argc, char **argv)
|
|||||||
int i, rc = 0;
|
int i, rc = 0;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
|
#ifdef HAVE_GEOIP_H
|
||||||
|
char *hostname;
|
||||||
|
GeoIP *gi;
|
||||||
|
#endif
|
||||||
|
|
||||||
pTTY = calloc(15, sizeof(char));
|
pTTY = calloc(15, sizeof(char));
|
||||||
tty = ttyname(1);
|
tty = ttyname(1);
|
||||||
@ -185,6 +215,16 @@ int main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Network connection, no tty checking but fill a ttyinfo record.
|
* Network connection, no tty checking but fill a ttyinfo record.
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAVE_GEOIP_H
|
||||||
|
hostname = xstrcpy(p);
|
||||||
|
_GeoIP_setup_dbfilename();
|
||||||
|
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
|
||||||
|
if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
|
||||||
|
geoiplookup(gi, hostname, GEOIP_COUNTRY_EDITION);
|
||||||
|
}
|
||||||
|
GeoIP_delete(gi);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
memset(&ttyinfo, 0, sizeof(ttyinfo));
|
memset(&ttyinfo, 0, sizeof(ttyinfo));
|
||||||
snprintf(ttyinfo.comment, 41, "%s", p);
|
snprintf(ttyinfo.comment, 41, "%s", p);
|
||||||
snprintf(ttyinfo.tty, 7, "%s", pTTY);
|
snprintf(ttyinfo.tty, 7, "%s", pTTY);
|
||||||
|
@ -346,7 +346,6 @@ int main(int argc, char **argv)
|
|||||||
* Network connection, no tty checking but fill a ttyinfo record.
|
* Network connection, no tty checking but fill a ttyinfo record.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_GEOIP_H
|
#ifdef HAVE_GEOIP_H
|
||||||
// hostname = inet_ntoa(peeraddr.sin_addr);
|
|
||||||
hostname = xstrcpy(p);
|
hostname = xstrcpy(p);
|
||||||
_GeoIP_setup_dbfilename();
|
_GeoIP_setup_dbfilename();
|
||||||
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
|
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
|
||||||
|
Reference in New Issue
Block a user