-u <url> | —url <url> argument
Now we can pass a single url as argument to be checked.
This commit is contained in:
@@ -14,7 +14,6 @@ green="\033[0;32m"
|
|||||||
greenbold="\033[1;32m"
|
greenbold="\033[1;32m"
|
||||||
reset="\033[0m"
|
reset="\033[0m"
|
||||||
|
|
||||||
command -v showcert >/dev/null 2>&1 || { echo -e "${bold}showcert${reset} is not installed ${italic}(pip install showcert)${reset}. Aborting..." >&2; exit 1; }
|
|
||||||
|
|
||||||
cat < /dev/null > /dev/tcp/1.1.1.1/53
|
cat < /dev/null > /dev/tcp/1.1.1.1/53
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
@@ -23,7 +22,7 @@ if [[ $? -ne 0 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#urls=("https://clicclac.info" "https://clicclac.info/wordpress" "https://sur-le-sentier.fr" "https://maboiteverte.fr")
|
url=
|
||||||
urls=()
|
urls=()
|
||||||
port=443
|
port=443
|
||||||
# Days left before notification
|
# Days left before notification
|
||||||
@@ -90,15 +89,21 @@ display_help() {
|
|||||||
# taken from https://stackoverflow.com/users/4307337/vincent-stans
|
# taken from https://stackoverflow.com/users/4307337/vincent-stans
|
||||||
echo "Usage: $0 " >&2
|
echo "Usage: $0 " >&2
|
||||||
echo
|
echo
|
||||||
echo "urls_check.sh will read a list of urls in urls_list.txt file, then return the status code for each url."
|
echo -e "${bold}urls_check.sh${reset} will read a list of urls in ${underline}urls_list.txt${reset} file, then return the status code for each url."
|
||||||
echo "If the site is up (status code: 200, 301, 302, 303, 307), then certificate information will be displayed."
|
echo -e "If the site is up (status code: 200, 301, 302, 303, 307), then certificate information will be displayed."
|
||||||
echo "If the site is down or the certificate is outdated, a Pushover (or Gotify) notification will be sent."
|
echo -e "If the site is down or the certificate is outdated, a Pushover (or Gotify) notification will be sent."
|
||||||
echo "status.txt give description and a link to Mozilla for each status code."
|
echo -e "${underline}status.txt${reset} give description and a link to Mozilla for each status code."
|
||||||
|
echo -e "${bold}showcert${reset} is required to check certificate ${italic}(pip install showcert)${reset}. If not, ${bold}openssl${reset} will be used."
|
||||||
|
echo
|
||||||
|
echo -e "${bold}Options:${reset}"
|
||||||
|
echo -e " -u <url> | --url <url> Check the url passed as argument."
|
||||||
|
echo -e " -h | --help Display this help."
|
||||||
echo
|
echo
|
||||||
# echo some stuff here for the -a or --add-options
|
# echo some stuff here for the -a or --add-options
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
: << 'COMMENTS'
|
||||||
while [[ "$#" -gt 0 ]]; do
|
while [[ "$#" -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help) display_help; shift ;;
|
-h|--help) display_help; shift ;;
|
||||||
@@ -106,8 +111,53 @@ while [[ "$#" -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
COMMENTS
|
||||||
|
|
||||||
|
optspec=":u:h-:"
|
||||||
|
while getopts "$optspec" opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
-) case "${OPTARG}" in
|
||||||
|
help) display_help;;
|
||||||
|
url)
|
||||||
|
url="${!OPTIND}"; OPTIND=$(( OPTIND + 1 ))
|
||||||
|
;;
|
||||||
|
url=*)
|
||||||
|
url=${OPTARG#*=}
|
||||||
|
#opt=${OPTARG%=$file}
|
||||||
|
opt="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f1 )" ; url="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f2-)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" = ":" ]; then
|
||||||
|
echo "Unknown option --${OPTARG}" >&2
|
||||||
|
fi
|
||||||
|
exit 3
|
||||||
|
;;
|
||||||
|
esac;;
|
||||||
|
u) url="${OPTARG}";;
|
||||||
|
h)
|
||||||
|
display_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
|
||||||
|
echo "Non-option argument: '-${OPTARG}'" >&2
|
||||||
|
fi
|
||||||
|
exit 4
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift "$((OPTIND-1))"
|
||||||
|
|
||||||
|
|
||||||
|
command -v showcertif >/dev/null 2>&1 || { echo -e "${bold}showcert${reset} is not installed ${italic}(pip install showcert)${reset}. ${bold}openssl${reset} will be used.\n" >&2; }
|
||||||
|
|
||||||
|
|
||||||
|
regex='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]+'
|
||||||
|
if [[ $url =~ $regex ]]; then
|
||||||
|
# L'URL passé en argument est checkée
|
||||||
|
|
||||||
|
urls+=("$url")
|
||||||
|
else
|
||||||
# Chargement de la liste des urls depuis urls_list.txt
|
# Chargement de la liste des urls depuis urls_list.txt
|
||||||
|
|
||||||
while read -r line
|
while read -r line
|
||||||
@@ -115,10 +165,11 @@ do
|
|||||||
[ ${line:0:1} != "#" ] && urls+=("$line")
|
[ ${line:0:1} != "#" ] && urls+=("$line")
|
||||||
done < urls_list.txt
|
done < urls_list.txt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Ajout des domaines non-requis
|
# Ajout des domaines non-requis
|
||||||
|
|
||||||
if [ -f "$not_required_domains" ]; then
|
if [ -f "$not_required_domains" ]; then
|
||||||
#a=$(grep 'not_required=' sync_pihole_lan.sh)
|
|
||||||
a=$(grep 'not_required=' $not_required_domains)
|
a=$(grep 'not_required=' $not_required_domains)
|
||||||
|
|
||||||
b=$(echo "$a" | awk -F"=" '{split($2, arr, "[()]"); print arr[2]}' | sed 's/\"//g')
|
b=$(echo "$a" | awk -F"=" '{split($2, arr, "[()]"); print arr[2]}' | sed 's/\"//g')
|
||||||
@@ -135,6 +186,7 @@ else
|
|||||||
echo "Domain like drive.photos-nas.ovh won't be checked.'"
|
echo "Domain like drive.photos-nas.ovh won't be checked.'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Tri du tableau d'urls
|
# Tri du tableau d'urls
|
||||||
|
|
||||||
IFS=$'\n' urls_sorted=($(sort <<<"${urls[*]}"))
|
IFS=$'\n' urls_sorted=($(sort <<<"${urls[*]}"))
|
||||||
@@ -147,6 +199,8 @@ do
|
|||||||
urls+=("$x")
|
urls+=("$x")
|
||||||
done < <(printf "%s\0" "${urls_sorted[@]}" | sort -uz)
|
done < <(printf "%s\0" "${urls_sorted[@]}" | sort -uz)
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# On efface la liste des urls down
|
# On efface la liste des urls down
|
||||||
|
|
||||||
[ -f "./urls_down_list_curl.txt" ] && rm "./urls_down_list_curl.txt"
|
[ -f "./urls_down_list_curl.txt" ] && rm "./urls_down_list_curl.txt"
|
||||||
@@ -180,9 +234,11 @@ check_url() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info_certif() {
|
info_certif() {
|
||||||
# cn=$(echo | openssl s_client -connect $1 2>/dev/null | openssl x509 -noout -subject -dates -issuer)
|
|
||||||
|
|
||||||
domain=$(echo "$1" | grep -Eo '^http[s]?://[^/]+' | cut -c 9- )
|
domain=$(echo "$1" | grep -Eo '^http[s]?://[^/]+' | cut -c 9- )
|
||||||
|
|
||||||
|
if command -v showcertif >/dev/null 2>&1; then
|
||||||
|
|
||||||
cert=$(showcert "$domain")
|
cert=$(showcert "$domain")
|
||||||
|
|
||||||
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
||||||
@@ -191,9 +247,31 @@ info_certif() {
|
|||||||
start=$(echo "$cert" | grep Before | awk -F": " '{print $2}')
|
start=$(echo "$cert" | grep Before | awk -F": " '{print $2}')
|
||||||
end=$(echo "$cert" | grep notAfter | awk -F": " '{print $2}')
|
end=$(echo "$cert" | grep notAfter | awk -F": " '{print $2}')
|
||||||
left=$(echo "$end" | awk -F" " '{split($3, arr, "[()]"); print arr[2]}')
|
left=$(echo "$end" | awk -F" " '{split($3, arr, "[()]"); print arr[2]}')
|
||||||
|
subject=""
|
||||||
|
else
|
||||||
|
cert=`echo |
|
||||||
|
openssl s_client -connect $domain:$port 2>/dev/null |
|
||||||
|
openssl x509 -issuer -subject -dates -noout`
|
||||||
|
|
||||||
|
issuer=$(echo "$cert" | grep issuer | awk -F"issuer=" '{print $2}')
|
||||||
|
subject=$(echo "$cert" | grep subject | awk -F"subject=" '{print $2}')
|
||||||
|
start=$(echo "$cert" | grep Before | awk -F"=" '{print $2}')
|
||||||
|
end=$(echo "$cert" | grep notAfter | awk -F"=" '{print $2}')
|
||||||
|
timestamp_current=$(date +"%s")
|
||||||
|
timestamp_end=$(date --date="$end" +"%s")
|
||||||
|
left=$(($((timestamp_end - timestamp_current))/(60*60*24)))
|
||||||
|
end="$end ($left days left)"
|
||||||
|
names=""
|
||||||
|
|
||||||
|
ip=$(dig +short $host)
|
||||||
|
fi
|
||||||
|
|
||||||
[ $left -lt $nday ] && echo -e "${red}"
|
[ $left -lt $nday ] && echo -e "${red}"
|
||||||
|
if [ -n "$names" ]; then
|
||||||
echo -e "Names: $names"
|
echo -e "Names: $names"
|
||||||
|
elif [ -n "$subject" ]; then
|
||||||
|
echo -e "Subject: $subject"
|
||||||
|
fi
|
||||||
echo -e "Issuer: $issuer"
|
echo -e "Issuer: $issuer"
|
||||||
echo -e "Date début: $start"
|
echo -e "Date début: $start"
|
||||||
echo -e "Date fin: $end\n"
|
echo -e "Date fin: $end\n"
|
||||||
@@ -238,8 +316,9 @@ done
|
|||||||
|
|
||||||
# Affichage des serveurs qui ne répondent pas
|
# Affichage des serveurs qui ne répondent pas
|
||||||
|
|
||||||
echo -e "\n${redbold}Url down: ${reset}"
|
|
||||||
if [ -f "./urls_down_list_curl.txt" ]; then
|
if [ -f "./urls_down_list_curl.txt" ]; then
|
||||||
|
echo -e "\n${redbold}Url down: ${reset}"
|
||||||
|
|
||||||
cp "./urls_down_list_curl.txt" urls_down_list_curl.bak
|
cp "./urls_down_list_curl.txt" urls_down_list_curl.bak
|
||||||
url_down=$(cat "./urls_down_list_curl.txt")
|
url_down=$(cat "./urls_down_list_curl.txt")
|
||||||
echo -e "$url_down\n"
|
echo -e "$url_down\n"
|
||||||
@@ -262,6 +341,8 @@ if [ -f "./urls_down_list_curl.txt" ]; then
|
|||||||
#pushover -a "bash" -m "A new version of Pi-hole is available: <br /> $msg_html <br /> $infos_html <br /> Please run <b>pihole -up</b> on $host to update" -p 2 -f 1
|
#pushover -a "bash" -m "A new version of Pi-hole is available: <br /> $msg_html <br /> $infos_html <br /> Please run <b>pihole -up</b> on $host to update" -p 2 -f 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -e "${green}\nNo url is down !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ for host in "${hosts[@]}"; do
|
|||||||
e="Date fin: $end"
|
e="Date fin: $end"
|
||||||
|
|
||||||
else
|
else
|
||||||
|
echo "$host"
|
||||||
cert=`echo |
|
cert=`echo |
|
||||||
openssl s_client -connect $host:$port 2>/dev/null |
|
openssl s_client -connect $host:$port 2>/dev/null |
|
||||||
openssl x509 -issuer -subject -dates -noout`
|
openssl x509 -issuer -subject -dates -noout`
|
||||||
|
|||||||
Reference in New Issue
Block a user