Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all articles
Browse latest Browse all 409

Sending SMS/Email Alert upon manager login

$
0
0

2016-05-31 10.36.22

 

a1



Reference Note:

As per requested by OP, following script will send email and SMS alert to manager whose account is logged in successfully in last minutes at admin panel (ACP).

In this example we have used Kannel as SMS gateway and sendEmail application to send email using standard Gmail account. Schedule it to run after every 5 minutes interval.

Regard’s
Syed Jahanzaib~



#!/bin/bash
# set -x
# SCRIPT to send email / sms alert when any admin or manager logged in to radius manager billing panel.
# SMS will be sent via kannel sms gateway, you can change it as per your requirements
# Email will be sent using sendEMAIL application, via your GMAIL account. I wrote post on howto setup sendEMAIL,
# You can modify it as well.

# Syed Jahanzaib / aacable @ hotmail.com / https://aacable.wordpress.com
# Created: 31-MAY-2016

# Setting FILE Variables
TMPFILE1="/tmp/adminlog.txt"
> $TMPFILE1

COMPANY="YOUR COMPANY"
FOOTER="Powered by Syed Jahanzaib"

#DATE TIME
CURDATE=`date`

#MYSQL INFO
SQLUSER="root"
SQLPASS="MYSQL-PASSWORD"

#Interval in minutes
INTERVAL="5"

# Kannel SMS Gateway IP and username password Details
KHOST="127.0.0.1"
KID="kannel"
KPASS="KANNEL-PASSWORD"

#GMAIL DETAILS for sending email alert
GMAILID="YOUR-GMAIL-ID@gmail.com"
GMAILPASS="YOUR-GMAIL-PASSWORD"
ADMINMAIL1="aacable @ hotmail . com"

# Mysql query to fetch users whoes accounts are deleted from radius database.
# Print info
mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; select name, ip, datetime from rm_syslog where eventid = '3' AND datetime >= NOW() - INTERVAL $INTERVAL MINUTE;" > $TMPFILE1

# Check if no user is deleted in DEFINED interval
# Echo this info for admin info purposes.

if [ -s $TMPFILE ]
then
echo "Following Managers have Found Logged in last $INTERVAL Minutes on Radius Billing System..."

# Apply Formula to read the file in which dismissed users list and act accordingly.
num=0
cat $TMPFILE1 | while read users
do
num=$[$num+1]
USERNAME=`echo $users | awk '{print $1}'`
IP=`echo $users | awk '{print $2}'`
DATETIME=`echo $users | awk '{print $3,$4}'`
FIRSTNAME=`mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; select firstname from rm_managers where managername = '$USERNAME';"`
LASTNAME=`mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; select lastname from rm_managers where managername = '$USERNAME';"`
MOBILE=`mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; select mobile from rm_managers where managername = '$USERNAME';"`
EMAIL=`mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; select email from rm_managers where managername = '$USERNAME';"`

# PRINT INFO , for review
echo "GT Alert:
$FIRSTNAME $LASTNAME, You have successfully logged-in to billing admin panel.
ID = $USERNAME
DATE = $DATETIME
IP = $IP
MOBILE = $MOBILE

Regard's
$COMPANY
$FOOTER"

# create temporary holder where sms will be stored
echo "$FIRSTNAME $LASTNAME, You have successfully logged-in to billing admin panel.
ID = $USERNAME
DATE = $DATETIME
IP = $IP
MOBILE = $MOBILE

Regard's
$COMPANY
$FOOTER" > /tmp/$USERNAME.login.sms

# Finally SENDING SMS using KANNEL SMS GATEWAY, you can use other functions as well : D ~
curl "http://$KHOST:13013/cgi-bin/sendsms?username=$KID&password=$KPASS&to=$MOBILE" -G --data-urlencode text@/tmp/$USERNAME.login.sms

# Make sure you install sendEMAIL tool and test it properly before using email section.
#SEND EMAIL Alert As well using sendEMAIL tool using GMAIL ADDRESS.
# If you want to send email , use below ...

echo "Sending SEMAIL ALERT to $EMAIL & $ADMINMAIL1..."
/temp/sendEmail-v1.56/sendEmail -u "GT Billing Alert: $USERNAME successfully logged-in to Billing Admin Panel." -o tls=yes -s smtp.gmail.com:587 -t $EMAIL -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=/tmp/$USERNAME.login.sms -o message-content-type=text

echo "$USERNAME loggedin at $DATETIME from $IP" >> /var/log/adminlog.txt
done
echo ""
else
echo "No MANAGER have found logged in last $INTERVAL minutes. Nothing to do..."
fi

# Script End
# Regard's / zaib

Filed under: Radius Manager

Viewing all articles
Browse latest Browse all 409

Trending Articles