Find pieces of apache configuration elsewhere that the default location

This commit is contained in:
Brice Waegeneire 2020-10-09 14:57:36 +02:00
parent 7ba2130393
commit 58c6db8185

View file

@ -1,7 +1,5 @@
#!/bin/sh
# TODO find pieces of apache conf in /etc
# TODO Handle /sur/share/scripts/vhost...
# TODO total by host: vhost, htaccess, conf, cgi
set -e
@ -15,6 +13,7 @@ confs=$tmp_dir/confs
confs_vhost=$tmp_dir/confs_vhost
confs_system=$tmp_dir/confs_system
confs_htaccess=$tmp_dir/confs_htaccess
confs_template=$tmp_dir/confs_template
result=$tmp_dir/result
summary=$tmp_dir/summary
@ -52,8 +51,18 @@ get_htaccess() {
| xargs -I _ find _ -type f -name .htaccess || true
}
# Find directives in non apache location. It can be configuration for
# phpmyadmin or the default vhost template for example.
get_template() {
template_dirs="/etc /usr/share/scripts"
grep -RE '^[[:space:]]*(Order|Allow|Deny|Satisfy)[[:space:]]' \
--exclude-dir=apache2 --exclude-dir=squid3 "$template_dirs" \
2>/dev/null
}
# Put different type of configs in different files
categorize_confs() {
get_template > "$confs_template"
get_htaccess > "$confs_htaccess"
grep -E "^${apache_dir}/sites-enabled/.*\\.conf" "$confs" > "$confs_vhost"
grep -Ev "^${apache_dir}/sites-enabled/.*\\.conf" "$confs" > "$confs_system"
@ -81,8 +90,8 @@ count_directives() {
display_results() {
mv -b "$result" "$result".bak || true
# Types: Vhost, System, Htaccess
printf 'File\tAllow\tOrder\tDeny\tSatsify\tTotal (directives)\tCGI\tType (V|S|H)\n' >&2
# Types: Vhost, System, Htaccess, Template
printf 'File\tAllow\tOrder\tDeny\tSatsify\tTotal (directives)\tCGI\tType (V|S|H|T)\n' >&2
while IFS= read -r file; do
count_directives "$file" V | tee -a "$result"
done < "$confs_vhost"
@ -92,6 +101,9 @@ display_results() {
while IFS= read -r file; do
count_directives "$file" H | tee -a "$result"
done < "$confs_htaccess"
while IFS= read -r file; do
count_directives "$file" T | tee -a "$result"
done < "$confs_template"
}
# One line machine summary of the results