[hamradio-commits] [dump1090] 01/01: this patch got truncated during the merge somehow...
Matthew Ernisse
mernisse-guest at moszumanska.debian.org
Wed Nov 5 00:30:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
mernisse-guest pushed a commit to branch master
in repository dump1090.
commit 06a2ad0eafa37a7f6b7ad621043cc289f993871e
Author: Matthew Ernisse <mernisse at ub3rgeek.net>
Date: Tue Nov 4 19:30:48 2014 -0500
this patch got truncated during the merge somehow...
---
.../05-disable-local-file-http-access.patch | 159 ++++++++++++++++++++-
1 file changed, 157 insertions(+), 2 deletions(-)
diff --git a/debian/patches/05-disable-local-file-http-access.patch b/debian/patches/05-disable-local-file-http-access.patch
index d8694c9..5206946 100644
--- a/debian/patches/05-disable-local-file-http-access.patch
+++ b/debian/patches/05-disable-local-file-http-access.patch
@@ -1,11 +1,10 @@
Description: Disable local file serving from the internal HTTP server.
- This patch relies somewhat on the 02-http-buffer.patch being applied.
.
This patch also adds support for user lattitude and longitude variables
on the command line to be passed up to the web ui, removing the need for
the user to edit both /etc/defaults/dump1090 AND config.js.
Author: Matthew John Ernisse <mernisse at ub3rgeek.net>
-Forwarded: no
+Forwarded: https://github.com/MalcolmRobb/dump1090/pull/53
--- a/public_html/script.js
+++ b/public_html/script.js
@@ -97,3 +96,159 @@ Forwarded: no
totlen += nwritten;
buf += nwritten;
}
+--- a/net_io.c
++++ b/net_io.c
+@@ -697,6 +697,11 @@
+ //
+ //=========================================================================
+ //
++
++// RFC2616 defines the status line as "Version Code Reason"
++#define HTTP_OK "200 OK"
++#define HTTP_NOTFOUND "404 Not Found"
++#define HTTP_SERVERERROR "500 Server Error"
+ #define MODES_CONTENT_TYPE_HTML "text/html;charset=utf-8"
+ #define MODES_CONTENT_TYPE_CSS "text/css;charset=utf-8"
+ #define MODES_CONTENT_TYPE_JSON "application/json;charset=utf-8"
+@@ -712,8 +717,8 @@
+ int handleHTTPRequest(struct client *c, char *p) {
+ char hdr[512];
+ int clen, hdrlen;
++ char *httpcode = HTTP_OK;
+ int httpver, keepalive;
+- int statuscode = 500;
+ char *url, *content;
+ char ctype[48];
+ char getFile[1024];
+@@ -755,42 +760,73 @@
+ // Select the content to send, we have just two so far:
+ // "/" -> Our google map application.
+ // "/data.json" -> Our ajax request to update planes.
++ // "/config.json" -> Our ajax request to configure the webui.
+ if (strstr(url, "/data.json")) {
+- statuscode = 200;
+ content = aircraftsToJson(&clen);
+ //snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_JSON);
++ } else if (strstr(url, "/config.json")) {
++ if (Modes.fUserLat != 0.0 && Modes.fUserLon != 0.0) {
++ char buf[128];
++ clen = snprintf(buf, sizeof(buf),
++ "{\"SiteLat\": %f, \"SiteLon\": %f}",
++ Modes.fUserLat, Modes.fUserLon);
++ content = strdup(buf);
++ } else {
++ content = strdup("{}");
++ clen = strlen(content);
++ }
+ } else {
++#ifndef DEBIAN
+ struct stat sbuf;
+ int fd = -1;
+ char *rp, *hrp;
++ char buf[128];
+
+ rp = realpath(getFile, NULL);
+ hrp = realpath(HTMLPATH, NULL);
+ hrp = (hrp ? hrp : HTMLPATH);
+- clen = -1;
+- content = strdup("Server error occured");
++
++ content = strdup("Not found.");
++ clen = strlen(content);
++ httpcode = HTTP_NOTFOUND;
++
+ if (rp && (!strncmp(hrp, rp, strlen(hrp)))) {
+- if (stat(getFile, &sbuf) != -1 && (fd = open(getFile, O_RDONLY)) != -1) {
++ if (stat(getFile, &sbuf) != -1 &&
++ (fd = open(getFile, O_RDONLY)) != -1) {
+ content = (char *) realloc(content, sbuf.st_size);
++
+ if (read(fd, content, sbuf.st_size) != -1) {
+ clen = sbuf.st_size;
+- statuscode = 200;
++ httpcode = HTTP_OK;
++ } else {
++ clen = snprintf(buf, sizeof(buf), "Error reading %s: %s",
++ getFile, strerror(errno));
++ httpcode = HTTP_SERVERERROR;
+ }
++ } else {
++ httpcode = HTTP_NOTFOUND;
++ clen = snprintf(buf, sizeof(buf), "Error opening %s: %s",
++ getFile, strerror(errno));
++ content = strdup(buf);
+ }
+- } else {
+- errno = ENOENT;
+- }
+-
+- if (clen < 0) {
+- content = realloc(content, 128);
+- clen = snprintf(content, 128,"Error opening HTML file: %s", strerror(errno));
+- statuscode = 404;
+ }
+
+ if (fd != -1) {
+ close(fd);
+ }
+ }
++#endif
++
++#ifdef DEBIAN
++ /* Disable local filesystem access in the Debian build. The package
++ * will use apache2 and a reverse proxy to serve HTTP due to the
++ * complexity of maintaining a secure HTTP implementation.
++ */
++ httpcode = HTTP_NOTFOUND;
++ content = strdup("File not found.");
++ clen = strlen(content);
++ }
++#endif
+
+ // Get file extension and content type
+ snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_HTML); // Default content type
+@@ -808,7 +844,7 @@
+
+ // Create the header and send the reply
+ hdrlen = snprintf(hdr, sizeof(hdr),
+- "HTTP/1.1 %d \r\n"
++ "HTTP/1.1 %s\r\n"
+ "Server: Dump1090\r\n"
+ "Content-Type: %s\r\n"
+ "Connection: %s\r\n"
+@@ -816,7 +852,7 @@
+ "Cache-Control: no-cache, must-revalidate\r\n"
+ "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
+ "\r\n",
+- statuscode,
++ httpcode,
+ ctype,
+ keepalive ? "keep-alive" : "close",
+ clen);
+@@ -827,15 +863,23 @@
+
+ // Send header and content.
+ #ifndef _WIN32
+- if ( (write(c->fd, hdr, hdrlen) != hdrlen)
+- || (write(c->fd, content, clen) != clen) ) {
++ if (anetWrite(c->fd, hdr, hdrlen) != hdrlen) {
++ perror("HTTP short write of reply header");
++ free(content);
++ return 1;
++ }
++ if (anetWrite(c->fd, content, clen) != clen) {
++ perror("HTTP short write of content");
++ free(content);
++ return 1;
++ }
+ #else
+ if ( (send(c->fd, hdr, hdrlen, 0) != hdrlen)
+ || (send(c->fd, content, clen, 0) != clen) ) {
+-#endif
+ free(content);
+ return 1;
+ }
++#endif
+ free(content);
+ Modes.stat_http_requests++;
+ return !keepalive;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git
More information about the pkg-hamradio-commits
mailing list