From ad0f393183453bbb0f35e831d0eb5ee950b465d8 Mon Sep 17 00:00:00 2001 From: MrSleeps Date: Sat, 5 Dec 2015 17:55:58 +0000 Subject: [PATCH 1/4] Added extra switch Added a switch to enable users to automatically get a list of domains from their Lets Encrypt Live directory (lists all live certificates) --- checkssl | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/checkssl b/checkssl index 7304bb8..990c42e 100755 --- a/checkssl +++ b/checkssl @@ -2,25 +2,19 @@ # --------------------------------------------------------------------------- # checkssl - checks ssl certs for a set of domains -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License at for -# more details. +# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License at for # more details. -# Usage: checkssl [-h|--help] [-d|--debug] [-f|--file filename] [-s|--server stype] +# Usage: checkssl [-h|--help] [-d|--debug] [-f|--file filename] [-s|--server stype] [-l|--location] # Revision history: # 2015-12-05 Created (v0.1) +# 2015-12-05 Added the ability to automatically search for domains from the letsencrypt live directory (v0.2 - sleeps) # --------------------------------------------------------------------------- PROGNAME=${0##*/} -VERSION="0.1" +VERSION="0.2" RENEW_ALERT="30" # set to number of days to be alerted for certificate renewal @@ -54,12 +48,11 @@ signal_exit() { # Handle trapped signals } usage() { - echo -e "Usage: $PROGNAME [-h|--help] [-d|--debug] [-f|--file filename] [-s|--server stype]" + echo -e "Usage: $PROGNAME [-h|--help] [-d|--debug] [-f|--file filename] [-s|--server stype] [-l|--location directory]" } log() { - echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $*" >> ${PROGNAME}.log -} + echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $*" >> ${PROGNAME}.log } debug() { if [[ "${_USE_DEBUG:-"0"}" -eq 1 ]]; then @@ -81,6 +74,9 @@ help_message() { Where 'filename' is a file containing a list of domain names -s, --server server_type Where 'server_type' is the server type (cpanel, ISPconfig, apache2 ...) + -l, --location directory + Where 'directory' is where your lets encrypt live directory is + (typically /etc/letsencrypt/live/) _EOF_ return @@ -103,6 +99,8 @@ while [[ -n $1 ]]; do FILEARG=true; shift; FILE="$1" ;; -s | --server) SERVERARG=true; shift; STYPE="$1" ;; + -l | --location) + LOCATIONARG=true; shift; LOC="$1";; -* | --*) usage error_exit "Unknown option $1" ;; @@ -114,7 +112,7 @@ done # Main logic -if [[ ! $FILEARG && ! $SERVERARG ]]; then +if [[ ! $FILEARG && ! $SERVERARG && ! $LOCATIONARG ]]; then help_message graceful_exit fi @@ -125,8 +123,7 @@ DATA_OUT=$(mktemp) debug "created tmp files for input (${LIST_OF_DOMAINS}) and output (${DATA_OUT})" echo "Domain|cert issued for|valid until|cert issued by| possible issues?" > $DATA_OUT -# check and inport file if specified on command line -if [ $FILEARG ]; then +# check and inport file if specified on command line if [ $FILEARG ]; then if [ -f $FILE ]; then cat $FILE >> $LIST_OF_DOMAINS else @@ -135,8 +132,7 @@ if [ $FILEARG ]; then fi fi -# get a list of domains from server (if -s flag used) -if [ $SERVERARG ]; then +# get a list of domains from server (if -s flag used) if [ $SERVERARG ]; then if [ "$STYPE" == "cpanel" ]; then cat /etc/userdomains | cut -d":" -f 1 | grep "\." >> $LIST_OF_DOMAINS elif [ "$STYPE" == "ISPconfig" ]; then @@ -147,6 +143,16 @@ if [ $SERVERARG ]; then fi fi +if [ $LOCATIONARG ]; then +LELOC=$LOC/* + for f in $LELOC; do + if [[ -d $f ]]; then + dir=$(basename "$f") + echo $dir >> $LIST_OF_DOMAINS + fi + done +fi + cat $LIST_OF_DOMAINS | while read -d $'\n\b' DOMAIN; do PROBLEMS="" debug " --------------- domain ${DOMAIN} ---------------------" @@ -177,11 +183,9 @@ cat $LIST_OF_DOMAINS | while read -d $'\n\b' DOMAIN; do PROBLEMS=$(echo "${PROBLEMS}- certificate near renewal date") fi fi - printf "%s|%s|%s|%s|%s\n" "$DOMAIN" "$ISSUEDTO" "$ENDDATE" "$ISSUER" "$PROBLEMS">> $DATA_OUT -done + printf "%s|%s|%s|%s|%s\n" "$DOMAIN" "$ISSUEDTO" "$ENDDATE" "$ISSUER" "$PROBLEMS">> $DATA_OUT done echo "" cat $DATA_OUT | column -t -s"|" graceful_exit - From 3cf16b650293180dcb0bb92c29dc3fbb62488647 Mon Sep 17 00:00:00 2001 From: MrSleeps Date: Sat, 5 Dec 2015 18:01:40 +0000 Subject: [PATCH 2/4] Added extra switch & fixed my typo! Added an extra switch to enable users to automatically get a list of domains from their Lets Encrypt live directory --- checkssl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/checkssl b/checkssl index 990c42e..15e6356 100755 --- a/checkssl +++ b/checkssl @@ -2,20 +2,26 @@ # --------------------------------------------------------------------------- # checkssl - checks ssl certs for a set of domains -# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. -# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License at for # more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License at for +# more details. # Usage: checkssl [-h|--help] [-d|--debug] [-f|--file filename] [-s|--server stype] [-l|--location] # Revision history: # 2015-12-05 Created (v0.1) -# 2015-12-05 Added the ability to automatically search for domains from the letsencrypt live directory (v0.2 - sleeps) +# 2015-12-05 Added the ability to automatically search for domains from the Lets Encrypt live directory (v0.2 - sleeps) # --------------------------------------------------------------------------- PROGNAME=${0##*/} VERSION="0.2" - RENEW_ALERT="30" # set to number of days to be alerted for certificate renewal clean_up() { # Perform pre-exit housekeeping @@ -52,7 +58,8 @@ usage() { } log() { - echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $*" >> ${PROGNAME}.log } + echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $*" >> ${PROGNAME}.log +} debug() { if [[ "${_USE_DEBUG:-"0"}" -eq 1 ]]; then @@ -123,7 +130,8 @@ DATA_OUT=$(mktemp) debug "created tmp files for input (${LIST_OF_DOMAINS}) and output (${DATA_OUT})" echo "Domain|cert issued for|valid until|cert issued by| possible issues?" > $DATA_OUT -# check and inport file if specified on command line if [ $FILEARG ]; then +# check and inport file if specified on command line +if [ $FILEARG ]; then if [ -f $FILE ]; then cat $FILE >> $LIST_OF_DOMAINS else @@ -132,7 +140,8 @@ echo "Domain|cert issued for|valid until|cert issued by| possible issues?" > $D fi fi -# get a list of domains from server (if -s flag used) if [ $SERVERARG ]; then +# get a list of domains from server (if -s flag used) +if [ $SERVERARG ]; then if [ "$STYPE" == "cpanel" ]; then cat /etc/userdomains | cut -d":" -f 1 | grep "\." >> $LIST_OF_DOMAINS elif [ "$STYPE" == "ISPconfig" ]; then @@ -183,7 +192,8 @@ cat $LIST_OF_DOMAINS | while read -d $'\n\b' DOMAIN; do PROBLEMS=$(echo "${PROBLEMS}- certificate near renewal date") fi fi - printf "%s|%s|%s|%s|%s\n" "$DOMAIN" "$ISSUEDTO" "$ENDDATE" "$ISSUER" "$PROBLEMS">> $DATA_OUT done + printf "%s|%s|%s|%s|%s\n" "$DOMAIN" "$ISSUEDTO" "$ENDDATE" "$ISSUER" "$PROBLEMS">> $DATA_OUT +done echo "" cat $DATA_OUT | column -t -s"|" From 9796c932275525e5f3531d9f2b1d854bb474ac32 Mon Sep 17 00:00:00 2001 From: MrSleeps Date: Sat, 5 Dec 2015 18:07:00 +0000 Subject: [PATCH 3/4] Fixed typos and updated for directory searching --- README | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README b/README index 42045ae..b869c9d 100644 --- a/README +++ b/README @@ -1,11 +1,15 @@ -With the good work by "Let’s Encrypt" in providing free SSL certs for users, I wanted a quick way to check all the domains I look aftet +With the good work by "Let’s Encrypt" in providing free SSL certs for users, I wanted a quick way to check all the domains I look after to determine which ones have correct SSL certs, and which ones are in need of updating etc. -This bash file is the first draft a a programto do that. It can either be run against a list of file names, or on a single server with -the aim of getting all the domain names from the server. The output looks like; +This bash file is the first draft a a program to do that. It can either be run against a list of file names, from the directories in your +Lets Encrypt live directory or on a single server with the aim of getting all the domain names from the server. + +The output looks like: Domain cert issued for valid until cert issued by possible issues? domain1.com domain1.com Dec 22 09:19:00 2016 GMT Let's Encrypt Authority X1 - certificate near renewal date domain2.com domain2.com (alt) Dec 22 11:42:00 2016 GMT Let's Encrypt Authority X1 - certificate near renewal date domain3.net domain3.net Mar 4 10:10:00 2016 GMT Let's Encrypt Authority X1 +V0.1 initial commit by SRVRCO +v0.2 modification by MrSleeps From 58e6800810eacc34fbf288745fab2c7ed7a16a5e Mon Sep 17 00:00:00 2001 From: MrSleeps Date: Sat, 5 Dec 2015 18:08:53 +0000 Subject: [PATCH 4/4] Update README --- README | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README b/README index b869c9d..757eec0 100644 --- a/README +++ b/README @@ -1,8 +1,6 @@ -With the good work by "Let’s Encrypt" in providing free SSL certs for users, I wanted a quick way to check all the domains I look after -to determine which ones have correct SSL certs, and which ones are in need of updating etc. +With the good work by "Let’s Encrypt" in providing free SSL certs for users, I wanted a quick way to check all the domains I look after to determine which ones have correct SSL certs, and which ones are in need of updating etc. -This bash file is the first draft a a program to do that. It can either be run against a list of file names, from the directories in your -Lets Encrypt live directory or on a single server with the aim of getting all the domain names from the server. +This bash file is the first draft a a program to do that. It can either be run against a list of file names, from the directories in your Lets Encrypt live directory or on a single server with the aim of getting all the domain names from the server. The output looks like: