Commit 3037dea7 authored by Zeeshan Ali's avatar Zeeshan Ali

Drop now redundant geoip server

The plan was to put this server running on a GNOME server but Mozilla
Location Service starting to support geoip as well, made us change that
plan. Now that we are using that and have dropped our standalone
ipclient, we can't even use this server readily any ways so there is no
point in keeping it around.
parent b6563179
......@@ -60,49 +60,6 @@ PKG_CHECK_MODULES(GEOCLUE, [
libxml-2.0 >= $LIBXML_MIN_VERSION
])
# Geoip server
AC_ARG_ENABLE(geoip-server,
AS_HELP_STRING([--enable-geoip-server=yes|no|auto], [Build geoip server]),
[enable_geoip_server=$enableval],
[enable_geoip_server=auto])
case "x$enable_geoip_server" in
xyes)
PKG_CHECK_MODULES(GEOIP_SERVER,
gio-2.0 >= $GLIB_MIN_VERSION
json-glib-1.0 >= $JSON_GLIB_MIN_VERSION
libsoup-2.4
geoip >= GEOIP_MIN_VERSION)
build_geoip_server="yes"
;;
xauto)
PKG_CHECK_MODULES(GEOIP_SERVER,
gio-2.0 >= $GLIB_MIN_VERSION
json-glib-1.0 >= $JSON_GLIB_MIN_VERSION
libsoup-2.4
geoip >= GEOIP_MIN_VERSION,
[build_geoip_server=yes],
[build_geoip_server=no])
;;
xno)
build_geoip_server="xno"
;;
x*)
AC_MSG_ERROR([Unknown --enable-geoip-server argument: $enable_geoip_server])
;;
esac
if test "x$build_geoip_server" = "xyes"; then
# Requires for the database update
PKG_CHECK_MODULES(GEOIP_DBUPDATE,
gio-2.0 >= $GLIB_MIN_VERSION
libsoup-2.4)
GEOIP_DATABASE_PATH=`$PKG_CONFIG --variable=databasedir geoip`
AC_SUBST(GEOIP_DATABASE_PATH)
AC_DEFINE([BUILD_GEOIP_SERVER], [1], [Build geoip server?])
else
AC_DEFINE([BUILD_GEOIP_SERVER], [0], [Build geoip server?])
fi
AM_CONDITIONAL([BUILD_GEOIP_SERVER], [test "x$build_geoip_server" = "xyes"])
# 3G source
AC_ARG_ENABLE(3g-source,
AS_HELP_STRING([--disable-3g-source], [Disable 3G backend (requires ModemManager)]),
......@@ -233,7 +190,6 @@ AC_CONFIG_FILES([
src/agent/Makefile
src/geocode-glib/Makefile
src/public-api/Makefile
src/geoip-server/Makefile
po/Makefile.in
data/org.freedesktop.GeoClue2.conf
data/Makefile
......
......@@ -4,10 +4,6 @@ libexec_PROGRAMS = geoclue
SUBDIRS = public-api agent geocode-glib
if BUILD_GEOIP_SERVER
SUBDIRS += geoip-server
endif # BUILD_GEOIP_SERVER
interfacedir = $(datadir)/dbus-1/interfaces
interface_DATA = org.freedesktop.GeoClue2.xml
......
1. What does the server do?
The server performs IP address and Wi-Fi based geolocation search.
2. How to set up the server?
After building geoclue, you will get a geoip-lookup binary that you can install
as a cgi-bin script inside your web server, or use the test application
("launch-web-server.sh") as below.
$ ./launch-web-server.sh start - to start the server
$ ./launch-web-server.sh stop - to stop the server
The script will set up the server at your http://localhost:12345.
And the URL will be - http://localhost:12345/cgi-bin/geoip-lookup
3. How should one query the server for IP address based Geolocation search?
There are 2 ways -
a. You can provide a query string in the format of "?ip=<IP address>". After
installing the server at your localhost using the script, you can use -
http://localhost:12345/cgi-bin/geoip-lookup?ip=123.23.23.23
b. If you do not provide the query string, the server will autodetect
the client's external IP address.
If you have used launch-web-server.sh script to launch the server, the script
sets HTTP_CLIENT_IP (one of the many proxy variables checked by the server to
guess client's IP address) and thus a simple
http://localhost:12345/cgi-bin/geoip-lookup works.
4. How should one query the server for Wi-Fi based geolocation search?
The query string should be in the format of -
?wifi=mac:<mac address>|ssid:<ssid>|ss:<signal strength>[&...]
The server installed by the script at your localhost can be queried using the
following URL -
http://localhost:12345/cgi-bin/geoip-lookup?wifi=mac:01-24-7c-bc-51-46%7Cssid:3x2x%7Css:-37&wifi=mac:09-86-3b-31-97-b2%7Cssid:belkin.7b2%7Css:-47&wifi=mac:28-cf-da-ba-be-13%7Cssid:HERESIARCH%20NETWORK%7Css:-49&wifi=mac:2b-cf-da-ba-be-10%7Cssid:%20ARCH%20GUESTS%7Css:-52&wifi=mac:08-56-3b-2b-e1-a8%7Cssid:belkin.1a8%7Css:-59&wifi=mac:02-1e-64-fd-df-67%7Cssid:Brown%20Cow%7Css:-59&wifi=mac:2a-cf-df-ba-be-10%7Cssid:%20ARCH%20GUESTS%7Css:-59
5. What is the output format of the server?
The server provides Geolocation information in JSON format.
An IP address based query would return -
{"ip":"123.23.23.23","latitude":10.25,"longitude":105.96669769287109,
"country_name":"Vietnam","country_code":"VN","region_name":"Phu Yen",
"city":"Vinh Long","accuracy":"city","timezone":"Asia/Phnom_Penh",
"attribution":"This product includes GeoLite data created by MaxMind,
available from http://www.maxmind.com\n"}
An Wi-Fi based query would return -
{"latitude":40.060449299999988,"longitude":-105.2094195,"accuracy":24}
6. What are the possible error scenarios and error messages?
The server gives the following errors in the following cases -
a. Invalid IP address -
{"error_code":0, "error_message":"Invalid IP address '123.23.23'"}
b. Reserved IP address -
{"error_code":1, "error_message":"Can not find the IP address '127.0.0.1' in the
database"}
c. Database not found by the server -
{"error_code":2, "error_message":"Can not open GeoLiteCity/GeoIP Binary database.
Set GEOIP_DATABASE_PATH env variable."}
The error codes in the JSON output shown above are enum values.
typedef enum {
INVALID_IP_ADDRESS_ERR = 0,
INVALID_ENTRY_ERR,
DATABASE_ERR
} GeoipServerError;
They are defined in
http://cgit.freedesktop.org/geoclue/tree/src/geoip-server/geoip-server.h
include $(top_srcdir)/Makefile.decl
BUILT_GIRSOURCES =
AM_CFLAGS = \
-I$(top_srcdir) \
$(GEOIP_SERVER_CFLAGS) \
$(COMMON_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
-DGEOIP_DATABASE_PATH=\""$(GEOIP_DATABASE_PATH)"\" \
-DTEST_SRCDIR=\""$(top_srcdir)/src/test-data/"\" \
-DBUILDDIR=\""$(builddir)/"\"
bin_PROGRAMS = geoip-lookup geoip-update
TEST_PROGS += test-geoipformat
noinst_PROGRAMS = $(TEST_PROGS)
geoip_lookup_SOURCES = geoip-lookup.c geoip-server.h
geoip_lookup_LDADD = $(GEOIP_SERVER_LIBS)
geoip_update_LDADD = $(GEOIP_DBUPDATE_LIBS)
test_geoipformat_LDADD = $(GEOCLUE_LIBS)
EXTRA_DIST = API-Documentation.txt
MAINTAINERCLEANFILES = Makefile.in
-include $(top_srcdir)/git.mk
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/* vim: set et ts=8 sw=8: */
/* geoip-server.h
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#ifndef GEOIP_SERVER_H
#define GEOIP_SERVER_H
#include <glib.h>
typedef enum {
INVALID_IP_ADDRESS_ERR = 0,
INVALID_ENTRY_ERR,
DATABASE_ERR
} GeoipServerError;
#endif /* GEOIP_SERVER_H */
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/* test-geoipformat.c
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
* Bastien Nocera <hadess@hadess.net>
*/
#include <glib.h>
#include <string.h>
#include <json-glib/json-glib.h>
static void
test_response_data (gconstpointer data)
{
JsonParser *parser;
JsonNode *node;
JsonObject *object;
double latitude, longitude;
parser = json_parser_new ();
g_assert (json_parser_load_from_data (parser, (const char *) data, -1, NULL));
node = json_parser_get_root (parser);
g_assert (JSON_NODE_HOLDS_OBJECT (node));
object = json_node_get_object (node);
g_assert (object != NULL);
g_assert (json_object_has_member (object, "ip"));
g_assert (strcmp (json_object_get_string_member (object, "ip"), "213.243.180.91") == 0);
g_assert (json_object_has_member (object, "latitude"));
latitude = json_object_get_double_member (object, "latitude");
g_assert (latitude > 60.1755 && latitude <= 60.1756);
g_assert (json_object_has_member (object, "longitude"));
longitude = json_object_get_double_member (object, "longitude");
g_assert (longitude >= 24.9342 && longitude < 24.9343);
g_assert (json_object_has_member (object, "city"));
g_assert (strcmp (json_object_get_string_member (object, "city"), "Helsinki") == 0);
g_assert (json_object_has_member (object, "region_name"));
g_assert (strcmp (json_object_get_string_member (object, "region_name"), "Southern Finland") == 0);
g_assert (json_object_has_member (object, "country_name"));
g_assert (strcmp (json_object_get_string_member (object, "country_name"), "Finland") == 0);
if (json_object_has_member (object, "accuracy"))
g_assert (strcmp (json_object_get_string_member (object, "accuracy"), "city") == 0);
if (json_object_has_member (object, "timezone"))
g_assert (strcmp (json_object_get_string_member (object, "timezone"), "Europe/Helsinki") == 0);
g_object_unref (parser);
}
static char *
get_freegeoip_response (void)
{
GFile *file;
char *contents = NULL;
char *path;
GError *error = NULL;
path = g_build_filename(TEST_SRCDIR, "freegeoip-results.json", NULL);
g_assert (path != NULL);
file = g_file_new_for_path(path);
if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error)) {
g_warning ("Failed to load file '%s': %s", path, error->message);
g_error_free (error);
g_assert_not_reached ();
}
g_free (path);
return contents;
}
static char *
get_fedora_geoip_response (void)
{
GFile *file;
char *contents = NULL;
char *path;
GError *error = NULL;
path = g_build_filename(TEST_SRCDIR, "fedora-geoip-results.json", NULL);
g_assert (path != NULL);
file = g_file_new_for_path(path);
if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error)) {
g_warning ("Failed to load file '%s': %s", path, error->message);
g_error_free (error);
g_assert_not_reached ();
}
g_free (path);
return contents;
}
static char *
get_our_server_response (const char *query)
{
char *response;
char *p;
char *standard_output;
int exit_status;
char **environ;
char *argv[] = { NULL, NULL };
GError *error = NULL;
environ = g_get_environ ();
environ = g_environ_setenv (environ, "QUERY_STRING", query, TRUE);
argv[0] = g_build_filename (BUILDDIR, "geoip-lookup", NULL);
g_assert (argv[0] != NULL);
if (!g_spawn_sync (BUILDDIR,
argv,
environ,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL,
NULL,
&standard_output,
NULL,
&exit_status,
&error)) {
g_warning ("Failed to execute '%s': %s", argv[0], error->message);
g_error_free (error);
g_assert_not_reached ();
}
g_strfreev (environ);
g_free (argv[0]);
/* Get rid of headers */
p = strstr (standard_output, "\n\n");
g_assert (p != NULL);
p += 2;
response = g_strdup (p);
g_free (standard_output);
return response;
}
int
main (int argc, char **argv)
{
char *our_response, *freegeoip_response, *fedora_geoip_response;
int ret;
#if (!GLIB_CHECK_VERSION (2, 36, 0))
g_type_init ();
#endif
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
our_response = get_our_server_response ("ip=213.243.180.91");
g_test_add_data_func ("/geoip/gclue-server-format",
our_response,
test_response_data);
freegeoip_response = get_freegeoip_response ();
g_test_add_data_func ("/geoip/freegeoip-format",
freegeoip_response,
test_response_data);
fedora_geoip_response = get_fedora_geoip_response ();
g_test_add_data_func ("/geoip/fedora-geoip-format",
fedora_geoip_response,
test_response_data);
ret = g_test_run ();
g_free (freegeoip_response);
g_free (fedora_geoip_response);
g_free (our_response);
return ret;
}
#!/bin/bash
# taken from http://git.gnome.org/browse/totem/tree/browser-plugin/tests/launch-web-server.sh with some necessary modifications
# Port to listen on
PORT=12345
usage()
{
echo "Usage: ./`basename $0` <--remote> [stop | start]"
echo " --remote: allow for connections from remote machines"
exit 1
}
# Find Apache first
if [ -x /usr/sbin/httpd ] ; then APACHE_HTTPD=/usr/sbin/httpd; fi
HTTPD=${APACHE_HTTPD:-/usr/sbin/apache2}
if [ -z $HTTPD ] ; then
echo "Could not find httpd at the usual locations"
exit 1
fi
# Check whether we in the right directory
if [ ! -f `basename $0` ] ; then
echo "You need to launch `basename $0` from within its directory"
echo "eg: ./`basename $0` <--remote> [stop | start]"
echo " --remote: allow for connections from remote machines"
exit 1
fi
ROOTDIR=`dirname $0`/root
# See if we shoud stop the web server
if [ -z $1 ] ; then
usage $0
fi
if [ x$1 = x"--remote" ] ; then
ADDRESS=
shift
else
ADDRESS=127.0.0.1
fi
if [ x$1 = xstop ] ; then
echo "Trying to stop $HTTPD(`cat root/pid`)"
pushd root/ > /dev/null
$HTTPD -f `pwd`/conf -k stop
popd > /dev/null
exit
elif [ x$1 != xstart ] ; then
usage $0
fi
# Setup the ServerRoot
if [ ! -d $ROOTDIR ] ; then
mkdir -p root/ || ( echo "Could not create the ServerRoot" ; exit 1 )
fi
DOCDIR=`pwd`
CGI_BIN_DIR=`pwd`/cgi-bin/
server_exec=geoip-lookup
#set up the cgi-bin directory
if [ ! -d $CGI_BIN_DIR ] ; then
mkdir -p cgi-bin/ || ( echo "Could not create the cgi-bin directory" ; exit 1 )
fi
if [ ! -f cgi-bin/$server_exec ] ; then
ln -s `pwd`/../$server_exec cgi-bin/$server_exec || ( echo "Could not create a symbolic link to the server executable" ; exit 1 )
fi
pushd root/ > /dev/null
# Resolve the relative ROOTDIR path
ROOTDIR=`pwd`
if [ -f pid ] && [ -f conf ] ; then
$HTTPD -f $ROOTDIR/conf -k stop
sleep 2
fi
rm -f conf pid lock log access_log
# Setup the config file
cat > conf <<EOF
LoadModule alias_module modules/mod_alias.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule access_compat_module modules/mod_access_compat.so
# Authentication modules
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_socache_module modules/mod_authn_socache.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_dbd_module modules/mod_authz_dbd.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgid_module modules/mod_cgid.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule status_module modules/mod_status.so
SetEnv HTTP_CLIENT_IP 24.24.24.24
ServerName localhost
ServerRoot "$ROOTDIR"
DefaultRuntimeDir "$ROOTDIR"
PidFile pid
#LockFile lock
# LogLevel crit
LogLevel info
ErrorLog log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog access_log combined
TypesConfig /etc/mime.types
# Socket for cgid communication
ScriptSock cgisock
<VirtualHost *:$PORT>
DocumentRoot "$DOCDIR"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "$DOCDIR">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ "$CGI_BIN_DIR"
<Directory "$CGI_BIN_DIR">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
StartServers 1
EOF
popd > /dev/null
# Launch!
#$HTTPD -f $ROOTDIR/conf -C "Listen 127.0.0.1:$PORT"
if [ -z $ADDRESS ] ; then
$HTTPD -f $ROOTDIR/conf -C "Listen $PORT"
else
$HTTPD -f $ROOTDIR/conf -C "Listen ${ADDRESS}:$PORT"
fi
echo "Please start debugging at http://localhost:$PORT/cgi-bin/$server_exec"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment