V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 37s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-07-23 23:00:38 +02:00
parent 4d204071b2
commit 62db940cec
10 changed files with 394 additions and 34 deletions

View File

@@ -19,7 +19,10 @@ set -Ceuo pipefail
# --log=/var/log/ufw.log \
# --output=/tmp/f2bchk.log
# Globals:
# None
# CGRE
# CRED
# CRES
# NL
# Arguments:
# None
# Returns:
@@ -27,7 +30,7 @@ set -Ceuo pipefail
# 1: In case of any errors
#######################################
f2bchk(){
# Declare default values (readonly)
### Declare default values (readonly)
declare -r DEFAULT_MODE="matched"
declare -r DEFAULT_FILTER="/etc/fail2ban/filter.d/ufw.aggressive.conf"
declare -r DEFAULT_LOG="/var/log/ufw.log"
@@ -45,7 +48,7 @@ f2bchk(){
--log=*) log="${arg#--log=}";;
--output=*) output="${arg#--output=}";;
*)
printf "\e[31m[ERROR]\e[0m Unknown argument: %s\n" "${arg}"
printf "%s[ERROR]%s Unknown argument: '%s' %s" "${CRED}" "${CRES}" "${arg}" "${CRED}"
return 1
;;
esac
@@ -57,7 +60,7 @@ f2bchk(){
matched) flag="--print-all-matched"; suffix="all.matched";;
missed) flag="--print-all-missed"; suffix="all.missed";;
*)
printf "\e[31m[ERROR]\e[0m Invalid mode: %s\n" "${mode}"
printf "%s[ERROR]%s Invalid mode: '%s' %s" "${CRED}" "${CRES}" "${mode}" "${NL}"
return 1
;;
esac
@@ -67,24 +70,30 @@ f2bchk(){
filter_name="${filter_name%.conf}"
output="/tmp/${filter_name}.${suffix}.log"
fi
if [[ ! -r "${log}" ]]; then
printf "\e[31m[ERROR]\e[0m Log file '%s' not found or not readable.\n" "${log}"
return 1
fi
if [[ ! -r "${filter}" ]]; then
printf "\e[31m[ERROR]\e[0m Filter file '%s' not found or not readable.\n" "${filter}"
printf "%s[ERROR]%s Log file '%s' not found or not readable. %s" "${CRED}" "${CRES}" "${log}" "${NL}"
return 1
fi
printf "\e[33m[INFO]\e[0m Running: fail2ban-regex %s %s %s\n" "${log}" "${filter}" "${flag}"
if fail2ban-regex "${log}" "${filter}" "${flag}" >| "${output}"; then
printf "\e[32m[SUCCESS]\e[0m Saved log to %s\n" "$output"
printf "You can view it with: cat %s\n" "$output"
else
printf "\e[31m[ERROR]\e[0m fail2ban-regex execution failed.\n"
if [[ ! -r "${filter}" ]]; then
printf "%s[ERROR]%s Filter file '%s' not found or not readable. %s" "${CRED}" "${CRES}" "${filter}" "${NL}"
return 1
fi
printf "%s[INFO]%s Running: fail2ban-regex '%s %s %s' %s" "${CGRE}" "${CRES}" "${log}" "${filter}" "${flag}" "${NL}"
if fail2ban-regex "${log}" "${filter}" "${flag}" >| "${output}"; then
printf "%s[SUCCESS]%s Saved log to: '%s' %s" "${CGRE}" "${CRES}" "${output}" "${NL}"
printf "You can view it with: cat %s%s" "${output}" "${NL}"
else
printf "%s[ERROR]%s fail2ban-regex execution failed. %s" "${CRED}" "${CRES}" "${NL}"
return 1
fi
exit 0
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh