From 99df0208c7a34b253ea539041443f16bfaad0e22 Mon Sep 17 00:00:00 2001 From: Herbert Graeber Date: Sat, 1 Jun 2024 18:25:21 +0200 Subject: [PATCH 1/3] Make the HOST case the last one after server file, cert file and cert directory Fixes #94 --- ssl-cert-check | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ssl-cert-check b/ssl-cert-check index 03819ef..0469943 100755 --- a/ssl-cert-check +++ b/ssl-cert-check @@ -13,6 +13,10 @@ PROGRAMVERSION=4.14 # # Revision History: # +# Unreleased +# - Fix '-f', '-c', und '-d' options without '-s', but HOST environment +# variable defined - Herbert Graeber +# # Version 4.14 # - Fixed HOST / PORT discovery @mhow2 # @@ -903,15 +907,10 @@ else exit 1 fi -### If a HOST was passed on the cmdline, use that value -if [ "${HOST}" != "" ]; then - print_heading - check_server_status "${HOST}" "${PORT:=443}" - print_summary ### If a file is passed to the "-f" option on the command line, check ### each certificate or server / port combination in the file to see if ### they are about to expire -elif [ -f "${SERVERFILE}" ]; then +if [ -f "${SERVERFILE}" ]; then print_heading IFS=$'\n' @@ -941,6 +940,11 @@ elif [ "${CERTDIRECTORY}" != "" ] && ("${FIND}" -L "${CERTDIRECTORY}" -type f > check_file_status "${FILE}" "FILE" "${FILE}" done print_summary +### If a HOST was passed on the cmdline, use that value +elif [ "${HOST}" != "" ]; then + print_heading + check_server_status "${HOST}" "${PORT:=443}" + print_summary ### There was an error, so print a detailed usage message and exit else usage From 7e94925138e0e28521289ca95061c1c776a224e9 Mon Sep 17 00:00:00 2001 From: Herbert Graeber Date: Sat, 1 Jun 2024 18:41:33 +0200 Subject: [PATCH 2/3] Do not check for server file existence So ssl-cert-check will be in '-s' mode independent from wheter the file exists or what type of file it is. Fixes #123 --- ssl-cert-check | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ssl-cert-check b/ssl-cert-check index 0469943..52c652c 100755 --- a/ssl-cert-check +++ b/ssl-cert-check @@ -16,6 +16,7 @@ PROGRAMVERSION=4.14 # Unreleased # - Fix '-f', '-c', und '-d' options without '-s', but HOST environment # variable defined - Herbert Graeber +# - Allow process substitution for '-s' option -- Herbert Graeber # # Version 4.14 # - Fixed HOST / PORT discovery @mhow2 @@ -910,7 +911,7 @@ fi ### If a file is passed to the "-f" option on the command line, check ### each certificate or server / port combination in the file to see if ### they are about to expire -if [ -f "${SERVERFILE}" ]; then +if [ -n "${SERVERFILE}" ]; then print_heading IFS=$'\n' @@ -928,20 +929,20 @@ if [ -f "${SERVERFILE}" ]; then IFS="${OLDIFS}" print_summary ### Check to see if the certificate in CERTFILE is about to expire -elif [ "${CERTFILE}" != "" ]; then +elif [ -n "${CERTFILE}" ]; then print_heading check_file_status "${CERTFILE}" "FILE" "${CERTFILE}" print_summary ### Check to see if the certificates in CERTDIRECTORY are about to expire -elif [ "${CERTDIRECTORY}" != "" ] && ("${FIND}" -L "${CERTDIRECTORY}" -type f > /dev/null 2>&1); then +elif [ -n "${CERTDIRECTORY}" ] && ("${FIND}" -L "${CERTDIRECTORY}" -type f > /dev/null 2>&1); then print_heading for FILE in $("${FIND}" -L "${CERTDIRECTORY}" -type f); do check_file_status "${FILE}" "FILE" "${FILE}" done print_summary ### If a HOST was passed on the cmdline, use that value -elif [ "${HOST}" != "" ]; then +elif [ -n "${HOST}" ]; then print_heading check_server_status "${HOST}" "${PORT:=443}" print_summary From 46700717387bbea05d9521d6251a158415e39961 Mon Sep 17 00:00:00 2001 From: Herbert Graeber Date: Sat, 1 Jun 2024 18:51:16 +0200 Subject: [PATCH 3/3] Make reading the server file more white space insensitive As side effect it will be easy to add further columns to the table, if needed... Fixes #122 --- ssl-cert-check | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ssl-cert-check b/ssl-cert-check index 52c652c..30943aa 100755 --- a/ssl-cert-check +++ b/ssl-cert-check @@ -17,6 +17,7 @@ PROGRAMVERSION=4.14 # - Fix '-f', '-c', und '-d' options without '-s', but HOST environment # variable defined - Herbert Graeber # - Allow process substitution for '-s' option -- Herbert Graeber +# - Relax with space handling in server files -- Herbert Graeber # # Version 4.14 # - Fixed HOST / PORT discovery @mhow2 @@ -914,20 +915,21 @@ fi if [ -n "${SERVERFILE}" ]; then print_heading - IFS=$'\n' - for LINE in $(grep -E -v '(^#|^$)' "${SERVERFILE}") + grep -E -v '(^#|^[[:space:]]*$)' "${SERVERFILE}" | while read HOST PORT do - HOST=${LINE%% *} - PORT=${LINE##* } - IFS=" " if [ "$PORT" = "FILE" ]; then check_file_status "${HOST}" "FILE" "${HOST}" else check_server_status "${HOST}" "${PORT}" fi done - IFS="${OLDIFS}" - print_summary + if [ ${PIPESTATUS[0]} != 0 ] + then + echo "Error opening ${SERVERFILE}" + else + print_summary + fi + ### Check to see if the certificate in CERTFILE is about to expire elif [ -n "${CERTFILE}" ]; then print_heading