Add input validation to most of the config questions.
> Some people, when confronted with a problem, think "I know, I'll use regular expressions." > Now they have two problems. Dongle "device index" actually accepts serial numbers too, document that.
This commit is contained in:
parent
9fa09e0e92
commit
55ecde9d53
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -7,6 +7,8 @@ dump1090-mutability (1.08.2302.14+1mu-3) UNRELEASED; urgency=medium
|
|||
* Use the package version as the version number compiled into the binary.
|
||||
* Add data/receiver.json (generated once) and support for it in script.js.
|
||||
* Internal webserver rearrangement to support multiple json files.
|
||||
* Dongle "device index" actually accepts serial numbers too, document that.
|
||||
* Add input validation to most of the config questions.
|
||||
|
||||
-- Oliver Jowett <oliver@mutability.co.uk> Wed, 10 Dec 2014 02:01:27 +0000
|
||||
|
||||
|
|
2
debian/config-template
vendored
2
debian/config-template
vendored
|
@ -19,7 +19,7 @@ LOGFILE=
|
|||
# Receiver options
|
||||
#
|
||||
|
||||
# RTLSDR device index to use
|
||||
# RTLSDR device index or serial number to use
|
||||
# If set to "none", dump1090 will be started in --net-only mode
|
||||
DEVICE=
|
||||
|
||||
|
|
141
debian/dump1090-mutability.config
vendored
141
debian/dump1090-mutability.config
vendored
|
@ -52,47 +52,148 @@ fi
|
|||
|
||||
# Ask questions.
|
||||
|
||||
db_input_verify() {
|
||||
# $1 = priority
|
||||
# $2 = db key
|
||||
# $3 = verification function, should return 0 if OK
|
||||
PRI=$1; KEY=$2; VERIFY=$3
|
||||
|
||||
set +e
|
||||
db_input $PRI $KEY; RESULT=$?
|
||||
db_go
|
||||
set -e
|
||||
while :
|
||||
do
|
||||
db_get $KEY
|
||||
if $VERIFY $RET; then return 0; fi
|
||||
if [ $RESULT -ne 0 ]; then
|
||||
# db_input failed, and the existing value does not validate
|
||||
if [ $RESULT = 30 ] && [ $PRI != high ]
|
||||
then
|
||||
# question wasn't displayed, but existing value is invalid
|
||||
# bump priority and try again
|
||||
PRI=high
|
||||
else
|
||||
# give up, use the default value
|
||||
db_reset $KEY
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# db_input was OK, but the value did not verify.
|
||||
# display an error and try again.
|
||||
set +e
|
||||
db_input high dump1090-mutability/invalid-$VERIFY
|
||||
db_fset $KEY seen false
|
||||
db_input high $KEY; RESULT=$?
|
||||
db_go
|
||||
set -e
|
||||
done
|
||||
}
|
||||
|
||||
is_unsigned_int() {
|
||||
if echo "$1" | grep -Eq '^(0|+?[1-9][0-9]*)$'; then return 0; else return 1; fi
|
||||
}
|
||||
|
||||
is_unsigned_int_or_empty() {
|
||||
if [ -z "$1" ]; then return 0
|
||||
elif is_unsigned_int "$1"; then return 0
|
||||
else return 1; fi
|
||||
}
|
||||
|
||||
is_signed_int() {
|
||||
if echo "$1" | grep -Eq '^(0|[+-]?[1-9][0-9]*)$'; then return 0; else return 1; fi
|
||||
}
|
||||
|
||||
is_signed_int_or_empty() {
|
||||
if [ -z "$1" ]; then return 0
|
||||
elif is_signed_int "$1"; then return 0
|
||||
else return 1; fi
|
||||
}
|
||||
|
||||
is_ipaddrish() {
|
||||
if echo "$1" | grep -Eq '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'; then return 0; else return 1; fi
|
||||
}
|
||||
|
||||
is_ipaddrish_or_empty() {
|
||||
if [ -z "$1" ]; then return 0
|
||||
elif is_ipaddrish "$1"; then return 0
|
||||
else return 1; fi
|
||||
}
|
||||
|
||||
is_number() {
|
||||
if echo "$1" | grep -Eq '^(0|[+-]?[1-9][0-9]*)(\.[0-9]+)?$'; then return 0; else return 1; fi
|
||||
}
|
||||
|
||||
is_number_or_empty() {
|
||||
if [ -z "$1" ]; then return 0
|
||||
elif is_number "$1"; then return 0;
|
||||
else return 1; fi
|
||||
}
|
||||
|
||||
is_valid_gain() {
|
||||
if is_number "$1"; then return 0;
|
||||
elif [ "$1" = "max" ]; then return 0;
|
||||
elif [ "$1" = "agc" ]; then return 0;
|
||||
else return 1; fi
|
||||
}
|
||||
|
||||
is_not_empty() {
|
||||
if [ -z "$1" ]; then return 1; else return 0; fi
|
||||
}
|
||||
|
||||
is_port_number() {
|
||||
if is_unsigned_int "$1"; then
|
||||
if [ "$1" -eq 0 ]; then return 0; fi
|
||||
if [ "$1" -lt 1024 ]; then return 1; fi
|
||||
if [ "$1" -gt 65535 ]; then return 1; fi
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
db_input high $NAME/auto-start || true
|
||||
|
||||
db_go || true; db_get $NAME/auto-start; if [ "$RET" = "true" ]; then
|
||||
# all of these are only relevant if the init script is enabled
|
||||
|
||||
db_input low $NAME/run-as-user || true
|
||||
db_input low $NAME/log-file || true
|
||||
db_input_verify low $NAME/run-as-user is_not_empty || true
|
||||
db_input_verify low $NAME/log-file is_not_empty || true
|
||||
|
||||
db_input medium $NAME/rtlsdr-device || true
|
||||
|
||||
db_go || true; db_get $NAME/rtlsdr-device; if [ "x$RET" != "xnone" ]; then
|
||||
# only if a real device was chosen:
|
||||
db_input medium $NAME/rtlsdr-gain || true
|
||||
db_input medium $NAME/rtlsdr-ppm || true
|
||||
db_input_verify medium $NAME/rtlsdr-gain is_valid_gain || true
|
||||
db_input_verify medium $NAME/rtlsdr-ppm is_signed_int || true
|
||||
db_input low $NAME/rtlsdr-oversample || true
|
||||
fi
|
||||
|
||||
db_input low $NAME/decode-fix-crc || true
|
||||
db_input low $NAME/decode-aggressive || true
|
||||
db_input medium $NAME/decode-lat || true
|
||||
db_input_verify medium $NAME/decode-lat is_number_or_empty || true
|
||||
|
||||
db_go || true; db_get $NAME/decode-lat; if [ -n "$RET" ]; then
|
||||
# only if latitude was given:
|
||||
db_input medium $NAME/decode-lon || true
|
||||
db_input_verify medium $NAME/decode-lon is_number_or_empty || true
|
||||
fi
|
||||
|
||||
db_input medium $NAME/net-http-port || true
|
||||
db_input low $NAME/net-ri-port || true
|
||||
db_input low $NAME/net-ro-port || true
|
||||
db_input low $NAME/net-bi-port || true
|
||||
db_input low $NAME/net-bo-port || true
|
||||
db_input low $NAME/net-sbs-port || true
|
||||
db_input low $NAME/net-fatsv-port || true
|
||||
db_input low $NAME/net-heartbeat || true
|
||||
db_input low $NAME/net-out-size || true
|
||||
db_input low $NAME/net-out-interval || true
|
||||
db_input low $NAME/net-buffer || true
|
||||
db_input medium $NAME/net-bind-address || true
|
||||
db_input_verify medium $NAME/net-http-port is_port_number || true
|
||||
db_input_verify low $NAME/net-ri-port is_port_number || true
|
||||
db_input_verify low $NAME/net-ro-port is_port_number || true
|
||||
db_input_verify low $NAME/net-bi-port is_port_number || true
|
||||
db_input_verify low $NAME/net-bo-port is_port_number || true
|
||||
db_input_verify low $NAME/net-sbs-port is_port_number || true
|
||||
db_input_verify low $NAME/net-fatsv-port is_port_number || true
|
||||
db_input_verify low $NAME/net-heartbeat is_unsigned_int || true
|
||||
db_input_verify low $NAME/net-out-size is_unsigned_int || true
|
||||
db_input_verify low $NAME/net-out-interval is_unsigned_int || true
|
||||
db_input_verify low $NAME/net-buffer is_unsigned_int || true
|
||||
db_input_verify medium $NAME/net-bind-address is_ipaddrish_or_empty || true
|
||||
|
||||
db_input low $NAME/stats-interval || true
|
||||
db_input low $NAME/json-interval || true
|
||||
db_input_verify low $NAME/stats-interval is_unsigned_int || true
|
||||
db_input_verify low $NAME/json-interval is_unsigned_int || true
|
||||
|
||||
db_go || true; db_get $NAME/json-interval; if [ -n "$RET" ] && [ "$RET" -gt 0 ]; then
|
||||
# only if json-interval was given and non-zero
|
||||
|
|
74
debian/dump1090-mutability.templates
vendored
74
debian/dump1090-mutability.templates
vendored
|
@ -2,6 +2,10 @@ Template: dump1090-mutability/auto-start
|
|||
Description: Start dump1090 automatically?
|
||||
dump1090 can be started automatically via an init-script.
|
||||
Otherwise, the init-script does nothing; you must run dump1090 by hand.
|
||||
.
|
||||
You can modify the options used when automatically starting
|
||||
dump1090 by running "dpkg-reconfigure dump1090-mutability" as root,
|
||||
or by editing /etc/default/dump1090-mutability.
|
||||
Type: boolean
|
||||
Default: true
|
||||
|
||||
|
@ -21,12 +25,15 @@ Default: /var/log/dump1090-mutability.log
|
|||
|
||||
Template: dump1090-mutability/rtlsdr-device
|
||||
Description: RTL-SDR dongle to use:
|
||||
If you have only one dongle connected, select 0. If you have more than one
|
||||
dongle connected, select the index of the dongle to use (0 is the first
|
||||
dongle). If you want to run dump1090 in "net only" mode, select "none".
|
||||
Type: select
|
||||
Choices: none, 0, 1, 2, 3, 4, 5
|
||||
Default: 0
|
||||
If you have only one dongle connected, you can leave this blank.
|
||||
.
|
||||
Otherwise, you can provide the serial number (more reliable) or device
|
||||
index (first device = 0, but the ordering is unpredictable) to choose
|
||||
a particular dongle to use.
|
||||
.
|
||||
To run dump1090 in "net only" mode, specify the literal word "none".
|
||||
Type: string
|
||||
Default:
|
||||
|
||||
Template: dump1090-mutability/rtlsdr-gain
|
||||
Description: RTL-SDR gain, in dB:
|
||||
|
@ -208,19 +215,22 @@ Default: 3600
|
|||
|
||||
Template: dump1090-mutability/json-dir
|
||||
Description: Directory to write JSON aircraft state to:
|
||||
dump1090 periodicallys write a list of aircraft, in JSON format, for use
|
||||
by the virtual radar view when using an external webserver. This setting
|
||||
controls the directory to write to.
|
||||
.
|
||||
As this is written frequently (by default, once a second), you should
|
||||
probably select a location that is not on a sdcard. The default path
|
||||
under /run is on tmpfs and will not write to the sdcard.
|
||||
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.
|
||||
Type: string
|
||||
Default: /run/dump1090-mutability
|
||||
|
||||
Template: dump1090-mutability/json-interval
|
||||
Description: Interval between writing JSON aircraft state, in seconds:
|
||||
Here you can control how often the JSON state is updated.
|
||||
dump1090 periodically write a list of aircraft, in JSON format, for use
|
||||
by the virtual radar view when using an external webserver. This setting
|
||||
controls the directory to write to.
|
||||
.
|
||||
Here you can control how often the JSON state is updated, which determines
|
||||
how frequently the virtual radar view updates.
|
||||
.
|
||||
A value of 0 will disable writing JSON state entirely.
|
||||
Type: string
|
||||
Default: 1
|
||||
|
||||
|
@ -229,3 +239,39 @@ Description: Extra arguments to pass to dump1090:
|
|||
Here you can add any extra arguments you want to pass to dump1090.
|
||||
Type: string
|
||||
Default:
|
||||
|
||||
Template: dump1090-mutability/invalid-is_unsigned_int
|
||||
Description: Value must be an unsigned integer.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_unsigned_int_or_empty
|
||||
Description: Value must be an unsigned integer, or blank.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_signed_int
|
||||
Description: Value must be an integer.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_signed_int_or_empty
|
||||
Description: Value must be an integer, or blank.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_not_empty
|
||||
Description: Value cannot be empty.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_port_number
|
||||
Description: Value must be a valid port number (1024-65535), or zero to disable.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_ipaddrish_or_empty
|
||||
Description: Value must be an IP address or empty.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_number_or_empty
|
||||
Description: Value must be a decimal number or empty.
|
||||
Type: error
|
||||
|
||||
Template: dump1090-mutability/invalid-is_valid_gain
|
||||
Description: Value must be a numeric gain value, or "max", or "agc".
|
||||
Type: error
|
||||
|
|
Loading…
Reference in a new issue