#!/bin/bash

NAGIOS_OK=0
NAGIOS_WARNING=1
NAGIOS_ERROR=2
NAGIOS_UNKNOWN=3

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 [ ! -f /etc/redhat-release ]; then
    echo "Only RedHat-based systems are affected"
    exit $NAGIOS_OK
fi

rpm -q NetworkManager > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "NetworkManager isn't installed, system isn't vulnerable"
    exit $NAGIOS_OK
fi

echo "No mitigation found for CVE-2018-1111"
exit $NAGIOS_ERROR
