From 9a10ef48866e03b94a3d01b43695a01d2462d9b4 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 11:41:02 +0100 Subject: [PATCH 1/6] Remove a stray "fi" in the initscript. Should fix #127. --- debian/dump1090-mutability.init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/dump1090-mutability.init b/debian/dump1090-mutability.init index c77d04e..33f3934 100644 --- a/debian/dump1090-mutability.init +++ b/debian/dump1090-mutability.init @@ -61,7 +61,7 @@ if [ -n "$PPM" ]; then ARGS="$ARGS --ppm $PPM"; fi if [ "x$FIX_CRC" = "xyes" ]; then ARGS="$ARGS --fix"; fi if [ -n "$LAT" ]; then ARGS="$ARGS --lat $LAT"; fi if [ -n "$LON" ]; then ARGS="$ARGS --lon $LON"; fi -ARGS="$ARGS --max-range $MAX_RANGE"; fi +ARGS="$ARGS --max-range $MAX_RANGE" # net: From e4ceea33dac83d3c2ea668141ddd51abf5342d0c Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 11:56:31 +0100 Subject: [PATCH 2/6] Disable the internal webserver at build time. --- dump1090.c | 10 ++++++++++ dump1090.h | 2 ++ net_io.c | 14 ++++++++++++-- stats.c | 4 ++++ stats.h | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dump1090.c b/dump1090.c index 41f8572..a2a6a31 100644 --- a/dump1090.c +++ b/dump1090.c @@ -150,7 +150,9 @@ void modesInitConfig(void) { Modes.net_output_sbs_ports = strdup("30003"); Modes.net_input_beast_ports = strdup("30004,30104"); Modes.net_output_beast_ports = strdup("30005"); +#ifdef ENABLE_WEBSERVER Modes.net_http_ports = strdup("8080"); +#endif Modes.interactive_rows = getTermRows(); Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL; Modes.html_dir = HTMLPATH; @@ -680,7 +682,9 @@ void showHelp(void) { "--modeac Enable decoding of SSR Modes 3/A & 3/C\n" "--net-only Enable just networking, no RTL device or file used\n" "--net-bind-address IP address to bind to (default: Any; Use 127.0.0.1 for private)\n" +#ifdef ENABLE_WEBSERVER "--net-http-port HTTP server ports (default: 8080)\n" +#endif "--net-ri-port TCP raw input listen ports (default: 30001)\n" "--net-ro-port TCP raw output listen ports (default: 30002)\n" "--net-sbs-port TCP BaseStation output listen ports (default: 30003)\n" @@ -993,8 +997,14 @@ int main(int argc, char **argv) { free(Modes.net_bind_address); Modes.net_bind_address = strdup(argv[++j]); } else if (!strcmp(argv[j],"--net-http-port") && more) { +#ifdef ENABLE_WEBSERVER free(Modes.net_http_ports); Modes.net_http_ports = strdup(argv[++j]); +#else + if (strcmp(argv[++j], "0")) { + fprintf(stderr, "warning: --net-http-port not supported in this build, option ignored.\n"); + } +#endif } else if (!strcmp(argv[j],"--net-sbs-port") && more) { free(Modes.net_output_sbs_ports); Modes.net_output_sbs_ports = strdup(argv[++j]); diff --git a/dump1090.h b/dump1090.h index 26a7941..d98353e 100644 --- a/dump1090.h +++ b/dump1090.h @@ -292,7 +292,9 @@ struct { // Internal state char *net_output_sbs_ports; // List of SBS output TCP ports char *net_input_beast_ports; // List of Beast input TCP ports char *net_output_beast_ports; // List of Beast output TCP ports +#ifdef ENABLE_WEBSERVER char *net_http_ports; // List of HTTP ports +#endif char *net_bind_address; // Bind address int net_sndbuf_size; // TCP output buffer size (64Kb * 2^n) int net_verbatim; // if true, send the original message, not the CRC-corrected one diff --git a/net_io.c b/net_io.c index d2b0a89..2d5dfc4 100644 --- a/net_io.c +++ b/net_io.c @@ -69,7 +69,9 @@ static int decodeBinMessage(struct client *c, char *p); static int decodeHexMessage(struct client *c, char *hex); +#ifdef ENABLE_WEBSERVER static int handleHTTPRequest(struct client *c, char *p); +#endif static void send_raw_heartbeat(struct net_service *service); static void send_beast_heartbeat(struct net_service *service); @@ -258,8 +260,10 @@ void modesInitNet(void) { s = makeBeastInputService(); serviceListen(s, Modes.net_bind_address, Modes.net_input_beast_ports); +#ifdef ENABLE_WEBSERVER s = serviceInit("HTTP server", NULL, NULL, "\r\n\r\n", handleHTTPRequest); serviceListen(s, Modes.net_bind_address, Modes.net_http_ports); +#endif } // //========================================================================= @@ -1083,9 +1087,11 @@ static char * appendStatsJson(char *p, else p += snprintf(p, end-p, ",%u", st->remote_accepted[i]); } - p += snprintf(p, end-p, "]"); + p += snprintf(p, end-p, "]}"); - p += snprintf(p, end-p, "},\"http_requests\":%u", st->http_requests); +#ifdef ENABLE_WEBSERVER + p += snprintf(p, end-p, ",\"http_requests\":%u", st->http_requests); +#endif } { @@ -1277,6 +1283,7 @@ void writeJsonToFile(const char *file, char * (*generator) (const char *,int*)) } +#ifdef ENABLE_WEBSERVER // //========================================================================= @@ -1471,6 +1478,9 @@ static int handleHTTPRequest(struct client *c, char *p) { Modes.stats_current.http_requests++; return !keepalive; } + +#endif + // //========================================================================= // diff --git a/stats.c b/stats.c index 46ee2a7..38ae169 100644 --- a/stats.c +++ b/stats.c @@ -155,8 +155,10 @@ void display_stats(struct stats *st) { printf("%u unique aircraft tracks\n", st->unique_aircraft); printf("%u aircraft tracks where only one message was seen\n", st->single_message_aircraft); +#ifdef ENABLE_WEBSERVER if (Modes.net) printf("%d HTTP requests\n", st->http_requests); +#endif { uint64_t demod_cpu_millis = (uint64_t)st->demod_cpu.tv_sec*1000UL + st->demod_cpu.tv_nsec/1000000UL; @@ -307,8 +309,10 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t // total messages: target->messages_total = st1->messages_total + st2->messages_total; +#ifdef ENABLE_WEBSERVER // network: target->http_requests = st1->http_requests + st2->http_requests; +#endif // CPR decoding: target->cpr_surface = st1->cpr_surface + st2->cpr_surface; diff --git a/stats.h b/stats.h index fee4d7d..cfbd854 100644 --- a/stats.h +++ b/stats.h @@ -95,8 +95,10 @@ struct stats { // total messages: uint32_t messages_total; +#ifdef ENABLE_WEBSERVER // network: uint32_t http_requests; +#endif // CPR decoding: unsigned int cpr_surface; From ebfa6f63be3e0cbf2a519a226329241dc723ded3 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 11:58:46 +0100 Subject: [PATCH 3/6] Strip out the config options for the internal webserver. --- debian/config-template | 8 -------- debian/dump1090-mutability.config | 2 -- debian/dump1090-mutability.init | 3 +-- debian/dump1090-mutability.postinst | 1 - debian/dump1090-mutability.templates | 11 ----------- 5 files changed, 1 insertion(+), 24 deletions(-) diff --git a/debian/config-template b/debian/config-template index ead9469..7d138a8 100644 --- a/debian/config-template +++ b/debian/config-template @@ -51,14 +51,6 @@ MAX_RANGE= # Networking options # -# Port to listen on for HTTP connections. 0 disables. -# HTTP defaults to being disabled unless you specify something here. I -# that you do not enable this, and instead serve the contents of -# /usr/share/dump1090-mutability and JSON_DIR (below) using a proper -# webserver. See /etc/lighttpd/conf-available/90-dump1090.conf -# for an example configuration ("sudo lighty-enable-mod dump1090" to enable) -HTTP_PORT= - # Port to listen on for raw (AVR-format) input connections. 0 disables. RAW_INPUT_PORT= diff --git a/debian/dump1090-mutability.config b/debian/dump1090-mutability.config index 435be45..08fec89 100644 --- a/debian/dump1090-mutability.config +++ b/debian/dump1090-mutability.config @@ -29,7 +29,6 @@ if [ -e $CONFIGFILE ]; then db_set $NAME/decode-lon "$LON" db_set $NAME/decode-max-range "$MAX_RANGE" - db_set $NAME/net-http-port "$HTTP_PORT" db_set $NAME/net-ri-port "$RAW_INPUT_PORT" db_set $NAME/net-ro-port "$RAW_OUTPUT_PORT" db_set $NAME/net-bi-port "$BEAST_INPUT_PORT" @@ -209,7 +208,6 @@ db_go || true; db_get $NAME/auto-start; if [ "$RET" = "true" ]; then db_input_verify medium $NAME/decode-lon is_number_or_empty || true fi - db_input_verify medium $NAME/net-http-port is_port_list || true db_input_verify low $NAME/net-ri-port is_port_list || true db_input_verify low $NAME/net-ro-port is_port_list || true db_input_verify low $NAME/net-bi-port is_port_list || true diff --git a/debian/dump1090-mutability.init b/debian/dump1090-mutability.init index 33f3934..1bb4adb 100644 --- a/debian/dump1090-mutability.init +++ b/debian/dump1090-mutability.init @@ -33,7 +33,6 @@ SCRIPTNAME=/etc/init.d/$NAME # sanitize missing settings [ -z "$START_DUMP1090" ] && START_DUMP1090=no [ -z "$DUMP1090_USER" ] && DUMP1090_USER="missing-DUMP1090_USER-setting-in-config" -[ -z "$HTTP_PORT" ] && HTTP_PORT=0 [ -z "$RAW_INPUT_PORT" ] && RAW_INPUT_PORT=0 [ -z "$RAW_OUTPUT_PORT" ] && RAW_OUTPUT_PORT=0 [ -z "$SBS_OUTPUT_PORT" ] && SBS_OUTPUT_PORT=0 @@ -65,7 +64,7 @@ ARGS="$ARGS --max-range $MAX_RANGE" # net: -ARGS="$ARGS --net-http-port $HTTP_PORT \ +ARGS="$ARGS \ --net-ri-port $RAW_INPUT_PORT --net-ro-port $RAW_OUTPUT_PORT \ --net-bi-port $BEAST_INPUT_PORT --net-bo-port $BEAST_OUTPUT_PORT \ --net-sbs-port $SBS_OUTPUT_PORT" diff --git a/debian/dump1090-mutability.postinst b/debian/dump1090-mutability.postinst index 189f603..244679f 100644 --- a/debian/dump1090-mutability.postinst +++ b/debian/dump1090-mutability.postinst @@ -79,7 +79,6 @@ case "$1" in subvar decode-lat LAT subvar decode-lon LON subvar decode-max-range MAX_RANGE - subvar net-http-port HTTP_PORT subvar net-ri-port RAW_INPUT_PORT subvar net-ro-port RAW_OUTPUT_PORT subvar net-bi-port BEAST_INPUT_PORT diff --git a/debian/dump1090-mutability.templates b/debian/dump1090-mutability.templates index bb59662..19762d2 100644 --- a/debian/dump1090-mutability.templates +++ b/debian/dump1090-mutability.templates @@ -94,17 +94,6 @@ Description: Absolute maximum range of receiver, in nautical miles: Type: string Default: 300 -Template: dump1090-mutability/net-http-port -Description: Port for internal webserver (0 disables): - dump1090 can provide an internal webserver that serves a basic "virtual - radar" map. - . - It is generally a better idea to use an external webserver, but if you - really want to use the internal one, you can select a port to listen - on here. -Type: string -Default: 0 - Template: dump1090-mutability/net-ri-port Description: Portsfor AVR-format input connections (0 disables): dump1090 can accept connections to receive data from other sources in From 9012b46ee17c27ed73d1b305302cdb4f97a4b5d9 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 12:00:46 +0100 Subject: [PATCH 4/6] Make the lighttpd enable/disable a bit more automatic. --- debian/dump1090-mutability.postinst | 8 ++++++++ debian/dump1090-mutability.postrm | 15 ++++++++++++--- debian/dump1090-mutability.templates | 11 ++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/debian/dump1090-mutability.postinst b/debian/dump1090-mutability.postinst index 244679f..5038c52 100644 --- a/debian/dump1090-mutability.postinst +++ b/debian/dump1090-mutability.postinst @@ -116,6 +116,14 @@ case "$1" in touch $RET chown $RUNAS $RET + # enable lighttpd if needed + db_get $NAME/use-lighttpd + if [ "$RET" = "true" -a -x /usr/sbin/lighty-enable-mod ] + then + echo "Enabling lighttpd integration.." >&2 + /usr/sbin/lighty-enable-mod dump1090 || true + fi + # this config file has changed a few times, restart lighttpd to make sure we # have the latest version if [ -e /etc/lighttpd/conf-enabled/89-dump1090.conf ]; then diff --git a/debian/dump1090-mutability.postrm b/debian/dump1090-mutability.postrm index f5405fa..6251a8f 100644 --- a/debian/dump1090-mutability.postrm +++ b/debian/dump1090-mutability.postrm @@ -24,10 +24,19 @@ case "$1" in rm -f /etc/default/dump1090-mutability rm -f /etc/cron.d/dump1090-mutability rm -rf /var/cache/dump1090-mutability - ;; + ;; - remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) - ;; + remove) + if [ -e /etc/lighttpd/conf-enabled/89-dump1090.conf ]; then + echo "Disabling lighttpd integration.." >&2 + lighty-disable-mod dump1090 || true + echo "Restarting lighttpd.." >&2 + invoke-rc.d lighttpd restart || echo "Warning: lighttpd failed to restart." >&2 + fi + ;; + + upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; *) echo "postrm called with unknown argument \`$1'" >&2 diff --git a/debian/dump1090-mutability.templates b/debian/dump1090-mutability.templates index 19762d2..fc9929e 100644 --- a/debian/dump1090-mutability.templates +++ b/debian/dump1090-mutability.templates @@ -186,13 +186,22 @@ Description: Interval between logging stats, in seconds: Type: string Default: 3600 +Template: dump1090-mutability/use-lighttpd +Description: Enable the lighttpd integration? + dump1090 can serve a virtual radar map via a separate webserver. + This package includes a configuration for lighttpd that does this. + To use that configuration, enable this option. +Type: boolean +Default: true + Template: dump1090-mutability/json-dir Description: Directory to write JSON aircraft state to: As this can be written frequently, you should select a location that is not on a sdcard. The default path under /run is on tmpfs and will not write to the sdcard. . - A blank path disables writing JSON state. + A blank path disables writing JSON state. This will also disable + the virtual radar map. Type: string Default: /run/dump1090-mutability From ad3d0e4d747a726fb131292c63948695e74af3ec Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 12:13:49 +0100 Subject: [PATCH 5/6] Upgrade the lighttpd dependency to Recommends --- debian/control | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/debian/control b/debian/control index e052b15..8c146e4 100644 --- a/debian/control +++ b/debian/control @@ -10,8 +10,7 @@ Vcs-Git: https://github.com/mutability/dump1090.git Package: dump1090-mutability Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, adduser -Recommends: python(>=2.5), cron | cron-daemon, curl -Suggests: lighttpd +Recommends: python(>=2.5), cron | cron-daemon, curl, lighttpd Provides: fatsv-data-source Description: ADS-B Ground Station System for RTL-SDR Networked Aviation Mode S / ADS-B decoder/translator with RTL-SDR software From b2aaa23984c374c7431c4f73ed392b0080c17a62 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 10 Jul 2016 12:21:35 +0100 Subject: [PATCH 6/6] Remove the last vestiges of the update-aircraft-db cronjob. --- debian/control | 2 +- debian/cron-template | 12 --- debian/dump1090-mutability.init | 1 - debian/dump1090-mutability.postinst | 4 +- debian/dump1090-mutability.postrm | 2 - tools/update-aircraft-database.sh | 109 ---------------------------- 6 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 debian/cron-template delete mode 100755 tools/update-aircraft-database.sh diff --git a/debian/control b/debian/control index 8c146e4..349c53d 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Git: https://github.com/mutability/dump1090.git Package: dump1090-mutability Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, adduser -Recommends: python(>=2.5), cron | cron-daemon, curl, lighttpd +Recommends: python(>=2.5), lighttpd Provides: fatsv-data-source Description: ADS-B Ground Station System for RTL-SDR Networked Aviation Mode S / ADS-B decoder/translator with RTL-SDR software diff --git a/debian/cron-template b/debian/cron-template deleted file mode 100644 index 38b1210..0000000 --- a/debian/cron-template +++ /dev/null @@ -1,12 +0,0 @@ -## TEMPLATE FILE - This is used to create /etc/cron.d/dump1090-mutability ## -## The first three lines will be discarded ## - -# Checks for updates to the VRS aircraft database once a day at around 5am; -# when an update is available, downloads it and regenerates the JSON data -# used by the webmap. - -# NB: the minute value below is randomly generated on install, to avoid -# all installs hitting the server at the same time. - -# m h dom mon dow user command -@MIN@ 5 * * * @USER@ test -x /usr/share/dump1090-mutability/update-aircraft-database.sh && /usr/share/dump1090-mutability/update-aircraft-database.sh --log-to-file diff --git a/debian/dump1090-mutability.init b/debian/dump1090-mutability.init index 1bb4adb..4ccbc36 100644 --- a/debian/dump1090-mutability.init +++ b/debian/dump1090-mutability.init @@ -126,7 +126,6 @@ do_start() fi # create logfile with the appropriate permissions if not already there - # (the cronjob running as DUMP1090_USER wants to append to it) touch $LOGFILE chown "$DUMP1090_USER":root $LOGFILE diff --git a/debian/dump1090-mutability.postinst b/debian/dump1090-mutability.postinst index 5038c52..30151d2 100644 --- a/debian/dump1090-mutability.postinst +++ b/debian/dump1090-mutability.postinst @@ -21,8 +21,6 @@ NAME=dump1090-mutability CONFIGFILE=/etc/default/$NAME SRCCONFIGFILE=$CONFIGFILE TEMPLATECONFIG=/usr/share/$NAME/config-template -CRONFILE=/etc/cron.d/$NAME -TEMPLATECRON=/usr/share/$NAME/cron-template SEDSCRIPT=$CONFIGFILE.sed.tmp subvar_raw() { @@ -111,7 +109,7 @@ case "$1" in adduser --system --home /usr/share/$NAME --no-create-home --quiet "$RUNAS" fi - # create log if missing; change ownership if needed so the cronjob works + # create log if missing; change ownership if needed db_get $NAME/log-file touch $RET chown $RUNAS $RET diff --git a/debian/dump1090-mutability.postrm b/debian/dump1090-mutability.postrm index 6251a8f..625de17 100644 --- a/debian/dump1090-mutability.postrm +++ b/debian/dump1090-mutability.postrm @@ -22,8 +22,6 @@ set -e case "$1" in purge) rm -f /etc/default/dump1090-mutability - rm -f /etc/cron.d/dump1090-mutability - rm -rf /var/cache/dump1090-mutability ;; remove) diff --git a/tools/update-aircraft-database.sh b/tools/update-aircraft-database.sh deleted file mode 100755 index af1c502..0000000 --- a/tools/update-aircraft-database.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash - -# This script checks for a new version of BasicAircraftLookup from -# the VRS website and, if one is available, downloads it and updates -# the dump1090 webmap json files. - -set -e - -# defaults that can be overridden: -VRS_URL=${VRS_URL:-http://www.virtualradarserver.co.uk/Files/BasicAircraftLookup.sqb.gz} -CACHEDIR=${CACHEDIR:-/var/cache/dump1090-mutability} -JSONDIR=${JSONDIR:-$CACHEDIR/db} -SQBDIR=${SQBDIR:-$CACHEDIR/sqb} -LOGFILE=${LOGFILE:-/var/log/dump1090-mutability.log} -UPDATESCRIPT=${UPDATESCRIPT:-/usr/share/dump1090-mutability/vrs-basicaircraft-to-json.py} - -if [ -f /etc/default/dump1090-mutability ] -then - . /etc/default/dump1090-mutability -fi - -ETAGFILE=$SQBDIR/BasicAircraftLookup.sqb.etag -SQBFILE=$SQBDIR/BasicAircraftLookup.sqb - -CHECKMODIFIED=true -LOGTOFILE=false -while [ "$#" -gt 0 ] -do - case "$1" in - -f|--force) CHECKMODIFIED=false ;; - -l|--log-to-file) LOGTOFILE=true ;; - *) echo "unrecognized option: $1" >&2; exit 1 ;; - esac - shift -done - -if $LOGTOFILE; then exec >>$LOGFILE 2>&1; fi - -log() { - date "+%c $*" >&2 -} - -mkdir -p $CACHEDIR $JSONDIR $SQBDIR -rm -f $ETAGFILE.new $SQBFILE.new - -log "Checking VRS server for an updated database.." - -# get ETag -curl --silent --fail --include --head $VRS_URL | grep ETag >$ETAGFILE.new - -# check for existing file -RETRIEVE=true -ARGS="" -if $CHECKMODIFIED && [ -f $SQBFILE ] -then - if [ -s $ETAGFILE -a -s $ETAGFILE.new ] - then - if cmp -s $ETAGFILE $ETAGFILE.new - then - log "Database not modified." - RETRIEVE=false - else - log "Database modified, will retrieve a new copy." - fi - else - # do an if-modified-since - log "Database possibly modified, will try to retrieve a new copy." - ARGS="-z $SQBFILE" - fi -fi - -if $RETRIEVE -then - log "Retrieving database.." - curl --silent --fail --remote-time --retry 2 $ARGS -o $SQBFILE.new $VRS_URL - mv $ETAGFILE.new $ETAGFILE - if [ -f $SQBFILE.new ] - then - log "Decompressing database.." - zcat $SQBFILE.new >$SQBFILE - touch -r $SQBFILE.new $SQBFILE - rm $SQBFILE.new - else - log "Database not modified." - fi -fi - -UPDATE=true -if $CHECKMODIFIED -then - if test -f $JSONDIR/last_update; then - if ! test $SQBFILE -nt $JSONDIR/last_update; then UPDATE=false; fi - fi -fi - -if $UPDATE -then - log "Updating JSON files from database.." - mkdir -p $JSONDIR/new - $UPDATESCRIPT $SQBFILE $JSONDIR/new - rm -f $JSONDIR/*.json - mv $JSONDIR/new/*.json $JSONDIR/ - touch -r $SQBFILE $JSONDIR/last_update - rmdir $JSONDIR/new - log "Done." -else - log "No update to JSON files needed." -fi -