-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlschecker.sh
66 lines (57 loc) · 2.13 KB
/
tlschecker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Check Linux OS
if [ ! $(uname) = "Linux" ]; then
echo "This script is Linux compatible only"
exit
fi
# Check root user
if [[ $(id -u) -ne 0 ]];then
echo "Please execute as root"
exit 1
fi
# Check if nmap is not installed
if ! command -v nmap >/dev/null 2>&1; then
echo "nmap is required for using this program"
# Package manager for Debian-based distributions (Ubuntu, Mint, etc...)
if command -v apt >/dev/null 2>&1; then
packagemanager=apt
# Package manager for Fedora-based distributions (CentOS, Red Hat, etc...)
elif command -v dnf >/dev/null 2>&1; then
packagemanager=dnf
# Package manager for SUSE / openSUSE-based distributions (GeckoLinux, Kamarada, etc...)
elif command -v zypper >/dev/null 2>&1; then
packagemanager=zypper
else
exit 1
fi
echo "Installing nmap..."; sleep 1
$packagemanager install nmap -y
fi
# Check number of arguments
if [[ $# -ne 1 ]]; then
echo "Usage: $0 example.com"
exit 1
fi
# Check if argument $1 is a domain name or IP address
valid_domain='^([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,}$'
valid_ip='^([0-9]{1,3}\.){3}[0-9]{1,3}$'
if [[ $1 =~ $valid_domain || $1 =~ $valid_ip ]]; then
target=$1
echo -e "\nGetting the information for $target, please be patient..."
else
echo -e "\n$1 is not a valid domain name or IP address\n"
exit 1
fi
# Create variables for validity date and date in 1 month from now
validity=$(nmap --script ssl-cert $target | grep "Not valid after" | cut -d ":" -f 2 | cut -d "T" -f 1)
onemonth=$(date -d "+1 month" +"%Y-%m-%d")
# Create the TLS_Reports folder if needed
if [[ ! -d "/root/TLS_Reports" ]]; then
mkdir /root/TLS_Reports
fi
# Check validity, display the result and save it in a TXT file
if [[ "$validity" < "$onemonth" ]]; then
echo "Update NOW the TLS certificate for $target!" | tee /root/TLS_Reports/tls_validity_$1_$(date +%F)_UPDATE_NOW.txt
else
echo "Everything is fine, the TLS certificate for $target is valid until:$validity" | tee /root/TLS_Reports/tls_validity_$1_$(date +%F).txt
fi