Merge pull request #71 from maxried/master

--html-dir option
This commit is contained in:
Oliver Jowett 2015-09-14 20:34:32 +01:00
commit 3b4c872ea6
3 changed files with 10 additions and 5 deletions

View file

@ -154,6 +154,7 @@ void modesInitConfig(void) {
Modes.net_fatsv_port = MODES_NET_OUTPUT_FA_TSV_PORT; Modes.net_fatsv_port = MODES_NET_OUTPUT_FA_TSV_PORT;
Modes.interactive_rows = getTermRows(); Modes.interactive_rows = getTermRows();
Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL; Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
Modes.html_dir = HTMLPATH;
Modes.json_interval = 1000; Modes.json_interval = 1000;
Modes.json_location_accuracy = 1; Modes.json_location_accuracy = 1;
Modes.maxRange = 1852 * 300; // 300NM default max range Modes.maxRange = 1852 * 300; // 300NM default max range
@ -713,6 +714,7 @@ void showHelp(void) {
"--quiet Disable output to stdout. Use for daemon applications\n" "--quiet Disable output to stdout. Use for daemon applications\n"
"--show-only <addr> Show only messages from the given ICAO on stdout\n" "--show-only <addr> Show only messages from the given ICAO on stdout\n"
"--ppm <error> Set receiver error in parts per million (default 0)\n" "--ppm <error> Set receiver error in parts per million (default 0)\n"
"--html-dir <dir> Use <dir> as base directory for the internal HTTP server. Defaults to " HTMLPATH "\n"
"--write-json <dir> Periodically write json output to <dir> (for serving by a separate webserver)\n" "--write-json <dir> Periodically write json output to <dir> (for serving by a separate webserver)\n"
"--write-json-every <t> Write json output every t seconds (default 1)\n" "--write-json-every <t> Write json output every t seconds (default 1)\n"
"--json-location-accuracy <n> Accuracy of receiver location in json metadata: 0=no location, 1=approximate, 2=exact\n" "--json-location-accuracy <n> Accuracy of receiver location in json metadata: 0=no location, 1=approximate, 2=exact\n"
@ -1060,6 +1062,8 @@ int main(int argc, char **argv) {
Modes.interactive_rtl1090 = 1; Modes.interactive_rtl1090 = 1;
} else if (!strcmp(argv[j],"--oversample")) { } else if (!strcmp(argv[j],"--oversample")) {
Modes.oversample = 1; Modes.oversample = 1;
} else if (!strcmp(argv[j], "--html-dir") && more) {
Modes.html_dir = strdup(argv[++j]);
#ifndef _WIN32 #ifndef _WIN32
} else if (!strcmp(argv[j], "--write-json") && more) { } else if (!strcmp(argv[j], "--write-json") && more) {
Modes.json_dir = strdup(argv[++j]); Modes.json_dir = strdup(argv[++j]);

View file

@ -325,6 +325,7 @@ struct { // Internal state
int interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090 int interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090
char *json_dir; // Path to json base directory, or NULL not to write json. char *json_dir; // Path to json base directory, or NULL not to write json.
uint64_t json_interval; // Interval between rewriting the json aircraft file, in milliseconds; also the advertised map refresh interval uint64_t json_interval; // Interval between rewriting the json aircraft file, in milliseconds; also the advertised map refresh interval
char *html_dir; // Path to www base directory.
int json_location_accuracy; // Accuracy of location metadata: 0=none, 1=approx, 2=exact int json_location_accuracy; // Accuracy of location metadata: 0=none, 1=approx, 2=exact
int throttle; // When reading from a file, throttle file playback to realtime? int throttle; // When reading from a file, throttle file playback to realtime?

View file

@ -1315,15 +1315,15 @@ static int handleHTTPRequest(struct client *c, char *p) {
char getFile[1024]; char getFile[1024];
if (strlen(url) < 2) { if (strlen(url) < 2) {
snprintf(getFile, sizeof getFile, "%s/gmap.html", HTMLPATH); // Default file snprintf(getFile, sizeof getFile, "%s/gmap.html", Modes.html_dir); // Default file
} else { } else {
snprintf(getFile, sizeof getFile, "%s/%s", HTMLPATH, url); snprintf(getFile, sizeof getFile, "%s/%s", Modes.html_dir, url);
} }
if (!realpath(getFile, rp)) if (!realpath(getFile, rp))
rp[0] = 0; rp[0] = 0;
if (!realpath(HTMLPATH, hrp)) if (!realpath(Modes.html_dir, hrp))
strcpy(hrp, HTMLPATH); strcpy(hrp, Modes.html_dir);
clen = -1; clen = -1;
content = strdup("Server error occured"); content = strdup("Server error occured");
@ -1342,7 +1342,7 @@ static int handleHTTPRequest(struct client *c, char *p) {
if (clen < 0) { if (clen < 0) {
content = realloc(content, 128); content = realloc(content, 128);
clen = snprintf(content, 128,"Error opening HTML file: %s", strerror(errno)); clen = snprintf(content, 128, "Error opening HTML file: %s", strerror(errno));
statuscode = 404; statuscode = 404;
statusmsg = "Not Found"; statusmsg = "Not Found";
} }