-u <url> | —url <url> argument
Now we can pass a single url as argument to be checked.
This commit is contained in:
191
urls_check.sh
191
urls_check.sh
@@ -14,7 +14,6 @@ green="\033[0;32m"
|
||||
greenbold="\033[1;32m"
|
||||
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
|
||||
if [[ $? -ne 0 ]]; then
|
||||
@@ -23,7 +22,7 @@ if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#urls=("https://clicclac.info" "https://clicclac.info/wordpress" "https://sur-le-sentier.fr" "https://maboiteverte.fr")
|
||||
url=
|
||||
urls=()
|
||||
port=443
|
||||
# Days left before notification
|
||||
@@ -90,15 +89,21 @@ display_help() {
|
||||
# taken from https://stackoverflow.com/users/4307337/vincent-stans
|
||||
echo "Usage: $0 " >&2
|
||||
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 "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 "status.txt give description and a link to Mozilla for each status code."
|
||||
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 -e "If the site is up (status code: 200, 301, 302, 303, 307), then certificate information will be displayed."
|
||||
echo -e "If the site is down or the certificate is outdated, a Pushover (or Gotify) notification will be sent."
|
||||
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 some stuff here for the -a or --add-options
|
||||
exit 1
|
||||
}
|
||||
|
||||
: << 'COMMENTS'
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help) display_help; shift ;;
|
||||
@@ -106,46 +111,95 @@ while [[ "$#" -gt 0 ]]; do
|
||||
esac
|
||||
shift
|
||||
done
|
||||
COMMENTS
|
||||
|
||||
|
||||
# Chargement de la liste des urls depuis urls_list.txt
|
||||
|
||||
while read -r line
|
||||
do
|
||||
[ ${line:0:1} != "#" ] && urls+=("$line")
|
||||
done < urls_list.txt
|
||||
|
||||
# Ajout des domaines non-requis
|
||||
|
||||
if [ -f "$not_required_domains" ]; then
|
||||
#a=$(grep 'not_required=' sync_pihole_lan.sh)
|
||||
a=$(grep 'not_required=' $not_required_domains)
|
||||
|
||||
b=$(echo "$a" | awk -F"=" '{split($2, arr, "[()]"); print arr[2]}' | sed 's/\"//g')
|
||||
not_required=(${b})
|
||||
|
||||
for val in "${!not_required[@]}"
|
||||
do
|
||||
z="https://${not_required[$val]}.photos-nas.ovh"
|
||||
urls+=("${z}")
|
||||
done
|
||||
|
||||
else
|
||||
echo "file $not_required_domains not find !"
|
||||
echo "Domain like drive.photos-nas.ovh won't be checked.'"
|
||||
fi
|
||||
|
||||
# Tri du tableau d'urls
|
||||
|
||||
IFS=$'\n' urls_sorted=($(sort <<<"${urls[*]}"))
|
||||
unset IFS
|
||||
|
||||
urls=()
|
||||
newArr=()
|
||||
while IFS= read -r -d '' x
|
||||
optspec=":u:h-:"
|
||||
while getopts "$optspec" opt
|
||||
do
|
||||
urls+=("$x")
|
||||
done < <(printf "%s\0" "${urls_sorted[@]}" | sort -uz)
|
||||
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
|
||||
|
||||
while read -r line
|
||||
do
|
||||
[ ${line:0:1} != "#" ] && urls+=("$line")
|
||||
done < urls_list.txt
|
||||
|
||||
|
||||
|
||||
# Ajout des domaines non-requis
|
||||
|
||||
if [ -f "$not_required_domains" ]; then
|
||||
a=$(grep 'not_required=' $not_required_domains)
|
||||
|
||||
b=$(echo "$a" | awk -F"=" '{split($2, arr, "[()]"); print arr[2]}' | sed 's/\"//g')
|
||||
not_required=(${b})
|
||||
|
||||
for val in "${!not_required[@]}"
|
||||
do
|
||||
z="https://${not_required[$val]}.photos-nas.ovh"
|
||||
urls+=("${z}")
|
||||
done
|
||||
|
||||
else
|
||||
echo "file $not_required_domains not find !"
|
||||
echo "Domain like drive.photos-nas.ovh won't be checked.'"
|
||||
fi
|
||||
|
||||
|
||||
# Tri du tableau d'urls
|
||||
|
||||
IFS=$'\n' urls_sorted=($(sort <<<"${urls[*]}"))
|
||||
unset IFS
|
||||
|
||||
urls=()
|
||||
newArr=()
|
||||
while IFS= read -r -d '' x
|
||||
do
|
||||
urls+=("$x")
|
||||
done < <(printf "%s\0" "${urls_sorted[@]}" | sort -uz)
|
||||
|
||||
fi
|
||||
|
||||
# On efface la liste des urls down
|
||||
|
||||
@@ -180,20 +234,44 @@ check_url() {
|
||||
}
|
||||
|
||||
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- )
|
||||
cert=$(showcert "$domain")
|
||||
|
||||
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
||||
names=$(echo "$cert" | grep Names | awk -F": " '{print $2}')
|
||||
issuer=$(echo "$cert" | grep Issuer | awk -F": " '{print $2}')
|
||||
start=$(echo "$cert" | grep Before | awk -F": " '{print $2}')
|
||||
end=$(echo "$cert" | grep notAfter | awk -F": " '{print $2}')
|
||||
left=$(echo "$end" | awk -F" " '{split($3, arr, "[()]"); print arr[2]}')
|
||||
|
||||
if command -v showcertif >/dev/null 2>&1; then
|
||||
|
||||
cert=$(showcert "$domain")
|
||||
|
||||
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
||||
names=$(echo "$cert" | grep Names | awk -F": " '{print $2}')
|
||||
issuer=$(echo "$cert" | grep Issuer | awk -F": " '{print $2}')
|
||||
start=$(echo "$cert" | grep Before | awk -F": " '{print $2}')
|
||||
end=$(echo "$cert" | grep notAfter | awk -F": " '{print $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}"
|
||||
echo -e "Names: $names"
|
||||
if [ -n "$names" ]; then
|
||||
echo -e "Names: $names"
|
||||
elif [ -n "$subject" ]; then
|
||||
echo -e "Subject: $subject"
|
||||
fi
|
||||
echo -e "Issuer: $issuer"
|
||||
echo -e "Date début: $start"
|
||||
echo -e "Date fin: $end\n"
|
||||
@@ -238,8 +316,9 @@ done
|
||||
|
||||
# Affichage des serveurs qui ne répondent pas
|
||||
|
||||
echo -e "\n${redbold}Url down: ${reset}"
|
||||
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
|
||||
url_down=$(cat "./urls_down_list_curl.txt")
|
||||
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
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "${green}\nNo url is down !${reset}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ for host in "${hosts[@]}"; do
|
||||
e="Date fin: $end"
|
||||
|
||||
else
|
||||
echo "$host"
|
||||
cert=`echo |
|
||||
openssl s_client -connect $host:$port 2>/dev/null |
|
||||
openssl x509 -issuer -subject -dates -noout`
|
||||
|
||||
Reference in New Issue
Block a user