2024-10-29 14:05:43 +01:00
#!/bin/bash
2024-10-29 14:37:11 +01:00
FLANAGAN="5.75.131.131"
2024-10-29 14:05:43 +01:00
source members.sh
NUMGRP="${#MEMBERS[@]}"
scriptdir="$(dirname "$0")"
# Out file
if [ "$1" = "" ]; then
out="list.html"
else
out="$1"
fi
# Temporary file location
TMPOUT="$(mktemp)"
# Outputfile for statistics over time
STATSOUT="$scriptdir/stats.txt"
DATE="$(date '+%Y-%m-%d %H:%M %Z')"
# Create head of output page in temp out
cat "$scriptdir/head.html" > "$TMPOUT"
printf '<p>Last updated %s</p>\n' "$DATE" >> "$TMPOUT"
total_ipv4=0
total_ipv6=0
try_url() {
2024-10-29 14:37:11 +01:00
curl --max-time 4 --connect-timeout 3 --resolve "*:443:$2" "$1" &>/dev/null
2024-10-29 14:05:43 +01:00
}
# Begin list of groups
printf "<table>\n<tr>\n\t<th>Member</th>\n\t<th>IPv4</th>\n\t<th>IPv6</th>\n\t<th>TLS report</th>\n</tr>\n" >> "$TMPOUT"
for i in "${MEMBERS[@]}"; do
hostname="$i.user.zeus.gent"
https="https://$hostname"
2024-10-29 14:37:11 +01:00
ipv4=""
ipv6=""
2024-10-29 14:05:43 +01:00
dns_ipv4=false
dns_ipv6=false
has_ipv4=false
has_ipv6=false
2024-10-29 14:37:11 +01:00
ipv4_report="<td>no</td>"
ipv6_report="<td>no</td>"
2024-10-29 14:05:43 +01:00
# Fetch DNS records
2024-10-29 14:37:11 +01:00
dns="$(host "$hostname" "$FLANAGAN")"
2024-10-29 14:05:43 +01:00
if printf '%s' "$dns" | grep -q "has address"; then
dns_ipv4=true
2024-10-29 14:37:11 +01:00
ipv4="$(printf '%s' "$dns" | sed -En '/has address/{s/^.* address //p;q}')"
2024-10-29 14:05:43 +01:00
fi
if printf '%s' "$dns" | grep -q "has IPv6 address"; then
dns_ipv6=true
2024-10-29 14:37:11 +01:00
ipv6="$(printf '%s' "$dns" | sed -En '/has IPv6 address/{s/^.* address //p;q}')"
2024-10-29 14:05:43 +01:00
fi
if [ $dns_ipv4 = false -a $dns_ipv6 = false ]; then
continue
fi
# Try site over HTTPS
2024-10-29 14:37:11 +01:00
if [ $dns_ipv4 = true ] && try_url "$https" "$ipv4"; then
2024-10-29 14:05:43 +01:00
((total_ipv4 ++))
has_ipv4=true
fi
2024-10-29 14:37:11 +01:00
if [ $dns_ipv6 = true ] && try_url "$https" "$ipv6"; then
2024-10-29 14:05:43 +01:00
((total_ipv6 ++))
has_ipv6=true
fi
ssltest=""
if [ "$has_ipv4" = true -o "$has_ipv6" = true ]; then
ssltest="<a href='https://www.ssllabs.com/ssltest/analyze.html?d=$hostname' class='httpstestlink'>analyze</a>"
fi
if [ "$has_ipv4" = true ]; then
2024-10-29 14:37:11 +01:00
ipv4_report="<td class='success'>yes</td>"
2024-10-29 14:05:43 +01:00
elif [ "$dns_ipv4" = true ]; then
2024-10-29 14:37:11 +01:00
ipv4_report="<td>no HTTPS</td>"
2024-10-29 14:05:43 +01:00
fi
if [ "$has_ipv6" = true ]; then
2024-10-29 14:37:11 +01:00
ipv6_report="<td class='success'>yes</td>"
2024-10-29 14:05:43 +01:00
elif [ "$dns_ipv6" = true ]; then
2024-10-29 14:37:11 +01:00
ipv6_report="<td>no HTTPS</td>"
2024-10-29 14:05:43 +01:00
fi
if [ "$has_ipv4" = true -o "$has_ipv6" = true ]; then
name="<a href='$https'>$i</a>"
else
name="$i"
fi
2024-10-29 14:37:11 +01:00
printf '\t<tr><td>%s</td>%s%s<td>%s</td></tr>\n' "$name" "$ipv4_report" "$ipv6_report" "$ssltest" >> "$TMPOUT"
2024-10-29 14:05:43 +01:00
done
printf '</table>\n' >> "$TMPOUT"
printf '<p>Members with an IPv4 website: <strong>%s</strong>/%s<br/>Members with an IPv6 website: <strong>%s</strong>/%s</p>\n' "$total_ipv4" "$NUMGRP" "$total_ipv6" "$NUMGRP" >> "$TMPOUT"
# Create bottom of page
cat "$scriptdir/foot.html" >> "$TMPOUT"
# Write statistics to statistics file
printf '%s\t%s\t%s\n' "$DATE" "$total_ipv4" "$total_ipv6" >> $STATSOUT
# Move temp output to real output
mv "$TMPOUT" "$out"
# vim: set ts=2 sw=2 tw=0 noet :