90 lines
1.8 KiB
Bash
90 lines
1.8 KiB
Bash
#!/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- |