#!/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" =~ \ ]]; 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 echo echo \\\\ echo Hier aanpassen: https://git.de-roo.org/DEROO/ApacheOverzicht/_edit/main/ApacheOverzicht.sh }