Compare commits

...

3 Commits

Author SHA1 Message Date
9817beaad9 v1.0 2024-11-02 11:20:44 +01:00
63c7790782 Clean code
and anonymise
2024-11-02 11:18:27 +01:00
ea50bd8613 Anonymise validity.sh
-put variables in $HOME/.env
-put list of domains in an validity_domains.txt file
2024-11-02 11:09:42 +01:00
3 changed files with 62 additions and 39 deletions

25
README.md Normal file
View File

@@ -0,0 +1,25 @@
# certificate
Bash scripts to check whether a site is available or not, and whether the certificate is valid or not.
#### 1) urls_check.sh
Usage: urls_check.sh
#### 2) validity.sh
Usage: ./validity.sh
Check whether the certificate is valid or not.
Required the <u>validity_domains.txt</u> file that contain a list of domains:
```bash
domain1.com
domain2.fr
```

View File

@@ -1,4 +1,9 @@
#!/usr/bin/env bash
# Check SSL certificates and http codes for key domains
#
# Run: ./url_check.sh
VERSION="v1.0"
italic="\033[3m"
underline="\033[4m"
@@ -39,21 +44,24 @@ dotenv () {
# shellcheck disable=SC1091
[ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github or send notification.'.${reset}"
set +a
#
# Gotify: $GOTIFY_SERVER (server url), $GOTIFY_BASH (token)
# Pushover: $USER_KEY$ (user) $BASH_APP (token)
}
dotenv
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
ScriptPath="$(readlink -f "$0")"
ScriptWorkDir="$(dirname "$ScriptPath")"
send_gotify_notification() {
# Enabled HSTS & created default WebSocket records in the DSM 7.2 reverse proxy window and it solved itself.
now=$(date +"%d-%m-%Y %T")
gotify_server="https://gotify.maboiteverte.fr"
gotify_server="$GOTIFY_SERVER"
gotify_token="$GOTIFY_BASH"
TITLE="$1"
MESSAGE="$2"
@@ -112,7 +120,6 @@ display_help() {
echo -e "https://www.domain2.com"
echo -e "${italic}Add a # to ignore url${reset}"
echo
# echo some stuff here for the -a or --add-options
exit 1
}
@@ -163,7 +170,6 @@ if [[ $url =~ $regex ]]; then
else
# Chargement de la liste des urls depuis urls_list.txt
while read -r line
do
[ ${line:0:1} != "#" ] && urls+=("$line")
@@ -188,7 +194,6 @@ else
echo "Domain like drive.photos-nas.ovh won't be checked.'"
fi
# Tri du tableau d'urls
IFS=$'\n' sorted=($(sort <<<"${urls[*]}"))
@@ -196,8 +201,8 @@ else
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 "./certificats_outdated.txt" ] && rm "./certificats_outdated.txt"
@@ -330,12 +335,10 @@ if [ -f "./urls_down_list_curl.txt" ]; then
if [ "$notif" == "gotify" ];then
msg_md="$url_down"
# MESSAGE="**A new version of Pi-hole is available:**\n\n $msg_md\n\n $infos\n\n Please run *pihole -up* on $host to update !"
send_gotify_notification "Several url are down !" "$msg_md"
elif [ "$notif" == "pushover" ];then
msg_html="$url_down"
send_pushover_notification "Several url are down !" "$msg_html"
#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
@@ -353,16 +356,13 @@ if [ -f "./certificats_outdated.txt" ]; then
if [ "$notif" == "gotify" ];then
msg_md="$certif_outdated"
# MESSAGE="**A new version of Pi-hole is available:**\n\n $msg_md\n\n $infos\n\n Please run *pihole -up* on $host to update !"
send_gotify_notification "Several certificats are outdated !" "$msg_md"
elif [ "$notif" == "pushover" ];then
msg_html="$certif_outdated"
send_pushover_notification "Several certificats are outdated !" "$msg_html"
#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 certificat outdated !${reset}"
fi
# curl --write-out "%{json}" https://nextcloud.photos-nas.ovh | jq

View File

@@ -3,7 +3,7 @@
#
# Run: ./validity.sh
VERSION="v0.9"
VERSION="v1.0"
red="\033[1;31m"
greenbold="\033[1;32m"
@@ -16,7 +16,6 @@ italic="\033[3m"
underline="\033[4m"
reset="\033[0m"
#echo | openssl s_client -servername maboiteverte.fr -connect maboiteverte.fr:443 2>/dev/null | openssl x509 -noout -issuer -subject -dates
#export PATH="/usr/local/bin:$PATH"
# run by cron $PATH=/usr/bin:/bin
@@ -30,31 +29,43 @@ if [ $? -eq 1 ]; then
exit 1
fi
hosts=("maboiteverte.fr" "sur-le-sentier.fr" "photos-nas.ovh" "clicclac.info")
#hosts=("maboiteverte.fr")
port=443
# Days left before notification
nday=15
# Choose the notification
notif="pushover"
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo .env file found ! No token for gotify.${reset}"
set +a
#
# Gotify: $GOTIFY_SERVER (server url), $GOTIFY_BASH (token)
# Pushover: $USER_KEY$ (user) $BASH_APP (token)
}
dotenv
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
# Domains to check
#hosts=("domain.com")
if [ -f "$ScriptWorkDir/validity_domains.txt" ]; then
readarray -t hosts < "$ScriptWorkDir/validity_domains.txt"
else echo -e "${red}No domain to check !${reset}"
fi
port=443
# Days left before notification
nday=15
# Choose the notification (pushover or gotify)
notif="pushover"
send_gotify_notification() {
# Enabled HSTS & created default WebSocket records in the DSM 7.2 reverse proxy window and it solved itself.
now=$(date +"%d-%m-%Y %T")
gotify_server="https://gotify.maboiteverte.fr"
gotify_server="$GOTIFY_SERVER"
gotify_token="$GOTIFY_BASH"
TITLE="$1"
MESSAGE="**A new version of Pi-hole is available:**\n\n $msg_md\n\n $infos\n\n Please run *pihole -up* on $host to update !"
MESSAGE="$2"
PRIORITY=8
URL="$gotify_server/message?token=$gotify_token&?format=markdown"
@@ -84,7 +95,7 @@ send_pushover_notification() {
for host in "${hosts[@]}"; do
if command -v showcertif >/dev/null 2>&1; then
if command -v showcert >/dev/null 2>&1; then
cert=$(showcert $host)
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
@@ -94,14 +105,6 @@ for host in "${hosts[@]}"; do
end=$(echo "$cert" | grep notAfter | awk -F": " '{print $2}')
left=$(echo "$end" | awk -F" " '{split($3, arr, "[()]"); print arr[2]}')
# maboiteverte.fr
# IP: 212.227.191.167
# Names: *.maboiteverte.fr maboiteverte.fr
# notBefore: 2024-01-08 00:00:00 (298 days old)
# notAfter: 2025-01-27 23:59:59 (87 days left)
# Issuer: C=US O=DigiCert Inc OU=www.digicert.com CN=Encryption Everywhere DV TLS CA - G2
# Tags: [CHAIN-VERIFIED]
h="$host ($ip)"
n="Names: $names"
i="Issuer: $issuer"
@@ -121,13 +124,8 @@ for host in "${hosts[@]}"; do
timestamp_current=$(date +"%s")
timestamp_end=$(date --date="$end" +"%s")
left=$(($((timestamp_end - timestamp_current))/(60*60*24)))
end="$end ($left days left)"
end="$end ($left days left)"
ip=$(dig +short $host)
# issuer=C=US, O=DigiCert Inc, OU=www.digicert.com, CN=Encryption Everywhere DV TLS CA - G2
# subject=CN=*.maboiteverte.fr
# notBefore=Jan 8 00:00:00 2024 GMT
# notAfter=Jan 27 23:59:59 2025 GMT
h="$host ($ip)"
n="Subject: $subject"