Update ApacheOverzicht.sh

This commit is contained in:
2026-03-05 14:18:11 +01:00
parent ee224ac822
commit 5a99144977
2 changed files with 89 additions and 90 deletions

89
ApacheOverzicht.sh Normal file
View File

@@ -0,0 +1,89 @@
#!/bin/bash
DATE=$(date)
declare -A HTTPS_DOMAINS
declare -A CONFIG_FILES
declare -A REVERSE_PROXIES
# Loop door alle config-bestanden
for conf in /etc/apache2/sites-enabled/*.conf; do
conf_file=$(basename "$conf")
in_vhost=0
current_port=""
current_domains=()
while IFS= read -r line; do
# VirtualHost start
if [[ "$line" =~ \<VirtualHost ]]; then
in_vhost=1
current_domains=()
current_port=$(echo "$line" | grep -oP ':[0-9]+' | tr -d ':')
continue
fi
# VirtualHost einde
if [[ "$line" =~ \</VirtualHost\> ]]; then
in_vhost=0
current_domains=()
current_port=""
continue
fi
if [[ $in_vhost -eq 1 ]]; then
# ServerName
if [[ "$line" =~ ^[[:space:]]*ServerName[[:space:]]+ ]]; then
domain=$(echo "$line" | awk '{print $2}')
CONFIG_FILES["$domain"]="$conf_file"
current_domains+=("$domain")
# Alleen HTTPS markeren
[[ "$current_port" == "443" ]] && HTTPS_DOMAINS["$domain"]=1
fi
# ServerAlias
if [[ "$line" =~ ^[[:space:]]*ServerAlias[[:space:]]+ ]]; then
domain=$(echo "$line" | awk '{print $2}')
CONFIG_FILES["$domain"]="$conf_file"
current_domains+=("$domain")
[[ "$current_port" == "443" ]] && HTTPS_DOMAINS["$domain"]=1
fi
# Reverse proxy: http(s) only
if [[ "$line" =~ ^[[:space:]]*ProxyPass[[:space:]]+ ]]; then
while [[ "$line" =~ ((https?|wss?)://[^[:space:]]+) ]]; do
url="${BASH_REMATCH[1]}"
for domain in "${current_domains[@]}"; do
if [[ -z "${REVERSE_PROXIES[$domain]}" ]]; then
REVERSE_PROXIES[$domain]="[[${url}|${url}]]"
else
# geen dubbele URLs
if [[ ! "${REVERSE_PROXIES[$domain]}" =~ "$url" ]]; then
REVERSE_PROXIES[$domain]+=", [[${url}|${url}]]"
fi
fi
done
# verwijder de eerste match uit line
line="${line#*${url}}"
done
fi
fi
done < "$conf"
done
# Output
{
echo "===== Apache websites overzicht ====="
echo
echo "Automatisch gegenereerd op $DATE"
echo
echo "^ URL ^ Reverse Proxy ^ Config File ^"
for domain in $(printf "%s\n" "${!CONFIG_FILES[@]}" | sort); do
[[ -n "${HTTPS_DOMAINS[$domain]}" ]] || continue
url="https://$domain"
rp="${REVERSE_PROXIES[$domain]:--}"
conf="${CONFIG_FILES[$domain]}"
echo "| [[${url}|${url}]] | $rp | $conf |"
done
}