From 5a99144977e618b4e25102bb7ac056d15b476898 Mon Sep 17 00:00:00 2001 From: Thomas de Roo Date: Thu, 5 Mar 2026 14:18:11 +0100 Subject: [PATCH] Update ApacheOverzicht.sh --- ApacheOverzicht.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++ ApacherOverzicht.sh | 90 --------------------------------------------- 2 files changed, 89 insertions(+), 90 deletions(-) create mode 100644 ApacheOverzicht.sh delete mode 100644 ApacherOverzicht.sh diff --git a/ApacheOverzicht.sh b/ApacheOverzicht.sh new file mode 100644 index 0000000..234ba30 --- /dev/null +++ b/ApacheOverzicht.sh @@ -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" =~ \ ]]; 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 + +} \ No newline at end of file diff --git a/ApacherOverzicht.sh b/ApacherOverzicht.sh deleted file mode 100644 index 64cfef4..0000000 --- a/ApacherOverzicht.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/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 "=== Apache websites ===" -echo "Onderstaande websites zijn op [[$(hostname)]] 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" - } - - /.*/,"",port) - f = cfgfile - sub(".*/", "", f) - } - - 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- \ No newline at end of file