Update ApacheOverzicht.sh
This commit is contained in:
89
ApacheOverzicht.sh
Normal file
89
ApacheOverzicht.sh
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
|
|
||||||
/<VirtualHost/ {
|
|
||||||
in_vhost=1
|
|
||||||
reverse_proxy="nee"
|
|
||||||
servername=""
|
|
||||||
aliases=""
|
|
||||||
port=$0
|
|
||||||
gsub(/.*:/,"",port)
|
|
||||||
gsub(/>.*/,"",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-
|
|
||||||
Reference in New Issue
Block a user