Syed Jahanzaib Personnel Blog to Share Knowledge !

May 26, 2015

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

Filed under: Linux Related, Radius Manager — Syed Jahanzaib / Pinochio~:) @ 12:59 PM

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

May 25, 2015

May 22, 2015

Give your hardware some freedom of Speech ;)

Filed under: Linux Related, Mikrotik Related — Tags: — Syed Jahanzaib / Pinochio~:) @ 11:53 AM

MT-REPORT-SMS

playSMS_logo_full

kick


 CHANGE LOG:

  • 23-05-2015 – Added few functions in mt.sh to avoid SSH delay bug with mikrotik and to avoid false result

 

Recently I was working on a SMS reporting system to somehow receive some specific information for the Mikrotik health & Radius server information via sending an SMS and it should reply back the required information in some user friendly format. In the beginning it seemed fairly an easy task to accomplish by simply ssh (pass-wordless) to mikrotik and get the required info, BUT … executing the script from the terminal was working flawless, but executing this script from the playSMS was returning command_output EMPTY for ssh $variables. It took almost 15-16 hours wall banging efforts and finally I took another long route in order to achieve my task. You may find many other short routes to achieve this task, but I managed to get it working this way. Share your thoughts please.

TASK:

Send an sms with specific keyword to playSMS server, and it should then SSH to Mikrotik, and get some information (as described in the script) and send back that info (after making it user friendly) to the sender. so in short it’s a very good and handy way to get the server’s health report via sms Quickly ;)

Requirements:

This task is for people with some firm knowledge on Mikrotik and specially with Linux BASH scripting. But even if you are  a simple beginner, you can learn a lot from it. This is how you begin your journey by seeing far objects and then eventually reach to them by finding ways :) and that’s the exact way I started my astronomy journey as well :D

jupiter-first-modified-pic-24-3-2015

My First Picture of ‘Jupiter’ planet taken with 10″ manual Dobsonian with AFOCAL method, It’s an amazing experience when you see the planet from your Eyes Live !

 

 

1- Mikrotik with SSH/FTP services enabled (I changed the ports for security reasons)
2- Linux base System, I used my existing radius server for this purpose. It already have Kannel+playSMS configured with Dlink USB DWM-156 Modem. It can also ssh to mikrotik without password using per-configured public keys.

So you should read following guides before proceeding further.


 

Linux Section:

Here is the main script which will actually perform all the required actions and will gather information from mirkotik and radius itself.


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

#!/bin/bash
# Script by Syed Jahanzaib / aacable@hotmail.com
# https://aacable.wordpress.com
# This script can inquire some specific Information from mikrotik and other server
# and send it back to sender via SMS on demand
# Version 2.0 -

MIKROTIK="192.168.1.2"
MTPORT="10001"
SERVER4="10.0.0.200"
SERVICE="radiusd"
DATE=`date`

# Check if Mikrotik is accessible or not, if not then EXIT immediately with error / zaib
if [[ $(ping -q -c 1 $MIKROTIK) == @(*100% packet loss*) ]]; then
echo "ALERT ..... MIKROTIK $MIKROTIK  is DOWN"
exit
else
echo "Galaxy Mikrotik Information SMS @ $DATE ..."
fi

# Execute Internetstatus script on mikrotik which will set the envrionment variable
ssh -q -p $MTPORT admin@$MIKROTIK /sys script run smsnetstatus > /tmp/pingresult

# Print PPP Active user in a file at Mikrotik
ssh -q -p $MTPORT admin@$MIKROTIK /ppp active print file=pppactive

# Print Internet Status Environment variables that we will use later
ssh admin@$MIKROTIK -p $MTPORT /sys script environment print file=netstatus

# Print Mikrotik Systems Resources in a file
ssh admin@$MIKROTIK -p $MTPORT /sys resource print file=resources

# Download pppactive file from mikrotik to local system in /tmp
scp -q -P $MTPORT admin@$MIKROTIK:pppactive.txt /tmp/pppactive.txt

# Verify if file is downloaded from mikrotik or not, if not dueo to ssh delay bug, then print error and exit :) Security Check by zaib
{
if [ ! -f /tmp/pppactive.txt ]; then
echo -e "ERROR: Mikrotik is live but it's SSH not accessible. Its a Mikrotik level BUG, You MUST upgrade with latest version. zaib"
exit 0
fi
}

# Download pppactive file from mikrotik to local system in /tmp
scp -q -P $MTPORT admin@$MIKROTIK:netstatus.txt /tmp/netstatus.txt

# Verify if file is downloaded from mikrotik or not, if not dueo to ssh delay bug, then print error and exit :) Security Check by zaib
{
if [ ! -f /tmp/netstatus.txt ]; then
echo -e "ERROR: Mikrotik is live but it's SSH not accessible. Its a Mikrotik level BUG, You MUST upgrade with latest version. zaib"
exit 0
fi
}

# Download Mikrotik System Resources file from mikrotik to local system in /tmp
scp -q -P $MTPORT admin@$MIKROTIK:resources.txt /tmp/resources.txt

# Verify if file is downloaded from mikrotik or not, if not dueo to ssh delay bug, then print error and exit :) Security Check by zaib
{
if [ ! -f /tmp/resources.txt ]; then
echo -e "ERROR: Mikrotik is live but it's SSH not accessible. Its a Mikrotik level BUG, You MUST upgrade with latest version. zaib"
exit 0
fi
}


# Print/Extract Uptime & CPU load only
cat /tmp/resources.txt  | awk 'NR==4' | sed -e 's/^[ \t]*//'
cat /tmp/resources.txt  | awk 'NR==11' | sed -e 's/^[ \t]*//'

# Extract Netstaus value from the csript we ran earlier on mt.
NETSTATUSVALUE=`grep "smsInternetStatus" /tmp/netstatus.txt | awk '{print $4}'`
echo "NET STATUS = $NETSTATUSVALUE"

# Print/Extract PPP Active Number of users
ACTIVE=`cat /tmp/pppactive.txt | wc -l`
echo "Active PPP users = $ACTIVE"

# Check RADIUS or whatever service PID status
pid=`pidof $SERVICE`
if [ "$pid" == "" ]; then
echo -e "$SERVICE service is NOT running, trying to start it ..."
service $SERVICE start
else
echo "$SERVICE = OK"
fi

# Check status of sharing media server
if [[ $(ping -q -c 1 $SERVER4) == @(*100% packet loss*) ]]; then
echo "ALERT ..... SERVER4 $SERVER4 is DOWN"
exit
else
echo "SERVER4 = OK"
fi
echo "Powered by Syed.Jahanzaib ..."

# Delete Files on Mikrotik so that false reproting may not occur / zaib
ssh -q -p $MTPORT admin@$MIKROTIK /file remove pppactive.txt
ssh -q -p $MTPORT admin@$MIKROTIK /file remove netstatus.txt
ssh -q -p $MTPORT admin@$MIKROTIK /file remove resources.txt

# delete files download from the local tmp folder in linux
rm -fr /tmp/netstatus.txt
rm -fr /tmp/pppactive.txt
rm -fr /tmp/resources.txt

exit 0

You should save this file mt.sh (or whatever name you decide) in following location

/var/lib/playsms/sms_command/1

 


Mikrotik Section

At mikrotik you should create and script which will actually check the internet status and update environment variable which we will fetch and use later via cat/awk.

Mikrotik Script name: smsnetstatus


# Modified few contents to suite local requirements and added descriptions
# Regard's / Syed Jahanzaib / https://aacable.wordpress.com

# Script Starts here...
# Internet Host to be checked You can modify them as per required, JZ
# We are using DOUBLE hosts to avoid FALSE REPORTING : ) / zaib

:local host1   "8.8.8.8"
:local host2   "192.0.78.13"

# Do not modify data below without proper understanding.
:local i 0;
:local F 0;
:local date;
:local time;
:global smsInternetStatus;
:global smsInternetLastChange;

# PING each host 5 times
:for i from=1 to=5 do={
if ([/ping $host1 count=1]=0) do={:set F ($F + 1)}
if ([/ping $host2 count=1]=0) do={:set F ($F + 1)}
:delay 1;
};

# If both links are down and all replies are timedout, then link is considered down
:if (($F=10)) do={
:if (($smsInternetStatus="UP")) do={
:log error "smsRESULT:  - WARNING : The INTERNET link seems to be DOWN. Please Check";
:set smsInternetStatus "DOWN";

:set date [/system clock get date];
:set time [/system clock get time];
:set smsInternetLastChange ($time . " " . $date);
} else={:set smsInternetStatus "DOWN";}
} else={

##      If reply is received , then consider the Link is UP
:if (($smsInternetStatus="DOWN")) do={
:log warning "smsRESULT: WARNING :The INTERNET link have been restored";
:set smsInternetStatus "UP";

##      MAKE SURE TO CHANGE PPPO-OUT1 TO MATCH YOUR WAN INTERFACE
:local currentIP
:local externalInterface "pppoe-out1"

# get the current IP address from the external interface
:set currentIP [/ip address get [find interface="$externalInterface"] address]
# Strip netmask
:for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]

:log warning "smsRESULT: PTCL LINK RE - CONNECTED with new WAN IP = $currentIP, Please check and confirm / zaib"

}
}

:set date [/system clock get date];
:set time [/system clock get time];
:set smsInternetLastChange ($time . " " . $date);
} else={:set smsInternetStatus "UP";}
}

# Script Ends Here.
# Thank you

Done!


Now you should create an SMS COMMAND in playSMS as showed below …

sms-command-fro-mt-report


 

TESTING …

Now test by sending an sms with word “mikrotik” to the playsms server mobile number. and you will shortly receive the reply :) Allah Shuker

MT-REPORT-SMS


 

playSMS LOG

here is the playsms log when it will receive the SMS with word mikrotik

127.0.0.1 localhost 2015-05-22 11:40:59 PID555ecf7b2f24c - L2 kannel__call # start load:/var/www/playsms/plugin/gateway/kannel/geturl.php
127.0.0.1 localhost 2015-05-22 11:40:59 PID555ecf7b2f24c - L3 kannel__incoming # addr:127.0.0.1 host:localhost t:2015-05-22 06:42:03 q:+923333021909 a:Mikrotik Q:13013 smsc:[]
127.0.0.1 localhost 2015-05-22 11:40:59 PID555ecf7b2f24c - L3 recvsms # isrecvsmsd:1 dt:2015-05-22 06:42:03 sender:+923333021909 m:Mikrotik receiver:13013 smsc:
127.0.0.1 localhost 2015-05-22 11:40:59 PID555ecf7b2f24c - L2 kannel__call # end load geturl
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 recvsmsd # id:195 dt:2015-05-22 06:42:03 sender:+923333021909 m:Mikrotik receiver:13013 smsc:
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 setsmsincomingaction # dt:2015-05-22 06:42:03 sender:+923333021909 m:Mikrotik receiver:13013 smsc:
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 sms__command # command_exec:/var/lib/playsms/sms_command/1/mt.sh
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 sms__command # command_output:Galaxy Mikrotik Information SMS @ Fri May 22 11:41:00 PKT 2015 ... uptime: 17h54m55s cpu-load: 13% NET STATUS = UP Active PPP users = 295 radiusd = OK SERVER4 = OK Powered by Syed.Jahanzaib ...
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L2 sendsms # start uid:1 sender_id:[1234] smsc:[]
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 sendsms # maxlen:15140 footerlen:7 footer:[ @admin] msglen:193 message:[Galaxy Mikrotik Information SMS @ Fri May 22 11:41:00 PKT 2015 ... uptime: 17h54m55s cpu-load: 13% NET STATUS = UP Active PPP users = 295 radiusd = OK SERVER4 = OK Powered by Syed.Jahanzaib ...]
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L2 sendsms_queue_create # saving queue_code:60c45bad522ae25332bf3b37c33ea19f src:1234 scheduled:2015-05-22 11:41:00
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L2 sendsms_queue_create # saved queue_code:60c45bad522ae25332bf3b37c33ea19f id:163
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 sendsms_manipulate_prefix # before prefix manipulation:[+923333021909]
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 sendsms_manipulate_prefix # after prefix manipulation:[+923333021909]
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:200 unicode:0 to:+923333021909 enable_credit_unicode:0 count:2 rate:1 charge:2
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L2 sendsms # dst:1 sms_count:2 total_charges:2
- - 2015-05-22 11:41:00 PID555ebd2ae9681 admin L2 sendsms_queue_push # saving queue_code:60c45bad522ae25332bf3b37c33ea19f dst:+923333021909
- - 2015-05-22 11:41:01 PID555ebd2ae9681 admin L2 sendsms_queue_push # saved queue_code:60c45bad522ae25332bf3b37c33ea19f smslog_id:157
- - 2015-05-22 11:41:01 PID555ebd2ae9681 admin L2 sendsms # end queue_code:60c45bad522ae25332bf3b37c33ea19f queue_count:1 sms_count:2 failed_queue:0 failed_sms:0
- - 2015-05-22 11:41:01 PID555ebd2ae9681 admin L3 setsmsincomingaction # feature:sms_command datetime:2015-05-22 06:42:03 sender:+923333021909 receiver:13013 keyword:MIKROTIK message: raw:Mikrotik smsc:
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 sendsmsd # start processing queue_code:60c45bad522ae25332bf3b37c33ea19f sms_count:2 scheduled:2015-05-22 11:41:00 uid:1 gpid:0 sender_id:1234
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 sendsmsd # sending queue_code:60c45bad522ae25332bf3b37c33ea19f smslog_id:157 to:+923333021909 sms_count:2 counter:1
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 sendsms_intercept # msgtemplate modified sms_sender:[1234] sms_footer:[@admin] sms_to:[+923333021909] sms_msg:[Galaxy Mikrotik Information SMS @ Fri May 22 11:41:00 PKT 2015 ... uptime: 17h54m55s cpu-load: 13% NET STATUS = UP Active PPP users = 295 radiusd = OK SERVER4 = OK Powered by Syed.Jahanzaib ...] uid:[1] gpid:[0] sms_type:[text] unicode:[0] queue_code:[60c45bad522ae25332bf3b37c33ea19f] smsc:[]
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 outgoing_hook_sendsms_intercept # no SMSC found uid:1 parent_uid:0 from:1234 to:+923333021909
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 sendsms_process # start
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:200 unicode:0 to:+923333021909 enable_credit_unicode:0 count:2 rate:1 charge:2
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 simplerate__cansend # allowed user uid:1 sms_to:+923333021909 credit:55324.000 count:2 rate:1 charge:2 balance:55322
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 sendsms # saving smslog_id:157 u:1 g:0 gw:kannel smsc:kannel s:1234 d:+923333021909 type:text unicode:0 status:0
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 sendsms_process # saved smslog_id:157 id:157
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 sendsms # final smslog_id:157 gw:kannel smsc:kannel message:Galaxy Mikrotik Information SMS @ Fri May 22 11:41:00 PKT 2015 ... uptime: 17h54m55s cpu-load: 13% NET STATUS = UP Active PPP users = 295 radiusd = OK SERVER4 = OK Powered by Syed.Jahanzaib ... @admin len:200
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 kannel_hook_sendsms # enter smsc:kannel smslog_id:157 uid:1 to:+923333021909
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 kannel_hook_sendsms # URL: http://localhost:13013/cgi-bin/sendsms?username=kannel&password=KANNELPASSWORD&from=1234&to=%2B923333021909&dlr-mask=31&dlr-url=http%3A%2F%2Fclick.onmypc.net%3A1235%2Fplaysms%2Findex.php%3Fapp%3Dcall%26cat%3Dgateway%26plugin%3Dkannel%26access%3Ddlr%26type%3D%25d%26smslog_id%3D157%26uid%3D1&account=admin&text=Galaxy+Mikrotik+Information+SMS+%40+Fri+May+22+11%3A41%3A00+PKT+2015+...%0Auptime%3A+17h54m55s%0Acpu-load%3A+13%25%0ANET+STATUS+%3D+UP%0AActive+PPP+users+%3D+295%0Aradiusd+%3D+OK%0ASERVER4+%3D+OK%0APowered+by+Syed.Jahanzaib+...+%40admin
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 kannel__outgoing # smslog_id:157 response:0: Accepted for delivery
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 dlr # isdlrd:1 smslog_id:157 p_status:0 uid:1
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 kannel__outgoing # end smslog_id:157 p_status:0
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 simplerate__deduct # enter smslog_id:157
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:200 unicode:0 to:+923333021909 enable_credit_unicode:0 count:2 rate:1 charge:2
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 credit_hook_rate_setusercredit # saving uid:1 balance:55322
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 credit_hook_rate_setusercredit # saved uid:1 balance:55322
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 simplerate__deduct # user uid:1 parent_uid: smslog_id:157 msglen:200 count:2 rate:1 charge:2 credit:55324.000 balance:55322
- - 2015-05-22 11:41:01 PID555ecf7da2f5f - L2 simplebilling__post # saving smslog_id:157 rate:1 credit:55324.000 count:2 charge:2
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L2 simplebilling__post # saved smslog_id:157 id:156
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L3 simplerate__deduct # deduct successful uid:1 parent_uid: smslog_id:157
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L3 simplerate__deduct # credit_lowest_limit:0 balance:55322 charge:2
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L2 sendsms_process # end
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L2 sendsmsd # result queue_code:60c45bad522ae25332bf3b37c33ea19f to:+923333021909 flag:1 smslog_id:157
- - 2015-05-22 11:41:02 PID555ecf7da2f5f - L2 sendsmsd # finish processing queue_code:60c45bad522ae25332bf3b37c33ea19f uid:1 sender_id:1234 sms_count:2
- - 2015-05-22 11:41:02 PID555ebd2ae3e02 - L3 dlrd # id:157 smslog_id:157 p_status:0 uid:1


 

Regard’s
Syed Jahanzaib

 

May 12, 2015

Sharing Ideas … Mikrotik with Kannel/playSMS

Filed under: Mikrotik Related — Syed Jahanzaib / Pinochio~:) @ 3:30 PM

Sharing an old idea , worked in Year 2008 …

mt - code found

Screenshot_2015-05-24-16-37-08

Post last updated: 20th May, 2015, 11:30AM

Changelog:
Added user friendly comments in the script section
Added Log entry in User Manager User comments section
Added Account Renewed Entry in the Return SMS Reply

24-05-2015   Added reboot script with protection code


 

Task:

  1. Renew expired users via sending Username and SCRATCH CODE to playSMS (Ubuntu Server)
  2. Reboot Linux or mikrotik server by sending sms with protection code (password)

 


Task # 1

  1. Renew expired users via sending Username and SCRATCH CODE to playSMS (Ubuntu Server)

Mikrotik is configured with User Manager.

playSMS with Kannel is already configured and working in separate box (Ubuntu)

 

Requirements:

  1. Mikrotik with User Manager . SSH must be enabled  (with public key to enable linux ssh connectivity to mikrotik without Password)
    Follow this guide
    https://aacable.wordpress.com/2011/11/25/howto-login-on-remote-mikrotik-linux-without-password-to-execute-commands/
  2. Linux OS with USB GSM modem [Teltonika usb modems are best, but you can use some cheaper modems like dlink dwm-156 used in this guide, Linux OS can be any flavor , I used Ubuntu in this example with playSMS & Kannel already configured)
    Follow this guide for kannel configuration
    https://aacable.wordpress.com/2015/05/08/fun-with-sms-management-system-playsms/

 

Remember, I took User Manager as an example and uses some low and un secure scripting method. The goal was to show you the capabilities and things we can do by combining various apps and cross platform OS to get our results. This is no way a perfect example, but I am sure it will give you some idea how things can be started : )

You can take this example , and you can generate you scratch card codes and store it in MYSQL DB and FREERADIUS, therefore you can then pull CODE from specific DB and act accordingly after receiving SMS. I am sharing just some thoughts : )

 

 


 

1- Renew expired users via sending SMS to playSMS (Ubuntu Server)

This one is a very basic task. It does not involve any code to profile match check.
In this method user send sms with his Username and the scratch CODE. Once the server will receive the sms, it will first check the USERNAME at mikrotik, if it found valid username, it will then check the CODE in local text files (in this example I created 3 files, 512k.txt 1mb.txt and 4mb.txt , script will check all of three files (infact *.txt files) and if it found the CODE, it will then ssh to mikrotik and re-activate the user account with the given code profile. if the code belongs to 512k, it will re-activate user with 512k profile, and if the code is from 1mb pacakge, it will re-activate the account with 1mb profile.

SMS with following format

REN zaib 123

Explanation:

REN is a keyword which SMS server will catch and consider it as renew command.
zaib is user id
123 is password


 

 

Pseudo Code:

Server receive SMS with username and code

Server will SSH into mikrotik and look for username

If valid username found then it proceed further, otherwise issue error INVALID USERNAME and EXIT

If valid username found, then script will pick the second variable (code) and will look for this variable in /temp/*.txt , if it found the CODE then proceed further, otherwise issue error INVALID CARD NUMBER

If valid CODE is found in text files, then script will SSH to mikrotik and will re-activate the user account according to the package (which was fetched from the text file) and also print LOG in the window. You can also create other functions too like Remove the SCRATCH code once used, email admin or user, etc etc

Here is the example:

First create text files with the Scratch codes

example

cat /temp/512k.txt

123

cat /temp/1mb.txt

555

cat /temp/4mb.txt

999

Add Command on playSMS Server

As showed in the image below … or read my previous guide on howto make custom commands in playSMS

https://aacable.wordpress.com/2015/05/08/fun-with-sms-management-system-playsms/

playsms_command


 

 

Create SCRIPT on SMS Server which will be executed after receiving SMS

 

Create following SCRIPT on SMS Server.

cat /temp/test.sh

#!/bin/bash
#set -x
# Syed Jahanzaib
# aacable.wordpress.com
# aacable@hotmail.com
# Version 1.3a
# Mikrotik IP Address
MT="101.11.11.255"
date=`date`

# Strip user name and card number separate oterhwise playsms will treat both variables as one
echo $1 > /tmp/user-card
USR=`cat /tmp/user-card | awk {' print $1 '}`
CARD=`cat /tmp/user-card | awk {' print $2 '}`

# Login to Mikrotik and look for User naem validity
validuser=`ssh admin@$MT :put [/tool user-manager user get value-name=actual-profile number=$USR]`
if [ -n "$validuser" ]; then

# If found, then print it with profile name, if account is expired profile name will not be printed
# Send return sms with username and its profile (if valid)
echo -e "User name - $USR - found with profile reported by Mikrotik = $validuser"

# Now Find EXACT match of card number
grep -Fx -r1 $CARD /temp/*.txt -q
              if [ $? -eq 0 ]; then
#If valid card number is found then record it in tmp file
grep -q -rl  $CARD /temp/*.txt  | sed 's/\///g' | sed 's/temp//g' |sed 's/\.//g' | sed 's/txt//g'

# TEST ZAIB
grep -rl  $CARD /temp/*.txt > /tmp/pkg
grep -rl $CARD /temp/*.txt | sed 's/\///g' | sed 's/temp//g' |sed 's/\.//g' | sed 's/txt//g' > /tmp/crd

VAR1=`cat /tmp/crd`
# Send return sms with Scratc card package
echo "Scratch CODE is valid & found in $VAR1 Package. "

# ssh to Mikrotik and activate the profile matched with the card number
ssh admin@$MT :put [/tool user-manager user create-and-activate-profile user=$USR customer=admin profile=$VAR1]

# Add comments in User COMMENTS section in user man
ssh admin@$MT :put [/tool user-manager user set comment="$USR_RENWED_BY_CARD_NUMBER_$VAR1" customer=admin numbers=zaib]

# Print Log entry
ssh admin@$MT /log warning \"$USR account have been renewed by scratch code $CARD at $date \"

# Also send following msg in return SMS to user
echo "Your Account have been Renewed on $date"
PKG=`cat /tmp/pkg`
sed -i "s/\<$CARD\>/This card is used by user id - $USR - and card number is USED_$CARD on $date/ig" /$PKG
#sed -i "s/\<$CARD\>/User $USR have used this card number_$CARD/ig" /$PKG

#Otherwise print errors if user name or card name not found
               else
                        /bin/echo "Invalid CARD Name!"
                fi
        else
                /bin/echo "Invalid User Name!"
        fi

 


 

TESTING ….

Send an sms to the server with following code

ren zaib 123

As soon the server will receive the SMS with the word REN, it will start act as following …

playSMS LOG [focus on sms__command # command_output:]

127.0.0.1 localhost 2015-05-20 01:01:14 PIDx- L2 kannel__call # start load:/var/www/playsms/plugin/gateway/kannel/geturl.php
127.0.0.1 localhost 2015-05-20 01:01:14 PIDx- L3 kannel__incoming # addr:127.0.0.1 host:localhost t:2015-05-20 05:01:11 q:+923333021909 a:ren zaib 123 Q:13013 smsc:[]
127.0.0.1 localhost 2015-05-20 01:01:14 PIDx- L3 recvsms # isrecvsmsd:1 dt:2015-05-20 05:01:11 sender:+923333021909 m:ren zaib 123 receiver:13013 smsc:
127.0.0.1 localhost 2015-05-20 01:01:14 PIDx- L2 kannel__call # end load geturl
- - 2015-05-20 01:01:14 PIDxxxadmin L3 recvsmsd # id:48 dt:2015-05-20 05:01:11 sender:+923333021909 m:ren zaib 123 receiver:13013 smsc:
- - 2015-05-20 01:01:14 PIDxxxadmin L3 setsmsincomingaction # dt:2015-05-20 05:01:11 sender:+923333021909 m:ren zaib 123 receiver:13013 smsc:
- - 2015-05-20 01:01:14 PIDxxxadmin L3 sms__command # command_exec:/var/lib/playsms/sms_command/1/test.sh 'zaib 123'
- - 2015-05-20 01:01:15 PIDxxxadmin L3 sms__command # command_output:User name - zaib 123 - found with profile reported by Mikrotik = 1mb  Scratch CODE is valid & found in 1mb Package.        Your Account have been Renewed
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms # start uid:1 sender_id:[1234] smsc:[]
- - 2015-05-20 01:01:15 PIDxxxadmin L3 sendsms # maxlen:1676 footerlen:7 footer:[ @admin] msglen:149 message:[User name - zaib 123 - found with profile reported by Mikrotik = 1mb Scratch CODE is valid & found in 1mb Package.     Your Account have been Renewed]
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms_queue_create # saving queue_code:fcedd9f9cb128b1baed4b015d660a35b src:1234 scheduled:2015-05-20 01:01:15
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms_queue_create # saved queue_code:fcedd9f9cb128b1baed4b015d660a35b id:40
- - 2015-05-20 01:01:15 PIDxxxadmin L3 sendsms_manipulate_prefix # before prefix manipulation:[+923333021909]
- - 2015-05-20 01:01:15 PIDxxxadmin L3 sendsms_manipulate_prefix # after prefix manipulation:[+923333021909]
- - 2015-05-20 01:01:15 PIDxxxadmin L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-20 01:01:15 PIDxxxadmin L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:156 unicode:0 to:+923333021909 enable_credit_unicode:0 count:1 rate:1 charge:1
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms # dst:1 sms_count:1 total_charges:1
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms_queue_push # saving queue_code:fcedd9f9cb128b1baed4b015d660a35b dst:+923333021909
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms_queue_push # saved queue_code:fcedd9f9cb128b1baed4b015d660a35b smslog_id:40
- - 2015-05-20 01:01:15 PIDxxxadmin L2 sendsms # end queue_code:fcedd9f9cb128b1baed4b015d660a35b queue_count:1 sms_count:1 failed_queue:0 failed_sms:0
- - 2015-05-20 01:01:15 PIDxxxadmin L3 setsmsincomingaction # feature:sms_command datetime:2015-05-20 05:01:11 sender:+923333021909 receiver:13013 keyword:REN message:zaib 123 raw:ren zaib 123 smsc:
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsmsd # start processing queue_code:fcedd9f9cb128b1baed4b015d660a35b sms_count:1 scheduled:2015-05-20 01:01:15 uid:1 gpid:0 sender_id:1234
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsmsd # sending queue_code:fcedd9f9cb128b1baed4b015d660a35b smslog_id:40 to:+923333021909 sms_count:1 counter:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 sendsms_intercept # msgtemplate modified sms_sender:[1234] sms_footer:[@admin] sms_to:[+923333021909] sms_msg:[User name - zaib 123 - found with profile reported by Mikrotik = 1mb Scratch CODE is valid & found in 1mb Package.     Your Account have been Renewed] uid:[1] gpid:[0] sms_type:[text] unicode:[0] queue_code:[fcedd9f9cb128b1baed4b015d660a35b] smsc:[]
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 outgoing_hook_sendsms_intercept # no SMSC found uid:1 parent_uid:0 from:1234 to:+923333021909
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsms_process # start
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:156 unicode:0 to:+923333021909 enable_credit_unicode:0 count:1 rate:1 charge:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 simplerate__cansend # allowed user uid:1 sms_to:+923333021909 credit:111111083.000 count:1 rate:1 charge:1 balance:111111082
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsms # saving smslog_id:40 u:1 g:0 gw:kannel smsc:kannel s:1234 d:+923333021909 type:text unicode:0 status:0
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsms_process # saved smslog_id:40 id:40
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 sendsms # final smslog_id:40 gw:kannel smsc:kannel message:User name - zaib 123 - found with profile reported by Mikrotik = 1mb Scratch CODE is valid & found in 1mb Package.     Your Account have been Renewed @admin len:156
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 kannel_hook_sendsms # enter smsc:kannel smslog_id:40 uid:1 to:+923333021909
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 kannel_hook_sendsms # URL: http://localhost:13013/cgi-bin/sendsms?username=kannel&password=kannel&from=1234&to=%2B923333021909&dlr-mask=31&dlr-url=http%3A%2F%2F101.11.11.241%2Fplaysms%2Findex.php%3Fapp%3Dcall%26cat%3Dgateway%26plugin%3Dkannel%26access%3Ddlr%26type%3D%25d%26smslog_id%3D40%26uid%3D1&account=admin&text=User+name+-+zaib+123+-+found+with+profile+reported+by+Mikrotik+%3D+1mb%0AScratch+CODE+is+valid+%26+found+in+1mb+Package.+%0A%0A%0A%0AYour+Account+have+been+Renewed+%40admin
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 kannel__outgoing # smslog_id:40 response:0: Accepted for delivery
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 dlr # isdlrd:1 smslog_id:40 p_status:0 uid:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 kannel__outgoing # end smslog_id:40 p_status:0
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 simplerate__deduct # enter smslog_id:40
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate_hook_rate_getbyprefix # rate not found to:+923333021909 default_rate:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:156 unicode:0 to:+923333021909 enable_credit_unicode:0 count:1 rate:1 charge:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 credit_hook_rate_setusercredit # saving uid:1 balance:111111082
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 credit_hook_rate_setusercredit # saved uid:1 balance:111111082
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 simplerate__deduct # user uid:1 parent_uid: smslog_id:40 msglen:156 count:1 rate:1 charge:1 credit:111111083.000 balance:111111082
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 simplebilling__post # saving smslog_id:40 rate:1 credit:111111083.000 count:1 charge:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 simplebilling__post # saved smslog_id:40 id:40
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate__deduct # deduct successful uid:1 parent_uid: smslog_id:40
- - 2015-05-20 01:01:16 PID555c151c1efaa - L3 simplerate__deduct # credit_lowest_limit:0 balance:111111082 charge:1
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsms_process # end
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsmsd # result queue_code:fcedd9f9cb128b1baed4b015d660a35b to:+923333021909 flag:1 smslog_id:40
- - 2015-05-20 01:01:16 PID555c151c1efaa - L2 sendsmsd # finish processing queue_code:fcedd9f9cb128b1baed4b015d660a35b uid:1 sender_id:1234 sms_count:1
- - 2015-05-20 01:01:17 PID555c0676a6be6 - L3 dlrd # id:40 smslog_id:40 p_status:0 uid:1
101.11.11.241 101.11.11.241 2015-05-20 01:01:22 PID555c15225bf5f - L2 kannel__call # start load:/var/www/playsms/plugin/gateway/kannel/dlr.php
101.11.11.241 101.11.11.241 2015-05-20 01:01:22 PID555c15225bf5f - L2 kannel__dlr # exit remote_addr:101.11.11.241 remote_host:101.11.11.241 bearerbox_host:localhost


Mikrotik LOG

& at Mikrotik LOG, You will see following

 

mtlog


 

 

SMS Reply Sent To The User …

and user will be replied with successful message
As showed in the image below …

mt - code found


 

Task # 2

 

  • 2- Reboot Linux or mikrotik server by sending sms with protection code (password)

 

 

Following script will reboot Linux server upon receiving SMS with protection code (password) adn this password must match with the /temp/password.txt content.


root@zaib:/var/lib/playsms/sms_command/1# cat radreboot.sh

#!/bin/bash
# Script to reboot with password protection matching with local
# By Syed Jahanzaib / aacable @ hotmail.com
# https://aacable.wordpress.com

# Local File which contain reboot password / CODE to be matched with sms parameter
LOCALPASS="localpass.txt"

# If no reboot code is supplied then Echo error and exit
if [ $1 = ]
   then
echo "No reboot code is supplied. Quitting Now !"
else

# Search for Password in /temp/password.txt and match it with supplied code from the SMS
grep -Fx -r1 $1 /temp/$LOCALPASS -q
              if [ $? -eq 0 ]; then

echo -e "Reboot code OK. This machine will reboot after 1 minute."

# REBOOT THIS MACHINE AFTER 1 Minute so that playSMS will get enough time to reply back the Ok response to the sender
echo /var/lib/playsms/sms_command/1/reboot1min.sh | at now + 1 min
exit

# Else print INVALID CODE if not matched
else
echo -e "ERROR: Invalid code for reboot!"
fi
fi

NOTE:

Don’t forget to create /temp/localpass.txt as showed below

root@zaib:/var/lib/playsms/sms_command/1# cat /temp/local pass.txt

12345

ALSO make sure you create following script as well which will be executed after one minute which will restart this server
root@zaib:/var/lib/playsms/sms_command/1# cat reboot1min.sh

shutdown -r now

Now create COMMAND from the playSMS menu.

As showed in the image below …

radreboot

Now send sms as following

reboot 12345

 As showed in the image below …

Screenshot_2015-05-24-16-37-08


 

I will add more details  later …

Regard’s
Syed Jahanzaib

May 8, 2015

Fun With SMS Management System [playSMS]

Filed under: Linux Related — Tags: , , , , , , , — Syed Jahanzaib / Pinochio~:) @ 4:26 PM

This post is a drafted version, You may miss many details in it. I will sanitize it and add more details with CHANGE-LOG later …

1


 

 

Recently I installed playsms at a network [where Radius manager along with Kannel was already configured to send sms notificatiosn to subscribers] and after seeing playSMS  amazing features , I thought to share some basics of it.

I found that many guides available on the internet for installing playSMS are either for older versions or with much manual methods which can be sometimes confusing for the beginners, therefore I decided to write an easier version of installation guide of playSMS.

 

kick

 

So what is playSMS ?

playSMS_logo_full

playSMS is a Free and Open Source web base SMS management software. designed by Mr. Anton Raharja at http://playsms.org.

Its main job is to handle outgoing and incoming SMS, single or bulk SMS. You can call it ‘SMS Gateway’ . A flexible Web-based mobile portal system that it can be made to fit to various services such as an SMS gateway, bulk SMS provider, personal messaging system, corporate and group communication tools

Since its open-source application therefore you can adjust it to suite your need, modify it as per your requirements and it can fit with other gateways as well like Kannel (which I have used in radius box). It can receive sms and act accordingly, you can create POLL, Quiz, subscription to any list/package via SMS. SMS 2 Email, Refresh user account via sms using scratch card like wi-tribe or some other ISP’s offers, or mobile companies like send sms to specific number with the specific text and scratch number, inquire system detail , execute specific command, etc etc.

Feature Highlights of playSMS [from official site]

  • Multiple database engine supported (through PHP PEAR DB)
  • Send SMS to single mobile phone
  • Send SMS broadcasted to a group of mobile phones, or SMS bulk
  • Support sending text, flash and unicode messages
  • Capable of handling large amount of SMS (user reported 500k SMS monthly)
  • Receive private SMS to Inbox and forward it to email (mobile2web) and user’s mobile phone
  • Forward single SMS from mobile to a group of mobile phones
  • Provides SMS to email and email to SMS by polling mailbox
  • SMS autoreply, for easy autoreplying formatted incoming SMS
  • SMS board, forward received SMS to email, export output in JSON and a few other formats
  • SMS command, execute server side shell script using SMS
  • SMS custom, forward incoming SMS to custom apps, locally or hosted on external URL
  • SMS poll, manage polling system using SMS, export output in graph, JSON and other formats
  • SMS quiz, serve quizzes on SMS
  • SMS subscribe, manage user subscribes to a service using SMS
  • SMS sync to utilize SMSSync app from http://smssync.ushahidi.com
  • Create your own features, tools, themes and gateway modules as a plugin
  • Supports Gammu, Gnokii, Kannel, SMS Server Tools, Msgtoolbox, Uplink, Nexmo, Twilio, Infobip and Clickatell
  • Supports multiple active SMSC
  • Supports simulation gateway for testing incoming and outgoing SMS
  • Route outgoing SMS by prefix
  • Route outgoing SMS per user
  • Webservices for sending SMS, retrieving delivery reports, checking credits and more
  • Long SMS support, length of text is configurable
  • Rate SMS by destination prefix
  • SMS credit system per user
  • Multiple SMSC activated and rout-able
  • Timezone settings
  • Multi-language user interface (English, French, Bahasa Indonesia, Russian and a few others)
  • Easily add new language for user interface
  • Web-based interface
  • Android client app

I used playSMS in conjunction with Kannel. So you should configure Kannel first and make sure you can send sms via kannel. You can follow my guide to install KANNEL first.

https://aacable.wordpress.com/2012/11/26/howto-configure-your-local-http-gateway-using-kannel-on-ubuntu/

 


Since its a long post with various section, I will update various section accordingly.

Sections:

 

  1. Hardware / Software used for this guide
  2. Kannel.Conf Sample for playSMS
  3. playSMS Install Instructions for Ubuntu OS
  4. Configuration of playSMS via admin panel
  5. Configure GATEWAY section to enable playsms send/receive sms
  6. Sending Test Message
  7. TROUBLESHOOTING VIA  LOGS
  8. Creating User Account with CREDITS base system, and send / receive in User Inbox / a type of SMS PABX :D
  9. Creating COMMAND to be executed via SMS
  10. Creating SMS base POLL system
  11. Scheduling SMS to be send at specific time to person or group   [added on 11th May, 2014]
  12. Add SMS base QUIZ System    [added on 11th May, 2014]

 

1- Hardware / Software used for this guide

  • OS = Ubuntu 12.04.5 LTS , 32bit
  • Hardware = Teltonika Modem USB/E12 UM1400 [This is best modem I have ever used, very stable :) but you can use any cheaper model too like Dlink DWM-156 I have also used, but sometimes I have to simply restart it or sometimes it gives unpredictable results

 

 

2- Kannel.Conf Sample for playSMS

As I mentioned in the beginning, I used KANNEL as gateway for playSMS, so you should configure KANNEL first and make sure you can send sms with it. Once successful, then you can add/replace following SMS_SERVICE section in /etc/kannel.conf to make playSMS handle the received SMS.

/etc/kannel/kannel.conf , modify only SMS-SERVICE section

group = sms-service
keyword = default
get-url = "http://localhost/playsms/index.php?app=call&cat=gateway&plugin=kannel&access=geturl&t=%t&q=%q&a=%a&Q=%Q"
accept-x-kannel-headers = true
max-messages = 1000
concatenation = true
catch-all = true
text = "Galaxy ROBOT by Zaib"
omit-empty = true

 

 

3- PLAYSMS [ver 1.0-rc9] Install Instructions for UBUNTU OS.

As usual first update Ubuntu , then install require packages.

apt-get update

apt-get install apache2 mysql-server php5 php5-cli php5-mysql php5-cgi php-pear php-gettext libapache2-mod-php5 apache2-mpm-prefork php-db make gcc lynx wget curl

Now you need to create MYSQL database for playsms. You can create it either via login to your mysql console , or issue direct command to create it as showed in the example below …

mysql -u root -pROOTPASS -e "create database playsms";
mysql -u root -pROOTPASS -e "grant usage on *.* to playsms@localhost identified by 'playsms';"

Change credentials as required.


 

Installing playSMS …

First download the playsms package, and unrar it

mkdir /temp
cd /temp
wget https://github.com/antonraharja/playSMS/archive/1.0-rc9.tar.gz
ls
tar zxvf 1.0-rc9.tar.gz
cd playSMS-1.0-rc9/
cp install.conf.dist install.conf

Now edit install.conf and change the info as required, like db name, mysql id password. The installer script uses this file to pick values and install the package accordingly. So make sure all directives are defined properly before firing up the actuall installation script.
Also make sure you change the PATH to match your linux distribution, like in ubuntu the path of www is /var/www

1

Once you done editing info, press b to continue & it will continue to install the playsms.

once all done verify that you can see the playsms in process

root@radius:/temp/playSMS-1.0-rc9# ps aux |grep playsms
root      4568  0.6  0.3  51032 15844 pts/1    S    10:58   0:26 /usr/bin/php -q /usr/local/bin/playsmsd schedule
root      4570  0.7  0.3  51032 15876 pts/1    S    10:58   0:30 /usr/bin/php -q /usr/local/bin/playsmsd dlrssmsd
root      4572  0.6  0.3  51816 16496 pts/1    S    10:58   0:27 /usr/bin/php -q /usr/local/bin/playsmsd recvsmsd
root      4574  0.5  0.3  51032 15412 pts/1    S    10:58   0:23 /usr/bin/php -q /usr/local/bin/playsmsd sendsmsd
root     20560  0.0  0.0   4388   824 pts/0    S+   12:06   0:00 grep --color=auto playsms

root@radius:/temp/playSMS-1.0-rc9#

If you see playSMS running, basic installation part is done, now moving to Configuration part…


 

4- Configuration of playSMS via admin panel …

Now login to playSMS web admin panel by

http://yourip/smsplay

Use default id password which is

id = admin
password = admin

2


5- Configure GATEWAY section to enable playsms send/receive sms

After successful login we have to first configure GATEWAY pointing to KANNEL to send receive sms using kannel as our main gateway. You can skip kannel or use other gateway too depend on your choice, but since I was already using kannel because of Radius Manager, so I simply used it because of its versatility and highly customization.

Goto Settings / Manage gateway and SMSC
As showed in the image below …

3


 

Now in the List of gateways, click on edit button (wheel) next to KANNEL.
As showed in the image below …

4

Now at Manage Kannel window adjust the parameters according to your old kannel configuration. pay attention to username password & proper ports.
As showed in the image below …

5Now save it.

 

Open Manage Gateway page again and click on + sign to add KANNEL as your gw.
As showed in the image below …

6


 

 

Now goto Settings / Main Configuration and select KANNEL as your Default SMSC
As showed in the image below …

7Save it.


 

6- SENDING TEST MESSAGE

Ok its time to hit the road.  for some test.

Goto My account / Compose Message and send msg to any number.
As showed in the image below …

8

and you should receive it on your handset.
As showed in the image below …

9


7- TROUBLESHOOTING VIA  LOGS

You can inspect logs in following folders (for playSMS)

tail -f /var/log/playsms/playsms.log

Successful sms sent result should be something like this

YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms # start uid:1 sender_id:[1234] smsc:[]
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L3 sendsms # maxlen:459 footerlen:7 footer:[ @admin] msglen:57 message:[test msg from zaib to mobile using playsms with kannel :)]
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms_queue_create # saving queue_code:8cf227742d7d5dab570f7ed4532cf936 src:1234 scheduled:2015-05-08 12:28:32
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms_queue_create # saved queue_code:8cf227742d7d5dab570f7ed4532cf936 id:14
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L3 sendsms_manipulate_prefix # before prefix manipulation:[03333021909]
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L3 sendsms_manipulate_prefix # after prefix manipulation:[03333021909]
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:0
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:64 unicode:0 to:03333021909 enable_credit_unicode:0 count:1 rate: charge:0
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms # dst:1 sms_count:1 total_charges:0
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms_queue_push # saving queue_code:8cf227742d7d5dab570f7ed4532cf936 dst:03333021909
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms_queue_push # saved queue_code:8cf227742d7d5dab570f7ed4532cf936 smslog_id:14
YOUR_IP YOUR_IP 2015-05-08 12:28:32 PID554c659fcb40d admin L2 sendsms # end queue_code:8cf227742d7d5dab570f7ed4532cf936 queue_count:1 sms_count:1 failed_queue:0 failed_sms:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsmsd # start processing queue_code:8cf227742d7d5dab570f7ed4532cf936 sms_count:1 scheduled:2015-05-08 12:28:32 uid:1 gpid:0 sender_id:1234
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsmsd # sending queue_code:8cf227742d7d5dab570f7ed4532cf936 smslog_id:14 to:03333021909 sms_count:1 counter:1
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 sendsms_intercept # msgtemplate modified sms_sender:[1234] sms_footer:[@admin] sms_to:[03333021909] sms_msg:[test msg from zaib to mobile using playsms with kannel :)] uid:[1] gpid:[0] sms_type:[text] unicode:[0] queue_code:[8cf227742d7d5dab570f7ed4532cf936] smsc:[]
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 outgoing_hook_sendsms_intercept # no SMSC found uid:1 parent_uid:0 from:1234 to:03333021909
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsms_process # start
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:64 unicode:0 to:03333021909 enable_credit_unicode:0 count:1 rate: charge:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 simplerate__cansend # allowed user uid:1 sms_to:03333021909 credit:0.000 count:1 rate: charge:0 balance:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsms # saving smslog_id:14 u:1 g:0 gw:kannel smsc:kannel s:1234 d:03333021909 type:text unicode:0 status:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsms_process # saved smslog_id:14 id:14
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 sendsms # final smslog_id:14 gw:kannel smsc:kannel message:test msg from zaib to mobile using playsms with kannel :) @admin len:64
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 kannel_hook_sendsms # enter smsc:kannel smslog_id:14 uid:1 to:03333021909
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 kannel_hook_sendsms # URL: http://localhost:13013/cgi-bin/sendsms?username=kannel&password=KANNELPASSWORD&from=1234&to=03333021909&dlr-mask=31&dlr-url=http%3A%2F%2Fclick.onmypc.net%3A1235%2Fplaysms%2Findex.php%3Fapp%3Dcall%26cat%3Dgateway%26plugin%3Dkannel%26access%3Ddlr%26type%3D%25d%26smslog_id%3D14%26uid%3D1&account=admin&text=test+msg+from+zaib+to+mobile+using+playsms+with+kannel+%3A%29+%40admin
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 kannel__outgoing # smslog_id:14 response:0: Accepted for delivery
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 dlr # isdlrd:1 smslog_id:14 p_status:0 uid:1
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 kannel__outgoing # end smslog_id:14 p_status:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 simplerate__deduct # enter smslog_id:14
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:64 unicode:0 to:03333021909 enable_credit_unicode:0 count:1 rate: charge:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 credit_hook_rate_setusercredit # no changes uid:1 balance:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 simplerate__deduct # user uid:1 parent_uid: smslog_id:14 msglen:64 count:1 rate: charge:0 credit:0.000 balance:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 simplebilling__post # saving smslog_id:14 rate: credit:0.000 count:1 charge:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 simplebilling__post # saved smslog_id:14 id:14
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate__deduct # deduct successful uid:1 parent_uid: smslog_id:14
- - 2015-05-08 12:28:32 PID554c65a055703 - L3 simplerate__deduct # credit_lowest_limit:0 balance:0 charge:0
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsms_process # end
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsmsd # result queue_code:8cf227742d7d5dab570f7ed4532cf936 to:03333021909 flag:1 smslog_id:14
- - 2015-05-08 12:28:32 PID554c507a0ec86 - L3 dlrd # id:14 smslog_id:14 p_status:0 uid:1
- - 2015-05-08 12:28:32 PID554c65a055703 - L2 sendsmsd # finish processing queue_code:8cf227742d7d5dab570f7ed4532cf936 uid:1 sender_id:1234 sms_count:1

[Be aware that I used Log Level 3 [debug mode to get more info] which is configurable in /var/www/playsms/config.php ]


 

8- Creating User Account with CREDITS base system, and send / receive in User Inbox / a type of SMS PABX :D

Using playSMS, we can create user accounts and add credits in it, so when user sends sms, balance would deduct from his account automatically , and once his balance finishes, he wont be able to send sms. User will be assigned with an ID and Password, He can send SMS via web panel, also he can receive SMS (the other party must reply to or send sms with @username in his sms in order to receive it in specific user inbox).

 

Enable SMS Routing to INBOX in playSMS

  • First enable Route incoming SMS
  • Goto  Settings / Route Incoming SMS
  • Select YES in Scan incoming SMS for @username and Scan incoming SMS for #groupcode
  • and SAVE.

 

10

 

Create User Account 

Now we will create a test user account and will add credits in it too.

  • Goto Settings / Manage Account > User
  • Click on + sign to add user

Add the details as required and click on SAVE.
As showed in the image below …

11

User Account Creation Done.

ADDING CREDITS in user Account

To add credits in user account,

  • Goto Settings / Manage Credit
  • Click on + sign
  • Select User
  • Add amount and Save

24

 

 

Now logout from admin ID, or use another browser to login to playSMS panel with the newly created account and send an test sms  to any number. After sending sms, you will see that your balance will be deducted (I added 10rs as a balance, and set per sms cost 5rs, so after sending my remaining balance is 5 rs only

12

Howto receive SMS in user INBOX ?

You have to inform the sender that they have to add @username in there sms , otherwise SMS will receive in SANDBOX, not user inbox.

Example for sender format

@test Ok I have received the sms” and send it to playSMS mobile number.
As showed in the image below …

14

Now the user test can goto My Account / Inbox and there he can see the received SMS.
As showed in the image below …

13

You can also setup SMS 2 EMAIL, SMS Forwarding to USER Mobile , etc etc , Its amazing that free open source tool can provide you this much Power of FREEDOM :)

 


 

9- Creating SMS base POLL system

You can create SMS poll system in playSMS, a kind of voting system as well so user can send sms to playSMS mobile number with his choice , and his entry will be made in the poll and will be visible via web page or likewise.

For example network operator wants to know how user feel about his network services. Follow this.

Goto Features / Manage Poll

Click on Add SMS poll

Now Add details, like

15 - Add Poll

.

Now Go back to MANAGE POLL , you will see Orange box on your newly created poll, which means its not activated yet, So simply click on the orange box to make it ACTIVE.

16

After Activation you will see something like below …

17

 

Casting VOTE to POLL

Now to cast vote, send SMS (with different choices multiple time for test) from user to playSMS number.

poll 1

19

 

Now to view POLL TEST result, goto Features / Manage POLL, there you will an EYE icon next to your POLL, click on it and you will be brought to POLL details.
As showed in the image below …

21

 


 

10- Creating COMMAND to be executed via SMS

You can create COMMAND base system and can execute script on the playSMS server, and it can reply you back with the result. For example If we want to inquire the UPTIME details via SMS.

  • Goto Features / Manage Command
  • Click on ADD SMS COMMAND
  • in SMS command keyword, add the catching word which playSMS will detect and consider it as COMMAND sms, and will run the command.
  • in SMS command exec, type the name of script (example status.sh) which will be executed , Make sure your scripts are in following folder

/var/lib/playsms/sms_command/1

  • Click on Make Return as Reply
  • Click on SAVE

As showed in the image below …

22

Now at playSMS server console , goto /var/lib/playsms/sms_command/1 and create simple script like.

  • touch status.sh
  • chmod + status.sh
  • nano status.sh
  • and add following command in it

uptime

Save & exit. And also run this command to verify if its working on console fine.

Now send sms to playSMS server like

run status.sh

and you will be replied back shortly from playSMS with the uptime status.
As showed in the image below …

23- command


11- Scheduling SMS to be send at specific time to person or group

playSMS have a very good feature to schedule SMS to be sent later or specific time, like a reminder too. It’s very useful for duffers like me who have week memory :D

To schedule a message,

Goto My Account / Schedule Message
and click on Add SMS Schedule

25- schdume msg

.

26- sch msgs msg

27- sch activate

First click on MANAGE (File Icon) and add the destination number and time

add-schuedl-etime

Click on SAVE and click on BACK, MAKE SURE TO click click on STATUS button (which is by default ORANGE means disabled, click it on to make GREEN, ACTIVE, This is important.

and here you can see the activity of playSMS in logs at that specific time.


- - 2015-05-11 09:04:59 PID554f7dbb44982 - L2 schedule_hook_playsmsd # sendsms uid:1 schedule_id:1 id:1 rule:0 schedule:[2014-05-11 09:06:00] scheduled:[2015-05-11 09:04:59]
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms # start uid:1 sender_id:[1234] smsc:[]
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L3 sendsms # maxlen:452 footerlen:7 footer:[ @admin] msglen:82 message:[Wife_Birthday, Don't forget to bring Gift or You will regret it for a long time :P]
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms_queue_create # saving queue_code:f2dd9833fb12f33283b424571d58c885 src:1234 scheduled:2015-05-11 09:04:59
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms_queue_create # saved queue_code:f2dd9833fb12f33283b424571d58c885 id:35
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L3 sendsms_manipulate_prefix # before prefix manipulation:[03333021909]
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L3 sendsms_manipulate_prefix # after prefix manipulation:[03333021909]
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:5
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:89 unicode: to:03333021909 enable_credit_unicode:0 count:1 rate:5 charge:5
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms # dst:1 sms_count:1 total_charges:5
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms_queue_push # saving queue_code:f2dd9833fb12f33283b424571d58c885 dst:03333021909
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms_queue_push # saved queue_code:f2dd9833fb12f33283b424571d58c885 smslog_id:29
- - 2015-05-11 09:04:59 PID554f7dbb44982 admin L2 sendsms # end queue_code:f2dd9833fb12f33283b424571d58c885 queue_count:1 sms_count:1 failed_queue:0 failed_sms:0
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsmsd # start processing queue_code:f2dd9833fb12f33283b424571d58c885 sms_count:1 scheduled:2015-05-11 09:04:59 uid:1 gpid:0 sender_id:1234
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsmsd # sending queue_code:f2dd9833fb12f33283b424571d58c885 smslog_id:29 to:03333021909 sms_count:1 counter:1
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 sendsms_intercept # msgtemplate modified sms_sender:[1234] sms_footer:[@admin] sms_to:[03333021909] sms_msg:[Wife_Birthday, Don't forget to bring Gift or You will regret it for a long time :P] uid:[1] gpid:[0] sms_type:[text] unicode:[0] queue_code:[f2dd9833fb12f33283b424571d58c885] smsc:[]
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 outgoing_hook_sendsms_intercept # no SMSC found uid:1 parent_uid:0 from:1234 to:03333021909
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsms_process # start
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:89 unicode:0 to:03333021909 enable_credit_unicode:0 count:1 rate:5 charge:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 simplerate__cansend # allowed user uid:1 sms_to:03333021909 credit:55500.000 count:1 rate:5 charge:5 balance:55495
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsms # saving smslog_id:29 u:1 g:0 gw:kannel smsc:kannel s:1234 d:03333021909 type:text unicode:0 status:0
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsms_process # saved smslog_id:29 id:29
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 sendsms # final smslog_id:29 gw:kannel smsc:kannel message:Wife_Birthday, Don't forget to bring Gift or You will regret it for a long time :P @admin len:90
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 kannel_hook_sendsms # enter smsc:kannel smslog_id:29 uid:1 to:03333021909
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 kannel_hook_sendsms # URL: http://localhost:13013/cgi-bin/sendsms?username=kannel&password=KANNEL_PASSWORD&from=1234&to=03333021909&dlr-mask=31&dlr-url=http%3A%2F%2Fclick.onmypc.net%3A1235%2Fplaysms%2Findex.php%3Fapp%3Dcall%26cat%3Dgateway%26plugin%3Dkannel%26access%3Ddlr%26type%3D%25d%26smslog_id%3D29%26uid%3D1&account=admin&text=Wife_Birthday%2C+Don%27t+forget+to+bring+Gift+or+You+will+regret+it+for+a+long+time+%3AP+%40admin
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 kannel__outgoing # smslog_id:29 response:0: Accepted for delivery
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 dlr # isdlrd:1 smslog_id:29 p_status:0 uid:1
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 kannel__outgoing # end smslog_id:29 p_status:0
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 simplerate__deduct # enter smslog_id:29
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate_hook_rate_getbyprefix # rate not found to:03333021909 default_rate:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate_hook_rate_getcharges # uid:1 u:admin len:89 unicode:0 to:03333021909 enable_credit_unicode:0 count:1 rate:5 charge:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 credit_hook_rate_setusercredit # saving uid:1 balance:55495
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 credit_hook_rate_setusercredit # saved uid:1 balance:55495
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 simplerate__deduct # user uid:1 parent_uid: smslog_id:29 msglen:89 count:1 rate:5 charge:5 credit:55500.000 balance:55495
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 simplebilling__post # saving smslog_id:29 rate:5 credit:55500.000 count:1 charge:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 simplebilling__post # saved smslog_id:29 id:28
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate__deduct # deduct successful uid:1 parent_uid: smslog_id:29
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L3 simplerate__deduct # credit_lowest_limit:0 balance:55495 charge:5
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsms_process # end
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsmsd # result queue_code:f2dd9833fb12f33283b424571d58c885 to:03333021909 flag:1 smslog_id:29
- - 2015-05-11 09:05:00 PID55502a6c2d5bc - L2 sendsmsd # finish processing queue_code:f2dd9833fb12f33283b424571d58c885 uid:1 sender_id:1234 sms_count:1
- - 2015-05-11 09:05:00 PID554f7dbb4db5f - L3 dlrd # id:29 smslog_id:29 p_status:0 uid:1

 

 

and reminder will be sent precisely :)

wbd

 

 


12- Add SMS base QUIZ System

  1. To add QUIZ
  2. Goto Features, Manage Quiz
  3. Click on ADD SMS QUIZ, and follow screenshot.

quiz-1

Click on SAVE , and then click on BACK, again make sure you click on STATUS icon to make it active otherwise it will remain dead body.

Now send SMS with the keyword and answer like as showed in the image below …

quiz-3


 

I will write more later …

If this guide helps you in any way, don’t forget to give credit :~)

 

Regard’s
Syed Jahanzaib

April 13, 2015

Short Notes Series: Adding VPN (PPTP) Dialer in Linux

Filed under: Linux Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 12:06 PM

 

vpn-animationAssalam Va Alaykum,

Following are short notes on How I added VPN [pptp] client in Linux [initially in centos, later I will add commands for Ubuntu as well] to a mikrotik base pptp vpn server. Mikrotik is using default profile for vpn users. Something like this

Mikrotik Section:

PPP Default Profile …

mt2

 

PPP Default Profile Protocols Section …

mt-ppp-default-profile

& PPP USER …

mt-3

Ok now moving to linux to add vpn client


 

Adding PPTP VPN Client in CENTOS 6

First install PPTP client.

yum install pptp -y

Now add the username and password inside /etc/ppp/chap-secrets file

Note: I used NANO editor as its easier, but you can use any other editor like VI or other

nano /etc/ppp/chap-secrets

Now add your USER ID and PASSWORD in following scheme …

# Secrets for authentication using CHAP
# client        server           secret                 IP addresses
test              PPTP           testpass                       *

In above example, my vpn user name is test, and password is testpass.

Save & Exit.

Now create a VPN Dialer configuration file under /etc/ppp/peers directory called testvpn  using any text editor

nano /etc/ppp/peers/testvpn

and use following format


pty "pptp 1.1.1.1 --nolaunchpppd"
lock
noauth
nobsdcomp
nodeflate
name test
remotename PPTP
require-mppe-128
#file /etc/ppp/options.pptp
ipparam testvpn

In above Example. Make sure to change following items

1.1.1.1 > with your target vpn server IP address or name
name test > Replace TEST with your supplied vpn dialer user name

Save & Exit.

 


 

Test Dialer Connectivity …

To dial , use following command from terminal …

pppd call testvpn

In second terminal, open messages log file so you can see the log info (and error messages if any, useful in troubleshooting) …

tail -f /var/log/messages

Upon successful logon,  the messages log shoul show you something as following …

Apr 13 06:43:39 radius pppd[1441]: pppd 2.4.5 started by root, uid 0
Apr 13 06:43:39 radius pppd[1441]: Using interface ppp0
Apr 13 06:43:39 radius pppd[1441]: Connect: ppp0 <--> /dev/pts/2
Apr 13 06:43:39 radius pptp[1442]: anon log[main:pptp.c:314]: The synchronous pptp option is NOT activated
Apr 13 06:43:39 radius pptp[1450]: anon log[ctrlp_rep:pptp_ctrl.c:251]: Sent control packet type is 1 'Start-Control-Connection-Request'
Apr 13 06:43:39 radius pptp[1450]: anon log[ctrlp_disp:pptp_ctrl.c:739]: Received Start Control Connection Reply
Apr 13 06:43:39 radius pptp[1450]: anon log[ctrlp_disp:pptp_ctrl.c:773]: Client connection established.
Apr 13 06:43:40 radius pptp[1450]: anon log[ctrlp_rep:pptp_ctrl.c:251]: Sent control packet type is 7 'Outgoing-Call-Request'
Apr 13 06:43:40 radius pptp[1450]: anon log[ctrlp_disp:pptp_ctrl.c:858]: Received Outgoing Call Reply.
Apr 13 06:43:40 radius pptp[1450]: anon log[ctrlp_disp:pptp_ctrl.c:897]: Outgoing call established (call ID 0, peer's call ID 921).
Apr 13 06:43:40 radius pppd[1441]: CHAP authentication succeeded
Apr 13 06:43:40 radius pppd[1441]: MPPE 128-bit stateless compression enabled
Apr 13 06:43:41 radius pppd[1441]: local  IP address 172.16.0.249
Apr 13 06:43:41 radius pppd[1441]: remote IP address 172.16.0.1

 

You can also check vpn interface via

ip a | grep ppp

Result:

[root@radius ~]# ip a | grep ppp
13: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1456 qdisc pfifo_fast state UNKNOWN qlen 3
link/ppp
inet 172.16.0.249 peer 172.16.0.1/32 scope global ppp0

Try pinging a system in the VPN network and you should get response from other side :)


 

 

ADDING ROUTE via pptp dialer to access remote / target destination

Khunjerab - Pass Route / Beautiful PAKISTAN :) / zaib

Khunjerab – Pass Route / Beautiful PAKISTAN :) / zaib

 

NOTE: This will not add any ROUTE information in routing table, you can add it manually or in ifup/down file, As I didn’t required any default gateway but I added just one static route to access specific server only, example:

> Edit or create following file /etc/ppp/ip-up.local

& add following entries

#!/bin/bash
route add -net 2.0.0.0/8 dev ppp0

Now assign it executable rights
chmod +x /etc/ppp/ip-up.local

Note: change 2.0.0.0/8 to match your remote target subnet you want to access via your linux pc. This is recommended method as it works on AUTO :)

 

Or if its just for one session , use following command

route add -net 192.168.10.0 netmask 255.255.255.0 gw 172.16.0.1 dev ppp0 

192.168.10.0 is the remote office server subnet, and 172.16.0.1 is the virtual gateway this pc should use to access remote site.

Or if all traffic should route via this , use (not tested yet)

route add default gw 172.16.0.1 ppp0

Howto Stop Dialer

To Stop dialer, you can simply kill it with

killall pppd

 


 

Howto add AUTO RE-CONNECT / RE-DIAL option

Note: To make it auto re-connect (redial) you can add following directives in your vpn configuration file (example /etc/ppp/peers/testvpn) to make it auto reconnect.

maxfail 0
persist

maxfail 0 and persist is for the connection to reconnect and retry forever.

You can also use script and schedule it to keep check on the dialer connectivity and perform specific action like inform you  via email, or whatever you like it to trigger. If interested in script base approach, there is already a good guide for this purposes here :)

http://www.jamescoyle.net/how-to/968-script-to-automatically-detect-and-restart-linux-pptp-client


 


.

Regard’s
Syed Jahanzaib

April 1, 2015

Howto display combined values of two interfaces in single MRTG graph

Filed under: Linux Related, Mikrotik Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 9:16 AM

mrtgmrtg-for-combo-wan

 


 

 

If you want to view combined value for two or more interfaces in single mrtg graph, here is the simple way to go…
[thanks to MRTG which supports simple math formulas as well :)  ]

Example:

On your router you have two wan interfaces (You’re not limited to just two) with the names of WAN1 and WAN2 (in load balancing mode or whatever) and you want to display single graph which should displays combined value for both interfaces so that you can have an idea how much WAN bandwidth is consuming (good to make average historical based graphs) , use following cfg

 


# combinedwan.cfg
Target[192.168.0.1_combowan]: #WAN1:publicsnmp@192.168.0.1: + #WAN2:publicsnmp@192.168.0.1:
MaxBytes[192.168.0.1_combowan]: 12500000
Title[192.168.0.1_combowan]: Traffic Analysis for BOTH DSL WAN Links WAN1+WAN2 -- MikroTik
PageTop[192.168.0.1_combowan]: <h1>Traffic Analysis for BOTH DSL WAN Links WAN1+WAN2  -- MikroTik</h1>
<div id="sysdetails">
<table>
<tr>
<td>System:</td>
<td>MikroTik Routerboard with Load Balacning</td>
</tr>
<tr>
<td>Maintainer:</td>
<td>aacable@hotmail.com</td>
</tr>
<tr>
<td>Description:</td>
<td>WAN1 + WAN2 Combined</td>
</tr>
<tr>
<td>ifType:</td>
<td>ethernetCsmacd (6)</td>
</tr>
<tr>
<td>ifName:</td>
<td>WAN1+WAN2</td>
</tr>
<tr>
<td>Max Speed:</td>
<td>100 Mbits/s</td>
</tr>
<tr>
<td>Ip: DYNAMIC</td>
<td>No Ip (No DNS name)</td>
</tr>
</table>
</div>

 


 

Note: Change the Interfaces names, SNMP string and IP according to your network setup. You can get interface numbers/names from the individual mrtg.cfg / router.cfg entries. cfgmaker can help you in this regard example

cfgmaker snmp@192.168.0.1 > router.cfg

 

Happy Graphing :)

Regard’s

Syed Jahanzaib

 

March 30, 2015

Playing with the Mikrotik’s PCC

Filed under: Mikrotik Related — Tags: — Syed Jahanzaib / Pinochio~:) @ 1:30 PM

GT_50mbx2


dual-wan-pcclb


Following post is an reference guide or scrapbook, which have working codes for following.

  1. Dual WAN PCC with 2 DSL modems [configured in bridge mode] and dialing is done via mikrotik
  2. Port forwarding various ports [as required] from the internet to local web server
  3. PPPoE Server

Note: I ahve used SOURCE BASE classifier in this example, to avoid common load balancing problems like https links breakup, buffering issues stuck problem etc etc : )

Just to remind this is not a copy paste version. its not complete export version. I modified the data for reference. Read them carefully for better understanding. You can pick any section of your choice or as required. I will add more sections later …


NETWORK DETAiLS :

Mikrotik LAN Interface name = Local
Mikrotik WAN 1 interface name = WAN1
Mikrotik WAN 2 interface name = WAN2

Mikrotik LAN IP Address = 192.168.0.1
WEB Server on LAN side = 192.168.0.10

Mikrotik IP POOL for LAN DHCP = 10.0.0.1/8
Mikrotik IP POOL for PPPoE Users = 172.16.0.0/16

Let’s Start ….

kick




# Syed Jahanzaib / aacable@hotmail.com
# https://aacable.wordpress.com
# Adding IP pool for dhcp and pppoe

/ip pool
add name=pppoe-pool ranges=172.16.0.1-172.16.1.255
add name=dhcp_pool ranges=10.0.0.1-10.0.0.255

# ADD dhcp server

/ip dhcp-server
add address-pool=dhcp_pool authoritative=after-2sec-delay bootp-support=static disabled=no interface=Local lease-time=6h name="ZAIB DHCP SERVER"
/ip dhcp-server config
set store-leases-disk=5m
/ip dhcp-server network
add address=10.0.0.0/8 comment="zaib DHCP SERVER" dhcp-option="" dns-server=192.168.0.1,8.8.8.8 gateway="" ntp-server="" wins-server=""

# Adding dsl pppoe client connections, make sure your dsl modems are in bridge mode.

/interface pppoe-client
add ac-name="" add-default-route=yes allow=pap,chap,mschap1,mschap2 dial-on-demand=no disabled=no interface=WAN1 max-mru=1480 max-mtu=1480 mrru=disabled name=pppoe-out1 password=ISP_DSL_PASSWORD profile=default \
service-name="" use-peer-dns=no user=ISP_DSL_USERNAME
add ac-name="" add-default-route=yes allow=pap,chap,mschap1,mschap2 dial-on-demand=no disabled=no interface=WAN2 max-mru=1480 max-mtu=1480 mrru=disabled name=pppoe-out2 password=ISP_DSL_PASSWORD profile=default \
service-name="" use-peer-dns=no user=ISP_DSL_USERNAME

# Adding PPPoE Default Profile

/ppp profile
add change-tcp-mss=default dns-server=192.168.0.1,8.8.8.8 local-address=192.168.0.1 name=pppoe-profile only-one=yes rate-limit=512k/512k remote-address=pppoe-pool use-compression=default use-encryption=no \
use-mpls=default use-vj-compression=default

# Adding PPPOE Server
/interface pppoe-server server
add authentication=pap default-profile=pppoe-profile disabled=no interface=Local keepalive-timeout=10 max-mru=1480 max-mtu=1480 max-sessions=0 mrru=disabled one-session-per-host=no service-name=service1

# Create address list and add your users pppoe pool and web server ip addresses in this list, later we will use this list as ACL to allow specific users internet access
/ip firewall address-list
add address=172.16.0.1-172.16.1.255 comment="Allowed Users to Use Internet" disabled=no list="allowed users"
add address=192.168.0.10 comment="Allowed Users to Use Internet" disabled=no list="allowed users"

# Now start Mangling /ip firewall mangle

############################################ &gt; Zaib
#  PORT FORWARDING RELATED MANGLE SECTION STARTS
############################################

# This section is related to packet marking for Marking connections/packets arrived at WAN1 link
add action=mark-connection chain=input comment="Mark Connection - IN wan1,OUT wan1 Syed.Jahanzaib" disabled=no in-interface=pppoe-out1 new-connection-mark=pppoe_out1_conn passthrough=yes
add action=mark-routing chain=output comment="Mark Routing - IN wan1,OUT wan1" connection-mark=pppoe_out1_conn disabled=no new-routing-mark=pppoe_out1_traffic passthrough=no

# This section is related to packet marking for Marking connections/packets arrived at WAN2 link
add action=mark-connection chain=input comment="Mark Connection - IN wan2, OUT wan2" disabled=no in-interface=pppoe-out2 new-connection-mark=pppoe_out2_conn passthrough=yes
add action=mark-routing chain=output comment="Mark Routing -  IN wan2,OUT wan2" connection-mark=pppoe_out2_conn disabled=no new-routing-mark=pppoe_out2_traffic passthrough=no

add action=mark-connection chain=forward comment="Mark Connection for new conn - Packet Forward wan1, out wan1" connection-state=new disabled=no in-interface=pppoe-out1 new-connection-mark=pppoe_out1_pfw \
passthrough=no
add action=mark-routing chain=prerouting comment="Mark Packets for new conn - Packet Forward wan1, out wan1" connection-mark=pppoe_out1_pfw disabled=no in-interface=Local new-routing-mark=\
pppoe_out1_traffic passthrough=no

add action=mark-connection chain=forward comment="Mark Connection for new conn - Packet Forward  wan2, out wan2" connection-state=new disabled=no in-interface=pppoe-out2 new-connection-mark=pppoe_out2_pfw \
passthrough=no
add action=mark-routing chain=prerouting comment="Mark Routing for new conn - Packet Forward  wan2, out wan2" connection-mark=pppoe_out2_pfw disabled=no in-interface=Local new-routing-mark=\
pppoe_out2_traffic passthrough=no

########################
#  GENERAL PCC SECTION
########################

# This section is related to packet marking for general PCC
add action=accept chain=prerouting disabled=no in-interface=pppoe-out1
add action=accept chain=prerouting disabled=no in-interface=pppoe-out2

# Classifier for dual WAN links
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=src-address:2/0 src-address-list="allowed users"
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=src-address:2/1 src-address-list="allowed users"

add action=mark-routing chain=prerouting connection-mark=wan1_conn disabled=no new-routing-mark=to_wan1 passthrough=yes src-address-list="allowed users"
add action=mark-routing chain=prerouting connection-mark=wan2_conn disabled=no new-routing-mark=to_wan2 passthrough=yes src-address-list="allowed users"

##########################################################
#  NAT / DST-NAT / MASQUERADE SECTION / PORT FORWARD
##########################################################

/ip firewall nat

###  Route WEB Port from wan links to local web server IP/PORT
add action=dst-nat chain=dstnat comment="Route WEB Server Port 80 from INTERNET LINK1" disabled=no dst-port=80 in-interface=pppoe-out1 protocol=tcp to-addresses=192.168.0.10 to-ports=80
add action=dst-nat chain=dstnat comment="Route WEB Server Port 80 from INTERNET LINK2" disabled=no dst-port=80 in-interface=pppoe-out2 protocol=tcp to-addresses=192.168.0.10 to-ports=80

### Allow internet access/masquerade to allowed users list only (ACL)
add action=masquerade chain=srcnat disabled=no out-interface=pppoe-out1 src-address-list="allowed users"
add action=masquerade chain=srcnat disabled=no out-interface=pppoe-out2 src-address-list="allowed users"

##################################################
#  ROUTE SECTION FOR PCC AND PORT FORWARD PACKETS
##################################################
# Add routes for general PCC
/ip route
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=to_wan1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=2 dst-address=0.0.0.0/0 gateway=pppoe-out2 routing-mark=to_wan2 scope=30 target-scope=10

# Add routes for IN/OUT port forwarding packets
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=pppoe_out1_traffic scope=30 target-scope=10
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out2 routing-mark=pppoe_out2_traffic scope=30 target-scope=10

Regard’s
Syed Jahanzaib

March 16, 2015

Windows 7 WEATHER GADGET ‘not working’ workaround!

Filed under: Microsoft Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 12:40 PM

UPDATE: May, 2015

The method defined in this post is now not working any more. [at the beginning it was working but not anymore] , I will see if alternate methods may work and will update this post in coming week, to see if its working … Insha Allah,  

 


 

 

From past few days, clients reported that Weather gadget stopped working with error “cannot connect to service …

gadgets-not-working

 


 

 

 

After doing some googling, it was revealed that dueto some security concerns Microsoft have discontinued it.  BUT  you can still Enable by following simple steps.

  1. Go to “C:\Users\USERNAME\AppData\Local\Microsoft\Windows Live\Services\Cache”
  2. Edit “Config.xml” by Right Click / EDIT
  3. Now donot change any thing & simply save it (CTRL+S or FILE -> Save) [without doing any modification]
  4. After 1-2 MINUTES, Restart the Gadget!

 

 

It will work Insha Allah !!!!

 

gadgets-working


 

 

Regard’s
Syed Jahanzaib

March 10, 2015

Extending Linux Partition in VMWARE ESXI

Filed under: Linux Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 4:36 PM

Reference Guide to extend partition size in Linux hosted on vmware

TASK: Linux (Centos) is hosted in Vmware  , Current size of disk is 10 GB, and we want to expand it to 15 GB.

First turn off the guess linux OS. and take its properties and extend the disk as showed in the image below…

 

1

2

Click on EXPAND and it will take some time to complete the operation …

.

once its completed, power ON the guest Linux.


 

 

Add a new partition with the free space of the virtual disk.

fdisk  /dev/sda

press n            < To add new partition
press p            < Select type PRIMARY
press 3            < Type number for new part…
(when it will ask for sectors numbers/values, pres Enter twice for default values)
press t            < To change partition type value
press 3           < Select partition number
press 8e         < Type 8e
press w          <type ‘w’ to write changes to disk

at end you will see following message…

The partition table has been altered!

As showed in the image below …

fdisk-gui

REBOOT THE GUEST OS NOW …

reboot


 

after reboot completes, Now, create a new physical volume from the new partition, issue following command two times

pvcreate /dev/sda3
pvcreate /dev/sda3

  Physical volume "/dev/sda3" successfully created

 

 

Then extend the existing volume group, you may want to use vgdisplay to list and identify the volume groups you have.

vgdisplay

vgdisplay
--- Volume group ---
VG Name               vg_radius
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               9.51 GiB
PE Size               4.00 MiB
Total PE              2434
Alloc PE / Size       2434 / 9.51 GiB
Free  PE / Size       0 / 0
VG UUID               MzawqN-X33a-e5AY-QxE4-WFHV-r5mh-IM4MuT

4

.

Now look at VG NAME value, note it down… (Your might be different)

vgextend vg_radius /dev/sda3

 Volume group "vg_radius" successfully extended

 

Now, extend the logical volume, again, use vgdisplay to list and identify the logical volumes you have.

lvextend /dev/vg_radius/lv_root  /dev/sda3

 Extending logical volume lv_root to 13.50 GiB
Logical volume lv_root successfully resized

 

And finally, resize the filesystem in the logical volume

resize2fs /dev/vg_radius/lv_root

 resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_radius/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg_radius/lv_root to 3539968 (4k) blocks.
The filesystem on /dev/vg_radius/lv_root is now 3539968 blocks long.


 

Now check the new DISK SIZE in Action !!! ; ) ALHAMDOLILLAH

df -h

 Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/vg_radius-lv_root   14G  897M   12G   7% /
tmpfs                          504M     0  504M   0% /dev/shm
/dev/sda1                      485M   31M  430M   7% /boot

 

after-size-increases-

 


 

 

Regard’s
Syed Jahanzaib

Older Posts »

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 2,764 other followers