Calculate total directives and CGI entries
This commit is contained in:
parent
62a2d8fb50
commit
096e04e61c
29
inventory.sh
29
inventory.sh
|
@ -59,17 +59,21 @@ categorize_confs() {
|
|||
grep -Ev "^${apache_dir}/sites-enabled/.*\\.conf" "$confs" > "$confs_system"
|
||||
}
|
||||
|
||||
# Takes argument: file type
|
||||
count_directives() {
|
||||
directives="Allow Order Deny Satisfy"
|
||||
|
||||
for directive in $directives; do
|
||||
export "$directive"="$(grep -Ec "^[[:blank:]]*$directive\\s" "$1")"
|
||||
done
|
||||
export CGI="$(grep -Ec "^[[:blank:]]*# CGI" "$1")"
|
||||
|
||||
# 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"
|
||||
export Total=$(( $Allow + $Order + $Deny + $Satisfy ))
|
||||
printf "%s %d %d %d %d %d %d %s\\n" "$1" \
|
||||
"$Allow" "$Order" "$Deny" "$Satisfy" "$Total" "$CGI" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -77,13 +81,26 @@ count_directives() {
|
|||
display_results() {
|
||||
mv -b "$result" "$result".bak || true
|
||||
|
||||
printf 'File\tAllow\tOrder\tDeny\tSatsify\n' >&2
|
||||
# TODO make shellcheck happy
|
||||
for file in $(cat $confs); do
|
||||
count_directives "$file" | tee -a "$result"
|
||||
done
|
||||
# Types: Vhost, System, Htaccess
|
||||
printf 'File\tAllow\tOrder\tDeny\tSatsify\tTotal (directives)\tCGI\tType (V|S|H)\n' >&2
|
||||
while IFS= read -r file; do
|
||||
count_directives "$file" V | tee -a "$result"
|
||||
done < "$confs_vhost"
|
||||
while IFS= read -r file; do
|
||||
count_directives "$file" S | tee -a "$result"
|
||||
done < "$confs_system"
|
||||
while IFS= read -r file; do
|
||||
count_directives "$file" H | tee -a "$result"
|
||||
done < "$confs_htaccess"
|
||||
}
|
||||
|
||||
# One line machine summary of the results
|
||||
display_summary() {
|
||||
# Types: Vhost, System, Htaccess
|
||||
printf 'Vhost\tSystem\tHtaccess\tTotal\tCGI\n' >&2
|
||||
}
|
||||
|
||||
get_confs
|
||||
categorize_confs
|
||||
display_results
|
||||
# display_summary
|
||||
|
|
Loading…
Reference in a new issue