119 lines
3.2 KiB
Text
119 lines
3.2 KiB
Text
|
#!/bin/bash
|
||
|
|
||
|
# This program is free software: you can redistribute it and/or modify it under the terms of the
|
||
|
# GNU Affero General Public License as published by the Free Software Foundation, either version 3
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||
|
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
# Affero General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU Affero General Public License along with this program.
|
||
|
# If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
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() {
|
||
|
# Use shell redirection to send all output to /dev/null because cURL is noisy at times, even with --silent
|
||
|
wget -O/dev/null --timeout 3 "$1" "$2" &>/dev/null
|
||
|
}
|
||
|
|
||
|
# 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"
|
||
|
dns_ipv4=false
|
||
|
dns_ipv6=false
|
||
|
has_ipv4=false
|
||
|
has_ipv6=false
|
||
|
ipv4="<td>no</td>"
|
||
|
ipv6="<td>no</td>"
|
||
|
|
||
|
# Fetch DNS records
|
||
|
dns="$(host "$hostname")"
|
||
|
if printf '%s' "$dns" | grep -q "has address"; then
|
||
|
dns_ipv4=true
|
||
|
fi
|
||
|
if printf '%s' "$dns" | grep -q "has IPv6 address"; then
|
||
|
dns_ipv6=true
|
||
|
fi
|
||
|
|
||
|
if [ $dns_ipv4 = false -a $dns_ipv6 = false ]; then
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
# Try site over HTTPS
|
||
|
if try_url --inet4-only "$https"; then
|
||
|
((total_ipv4 ++))
|
||
|
has_ipv4=true
|
||
|
fi
|
||
|
if try_url --inet6-only "$https"; then
|
||
|
((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
|
||
|
ipv4="<td class='success'>yes</td>"
|
||
|
elif [ "$dns_ipv4" = true ]; then
|
||
|
ipv4="<td>no HTTPS</td>"
|
||
|
fi
|
||
|
if [ "$has_ipv6" = true ]; then
|
||
|
ipv6="<td class='success'>yes</td>"
|
||
|
elif [ "$dns_ipv6" = true ]; then
|
||
|
ipv6="<td>no HTTPS</td>"
|
||
|
fi
|
||
|
|
||
|
if [ "$has_ipv4" = true -o "$has_ipv6" = true ]; then
|
||
|
name="<a href='$https'>$i</a>"
|
||
|
else
|
||
|
name="$i"
|
||
|
fi
|
||
|
printf '\t<tr><td>%s</td>%s%s<td>%s</td></tr>\n' "$name" "$ipv4" "$ipv6" "$ssltest" >> "$TMPOUT"
|
||
|
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 :
|