HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //usr/lib64/nagios/plugins/a2_csf_modsecsync.mvps.mdedi
#!/bin/bash
#
# Ensure CSF and Modsec are in sync - OPSPROJ-8

imunify360_binary="/usr/sbin/imunify360-webshield"

# Skip unsupported (MWP) Plesk type servers
if [ -f /sbin/plesk ]; then
  exit
fi

# CSF is not supported if Imunify360 is installed.
if [ -f "${imunify360_binary}" ]; then
  exit
fi

# CSF may be unmanaged - SYSENG-14499
if [ -f /opt/csf_unmanaged ]; then
  echo "OK - unmanaged"
  exit 0
fi

cmk_name="csfmodsec_sync"
csf_sync="/etc/csf/a2_sync"
modsec_sync="/etc/apache2/conf.d/modsec/a2_sync"

cfm_get_status=$(/opt/bin/cfm_control status)
cfm_type=$(echo ${cfm_get_status} | awk '{print $2}' | sed 's/://')

if echo "${cfm_get_status}" | grep -q active; then
  exit_status=2
  cfm_status="active"
else
  exit_status=1
  cfm_status="downtimed"  
fi

if [ -f ${csf_sync} ] && [ -f ${modsec_sync} ]; then
  echo "CSF and Modsec is in sync"
  exit 0
elif [ ! -f ${csf_sync} ] && [ -f ${modsec_sync} ]; then
  echo "CSF is not in sync and ${cfm_type} is ${cfm_status}"
  exit ${exit_status}
elif [ -f ${csf_sync} ] && [ ! -f ${modsec_sync} ]; then
  echo "Modsec is not in sync and ${cfm_type} is ${cfm_status}"
  exit ${exit_status}
elif [ ! -f ${csf_sync} ] && [ ! -f ${modsec_sync} ]; then
  echo "CSF and Modsec is not in sync and ${cfm_type} is ${cfm_status}"
  exit ${exit_status}
fi