mirror of
https://github.com/owntracks/recorder.git
synced 2026-02-13 20:49:51 +00:00
NEW: tour views are stored in/read from STORAGEDIR/tours/
this separates manually created views from those submitted automatically from the apps, and solves the problem of having to make viewsdir writeable by the process owner of ot-recorder, which I find is a cleaner solution.
This commit is contained in:
@@ -244,7 +244,7 @@ This section lists the most important options of the Recorder with their long na
|
||||
|
||||
`--docroot` overrides the compile-time setting of the HTTP document root.
|
||||
|
||||
`--viewsdir` overrides the path to the JSON views, which defaults to `<docroot>/views`.
|
||||
`--viewsdir` overrides the path to the JSON views, which defaults to `<docroot>/views`. (Note that for the experimental _tours_ functionality the directory for the _tour views_ is in `<STORAGEDIR>/tours`.)
|
||||
|
||||
`--lua-script` specifies the path to the Lua script. If not given, Lua support is disabled.
|
||||
|
||||
|
||||
18
http.c
18
http.c
@@ -139,8 +139,17 @@ static JsonNode *loadview(struct udata *ud, const char *viewname)
|
||||
|
||||
view = json_mkobject();
|
||||
if (json_copy_from_file(view, UB(fpath)) != TRUE) {
|
||||
#ifdef WITH_SHARES
|
||||
/* Now try second possibility */
|
||||
utstring_renew(fpath);
|
||||
utstring_printf(fpath, "%s/%s.json", toursdir(), viewname);
|
||||
if (json_copy_from_file(view, UB(fpath)) != TRUE) {
|
||||
#endif
|
||||
json_delete(view);
|
||||
return (NULL);
|
||||
#ifdef WITH_SHARES
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return (view);
|
||||
@@ -962,8 +971,17 @@ static int view(struct mg_connection *conn, const char *viewname)
|
||||
debug(ud, "page file=%s", UB(fpath));
|
||||
|
||||
if ((fp = fopen(UB(fpath), "r")) == NULL) {
|
||||
#ifdef WITH_SHARES
|
||||
utstring_renew(fpath);
|
||||
utstring_printf(fpath, "%s/%s", toursdir(), j->string_);
|
||||
debug(ud, "page file=%s", UB(fpath));
|
||||
if ((fp = fopen(UB(fpath), "r")) == NULL) {
|
||||
#endif
|
||||
json_delete(view);
|
||||
return send_status(conn, 404, "Cannot open view page");
|
||||
#ifdef WITH_SHARES
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
mg_send_header(conn, "Content-type", "text/html");
|
||||
|
||||
14
recorder.c
14
recorder.c
@@ -460,11 +460,8 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
|
||||
json_append_member(o, "uuid", json_mkstring(uuid));
|
||||
json_append_member(o, "url", json_mkstring(UB(url)));
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s.json", ud->viewsdir, uuid);
|
||||
|
||||
olog(LOG_DEBUG, "New share %s for %s/%s", uuid, UB(username), UB(device));
|
||||
|
||||
if ((fp = fopen(path, "w")) != NULL) {
|
||||
snprintf(path, sizeof(path), "%s.json", uuid);
|
||||
if ((fp = tourfile(ud, path, "w")) != NULL) {
|
||||
char *js = json_stringify(o, " ");
|
||||
fprintf(fp, "%s\n", js);
|
||||
free(js);
|
||||
@@ -503,7 +500,6 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
|
||||
|
||||
} else if (strcmp(request_type, "shares") == 0) {
|
||||
|
||||
//FILE *fp;
|
||||
JsonNode *arr, *o;
|
||||
char path[BUFSIZ];
|
||||
DIR *dirp;
|
||||
@@ -517,7 +513,7 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
|
||||
|
||||
arr = json_mkarray();
|
||||
|
||||
if ((dirp = opendir(ud->viewsdir)) != NULL) {
|
||||
if ((dirp = opendir(toursdir())) != NULL) {
|
||||
while ((dp = readdir(dirp)) != NULL) {
|
||||
char *fn = dp->d_name;
|
||||
|
||||
@@ -529,7 +525,7 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
|
||||
continue;
|
||||
|
||||
o = json_mkobject();
|
||||
snprintf(path, sizeof(path), "%s/%s", ud->viewsdir, fn);
|
||||
snprintf(path, sizeof(path), "%s/%s", toursdir(), fn);
|
||||
if (json_copy_from_file(o, path) == false) {
|
||||
olog(LOG_ERR, "Can't copy JSON from %s", path);
|
||||
json_delete(o);
|
||||
@@ -578,7 +574,7 @@ void do_request(struct udata *ud, UT_string *username, UT_string *device, char *
|
||||
|
||||
olog(LOG_DEBUG, "Unshare %s for %s/%s", r->string_, UB(username), UB(device));
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s.json", ud->viewsdir, r->string_);
|
||||
snprintf(path, sizeof(path), "%s/%s.json", toursdir(), r->string_);
|
||||
if (access(path, R_OK) < 0) {
|
||||
olog(LOG_ERR, "Can't find share %s: %m", r->string_);
|
||||
}
|
||||
|
||||
28
util.c
28
util.c
@@ -642,4 +642,32 @@ char *uuid4()
|
||||
|
||||
return (uustr);
|
||||
}
|
||||
|
||||
char *toursdir()
|
||||
{
|
||||
static UT_string *path = NULL;
|
||||
|
||||
utstring_renew(path);
|
||||
utstring_printf(path, "%s/tours", STORAGEDIR);
|
||||
|
||||
return (UB(path));
|
||||
}
|
||||
|
||||
FILE *tourfile(struct udata *ud, char *filename, char *mode)
|
||||
{
|
||||
static UT_string *path = NULL;
|
||||
|
||||
utstring_renew(path);
|
||||
|
||||
utstring_printf(path, "%s", toursdir());
|
||||
|
||||
ut_clean(path);
|
||||
|
||||
if (mkpath(UB(path)) < 0) {
|
||||
olog(LOG_ERR, "Cannot create directory at %s: %m", UB(path));
|
||||
return (NULL);
|
||||
}
|
||||
utstring_printf(path, "/%s", filename);
|
||||
return (fopen(UB(path), mode));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user