Skip to content

Commit

Permalink
Update old VD config when installing Wazuh manager
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Cardenas <[email protected]>
  • Loading branch information
tsarquis88 and Kevin Cardenas committed Dec 12, 2023
1 parent 6c8bd2b commit 283fd82
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion debs/SPECS/wazuh-manager/debian/postinst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# postinst script for Wazuh
# Wazuh, Inc 2015
set -e
Expand Down Expand Up @@ -264,6 +264,52 @@ case "$1" in
fi
fi

# Function that checks if the old (< v4.8) VD configuration is present.
is_old_vulndet_config_present()
{
local OSSEC_CONFIGURATION_FILE="$1"
local VULNERABILITY_DETECTOR_PATTERN="<vulnerability-detector>"

if ( grep -q "$VULNERABILITY_DETECTOR_PATTERN" "$OSSEC_CONFIGURATION_FILE" ); then
return 0
fi
return 1
}

# Function that updates the old (< v4.8) VD configuration with the latest one.
update_vulndet_config()
{
local OSSEC_CONFIGURATION_FILE="$1"
local OSSEC_CONFIGURATION_FILE_TMP="$1.tmp"

touch $OSSEC_CONFIGURATION_FILE_TMP
local OSSEC_CONFIGURATION_FILE_BEFORE_VD="$(sed -ne '/<vulnerability-detector>/q;p' $OSSEC_CONFIGURATION_FILE)"
local OSSEC_CONFIGURATION_FILE_AFTER_VD="$(sed -e '1,/<\/vulnerability-detector>/d' $OSSEC_CONFIGURATION_FILE)"

# Append current config preceding the old VD config.
echo "${OSSEC_CONFIGURATION_FILE_BEFORE_VD}" >> $OSSEC_CONFIGURATION_FILE_TMP
echo "" >> $OSSEC_CONFIGURATION_FILE_TMP

# Append new VD config.
local VULNDET_TEMPLATE_FILE="${SCRIPTS_DIR}/etc/templates/config/generic/wodle-vulnerability-detection.manager.template"
cat ${VULNDET_TEMPLATE_FILE} >> $OSSEC_CONFIGURATION_FILE_TMP
echo "" >> $OSSEC_CONFIGURATION_FILE_TMP

# Append new Indexer config.
local INDEXER_TEMPLATE_FILE="${SCRIPTS_DIR}/etc/templates/config/generic/wodle-indexer.manager.template"
cat ${INDEXER_TEMPLATE_FILE} >> $OSSEC_CONFIGURATION_FILE_TMP

# Append current config succeeding the old VD config.
echo "$OSSEC_CONFIGURATION_FILE_AFTER_VD" >> $OSSEC_CONFIGURATION_FILE_TMP

mv $OSSEC_CONFIGURATION_FILE_TMP $OSSEC_CONFIGURATION_FILE
}

# Update VD configuration if necessary.
if is_old_vulndet_config_present "${DIR}/etc/ossec.conf"; then
update_vulndet_config "${DIR}/etc/ossec.conf"
fi

if [ ! -z "$2" ]; then
if [ -f ${WAZUH_TMP_DIR}/wazuh.restart ] ; then
if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then
Expand Down

0 comments on commit 283fd82

Please sign in to comment.