diff --git a/ChangeLog b/ChangeLog index 0785139a..7f9be67b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,16 @@ $Id$ 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 libmsgbase: diff --git a/mbcico/session.c b/mbcico/session.c index 48bdaffc..3b949829 100644 --- a/mbcico/session.c +++ b/mbcico/session.c @@ -85,37 +85,22 @@ char *typestr(int tp) 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_name; + const char * country_continent; int country_id; - GeoIPRecord * gir; if (GEOIP_COUNTRY_EDITION == i) { country_id = GeoIP_id_by_name(gi, hostname); 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('+', "%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name); - } - } 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); + Syslog('+', "GeoIP location: %s, %s %s\n", country_name, country_code, country_continent); } } } @@ -132,7 +117,6 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) pid_t ipid, opid; #ifdef HAVE_GEOIP_H char *hostname; - int i; GeoIP *gi; #endif @@ -163,18 +147,11 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) #ifdef HAVE_GEOIP_H hostname = inet_ntoa(peeraddr.sin_addr); _GeoIP_setup_dbfilename(); - Syslog('-', "Start GeoIP %s", hostname); - for (i = 0; i < NUM_DB_TYPES; ++i) { - if (GeoIP_db_avail(i)) { - 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); + 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 diff --git a/mbsebbs/mbnewusr.c b/mbsebbs/mbnewusr.c index 8e0ae583..e3464e23 100644 --- a/mbsebbs/mbnewusr.c +++ b/mbsebbs/mbnewusr.c @@ -50,6 +50,32 @@ char *StartTime; int cols = 80; /* Screen columns */ 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) { @@ -58,6 +84,10 @@ int main(int argc, char **argv) int i, rc = 0; struct passwd *pw; struct winsize ws; +#ifdef HAVE_GEOIP_H + char *hostname; + GeoIP *gi; +#endif pTTY = calloc(15, sizeof(char)); tty = ttyname(1); @@ -185,6 +215,16 @@ int main(int argc, char **argv) /* * 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)); snprintf(ttyinfo.comment, 41, "%s", p); snprintf(ttyinfo.tty, 7, "%s", pTTY); diff --git a/mbsebbs/mbsebbs.c b/mbsebbs/mbsebbs.c index 1133418e..c86588d4 100644 --- a/mbsebbs/mbsebbs.c +++ b/mbsebbs/mbsebbs.c @@ -346,7 +346,6 @@ int main(int argc, char **argv) * Network connection, no tty checking but fill a ttyinfo record. */ #ifdef HAVE_GEOIP_H -// hostname = inet_ntoa(peeraddr.sin_addr); hostname = xstrcpy(p); _GeoIP_setup_dbfilename(); if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {