banip: update 0.2.0

* remove 'http-only' mode, all sources are now fetched from https sites
* the backup mode is now mandatory ('/tmp' is the default backup
  directory), always create and re-use backups if available.
  To force a re-download take the 'reload' action.
* support 'sshd' in addition to 'dropbear' for logfile parsing
  to detect break-in events
* always update the black-/whitelist with logfile parsing results
  in 'refresh' mode (no new downloads)
* rework the return code handling
* tweak procd trigger
* various small fixes
* (s)hellsheck cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
Dirk Brenken
2019-09-09 17:12:52 +02:00
parent 0849e32659
commit 5f49601e63
6 changed files with 215 additions and 204 deletions
+22 -15
View File
@@ -20,17 +20,17 @@ boot()
start_service()
{
if [ $("${ban_init}" enabled; printf "%u" ${?}) -eq 0 ]
if [ "$("${ban_init}" enabled; printf "%u" ${?})" -eq 0 ]
then
if [ "${ban_boot}" = "1" ]
then
return 0
fi
local nice="$(uci_get banip extra ban_nice)"
local nice="$(uci_get banip extra ban_nice "0")"
procd_open_instance "banip"
procd_set_param command "${ban_script}" "${@}"
procd_set_param pidfile "${ban_pidfile}"
procd_set_param nice ${nice:-0}
procd_set_param nice "${nice}"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
@@ -39,6 +39,7 @@ start_service()
refresh()
{
[ -s "${ban_pidfile}" ] && return 1
rc_procd start_service refresh
}
@@ -54,34 +55,40 @@ stop_service()
status()
{
local key keylist value rtfile="$(uci_get banip global ban_rtfile)"
local key keylist value
local rtfile="$(uci_get banip global ban_rtfile "/tmp/ban_runtime.json")"
rtfile="${rtfile:-"/tmp/ban_runtime.json"}"
json_load_file "${rtfile}" >/dev/null 2>&1
json_select data >/dev/null 2>&1
if [ ${?} -eq 0 ]
if [ "${?}" -eq 0 ]
then
printf "%s\n" "::: banIP runtime information"
printf "%s\\n" "::: banIP runtime information"
json_get_keys keylist
for key in ${keylist}
do
json_get_var value "${key}"
printf " + %-10s : %s\n" "${key}" "${value}"
printf " + %-10s : %s\\n" "${key}" "${value}"
done
else
printf "%s\n" "::: no banIP runtime information available"
printf "%s\\n" "::: no banIP runtime information available"
fi
}
service_triggers()
{
local ban_iface="$(uci_get banip global ban_iface)"
local delay="$(uci_get banip extra ban_triggerdelay)"
local delay="$(uci_get banip extra ban_triggerdelay "2")"
local type="$(uci_get banip extra ban_starttype "start")"
PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
for iface in ${ban_iface:-"wan"}
do
procd_add_interface_trigger "interface.*.up" "${iface}" "${ban_init}" start
done
PROCD_RELOAD_DELAY=$((${delay}*1000))
if [ -n "${ban_iface}" ]
then
for iface in ${ban_iface}
do
procd_add_interface_trigger "interface.*.up" "${iface}" "${ban_init}" "${type}"
done
else
procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${ban_init}" "${type}"
fi
procd_add_reload_trigger "banip"
}