From 0720ffafb91dc68b008d315af75a876215f8cf2d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 16 Sep 2016 14:04:16 -0500 Subject: [PATCH] Fixes --- setup/login-alerts.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/setup/login-alerts.sh b/setup/login-alerts.sh index cc90ec94..3741f59a 100644 --- a/setup/login-alerts.sh +++ b/setup/login-alerts.sh @@ -1,18 +1,21 @@ +#!/bin/bash + +cat << 'EOF' > /etc/ssh/login-alert.sh +#!/bin/bash + source /etc/mailinabox.conf # load global vars -cat <> /etc/ssh/login-alert.sh -#!/bin/sh -sender="bot@PRIMARY_HOSTNAME" -recepient="admin@$PRIMARY_HOSTNAME" - if [ "$PAM_TYPE" != "close_session" ]; then - subject="SSH Login: $PAM_USER from $PAM_RHOST" - # Message to send, e.g. the current environment variables. - message="If you don't recognize this login, your key or password may be compromised." - echo "$message" | mailx -r "$sender" -s "$subject" "$recepient" + IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 1) + sendEmail -q -f "bot@$PRIMARY_HOSTNAME" -t "admin@$PRIMARY_HOSTNAME" -u "SSH Login: $PAM_USER from $PAM_RHOST" -m "If you don't recognize this login, your key or password may be compromised." fi EOF chmod +x /etc/ssh/login-alert.sh -echo 'session optional pam_exec.so seteuid /etc/ssh/login-alert.sh' >> /etc/pam.d/sshd +if grep -Fq "login-alert" /etc/pam.d/sshd +then + : +else + echo 'session optional pam_exec.so seteuid /etc/ssh/login-alert.sh' >> /etc/pam.d/sshd +fi