remove support for Greenwich devices

closes #484
This commit is contained in:
Jan-Piet Mens
2024-07-30 17:08:21 +02:00
parent aae3dae4b6
commit 229ad96ba6
9 changed files with 0 additions and 258 deletions

View File

@@ -72,10 +72,6 @@ ifeq ($(WITH_TOURS),yes)
endif endif
endif endif
ifeq ($(WITH_GREENWICH),yes)
CFLAGS += -DWITH_GREENWICH=1
endif
ifeq ($(WITH_TZ),yes) ifeq ($(WITH_TZ),yes)
CFLAGS += -DWITH_TZ CFLAGS += -DWITH_TZ
CFLAGS += -DTZDATADB=\"$(TZDATADB)\" CFLAGS += -DTZDATADB=\"$(TZDATADB)\"

View File

@@ -58,9 +58,6 @@ WITH_KILL ?= no
# This requires WITH_LMDB to be configured. # This requires WITH_LMDB to be configured.
WITH_ENCRYPT ?= no WITH_ENCRYPT ?= no
# Do you require support for OwnTracks Greenwich firmware?
WITH_GREENWICH ?= no
# Where should the recorder store its data? This directory must # Where should the recorder store its data? This directory must
# exist and be writeable by recorder (and readable by ocat) # exist and be writeable by recorder (and readable by ocat)
STORAGEDEFAULT = /var/spool/owntracks/recorder/store STORAGEDEFAULT = /var/spool/owntracks/recorder/store

View File

@@ -11,7 +11,6 @@ WITH_LUA ?= yes
WITH_PING ?= yes WITH_PING ?= yes
WITH_KILL ?= yes WITH_KILL ?= yes
WITH_ENCRYPT ?= yes WITH_ENCRYPT ?= yes
WITH_GREENWICH ?= yes
STORAGEDEFAULT = /var/spool/owntracks/recorder/store STORAGEDEFAULT = /var/spool/owntracks/recorder/store
DOCROOT = /var/spool/owntracks/recorder/htdocs DOCROOT = /var/spool/owntracks/recorder/htdocs

View File

@@ -11,7 +11,6 @@ WITH_LUA ?= yes
WITH_PING ?= yes WITH_PING ?= yes
WITH_KILL ?= yes WITH_KILL ?= yes
WITH_ENCRYPT ?= yes WITH_ENCRYPT ?= yes
WITH_GREENWICH ?= yes
WITH_TZ ?= yes WITH_TZ ?= yes
STORAGEDEFAULT = /var/spool/owntracks/recorder/store STORAGEDEFAULT = /var/spool/owntracks/recorder/store

View File

@@ -12,7 +12,6 @@ WITH_LUA ?= yes
WITH_PING ?= yes WITH_PING ?= yes
WITH_KILL ?= yes WITH_KILL ?= yes
WITH_ENCRYPT ?= yes WITH_ENCRYPT ?= yes
WITH_GREENWICH ?= yes
WITH_TZ ?= yes WITH_TZ ?= yes
STORAGEDEFAULT = /var/spool/owntracks/recorder/store STORAGEDEFAULT = /var/spool/owntracks/recorder/store

98
http.c
View File

@@ -709,99 +709,6 @@ static int dopublish(struct mg_connection *conn, const char *uri)
return json_response(conn, jarray); return json_response(conn, jarray);
} }
#if WITH_GREENWICH
/*
# OLD
* username=XXX&password=YYY&tid=ZZ&nrecs=NNNN&topic=owntracks/gw/K2
*
* NEW
* user=XXX&device=YYYY&limit=NNNN
*
*/
static int ctrl_track(struct mg_connection *conn)
{
struct udata *ud = (struct udata *)conn->server_param;
int limit = 500;
char *p, *username = NULL, *device = NULL;
char *from = NULL, *to = NULL;
time_t s_lo, s_hi;
JsonNode *response, *obj, *locs, *fields, *json, *arr;
if ((p = field(conn, "user")) != NULL) {
username = strdup(p);
}
if ((p = field(conn, "device")) != NULL) {
device = strdup(p);
}
if ((p = field(conn, "limit")) != NULL) {
limit = atoi(p);
free(p);
}
if (!username || !device) {
send_status(conn, 416, "user and/or device missing");
return (MG_TRUE);
}
if (make_times(from, &s_lo, to, &s_hi, 0) != 1) {
send_status(conn, 416, "impossible date/time ranges");
return (MG_TRUE);
}
s_lo -= (30 * 24 * 60 * 60); /* move start point to a month prior */
response = json_mkobject();
json_append_member(response, "message", json_mkstring("OK"));
fields = json_mkarray();
json_append_element(fields, json_mkstring("tst"));
json_append_element(fields, json_mkstring("lat"));
json_append_element(fields, json_mkstring("lon"));
/*
* Obtain a list of .rec files from lister(), possibly limited
* by s_lo/s_hi times, process each and build the JSON object
* `obj` containing an array of locations.
*/
obj = json_mkobject();
locs = json_mkarray();
debug(ud, "ctrl_track u=%s, d=%s, f=%ld, t=%ld", username, device, s_lo, s_hi);
if ((json = lister(username, device, s_lo, s_hi, (limit > 0) ? TRUE : FALSE)) != NULL) {
int i_have = 0;
if ((arr = json_find_member(json, "results")) != NULL) {
JsonNode *f;
json_foreach(f, arr) {
locations(f->string_, obj, locs, s_lo, s_hi, JSON, limit, fields, NULL, NULL);
if (limit) {
i_have += limit;
if (i_have >= limit) {
break;
}
}
}
}
json_delete(json);
}
json_delete(obj);
json_delete(fields);
json_append_member(response, "track", locs);
return (json_response(conn, response));
}
#endif /* WITH_GREENWICH */
/* /*
* Procure back-end data for a VIEW. `view' is the JSON view from which * Procure back-end data for a VIEW. `view' is the JSON view from which
* we obtain who/what to get. This returns a JSON array of location * we obtain who/what to get. This returns a JSON array of location
@@ -1547,11 +1454,6 @@ int ev_handler(struct mg_connection *conn, enum mg_event ev)
if (!strcmp(conn->request_method, "POST")) { if (!strcmp(conn->request_method, "POST")) {
#if WITH_GREENWICH
if (!strncmp(conn->uri, "/ctrl/track", strlen("/ctrl/track"))) {
return ctrl_track(conn);
}
#endif /* WITH_GREENWICH */
if (!strcmp(conn->uri, "/block")) { if (!strcmp(conn->uri, "/block")) {
int blocked = TRUE; int blocked = TRUE;
char buf[BUFSIZ], *u; char buf[BUFSIZ], *u;

5
misc.c
View File

@@ -321,11 +321,6 @@ void display_json_variables(struct udata *ud, bool plain)
#else #else
j_bool(json, "WITH_ENCRYPT", false); j_bool(json, "WITH_ENCRYPT", false);
#endif #endif
#ifdef WITH_GREENWICH
j_bool(json, "WITH_GREENWICH", true);
#else
j_bool(json, "WITH_GREENWICH", false);
#endif
#ifdef WITH_HTTP #ifdef WITH_HTTP
j_bool(json, "WITH_HTTP", true); j_bool(json, "WITH_HTTP", true);
#else #else

View File

@@ -627,77 +627,6 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
} }
#endif /* WITH_TOURS */ #endif /* WITH_TOURS */
#ifdef WITH_GREENWICH
/*
* key is "batt", "ext", or "status"
* value is a string which contains a number
*
* Open/create a file at gw/user/device/user-device.json. Append to the existing array,
* limiting the number of array entries.
*/
void store_gwvalue(char *username, char *device, time_t tst, char *key, char *value)
{
static UT_string *ts = NULL, *u = NULL, *d = NULL;
JsonNode *array, *o, *j;
int count = 0;
char *js;
utstring_renew(ts);
utstring_renew(u);
utstring_renew(d);
utstring_printf(u, "%s", username);
utstring_printf(d, "%s", device);
lowercase(UB(u));
lowercase(UB(d));
utstring_printf(ts, "%s/last/%s/%s",
STORAGEDIR,
UB(u),
UB(d));
if (mkpath(UB(ts)) < 0) {
olog(LOG_ERR, "Cannot mkdir %s: %m", UB(ts));
return;
}
utstring_printf(ts, "/%s.json", key);
/* Read file into array or create array on error */
if ((js = slurp_file(UB(ts), TRUE)) != NULL) {
if ((array = json_decode(js)) == NULL) {
array = json_mkarray();
}
free(js);
} else {
array = json_mkarray();
}
/* Count elements in array and pop first if too long */
json_foreach(j, array) {
++count;
}
if (count >= GWNUMBERSMAX) {
j = json_first_child(array);
json_delete(j);
}
o = json_mkobject();
json_append_member(o, "tst", json_mknumber(tst));
json_append_member(o, key, json_mknumber(atof(value)));
json_append_element(array, o);
if ((js = json_stringify(array, NULL)) != NULL) {
safewrite(UB(ts), js);
free(js);
}
json_delete(array);
}
#endif /* GREENWICH */
#if WITH_ENCRYPT #if WITH_ENCRYPT
/* /*
* Decrypt the payload and return a pointer to allocated space containing * Decrypt the payload and return a pointer to allocated space containing
@@ -907,25 +836,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
} }
#endif #endif
#ifdef WITH_GREENWICH
/*
* For Greenwich: handle owntracks/user/device/voltage/batt, voltage/ext, and
* status all of which have a numeric payload.
*/
if ((count == 5+skipslash && !strcmp(topics[3+skipslash], "voltage")) &&
(!strcmp(topics[4+skipslash], "batt") || !strcmp(topics[4+skipslash], "ext"))) {
store_gwvalue(UB(username), UB(device), now, topics[4+skipslash], payload);
}
if (count == 4+skipslash && !strcmp(topics[3+skipslash], "status")) {
store_gwvalue(UB(username), UB(device), now, "status", payload);
}
/* Fall through to store this payload in the REC file as well. */
#endif
splitterfree(topics); splitterfree(topics);
/* /*
@@ -1318,16 +1228,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle
* of which device is being updated; use topic. * of which device is being updated; use topic.
*/ */
#if WITH_GREENWICH
if (strcmp(UB(reltopic), "alarm") == 0) {
json_append_member(json, "topic", json_mkstring(UB(basetopic)));
json_append_member(json, "_reltopic", json_mkstring("alarm"));
} else {
json_append_member(json, "topic", json_mkstring(topic));
}
#else
json_append_member(json, "topic", json_mkstring(topic)); json_append_member(json, "topic", json_mkstring(topic));
#endif
/* /*
* We have to know which user/device this is for in order to * We have to know which user/device this is for in order to

View File

@@ -169,49 +169,6 @@ static int user_device_list(char *name, int level, JsonNode *obj)
return (rc); return (rc);
} }
#if WITH_GREENWICH
/*
* See if we have batt,ext,status data for this device, and if so, add
* their arrays into the JSON object at `last'.
*/
static void get_gw_data(char *username, char *device, JsonNode *last)
{
JsonNode *array;
static char *types[] = { "batt", "ext", "status", NULL };
char **t, *js;
static UT_string *ts = NULL, *u = NULL, *d = NULL;
if (last == NULL || last->tag != JSON_OBJECT)
return;
for (t = types; t && *t; t++) {
utstring_renew(u);
utstring_renew(d);
utstring_printf(u, "%s", username);
utstring_printf(d, "%s", device);
lowercase(UB(u));
lowercase(UB(d));
utstring_renew(ts);
utstring_printf(ts, "%s/last/%s/%s/%s.json",
STORAGEDIR,
UB(u),
UB(d),
*t);
/* Read file into JSON array and append to `last' object */
if ((js = slurp_file(UB(ts), TRUE)) != NULL) {
if ((array = json_decode(js)) != NULL) {
json_append_member(last, *t, array);
}
free(js);
}
}
}
#endif /* GREENWICH */
void append_card_to_object(JsonNode *obj, char *user, char *device) void append_card_to_object(JsonNode *obj, char *user, char *device)
{ {
char path[LARGEBUF], path1[LARGEBUF], *cardfile = NULL; char path[LARGEBUF], path1[LARGEBUF], *cardfile = NULL;
@@ -297,9 +254,6 @@ void append_device_details(JsonNode *userlist, char *user, char *device)
snprintf(path, LARGEBUF, "%s/last/%s/%s/extra.json", snprintf(path, LARGEBUF, "%s/last/%s/%s/extra.json",
STORAGEDIR, user, device); STORAGEDIR, user, device);
json_copy_from_file(last, path); json_copy_from_file(last, path);
#if WITH_GREENWICH
get_gw_data(user, device, last);
#endif
json_append_element(userlist, last); json_append_element(userlist, last);
} }