Add ApacherOverzicht.sh

This commit is contained in:
2026-02-25 14:59:46 +01:00
commit 5d811107d6

90
ApacherOverzicht.sh Normal file
View File

@@ -0,0 +1,90 @@
#!/usr/bin/env bash
CONFIG_DIR="${1:-/etc/apache2/sites-enabled}"
if [ ! -d "$CONFIG_DIR" ]; then
echo "Config directory bestaat niet: $CONFIG_DIR"
exit 1
fi
echo "=== Websites op [[$(hostname)]] ==="
echo "Onderstaande websites zijn in Apache geconfigureerd in: $CONFIG_DIR"
echo "\\\\"
# Print DokuWiki header
echo "^ URL ^ PORT ^ REVERSE_PROXY ^ CONFIG_FILE ^"
{
find -L "$CONFIG_DIR" -type f \( -name "*.conf" -o -name "*.vhost" -o -name "*.cfg" \) | while read -r file; do
awk -v cfgfile="$file" '
BEGIN {
in_vhost=0
servername=""
aliases=""
port=""
reverse_proxy="nee"
}
/<VirtualHost/ {
in_vhost=1
reverse_proxy="nee"
servername=""
aliases=""
port=$0
gsub(/.*:/,"",port)
gsub(/>.*/,"",port)
n=split(cfgfile, a, "/")
f=a[n]
}
in_vhost && /ServerName/ {
servername=$2
}
in_vhost && /ServerAlias/ {
for (i=2;i<=NF;i++) {
aliases=aliases $i " "
}
}
in_vhost && (/ProxyPass/ || /ProxyPassMatch/ || /\[P\]/) {
reverse_proxy="ja"
}
function add_scheme(host, port) {
if (port == "443") {
return "https://" host
} else if (port == "80") {
return "http://" host
} else {
return "http://" host ":" port
}
}
function print_entry(host) {
if (host == "") return
url = add_scheme(host, port)
fqdn = host
# TAB als scheiding tussen sort-key en tabelregel
printf "%s\t| %s | %s | %s | %s |\n", fqdn, url, port, reverse_proxy, f
}
/<\/VirtualHost>/ {
if (servername != "") {
print_entry(servername)
}
if (aliases != "") {
split(aliases, arr, " ")
for (a in arr) {
if (arr[a] != "") {
print_entry(arr[a])
}
}
}
in_vhost=0
}
' "$file"
done
} | sort -f -k1,1 | cut -f2-