#!/bin/bash

WPCLIPATH='/path/to/wp'
if [ ! -f $WPCLIPATH ]; then
    WPCLIPATH=`which wp`
    if [ -z $WPCLIPATH ]; then exit 1; fi;
fi;

RECIPIENT="user@example.com"
SUBJECT="Vulnerabilities detected"
SUBJECT2="No vulnerabilities detected"

core=$($WPCLIPATH vuln core-status --nagios --allow-root)
novuln="OK - no vulnerabilities found"
if echo "$core" | grep -q "$novuln"; then
    echo "No core vulnerabilities detected at '$path'" | mail -s "$SUBJECT2" $RECIPIENT
else
    echo "Core vulnerability found at '$path'" | mail -s "$SUBJECT" $RECIPIENT
fi

plugins=$($WPCLIPATH vuln plugin-status --porcelain)
if [ ! -z "$plugins" ]; then
    echo "Vuln plugins: $plugins" | mail -s $SUBJECT $RECIPIENT
    echo "$WPCLIPATH plugin update $plugins"
else
    echo "No plugin vulnerabilities detected at '$path'" | mail -s "$SUBJECT2" $RECIPIENT
fi

themes=$($WPCLIPATH vuln theme-status --porcelain)
if [ ! -z "$themes" ]; then
    echo "Vuln themes: $themes" | mail -s $SUBJECT $RECIPIENT
    echo "$WPCLIPATH theme update $themes"
else
    echo "No theme vulnerabilities detected at '$path'" | mail -s "$SUBJECT2" $RECIPIENT
fi
