-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpam_alert.sh
36 lines (29 loc) · 1.14 KB
/
pam_alert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [ "$PAM_TYPE" != "close_session" ]; then
#Setting
API='' #Your Mailgun API
DOMAIN='' #Domain provided by Mailgun
TO='' #The email you want to send the alerts
#Don't touch! Grrr.
FROM="SSH Login Alert <mailgun@$DOMAIN>"
DATE=$(date) #This line of code is not neccessary.
SERVER=`uname -a`
SNAME=`uname -sn` #This line is also not neccessary. I want to look cool, ok?
SUBJECT="Login: $PAM_USER @ $SNAME from $PAM_RHOST" #Title of the email in regards to the person that has logged into the server successfully
#Email text format - All the information you want to know
BODY="
SSH login was successful, here is the following information:
User: $PAM_USER
User IP: $PAM_RHOST
Service: $PAM_SERVICE
Date: $DATE
Server: $SERVER
"
#This will use the cURL method to interact with Mailgun's API, and it will gather the information from above.
curl -s --user $API \
https://api.mailgun.net/v3/$DOMAIN/messages \
-F from="$FROM" \
-F to="$TO" \
-F subject="$SUBJECT" \
-F text="$BODY"
fi