mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-23 11:26:16 +00:00
Maps browser API key file (apikey.js) is now served by the Recorder
- new option in Recorder: --browser-apikey addresses #146
This commit is contained in:
@@ -869,11 +869,10 @@ Note, that Jane's user/device tuple should also be returned in order to display
|
||||
|
||||
### Browser API keys
|
||||
|
||||
In order to use the Recorder's maps and views, you have to obtain a [Google API "Browser key"](https://developers.google.com/maps/documentation/javascript/get-api-key). You then add this key to your docroot directory so that the Recorder can find it. (You should already have a file called `apikey.js.sample` in that directory; copy or rename the file to `apikey.js` and ensure its content is valid JavaScript:
|
||||
In order to use the Recorder's maps and views, you have to obtain a [Google API "Browser key"](https://developers.google.com/maps/documentation/javascript/get-api-key). You then pass this key to your Recorder invocation.
|
||||
|
||||
```bash
|
||||
$ cat .../static/apikey.js
|
||||
var apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
$ ot-recorder --browser-apikey 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ...
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
apikey.js
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
var apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
@@ -826,6 +826,23 @@ static JsonNode *viewdata(struct mg_connection *conn, JsonNode *view, int limit)
|
||||
return (locs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build and return JavaScript file containing an API key variable in it.
|
||||
*/
|
||||
|
||||
static int apikey(struct mg_connection *conn)
|
||||
{
|
||||
struct udata *ud = (struct udata *)conn->server_param;
|
||||
static UT_string *sbuf = NULL;
|
||||
|
||||
utstring_renew(sbuf);
|
||||
utstring_printf(sbuf, "var apiKey = '%s';",
|
||||
ud->browser_apikey ? ud->browser_apikey : "");
|
||||
|
||||
mg_printf_data(conn, "%s", UB(sbuf));
|
||||
return (MG_TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* We're being asked for a view. `viewname' contains the ID for this view.
|
||||
* A view is a JSON file in docroot. The JSON describes which file
|
||||
@@ -1393,6 +1410,9 @@ int ev_handler(struct mg_connection *conn, enum mg_event ev)
|
||||
return view(conn, conn->uri + strlen("/view/"));
|
||||
}
|
||||
|
||||
if (strstr(conn->uri, "/apikey.js") != NULL) {
|
||||
return apikey(conn);
|
||||
}
|
||||
|
||||
|
||||
if (!strcmp(conn->request_method, "POST")) {
|
||||
|
||||
@@ -1144,6 +1144,7 @@ void usage(char *prog)
|
||||
printf(" --http-port <port> -A HTTP port (8083); 0 to disable HTTP\n");
|
||||
printf(" --doc-root <directory> document root (%s)\n", DOCROOT);
|
||||
printf(" --http-logdir <directory> directory in which to store access.log\n");
|
||||
printf(" --browser-apikey <key> Google maps browser API key\n");
|
||||
#endif
|
||||
#ifdef WITH_LUA
|
||||
printf(" --lua-script <script.lua> path to Lua script. If unset, no Lua hooks\n");
|
||||
@@ -1212,6 +1213,7 @@ int main(int argc, char **argv)
|
||||
udata.http_host = strdup("localhost");
|
||||
udata.http_port = 8083;
|
||||
udata.http_logdir = NULL;
|
||||
udata.browser_apikey = NULL;
|
||||
#endif
|
||||
#ifdef WITH_LUA
|
||||
udata.luascript = NULL;
|
||||
@@ -1302,6 +1304,7 @@ int main(int argc, char **argv)
|
||||
{ "http-port", required_argument, 0, 'A'},
|
||||
{ "doc-root", required_argument, 0, 2},
|
||||
{ "http-logdir", required_argument, 0, 14},
|
||||
{ "browser-apikey", required_argument, 0, 15},
|
||||
#endif
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@@ -1386,6 +1389,11 @@ int main(int argc, char **argv)
|
||||
case 14:
|
||||
if (ud->http_logdir) free(ud->http_logdir);
|
||||
ud->http_logdir = strdup(optarg);
|
||||
break;
|
||||
case 15:
|
||||
if (ud->browser_apikey) free(ud->browser_apikey);
|
||||
ud->browser_apikey = strdup(optarg);
|
||||
break;
|
||||
#endif
|
||||
case 'D':
|
||||
ud->skipdemo = FALSE;
|
||||
@@ -1705,6 +1713,7 @@ int main(int argc, char **argv)
|
||||
#ifdef WITH_HTTP
|
||||
mg_destroy_server(&udata.mgserver);
|
||||
free(ud->http_host);
|
||||
free(ud->browser_apikey);
|
||||
if (ud->http_logdir) free(ud->http_logdir);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ struct udata {
|
||||
char *http_host; /* address of http bind */
|
||||
int http_port; /* port number for above */
|
||||
char *http_logdir; /* full path to http access log */
|
||||
char *browser_apikey; /* Google maps browser API key */
|
||||
#endif
|
||||
#ifdef WITH_LUA
|
||||
char *luascript; /* Path to Lua script */
|
||||
|
||||
Reference in New Issue
Block a user