#!/bin/sh # TODO Find .htacces from ServerHome set -e apache_dir=/etc/apache2 apache_conf=$apache_dir/apache2.conf tmp_dir=/tmp/apache-require conf_files=$tmp_dir/conf_files files_with_directives=$tmp_dir/files_with_directives mkdir -p "$tmp_dir" module_loaded() { apache2ctl -D DUMP_MODULES | grep -q access_compat_module } # Get all config files included the get_conf_files() { # Initialize le the list of configuration files with the default conf test ! -e "$conf_files" && printf "%s\\n" $apache_conf > "$conf_files" cd "$apache_dir" # TODO: Refactor this mess conf_files_size=0 while [ "$conf_files_size" -lt "$(stat -c %s "$conf_files")" ]; do conf_files_size=$(stat -c %s "$conf_files") for conf_file in $(cat "$conf_files"); do # XXX: Expand the filenames for glob in $(awk '/^[[:space:]]*Include/ {print $2}' "$conf_file"); do realpath $glob >> "$conf_files" done done sort "$conf_files" | uniq > "$conf_files"_tmp && mv "$conf_files"_tmp "$conf_files" done cd - 1>/dev/null } count_directives() { directives="Allow Order Deny Satisfy" for directive in $directives; do export "$directive"="$(grep -Ec "^[[:blank:]]*$directive\\s" "$1")" done # shellcheck disable=SC2154 if [ "$Allow" -ne 0 ] || [ "$Order" -ne 0 ] || \ [ "$Deny" -ne 0 ] || [ "$Satisfy" -ne 0 ]; then printf "%s %d %d %d %d\\n" "$1" "$Allow" "$Order" "$Deny" "$Satisfy" fi } display_results() { printf 'File\tAllow\tOrder\tDeny\tSatsify\n' # TODO make shellcheck happy for file in $(cat $conf_files); do count_directives "$file" | tee -a "$files_with_directives" done } get_conf_files display_results