#!/bin/bash

NAGIOS_OK=0
NAGIOS_ERROR=2

PAKITI_RESULT="pakiti_results"

if [ -f "$PAKITI_RESULT" ]; then
    cve=$(echo $0 | sed 's/.*check_//')
    grep -q "$cve" "$PAKITI_RESULT" 2>/dev/null
    if [ $? -eq 1 ]; then
        echo "No $cve vulnerability found, skipping the mitigation check"
        exit $NAGIOS_OK
    fi
fi

if grep -q -r -E "^blacklist esp4|^install esp4" /etc/modprobe.d && ! lsmod | grep -q esp4; then
    if grep -q -r -E "^blacklist esp6|^install esp6" /etc/modprobe.d && ! lsmod | grep -q esp6; then
        if grep -q -r -E "^blacklist rxrpc|^install rxrpc" /etc/modprobe.d && ! lsmod | grep -q rxrpc; then
            echo "Modules esp4, esp6 and rxrpc are blocked"
            exit $NAGIOS_OK
        fi
    fi
fi

echo "No known mitigation of $cve detected"
exit $NAGIOS_ERROR
