Syed Jahanzaib Personal Blog to Share Knowledge !

May 28, 2015

Modem Status and SIM Balance info via EMAIL or SMS

Filed under: Linux Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 10:27 AM

 


 

Task:

Requirement:

Daily reporting for the Modem status and SIM balance via email (or sms)
In this example I had TELTNOKIA SERIAL Modem (Model: Teltonika ModemCOM/G10 Serial ) attached with Linux base system [Ubuntu 12.4].
This system had kannel/playsms installed which sends sms alerts for various events and can trigger different scripts upon receiving SMS with specific codes or instructions. I created this script which run daily in morning  sends email info / alerts for any issue related to modem and sim balance. on internet there might be some better guides or methods to do the same task, but this one fulfilled my custom requirement with my text.

At a moment its on a very basic level, later we will modify it if required further 🙂
Sharing this script, maybe some one will get benefit from it or improve it on a pro level.


 

Requirement:

GAMMU must be installed and must be configured with the modem. you should run gammu –identify to make sure its detecting  the modem.

 


 

Bash Script to do the job:

######################
cat /temp/checkbal.sh
######################

#!/bin/bash
# Script to check Modem status and SIM balance via GAMMU and send email alerts accordingly.
# Syed Jahanzaib / aacable @ hotmail.com
# http//aacable.wordpress.com
# Version 2.0 / Modified on 25-08-2015

# Stop Kannel and playsms
# EMAIL RELATED STUFF
TO1="aacableathotmaildotcom"
GMAILID="YOURGMAILID@gmail.com"
GMAILPASS="GMAILPASSWORD"
CONTENT_TYPE="text/html"
MAILFILE="/tmp/mail.txt"
COMPANY="ZAIB"
CURDATE=`date`

# STOP KANNEL so that GAMMU CAN RUN
service kannel stop
sleep 2
killall -9 bearerbox

# Check for temporary files that might be created by earlier
clear
echo -e "$CURDATE Checking for old garbage files created earlier tby this script"
> /tmp/modeminfo

# Identify MODEM and output its result in tmp file
echo -e "Checking MODEM status"
gammu --identify > /tmp/modeminfo

# Look for Modem string , if not found give error and exit.
A=`grep TELTONIKA "/tmp/modeminfo"`
if [ "$A" == "" ]; then
echo -e "$CURDATE Modem NOT Responding.."
echo -e "$CURDATE Modem NOT Responding.." > $MAILFILE

# START KANNEL which was stopped earlier
service kannel start
/temp/sendEmail-v1.56/sendEmail -t $TO1 -u "ALERT: $CURDATE Modem Daily Report: $COMPANY  Modem NOT RESPONDING!" -o tls=yes -s smtp.gmail.com:587 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$MAILFILE  -o message-content-type=$CONTENT_TYPE

exit 0
else

# If modem found, then execute USSD code to inquire Mobile SIM Balance in tmp file (FOR ZONG SERVICE)
echo -e "Modem seems to be responding OK"
echo -e "================================="
echo -e "Now executing USSD code FOR ZONG MOBILE SERVICE via GAMMU"
gammu --getussd *222# > /tmp/mobilebal

# Look for word insufficient in above output file, if found then give error and exit.
B=`grep insufficient "/tmp/mobilebal"`
if [ "$B" == "" ]
then

BAL=`cat /tmp/mobilebal  |awk 'FNR == 3 {print $8}' |cut -f1 -d"."`
echo -e "Balance & Modem both OK, Alhamdolillah"
echo -e "Balance & Modem both OK, Alhamdolillah" > $MAILFILE
echo -e "Balance is:  $BAL"
echo -e "Balance is  $BAL  RS" |cut -f1 -d"." >> /tmp/mail.txt
/temp/sendEmail-v1.56/sendEmail -t $TO1 -u "INFO: $CURDATE Modem Daily Report is OK with balance of $BAL" -o tls=yes -s smtp.gmail.com:587 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$MAILFILE  -o message-content-type=$CONTENT_TYPE

# START KANNEL which was stopped earlier
service kannel start

exit 0

# ELSE print modem and sim status
else
echo -e "Modem Reponding but ZONG SIM may have not enough balance"
echo -e "Modem Reponding but ZONG SIM may have not enough balance" > /tmp/mail.txt
/temp/sendEmail-v1.56/sendEmail -t $TO1 -u "ALERT: $CURDATE Modem Daily Report: $COMPANY  Modem OK BUT SIM have no Balance" -o tls=yes -s smtp.gmail.com:587 -xu $GMAILID -xp $GMAILPASS -f $GMAILID -o message-file=$MAILFILE  -o message-content-type=$CONTENT_TYPE

# START KANNEL which was stopped earlier
service kannel start

fi
fi
## START


Result:

CLI result:

Modem responding, but SIM have no balance

 

modem-not-balance

 

Modem responding, & SIM also have enough balance

report3-cli

 

Email Result:

 

MODEM-BAL-OK

Report1

 

 

 


 

Its just rough notes, you must modify things according to your network and requirements.

Regard’s
Syed Jahanzaib

Advertisements

May 26, 2015

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

userinf-2

 

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
  • 08/06-2015 – Added individual dealer’s online users details according to VLAN, and user current online status with quota limits showing like data assigned, used and remained.

 

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 😀

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


Another version of Mikrotik Info Script with Dealers online users details [in VLAN]

Another version which have some extended details like each dealer online users count which is helpful for dealers who can send sms to query there online users. script can be modified with security code or individual dealer by adding directives.


#!/bin/bash
MIKROTIK="192.168.1.1"
MTPORT="50001"
SERVER4="192.168.1.10" # Any other Server you may want to monitor in the report
SERVICE="radiusd" # Service you want to monitor like radius
DATE=`date`

# Check if Mikrotik is accessibel 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"

# Extract PPP Active Number of users ACCORDING TO vlan
# These are pools assigned to pppoe users for different vlan's
VLAN9=`grep 10.0.9  /tmp/pppactive.txt | wc -l`
VLAN10=`grep 10.0.10  /tmp/pppactive.txt | wc -l`
VLAN13=`grep 10.0.13  /tmp/pppactive.txt | wc -l`
VLAN14=`grep 10.0.14  /tmp/pppactive.txt | wc -l`
VLAN15=`grep 10.0.15  /tmp/pppactive.txt | wc -l`
VLAN16=`grep 10.0.16  /tmp/pppactive.txt | wc -l`
VLAN17=`grep 10.0.17  /tmp/pppactive.txt | wc -l`
VLAN18=`grep 10.0.18  /tmp/pppactive.txt | wc -l`
VLAN19=`grep 10.0.19 /tmp/pppactive.txt | wc -l`

# Trim excess lines inlcuding license detgails and un-necessary stuff
TOTACTIVE=`cat /tmp/pppactive.txt |sed '1,5d' | wc -l`

# Print total and each vlan users according to above
echo "Total Active Users = $TOTACTIVE"
echo "Dealer = No. Of Online Users"
echo "DEALER-1 = $VLAN9"
echo "DEALER-2 = $VLAN10"
echo "DEALER-3 = $VLAN13"
echo "DEALER-4 = $VLAN14"
echo "DEALER-5 = $VLAN15"
echo "DEALER-6 = $VLAN16"
echo "DEALER-7 = $VLAN17"
echo "DEALER-8 = $VLAN18"
echo "DEALER-9 = $VLAN19"

# 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 reporting 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

Results of above script can be seen here


Galaxy Mikrotik Information SMS @ Mon Jun  8 12:55:49 PKT 2015 ...
uptime: 1d15h38m41s
cpu-load: 24%
NET STATUS = UP
Total Active Users = 414
Dealer = No. Of Online Users
DEALER-1 = 46
DEALER-2 = 42
DEALER-3 = 117
DEALER-4 = 6
DEALER-5 = 22
DEALER-6 = 17
DEALER-7 = 11
DEALER-8 = 53
DEALER-9 = 96
radiusd = OK
SERVER4 = OK
Powered by Syed.Jahanzaib ...

 


 

Regard’s
Syed Jahanzaib

 

May 12, 2015

Sharing Ideas … Mikrotik with Kannel/playSMS

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

UPDATED LINK is here:

https://aacable.wordpress.com/2015/05/25/sharing-ideas-renew-expired-user-account-via-sms-in-dmasoftlab-radius-manager/

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

UPDATED LINK is here:

https://aacable.wordpress.com/2015/05/25/sharing-ideas-renew-expired-user-account-via-sms-in-dmasoftlab-radius-manager/

May 8, 2015

Fun With SMS Management System [playSMS]

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

Note: This post is a drafted version which used beta version of playSMS at the time of writing. You may install latest stable release. 

1


Recently I installed playsms at a network [where Radius manager along with Kannel was already configured to send sms notifications 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 😀
  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.

[Please download latest version available]

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 😀

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 😀

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 😛 @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

%d bloggers like this: