diff --git a/Makefile b/Makefile index 334b846..b379c65 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,10 @@ else CFLAGS += -DJSON_INDENT=NULL endif +ifneq ($(APIKEY),) + CFLAGS += -DAPIKEY="\"$(APIKEY)\"" +endif + CFLAGS += -DSTORAGEDEFAULT=\"$(STORAGEDEFAULT)\" @@ -63,20 +67,19 @@ ghash2lmdb: ghash2lmdb.o $(OTR_OBJS) $(CC) $(CFLAGS) -o ghash2lmdb ghash2lmdb.o $(OTR_OBJS) $(LIBS) -ot-recorder.o: ot-recorder.c storage.h util.h Makefile geo.h udata.h config.h json.h http.h gcache.h -geo.o: geo.h geo.c udata.h Makefile config.mk config.h +ot-recorder.o: ot-recorder.c storage.h util.h Makefile geo.h udata.h json.h http.h gcache.h config.mk +geo.o: geo.h geo.c udata.h Makefile config.mk geohash.o: geohash.h geohash.c udata.h Makefile config.mk base64.o: base64.h base64.c -gcache.o: gcache.c gcache.h json.h -jget.o: jget.c jget.h json.h Makefile config.mk +gcache.o: gcache.c gcache.h json.h config.mk misc.o: misc.c misc.h udata.h Makefile config.mk -http.o: http.c mongoose.h util.h http.h storage.h +http.o: http.c mongoose.h util.h http.h storage.h config.mk util.o: util.c util.h Makefile config.mk -ghashfind.o: ghashfind.c util.h +ghashfind.o: ghashfind.c util.h config.mk mongoose.o: mongoose.c mongoose.h ocat.o: ocat.c storage.h util.h config.mk version.h -storage.o: storage.c storage.h config.h util.h gcache.h -ghash2lmdb.o: ghash2lmdb.c gcache.h +storage.o: storage.c storage.h util.h gcache.h config.mk +ghash2lmdb.o: ghash2lmdb.c gcache.h config.mk clean: diff --git a/README.md b/README.md index 2da443c..50de718 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ As mentioned earlier, data is stored in files, and these files are relative to ` ## Installation 1. Copy `config.mk.in` to `config.mk` and select the features you want (defaults should be ok). -2. Copy `config.h.example` to `config.h` and edit. 3. Type `make` ## Reverse Geo diff --git a/config.h.example b/config.h.example deleted file mode 100644 index a9b1d5c..0000000 --- a/config.h.example +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Google Maps reverse geocoding URL. - * If you need to use an API KEY, change the scheme to "https:" - * and add "&key=xxxxx" to the end of this URL - */ - -#define GURL "http://maps.googleapis.com/maps/api/geocode/json?latlng=%lf,%lf&sensor=false&language=EN" - diff --git a/config.mk.in b/config.mk.in index bb98727..aa2d051 100644 --- a/config.mk.in +++ b/config.mk.in @@ -1,16 +1,20 @@ -# Select features +# Select features you want. Default is fine for most installations + +# Do you want recorder's built-in HTTP REST API? HAVE_HTTP ?= yes + +# Do you want to use reverse-geo caching? (Highly recommended) HAVE_LMDB ?= yes + +# Do you want support for the `pingping' monitoring feature? HAVE_PING ?= yes -STORAGEDEFAULT = "./store" - -# Optionally specify the path to the Mosquitto libs, include here -MOSQUITTO_INC = -I/usr/include -MOSQUITTO_LIB = -L/usr/lib +# Where should the recorder store its data? This directory must +# exist and be writeable by recorder (and readable by ocat) +STORAGEDEFAULT = "/var/spool/owntracks/recorder/store" # Define the precision for reverse-geo lookups. The higher -# the number, the more granular reverse-geo will be. +# the number, the more granular reverse-geo will be: # # 1 => 5,009.4km x 4,992.6km # 2 => 1,252.3km x 624.1km @@ -27,4 +31,15 @@ GHASHPREC = 7 # Should the JSON emitted by recorder be indented? (i.e. beautified) # yes or no -JSON_INDENT ?= yes +JSON_INDENT ?= no + +# If you do more than 2500 (currently) reverse-geo requests per day, +# you'll need an API key for Google's geocoding service. Specify +# that here +# APIKEY ?= YYYYYYYYYY +APIKEY ?= + +# Optionally specify the path to the Mosquitto libs, include here +MOSQUITTO_INC = -I/usr/include +MOSQUITTO_LIB = -L/usr/lib + diff --git a/geo.c b/geo.c index 6514ded..bad41ab 100644 --- a/geo.c +++ b/geo.c @@ -25,10 +25,11 @@ #include #include #include "utstring.h" -#include "config.h" #include "geo.h" #include "json.h" +#define GURL "%s://maps.googleapis.com/maps/api/geocode/json?latlng=%lf,%lf&sensor=false&language=EN" + static CURL *curl; static size_t writemem(void *contents, size_t size, size_t nmemb, void *userp) @@ -144,7 +145,12 @@ JsonNode *revgeo(double lat, double lon, UT_string *addr, UT_string *cc) utstring_renew(url); utstring_renew(cbuf); - utstring_printf(url, GURL, lat, lon); +#ifdef APIKEY + utstring_printf(url, GURL, "https", lat, lon); + utstring_printf(url, "&key=%s", APIKEY); +#else + utstring_printf(url, GURL, "http", lat, lon); +#endif curl_easy_setopt(curl, CURLOPT_URL, utstring_body(url)); curl_easy_setopt(curl, CURLOPT_USERAGENT, "ot-recorder-agent/1.0"); diff --git a/http.c b/http.c index 4f38957..6a32888 100644 --- a/http.c +++ b/http.c @@ -26,7 +26,6 @@ #include #include #include "json.h" -#include "config.h" #include "util.h" #include "misc.h" #include "storage.h" diff --git a/jget.h b/jget.h deleted file mode 100644 index fbd85eb..0000000 --- a/jget.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "json.h" - -JsonNode *jget(JsonNode *json, char *args); diff --git a/ot-recorder.c b/ot-recorder.c index f354c0f..baec614 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -35,7 +35,6 @@ #include "utstring.h" #include "utarray.h" #include "geo.h" -#include "config.h" #include "geohash.h" #include "base64.h" #include "misc.h" diff --git a/storage.c b/storage.c index 274db50..5e4b6f7 100644 --- a/storage.c +++ b/storage.c @@ -32,7 +32,6 @@ #include #include #include "utstring.h" -#include "config.h" #include "storage.h" #include "geohash.h" #include "util.h" diff --git a/udata.h b/udata.h index 8bec50e..d070e41 100644 --- a/udata.h +++ b/udata.h @@ -1,7 +1,6 @@ #ifndef UDATA_H_INCLUDED # define UDATA_H_INCLUDED -#include "config.h" #include "utarray.h" #ifdef HAVE_HTTP diff --git a/util.c b/util.c index 3b21bc3..82e9587 100644 --- a/util.c +++ b/util.c @@ -24,7 +24,6 @@ #include #include #include -#include "config.h" #include "util.h" #include "misc.h" #include diff --git a/util.h b/util.h index 988b14a..d57a63f 100644 --- a/util.h +++ b/util.h @@ -7,7 +7,6 @@ #endif #include -#include "config.h" #include #include "json.h" #include "utstring.h"