banip: update 0.3.6
* more startup tweaks * re-use f_log function in helper scripts * small fixes / polish up for forthcoming 19.07 release Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
fcea2f75c3
commit
72fba3a17b
4 changed files with 38 additions and 38 deletions
|
@ -6,7 +6,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=banip
|
PKG_NAME:=banip
|
||||||
PKG_VERSION:=0.3.5
|
PKG_VERSION:=0.3.6
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=GPL-3.0-or-later
|
PKG_LICENSE:=GPL-3.0-or-later
|
||||||
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
||||||
|
|
|
@ -12,14 +12,15 @@ ban_init="/etc/init.d/banip"
|
||||||
ban_script="/usr/bin/banip.sh"
|
ban_script="/usr/bin/banip.sh"
|
||||||
ban_pidfile="/var/run/banip.pid"
|
ban_pidfile="/var/run/banip.pid"
|
||||||
|
|
||||||
if [ -s "${ban_pidfile}" ] && [ "${action}" != "help" ] && [ "${action}" != "status" ]
|
if [ -s "${ban_pidfile}" ] && \
|
||||||
|
[ "${action}" != "help" ] && [ "${action}" != "status" ] && [ "${action}" != "boot" ]
|
||||||
then
|
then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
ban_boot="1"
|
[ -s "${ban_pidfile}" ] && > "${ban_pidfile}"
|
||||||
rc_procd start_service
|
rc_procd start_service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,15 +28,14 @@ start_service()
|
||||||
{
|
{
|
||||||
if [ "$("${ban_init}" enabled; printf "%u" ${?})" -eq 0 ]
|
if [ "$("${ban_init}" enabled; printf "%u" ${?})" -eq 0 ]
|
||||||
then
|
then
|
||||||
if [ "${ban_boot}" = "1" ]
|
if [ "${action}" = "boot" ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local nice="$(uci_get banip extra ban_nice "0")"
|
|
||||||
procd_open_instance "banip"
|
procd_open_instance "banip"
|
||||||
procd_set_param command "${ban_script}" "${@}"
|
procd_set_param command "${ban_script}" "${@}"
|
||||||
procd_set_param pidfile "${ban_pidfile}"
|
procd_set_param pidfile "${ban_pidfile}"
|
||||||
procd_set_param nice "${nice}"
|
procd_set_param nice "$(uci_get banip extra ban_nice "0")"
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr 1
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
|
|
|
@ -13,19 +13,23 @@ ban_sshdaemon="${2}"
|
||||||
ban_logger="$(command -v logger)"
|
ban_logger="$(command -v logger)"
|
||||||
ban_logread="$(command -v logread)"
|
ban_logread="$(command -v logread)"
|
||||||
|
|
||||||
|
f_log()
|
||||||
|
{
|
||||||
|
local class="${1}" log_msg="${2}"
|
||||||
|
|
||||||
|
if [ -x "${ban_logger}" ]
|
||||||
|
then
|
||||||
|
"${ban_logger}" -p "${class}" -t "banIP-${ban_ver}[${$}]" "${log_msg}"
|
||||||
|
else
|
||||||
|
printf "%s %s %s\\n" "${class}" "banIP-${ban_ver}[${$}]" "${log_msg}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ -x "${ban_logread}" ]
|
if [ -x "${ban_logread}" ]
|
||||||
then
|
then
|
||||||
|
f_log "info" "log/banIP service started"
|
||||||
"${ban_logread}" -f -e "${ban_sshdaemon}\|luci: failed login" | \
|
"${ban_logread}" -f -e "${ban_sshdaemon}\|luci: failed login" | \
|
||||||
{ grep -qE "Exit before auth|luci: failed login|[0-9]+ \[preauth\]$"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
|
{ grep -qE "Exit before auth|luci: failed login|[0-9]+ \[preauth\]$"; [ $? -eq 0 ] && /etc/init.d/banip refresh; }
|
||||||
class="info"
|
|
||||||
log_msg="log/banIP service started"
|
|
||||||
else
|
else
|
||||||
class="err"
|
f_log "err" "can't start log/banIP service"
|
||||||
log_msg="can't start log/banIP service"
|
|
||||||
fi
|
|
||||||
if [ -x "${ban_logger}" ]
|
|
||||||
then
|
|
||||||
"${ban_logger}" -p "${class}" -t "banIP-${ban_ver}[${$}]" "${log_msg}"
|
|
||||||
else
|
|
||||||
printf "%s %s %s\\n" "${class}" "banIP-${ban_ver}[${$}]" "${log_msg}"
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
ban_ver="0.3.5"
|
ban_ver="0.3.6"
|
||||||
ban_basever=""
|
ban_basever=""
|
||||||
ban_enabled=0
|
ban_enabled=0
|
||||||
ban_automatic="1"
|
ban_automatic="1"
|
||||||
|
@ -221,21 +221,24 @@ f_envcheck()
|
||||||
cnt=$((cnt+1))
|
cnt=$((cnt+1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
utils="aria2c curl wget uclient-fetch"
|
if [ -n "${packages}" ]
|
||||||
for util in ${utils}
|
then
|
||||||
do
|
utils="aria2c curl wget uclient-fetch"
|
||||||
if { [ "${util}" = "uclient-fetch" ] && [ -n "$(printf "%s\\n" "${packages}" | grep "^libustream-")" ]; } || \
|
for util in ${utils}
|
||||||
{ [ "${util}" = "wget" ] && [ -n "$(printf "%s\\n" "${packages}" | grep "^wget -")" ]; } || \
|
do
|
||||||
{ [ "${util}" != "uclient-fetch" ] && [ "${util}" != "wget" ]; }
|
if { [ "${util}" = "uclient-fetch" ] && [ -n "$(printf "%s\\n" "${packages}" | grep "^libustream-")" ]; } || \
|
||||||
then
|
{ [ "${util}" = "wget" ] && [ -n "$(printf "%s\\n" "${packages}" | grep "^wget -")" ]; } || \
|
||||||
ban_fetchutil="$(command -v "${util}")"
|
{ [ "${util}" != "uclient-fetch" ] && [ "${util}" != "wget" ]; }
|
||||||
if [ -x "${ban_fetchutil}" ]
|
|
||||||
then
|
then
|
||||||
break
|
ban_fetchutil="$(command -v "${util}")"
|
||||||
|
if [ -x "${ban_fetchutil}" ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
unset ban_fetchutil util
|
||||||
unset ban_fetchutil util
|
done
|
||||||
done
|
fi
|
||||||
else
|
else
|
||||||
util="${ban_fetchutil}"
|
util="${ban_fetchutil}"
|
||||||
ban_fetchutil="$(command -v "${util}")"
|
ban_fetchutil="$(command -v "${util}")"
|
||||||
|
@ -296,7 +299,7 @@ f_temp()
|
||||||
f_log "err" "the temp directory '/tmp' does not exist or has not been mounted yet, please create the directory or raise the 'ban_triggerdelay' to defer the banIP start"
|
f_log "err" "the temp directory '/tmp' does not exist or has not been mounted yet, please create the directory or raise the 'ban_triggerdelay' to defer the banIP start"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -s "${ban_pidfile}" ]
|
if [ ! -f "${ban_pidfile}" ] || [ ! -s "${ban_pidfile}" ]
|
||||||
then
|
then
|
||||||
printf "%s" "${$}" > "${ban_pidfile}"
|
printf "%s" "${$}" > "${ban_pidfile}"
|
||||||
fi
|
fi
|
||||||
|
@ -582,13 +585,6 @@ f_log()
|
||||||
f_ipset destroy
|
f_ipset destroy
|
||||||
f_rmbackup
|
f_rmbackup
|
||||||
f_rmtemp
|
f_rmtemp
|
||||||
log_msg="Please also check 'https://github.com/openwrt/packages/blob/master/net/banip/files/README.md'"
|
|
||||||
if [ -x "${ban_logger}" ]
|
|
||||||
then
|
|
||||||
"${ban_logger}" -p "${class}" -t "banIP-${ban_ver}[${$}]" "${log_msg}"
|
|
||||||
else
|
|
||||||
printf "%s %s %s\\n" "${class}" "banIP-${ban_ver}[${$}]" "${log_msg}"
|
|
||||||
fi
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue