From 472d770463b8a338c454d31e2c39b250aee40ed6 Mon Sep 17 00:00:00 2001 From: Developer Date: Sat, 21 Mar 2026 19:43:41 -0400 Subject: [PATCH] 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 --- modules/security/malware-scanner.sh | 33 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/modules/security/malware-scanner.sh b/modules/security/malware-scanner.sh index d338b53..6bc8f55 100755 --- a/modules/security/malware-scanner.sh +++ b/modules/security/malware-scanner.sh @@ -412,13 +412,36 @@ install_all_scanners() { echo -e " ${GREEN}✓${NC} integration.conf already exists with ui_path: $imav_ui_path" echo " Proceeding with existing configuration." 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 " 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 "" - read -p " ui_path [/var/www/html/imunifyav]: " imav_ui_input + read -p " ui_path [$imav_default_path]: " imav_ui_input # Handle cancel if [ "$imav_ui_input" = "0" ]; then @@ -428,9 +451,9 @@ install_all_scanners() { fi 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 - imav_ui_path="/var/www/html/imunifyav" + imav_ui_path="$imav_default_path" else imav_ui_path="$imav_ui_input" fi