feat: Fully automated web server detection for ImunifyAV standalone UI path
- Add get_web_root_for_imunify() function with comprehensive detection: - Detect Apache (apache2ctl -S) on Debian/Ubuntu - Detect Apache (httpd -S) on RHEL/CentOS/AlmaLinux/Rocky - Detect Nginx (nginx -T) on all platforms - Parse Apache and Nginx config files directly as fallback - Check common default locations if auto-detection fails - All detection happens automatically, no user prompts - ImunifyAV standalone setup now uses auto-detected path: - Shows detected web root during installation - Uses detected_root + /imunifyav as UI path - Zero user input required - Works on all supported OS and web server combinations
This commit is contained in:
@@ -63,6 +63,71 @@ if ! validate_required_functions; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Auto-detect web server document root for ImunifyAV standalone UI path
|
||||||
|
get_web_root_for_imunify() {
|
||||||
|
local detected_root=""
|
||||||
|
|
||||||
|
# Try Apache on Debian/Ubuntu (apache2ctl)
|
||||||
|
if command -v apache2ctl &>/dev/null; then
|
||||||
|
detected_root=$(apache2ctl -S 2>/dev/null | grep "^\*:" | head -1 | awk '{print $NF}' | sed 's/*://' || echo "")
|
||||||
|
if [ -n "$detected_root" ] && [ -d "$detected_root" ]; then
|
||||||
|
echo "$detected_root"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try Apache on RHEL/CentOS (httpd -S)
|
||||||
|
if command -v httpd &>/dev/null; then
|
||||||
|
detected_root=$(httpd -S 2>/dev/null | grep "^\*:" | head -1 | awk '{print $NF}' | sed 's/*://' || echo "")
|
||||||
|
if [ -n "$detected_root" ] && [ -d "$detected_root" ]; then
|
||||||
|
echo "$detected_root"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try Nginx (nginx -T)
|
||||||
|
if command -v nginx &>/dev/null; then
|
||||||
|
detected_root=$(nginx -T 2>/dev/null | grep "^\s*root " | head -1 | awk '{print $NF}' | sed 's/;//' || echo "")
|
||||||
|
if [ -n "$detected_root" ] && [ -d "$detected_root" ]; then
|
||||||
|
echo "$detected_root"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try parsing Apache config files directly
|
||||||
|
for conf_file in /etc/apache2/apache2.conf /etc/httpd/conf/httpd.conf /etc/apache2/sites-enabled/*.conf /etc/httpd/conf.d/*.conf; do
|
||||||
|
if [ -f "$conf_file" ] 2>/dev/null; then
|
||||||
|
detected_root=$(grep -E "^\s*DocumentRoot|^\s*root " "$conf_file" 2>/dev/null | head -1 | awk '{print $NF}' | sed 's/"//g' || echo "")
|
||||||
|
if [ -n "$detected_root" ] && [ -d "$detected_root" ]; then
|
||||||
|
echo "$detected_root"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Try Nginx config files directly
|
||||||
|
for conf_file in /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/*.conf; do
|
||||||
|
if [ -f "$conf_file" ] 2>/dev/null; then
|
||||||
|
detected_root=$(grep -E "^\s*root " "$conf_file" 2>/dev/null | head -1 | awk '{print $NF}' | sed 's/;//' || echo "")
|
||||||
|
if [ -n "$detected_root" ] && [ -d "$detected_root" ]; then
|
||||||
|
echo "$detected_root"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Try common default locations in order of likelihood
|
||||||
|
for path in /var/www/html /home /srv/www /var/www /usr/share/nginx/html /var/www/vhosts; do
|
||||||
|
if [ -d "$path" ] && [ -w "$path" ]; then
|
||||||
|
echo "$path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Absolute fallback
|
||||||
|
echo "/var/www/html"
|
||||||
|
}
|
||||||
|
|
||||||
# Individual scanner detection functions
|
# Individual scanner detection functions
|
||||||
is_imunify_installed() {
|
is_imunify_installed() {
|
||||||
command -v imunify-antivirus &>/dev/null || [ -f "/usr/bin/imunify-antivirus" ]
|
command -v imunify-antivirus &>/dev/null || [ -f "/usr/bin/imunify-antivirus" ]
|
||||||
@@ -412,64 +477,17 @@ 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
|
||||||
# Auto-detect web server document root
|
# Auto-detect web server document root (no prompting)
|
||||||
local imav_default_path="/var/www/html/imunifyav"
|
local imav_detected_root
|
||||||
|
imav_detected_root=$(get_web_root_for_imunify)
|
||||||
|
imav_ui_path="$imav_detected_root/imunifyav"
|
||||||
|
|
||||||
# Try Apache
|
echo -e " ${GREEN}✓${NC} Auto-detected web root: $imav_detected_root"
|
||||||
if command -v apache2ctl &>/dev/null; then
|
echo " UI will be deployed to: $imav_ui_path"
|
||||||
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
|
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 " Enter 0 to cancel ImunifyAV installation."
|
|
||||||
echo ""
|
|
||||||
read -p " ui_path [$imav_default_path]: " imav_ui_input
|
|
||||||
|
|
||||||
# Handle cancel
|
|
||||||
if [ "$imav_ui_input" = "0" ]; then
|
|
||||||
echo " → Skipping ImunifyAV installation."
|
|
||||||
# Jump past the download/deploy block entirely
|
|
||||||
imav_is_standalone=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$imav_is_standalone" -ne 2 ]; then
|
|
||||||
# Apply default if blank, otherwise use user input
|
|
||||||
if [ -z "$imav_ui_input" ]; then
|
|
||||||
imav_ui_path="$imav_default_path"
|
|
||||||
else
|
|
||||||
imav_ui_path="$imav_ui_input"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Input validation: must be an absolute path, no spaces
|
|
||||||
if [[ "$imav_ui_path" != /* ]]; then
|
|
||||||
echo -e "${RED} ✗ Path must be absolute (start with /). Skipping ImunifyAV.${NC}"
|
|
||||||
imav_is_standalone=2
|
|
||||||
elif [[ "$imav_ui_path" =~ [[:space:]] ]]; then
|
|
||||||
echo -e "${RED} ✗ Path must not contain spaces. Skipping ImunifyAV.${NC}"
|
|
||||||
imav_is_standalone=2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$imav_is_standalone" -ne 2 ]; then
|
|
||||||
# Create config directory if needed
|
# Create config directory if needed
|
||||||
|
if [ "$imav_is_standalone" -ne 2 ]; then
|
||||||
echo " → Creating $imav_conf_dir ..."
|
echo " → Creating $imav_conf_dir ..."
|
||||||
mkdir -p "$imav_conf_dir" || {
|
mkdir -p "$imav_conf_dir" || {
|
||||||
echo -e "${RED} ✗ Cannot create $imav_conf_dir - check permissions. Skipping ImunifyAV.${NC}"
|
echo -e "${RED} ✗ Cannot create $imav_conf_dir - check permissions. Skipping ImunifyAV.${NC}"
|
||||||
@@ -477,8 +495,8 @@ install_all_scanners() {
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$imav_is_standalone" -ne 2 ]; then
|
|
||||||
# Write minimal integration.conf (only ui_path is required)
|
# Write minimal integration.conf (only ui_path is required)
|
||||||
|
if [ "$imav_is_standalone" -ne 2 ]; then
|
||||||
printf '[paths]\nui_path = %s\n' "$imav_ui_path" > "$imav_conf_file" || {
|
printf '[paths]\nui_path = %s\n' "$imav_ui_path" > "$imav_conf_file" || {
|
||||||
echo -e "${RED} ✗ Cannot write $imav_conf_file. Skipping ImunifyAV.${NC}"
|
echo -e "${RED} ✗ Cannot write $imav_conf_file. Skipping ImunifyAV.${NC}"
|
||||||
imav_is_standalone=2
|
imav_is_standalone=2
|
||||||
@@ -488,7 +506,6 @@ install_all_scanners() {
|
|||||||
if [ "$imav_is_standalone" -ne 2 ]; then
|
if [ "$imav_is_standalone" -ne 2 ]; then
|
||||||
echo -e " ${GREEN}✓${NC} integration.conf written: ui_path = $imav_ui_path"
|
echo -e " ${GREEN}✓${NC} integration.conf written: ui_path = $imav_ui_path"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# SELinux warning for RHEL-family systems
|
# SELinux warning for RHEL-family systems
|
||||||
if [ "$imav_is_standalone" -ne 2 ] && command -v getenforce &>/dev/null; then
|
if [ "$imav_is_standalone" -ne 2 ] && command -v getenforce &>/dev/null; then
|
||||||
|
|||||||
Reference in New Issue
Block a user