X-Git-Url: https://git.madduck.net/code/molly-guard.git/blobdiff_plain/ecdbd1cb447dca36108ca5fe0c4c6d366a09ae70..d488a885cd818fb809a2c82e629bc4c37eeb7fc3:/checks.d/molly-guard diff --git a/checks.d/molly-guard b/checks.d/molly-guard index a9a2e90..968dd95 100755 --- a/checks.d/molly-guard +++ b/checks.d/molly-guard @@ -9,9 +9,11 @@ set -eu ME=molly-guard +ALWAYS_MOLLY=${ALWAYS_MOLLY:-"0"} +[ -f /etc/default/${ME} ] && . /etc/default/${ME} + +CMD=$1; shift PRETEND_SSH=0 -CMD=$1 -shift for arg in "$@"; do case "$arg" in (*-help) @@ -26,18 +28,23 @@ done # require an interactive terminal connected to stdin test -t 0 || exit 0 -# only run if we are being called over SSH, that is if the current terminal -# was created by sshd. -PTS=$(readlink /proc/$$/fd/0) -if ! pgrep -f "^sshd.+${PTS#/dev/}[[:space:]]*$" >/dev/null \ - && [ -z "${SSH_CONNECTION:-}" ]; then - if [ $PRETEND_SSH -eq 1 ]; then - echo "I: this is not an SSH session, but --pretend-ssh was given..." - else - exit 0 - fi +# we've been asked to always protect this host +if [ ${ALWAYS_MOLLY} -eq 1 ]; then + echo "W: $ME: ${CMD} is always molly-guarded on this server." else - echo "W: $ME: SSH session detected!" + # only run if we are being called over SSH, that is if the current terminal + # was created by sshd. + PTS=$(readlink /proc/$$/fd/0) + if ! pgrep -f "^sshd.+${PTS#/dev/}[[:space:]]*$" >/dev/null \ + && [ -z "${SSH_CONNECTION:-}" ]; then + if [ $PRETEND_SSH -eq 1 ]; then + echo "I: this is not an SSH session, but --pretend-ssh was given..." + else + exit 0 + fi + else + echo "W: $ME: SSH session detected!" + fi fi