improve: Auto-detect web server document root for ImunifyAV standalone UI path

- Detect Apache (apache2ctl -S) and extract default document root
- Detect Nginx (nginx -T) and extract default document root
- Use detected root + /imunifyav as default suggestion
- Fall back to /var/www/html/imunifyav if no web server detected
- Still allows user to manually override the suggested path
- Eliminates need for hardcoded default paths
This commit is contained in:
Developer
2026-03-21 19:43:41 -04:00
parent 7ad35f59d8
commit 472d770463
+28 -5
View File
@@ -412,13 +412,36 @@ install_all_scanners() {
echo -e " ${GREEN}${NC} integration.conf already exists with ui_path: $imav_ui_path" echo -e " ${GREEN}${NC} integration.conf already exists with ui_path: $imav_ui_path"
echo " Proceeding with existing configuration." echo " Proceeding with existing configuration."
else else
# Prompt user for ui_path with sensible default # Auto-detect web server document root
local imav_default_path="/var/www/html/imunifyav"
# Try Apache
if command -v apache2ctl &>/dev/null; then
local apache_root=$(apache2ctl -S 2>/dev/null | grep "^\*:" | head -1 | awk '{print $NF}' | sed 's/*://' || echo "")
if [ -n "$apache_root" ] && [ -d "$apache_root" ]; then
imav_default_path="$apache_root/imunifyav"
fi
elif command -v httpd &>/dev/null; then
local httpd_root=$(httpd -S 2>/dev/null | grep "^\*:" | head -1 | awk '{print $NF}' | sed 's/*://' || echo "")
if [ -n "$httpd_root" ] && [ -d "$httpd_root" ]; then
imav_default_path="$httpd_root/imunifyav"
fi
fi
# Try Nginx if Apache not found
if [ "$imav_default_path" = "/var/www/html/imunifyav" ] && command -v nginx &>/dev/null; then
local nginx_root=$(nginx -T 2>/dev/null | grep "root " | head -1 | awk '{print $NF}' | sed 's/;//' || echo "")
if [ -n "$nginx_root" ] && [ -d "$nginx_root" ]; then
imav_default_path="$nginx_root/imunifyav"
fi
fi
# Prompt user for ui_path with detected default
echo " Enter the web server document root path for the ImunifyAV UI." echo " Enter the web server document root path for the ImunifyAV UI."
echo " This directory will be served by your web server (Apache/Nginx)." echo " This directory will be served by your web server (Apache/Nginx)."
echo " Example: /var/www/html/imunifyav"
echo " Enter 0 to cancel ImunifyAV installation." echo " Enter 0 to cancel ImunifyAV installation."
echo "" echo ""
read -p " ui_path [/var/www/html/imunifyav]: " imav_ui_input read -p " ui_path [$imav_default_path]: " imav_ui_input
# Handle cancel # Handle cancel
if [ "$imav_ui_input" = "0" ]; then if [ "$imav_ui_input" = "0" ]; then
@@ -428,9 +451,9 @@ install_all_scanners() {
fi fi
if [ "$imav_is_standalone" -ne 2 ]; then if [ "$imav_is_standalone" -ne 2 ]; then
# Apply default if blank # Apply default if blank, otherwise use user input
if [ -z "$imav_ui_input" ]; then if [ -z "$imav_ui_input" ]; then
imav_ui_path="/var/www/html/imunifyav" imav_ui_path="$imav_default_path"
else else
imav_ui_path="$imav_ui_input" imav_ui_path="$imav_ui_input"
fi fi