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

Sharing Ideas … Get User Account Info via SMS in DMASOFTLAB Radius Manager

$
0
0

userinfo


1- TASK

The task was to provide user a method to inquire his/her account information via sending SMS in specific format to the Billing system.

In this example, we are using DMASOFTLAB Radius Manager as our billing system, and KANNEL along-with the playSMS is already configured and in working condition. kannel+playSMS configuration details have already been described briefly with examples in my previous posts.

We have created an script on the billing system which fetches the user account status and other information from the MYSQL database and print them as per our defined format.

This is just for demonstration purpose. the script have lot of junk data and should be modified before production deployment. I am just sharing some thoughts and ideas only :)

Script is as follows FYR. Hope it may help someone :$

root@radius:/var/lib/playsms/sms_command/1# cat userinfo.sh

#!/bin/bash
# Script to check Radius Manager Status , Expiry Date, Service Plan, Data Used
# Syed Jahanzaib
# aacable @ hotmail.com
# https://aacable.wordpress.com
# Modified on 26 / 05 / 2015
SQLUSER="root"
SQLPASS="sqlpass"
echo

# Check User Validation
USRVALID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT * FROM radius.rm_users WHERE rm_users.username = '$1';"`
if [ "$USRVALID" == "" ]; then
echo -e "USER NOT FOUND !"
else

# Check ACCOUNT EXPIRY Status and act accordingly

TODAY=$(date +"%Y-%m-%d")
TODAYDIGIT=`echo $TODAY  | sed -e 's/-//g'`
SRVEXPIRYFULL=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$1';" |awk 'FNR == 2'`
SRVEXPIRY=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$1';" |awk 'FNR == 2' | sed 's/00:.*//' | sed -e 's/-//g'`
LOGOFFDATE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT lastlogoff FROM radius.rm_users WHERE username = '$1';"  |awk 'FNR == 2 {print $1,$2}'`

if [ $SRVEXPIRY -eq $TODAYDIGIT ]
then
        echo "Account have been EXPIRED TODAY! Last LOGOFF date was $LOGOFFDATE"

elif [ $SRVEXPIRY -lt $TODAYDIGIT ]
then
        echo "ACCOUNT WAS EXPIRED on $SRVEXPIRYFULL !  Last LOGOFF date was $LOGOFFDATE"

else
        echo "Account STATUS= OK! It will expire on $SRVEXPIRYFULL !  Last LOGOFF date was $LOGOFFDATE"

###############

EXPIRY=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$1';" |awk 'FNR == 2'`
SRVLIMIT=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT comblimit FROM radius.rm_users WHERE username = '$1';" |awk 'FNR == 2'`

#Get Accounting Data
DOWNDATA=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT SUM(acctoutputoctets), SUM(acctinputoctets), SUM(acctsessiontime), MAX(acctstoptime) FROM radacct WHERE username = '$1';"  |awk 'FNR == 2 {print $1}'`
UPDATA=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT SUM(acctoutputoctets), SUM(acctinputoctets), SUM(acctsessiontime), MAX(acctstoptime) FROM radacct WHERE username = '$1';" |awk 'FNR == 2 {print $2}'`
TOTCOMBINED=`echo "($DOWNDATA+$UPDATA)/(1024)/(1024)" |bc`
SRVLIMITMB=`echo "($SRVLIMIT)/(1024)/(1024)" |bc`
DOWNDATAUSED=`echo "($DOWNDATA)/(1024)/(1024)" |bc`
UPDATAUP=`echo "($UPDATA)/(1024)/(1024)" |bc`
CURRENCY="PKR"

#Print Service ID for SPECIFIC_USER via CLI
SRVID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$1';" |awk 'FNR == 2 {print $1}'`

#Print SPECIFIC Service PRICE value via CLI
SRVPRICE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius;  SELECT unitprice FROM radius.rm_services WHERE rm_services.srvid = $SRVID;" |awk 'FNR == 2 {print $1}' | cut -f1 -d"."`

# Print Package Name of current service via CLI
PKGNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvname FROM radius.rm_services WHERE rm_services.srvid = '$SRVID';" |awk 'FNR == 2'`

# Account Registration FIRST n LAST NAME
USERFLNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT firstname,lastname FROM radius.rm_users WHERE rm_users.username = '$1';" |awk 'FNR == 2 {print $1,$2}';`

##################
# Finally ECHO all the DATA to be print on screen or sent via SMS (I used playSMS and kannel)
##################
echo -e "Account Registed to = $USERFLNAME"
echo -e "User Package  = $PKGNAME"
echo -e "Service Price = $SRVPRICE $CURRENCY"
echo -e "Expiration Date: $EXPIRY"
echo -e "Service Quota Limit = $SRVLIMITMB MB"
echo -e "Data Used = $TOTCOMBINED - MB"
echo -e "Downloaded Data = $DOWNDATAUSED - MB"
echo -e "Uploaded Data = $UPDATAUP - MB"
fi
fi

# THE END ! GOTO HOME

2- playSMS SECTION

Now we have to add COMMAND in playSMS which will actually receive the sms and will act accordingly if found the keyword info

userinfo-playsms-=command


 3- TEST PHASE

You can test by executing the script or send sms , as per your choice.

Both methods results are as follows …

 

by CLI

userinfo-cli

by SMS

userinfo

Regard’s
SYED JAHANZAIB


Filed under: Linux Related, Radius Manager

Viewing all articles
Browse latest Browse all 409

Trending Articles