Hello,
Here is a patch for mathopd to populate GEOIP data (similar to mod_geoip for
apache).
Enjoy!
--- Makefile.orig Sun Aug 1 18:04:12 2004
+++ Makefile Sun Aug 1 18:04:30 2004
@@ -28,6 +28,11 @@
# Unomment the following if your system has a working vfork() function
# CPPFLAGS += -DHAVE_VFORK
+# Uncomment these lines for GeoIP support
+#CPPFLAGS += -DGEOIP
+#LIBS += -L/usr/local/lib -lGeoIP
+#CFLAGS += -I/usr/local/include
+
# Currently, sendfile support is available in two flavours: Linux and FreeBSD
# Uncomment one of the following two to enable sendfile() support
# CPPFLAGS += -DLINUX_SENDFILE
--- cgi.c.orig Sun Aug 1 18:05:32 2004
+++ cgi.c Sun Aug 1 18:05:54 2004
@@ -203,6 +203,12 @@
struct simple_list *e;
char path_translated[PATHLEN];
char *tmp;
+ #ifdef GEOIP
+ GeoIP *gip;
+ short int country_id;
+ const char *country_code;
+ const char *country_name;
+ #endif
if (add_http_vars(r, cp) == -1)
return -1;
@@ -244,6 +250,21 @@
sprintf(t, "%s", inet_ntoa(r->cn->peer.sin_addr));
if (add("REMOTE_ADDR", t, 0, cp) == -1)
return -1;
+ #ifdef GEOIP
+ gip=GeoIP_new(GEOIP_STANDARD);
+ country_id=GeoIP_country_id_by_addr(gip,inet_ntoa(r->cn->peer.sin_addr));
+ country_code=GeoIP_country_code[country_id];
+ if (add("GEOIP_COUNTRY_CODE", country_code, 0, cp) == -1) {
+ GeoIP_delete(gip);
+ return -1;
+ }
+ country_name=GeoIP_country_name[country_id];
+ if (add("GEOIP_COUNTRY_NAME", country_name, 0, cp) == -1) {
+ GeoIP_delete(gip);
+ return -1;
+ }
+ GeoIP_delete(gip);
+ #endif
sprintf(t, "%hu", ntohs(r->cn->peer.sin_port));
if (add("REMOTE_PORT", t, 0, cp) == -1)
return -1;
--- mathopd.h.orig Sun Aug 1 18:06:56 2004
+++ mathopd.h Sun Aug 1 18:07:37 2004
@@ -43,6 +43,9 @@
#include <sys/time.h>
#include <netinet/in.h>
#include <signal.h>
+#ifdef GEOIP
+#include <GeoIP.h>
+#endif
#define CGI_MAGIC_TYPE "CGI"
#define IMAP_MAGIC_TYPE "Imagemap"