EXPANDING POSSIBILITIES
DMASOFTLAB RADIUS MANAGER ACCOUNT RENEWAL ALERT VIA SMS THROUGH KANNEL VIA USING REFILL CARD
LAST UPDATED: 29th July, 2015 / 15:00
Sharing another theory which can actually work and can be modified to perform about any function which is accessible by web panel in DMASOFTLAB Radius Manager.
Do remember that this is just an lab test scripts , in reality radius manager do add few other info in different tables and places. RM recharge method is somewhat quite different then other billing systems. For the demonstration purpose only, I selected an short route by bypassing all extra codes and just added 30 days in the user account via script .
These are just my own thoughts in old days. Lot of improvement can be made in this regard but all of these things requires dedicated time 🙂 Hope you understand.
-
PSEUDO CODE [BY ZAiB]
- PlaySMS received SMS with script KEYWORD , username and refill card code
- the script will check user name , if found valid then CONTINUE, otherwise EXIT with specific ERROR
- the script will check refill card status, if found valid and usable THEN continue , otherwise EXIT with specific ERROR
- the script will compare refill card price with the user current service price, if its equal or greater it will CONTINUE, otherwise EXIT with specific ERROR
- the script will check for current user account expiry status, and act accordingly, example
- >> if the account was expired in past, it will print last expiry date and will add 30 days to it,
- >> if the account was expired today, it will print last expiry date and will add 30 days to it,
- >> if the account is already active, it will take this expiry date, and will ADD more 30 days 30 days to it, and CONTINUE
- the script will check if the service have Quota limit, it will add the quota to the user account, if no quota is implemented it will simply ignore and print the result as well
- ONCE all the conditions are OK, then it will
- >> echo the results and will add 30 days, if the account is already active with lets say next month date, it will take that date and will add 30 more days in it
- >> Add comments in user properties so that admin can see it in user properties
- >> Add SYSLOG entry in RM last log event
- >> Add entry to mark card as used to prevent re-usage
- >> Print QUOTA information accordingly, if any
- SEND ALL REPLIES VIA SMS USING KANNEL
- and if required you can send report via EMAIL to admin or the user as well including many details you like,.
1- RADIUS SECTION TO CREATE REFILL CARDS:
Create REFILL cards so that we can use it to refill our expired account. Make sure your service have PRICE defined, and the refill card you generate are equal or higher then the service price.
As showed in the image below … [just for example]
2- SCRIPT SECTION
#!/bin/bash # Script to renew user account via SMS using refill card in # Radius Manager # Created by Syed Jahanzaib # July, 2014 SQLUSER="root" SQLPASS="sql_password" echo $1 > /tmp/user-card USR=`cat /tmp/user-card | awk {' print $1 '}` CARD=`cat /tmp/user-card | awk {' print $2 '}` NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days") #LOOK FOR VALID USER IN RADIUS USRVALID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$USR';"` if [ "$USRVALID" == "" ]; then echo -e "ERROR: USER NOT FOUND!" exit 0 fi ###################### # ACCOUNT EXPIRY CHECK ###################### TODAY=$(date +"%Y-%m-%d") TODAYDIGIT=`echo $TODAY | sed -e 's/-//g'` MONTH=$(date +"-%m") CMONTH=`echo $MONTH | sed -e 's/-//g'` MONTHYEAR=$(date +"%B-%Y") ALPHAMONTHYEAR=`echo $MONTHYEAR #| sed -e 's/-//g'` SRVEXPIRYFULL=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk 'FNR == 2'` SRVEXPIRYFULLD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk '{print $1}' | sed 's/expiration//'` SRVEXPIRY=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT expiration FROM radius.rm_users WHERE username = '$USR';" |awk 'FNR == 2' | sed -e 's/-//g' | sed 's/00:.*//'` LOGOFFDATE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT lastlogoff FROM radius.rm_users WHERE username = '$USR';" |awk 'FNR == 2 {print $1,$2}'` SRVID=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$USR';" |awk 'FNR == 2 {print $1}'` 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"."` CARDPRICE=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT value FROM rm_cards WHERE cardnum = $CARD;" |awk 'FNR == 2 {print $1}' | cut -f1 -d"."` #LOOK FOR USER ACTUAL SERVICE NAME PKGNAME=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT srvname FROM radius.rm_services WHERE rm_services.srvid = '$SRVID';" |awk 'FNR == 2'` # Look for Pakacge Quota trafficunitcomb PKGQUOTA=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT trafficunitcomb FROM rm_services WHERE srvid= '$SRVID';" |awk 'FNR == 2'` PKGQUOTAB=$(($PKGQUOTA / 1024)) # LOOK FOR VALID REFILL CARD CODE IN RADIUS CARDS LIST CARDVALIDATION=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; SELECT value, expiration FROM rm_cards WHERE cardnum = '$CARD' AND used = '0000-00-00 00:00:00';"` if [ "$CARDVALIDATION" == "" ]; then echo -e "ERROR: INVALID CARD NUMBER!" exit 0 else # IF CARD VALUE IS LESS THEN CURRENT PACKAGE PRICE THEN PRINT ERROR AND GOTO END if [ $CARDPRICE -lt $SRVPRICE ] then echo -e "ERROR: CARD PRICE IS NOT SUFFICIENT TO REFRESH $PKGNAME SERVICE" exit 0 else # IF CARD VALUE IS EQUAL OR HIGHER THEN CURRENT PACKAGE PRICE THEN OK if [ $CARDPRICE -eq $SRVPRICE ] then echo fi ########### ACCOUNT STATUS EXPIRED TODAY ACTION ############ if [ $SRVEXPIRY -eq $TODAYDIGIT ] then echo "Account have been EXPIRED TODAY! Last LOGOUT date was $LOGOFFDATE" NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days") # PRINT FETCHED VALUES , JUST FOR INFO / ZAIB echo User Account = $USR echo User Actual Package at Billing = $PKGNAME echo Service Price at Billing = $SRVPRICE PKR echo This Card Value is = $CARDPRICE PKR echo -e "Next Expiry = $NEXTEXPIRYADD" # ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';" # ADD COMMENTS mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comment = 'This account was last refresh from scratch code by SMS' WHERE username = '$USR';" # ADD SYSLOG ENTRY mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), 'n/a', 'SMSUSER_$USR', '$USR', '$USR renewd service > $PKGNAME');" # ADD ENTRY FOR CURRENT DATE TIME IN REFIL CARD TO PREVENT RE-USAGE OF SAME CARD NUMBER mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_cards SET owner = '$USR', used = NOW() WHERE cardnum = '$CARD';" ########### ACCOUNT STATUS EXPIRED IN PAST ACTION ############ elif [ $SRVEXPIRY -lt $TODAYDIGIT ] then echo "ACCOUNT WAS EXPIRED on $SRVEXPIRYFULL ! Last LOGOUT date was $LOGOFFDATE" NEXTEXPIRYADD=$(date +"%Y-%m-%d" -d "+31 days") # PRINT FETCHED VALUES , JUST FOR INFO / ZAIB echo User Account = $USR echo User Actual Package at Billing = $PKGNAME PKR echo Service Price at Billing = $SRVPRICE PKR echo This Card Value is = $CARDPRICE PKR echo -e "Next Expiry = $NEXTEXPIRYADD" # ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';" # ADD COMMENTS mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comment = 'This account was last refresh from scratch code by SMS';" # ADD SYSLOG ENTRY mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), 'n/a', 'SMSUSER_$USR', '$USR', '$USR renewd service > $PKGNAME');" # ADD ENTRY FOR CURRENT DATE TIME IN REFIL CARD TO PREVENT RE-USAGE OF SAME CARD NUMBER mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_cards SET owner = '$USR', used = NOW() WHERE cardnum = '$CARD';" # Update QUOTA for the USER mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comblimit = '$PKGQUOTAB' WHERE username = '$USR';" else ########### ACCOUNT STATUS OK! ACTION ############ echo -e "User Billing Info:" echo "Account STATUS= OK!" NEXTEXPIRYADD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; select DATE_ADD(expiration, INTERVAL 31 DAY) as x from rm_users where username= '$USR';" |awk 'FNR == 2'` # PRINT FETCHED VALUES , JUST FOR INFO / ZAIB echo User Account = $USR echo User Actual Package at Billing = $PKGNAME PKR echo Service Price at Billing = $SRVPRICE PKR echo This Card Value is = $CARDPRICE PKR echo -e "Next Expiry = $NEXTEXPIRYADD" NEXTEXPIRYADD=`mysql -u$SQLUSER -p$SQLPASS -e "use radius; select DATE_ADD(expiration, INTERVAL 31 DAY) as x from rm_users where username= '$USR';" |awk 'FNR == 2'` # ADD 30 DAYS VALUE TO EXPIRED USER ACCOUNT mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET expiration = '$NEXTEXPIRYADD' WHERE username = '$USR';" # ADD COMMENTS mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_users SET comment = 'This account was last refresh from scratch code by SMS' WHERE username = '$USR';" # ADD SYSLOG ENTRY mysql -u$SQLUSER -p$SQLPASS -e "use radius; INSERT INTO rm_syslog (datetime, ip, name, eventid, data1) VALUES (NOW(), 'n/a', 'SMSUSER_$USR', '$USR', '$USR renewd service > $PKGNAME');" # ADD ENTRY FOR CURRENT DATE TIME IN REFIL CARD TO PREVENT RE-USAGE OF SAME CARD NUMBER mysql -u$SQLUSER -p$SQLPASS -e "use radius; UPDATE rm_cards SET owner = '$USR', used = NOW() WHERE cardnum = '$CARD';" fi fi fi ########### ACCOUNT STATUS EXPIRED TODAY ACTION ############ if [ $PKGQUOTA -eq 0 ] then echo -e "Total Quota Allowed = UNLIMITED" else echo -e "Total Quota Allowed = $PKGQUOTAB GB" fi
Copy the script in playsms script admin folder
copy the above renew.sh script into /var/lib/playsms/sms_command/1
3- playSMS COMMAND SECTION
Create command in playSMS
As showed in the image below ..
4- TESTING RENEWAL VIA SENDING SMS
Send sms to the server (playSMS) with following format
renew refilltest 0942
renew = is the keyword that playSMS will catch and will execute the renew.sh
refilltest = is the user name
0942 = REFILL card number/code
and if all conditions matched like user name and card number valid, then it will execture the rest of script and will add 30 days expiry limit to the account (so if the account is expired it will be re-activated). It will also check if total quota is implemented on the service, it will add the appropriate quota as well.
and if the specific service dont ahve any QUOTA , it will display the result
if the code is wrong it will send error
and if user is invalid, it will let you know as well.
You can also see its entry in SYSLOG and user properties comments section as well.
Lot’s of possibilities here. You can add more details in the script to do more Logging , send alerts etc etc .
All depend on your capabilities and passion towards achieving the Goal !
If time will allow, I will add more details Insha Allah !
Regard’s
Syed Jahanzaib
Sir plz send me 3 wan unequal balancing script with bridging mode modem…I really need it .I config it connect Ptcl modem on routerboard but no internet access while routerboard bridging successfully On May 25, 2015 4:46 PM, “Syed Jahanzaib Personnel Blog to Share Knowledge
LikeLike
Comment by zameer196 — May 25, 2015 @ 5:50 PM
Dear Zaib
thanks for your best posts
if this possible user send his username to kannel phone number and kannel reply user expire date = with totall traffic =
if this possible please let us now
thanks
allah save you
LikeLike
Comment by haroonnimroozy — May 26, 2015 @ 1:03 AM
root@xxx:/var/lib/playsms/sms_command/1# ./userinfo.sh 1234
./userinfo.sh: line 66: unexpected EOF while looking for matching `”
./userinfo.sh: line 84: syntax error: unexpected end of file
LikeLike
Comment by ellaham — June 1, 2015 @ 3:56 AM
Sorry for wrong post i can try this script. i get this code error this post https://aacable.wordpress.com/2015/05/26/sharing-ideas-get-user-account-info-via-sms-in-dmasoftlab-radius-manager/
LikeLike
Comment by ellaham — June 1, 2015 @ 4:11 AM
I am not sure, but i guess they will work on next schedule, to confirm you should try it.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — September 16, 2015 @ 1:49 PM
[…] https://aacable.wordpress.com/2015/05/25/sharing-ideas-renew-expired-user-account-via-sms-in-dmasoft… […]
LikeLike
Pingback by Sharing Ideas … Mikrotik with Kannel/playSMS | Syed Jahanzaib Personal Blog to Share Knowledge ! — July 29, 2015 @ 4:37 PM
Due to power challenges, we normally shutdown radius manager before midnight and start it up in the morning. Will this affect the auto-renewal of accounts considering that the cron runs at midnight? If yes how can i resolve the issue?
Thanks
LikeLike
Comment by OJ — September 16, 2015 @ 1:14 PM
Thank you for all the help you have being offering us.
Please Have a project
But this time just want to add money to the account instead of loading the card using sms.
Any help.
LikeLike
Comment by Baba- — April 20, 2017 @ 2:13 AM
[…] https://aacable.wordpress.com/2015/05/25/sharing-ideas-renew-expired-user-account-via-sms-in-dmasoft… […]
LikeLiked by 1 person
Pingback by Generating Refill Cards in Radius Manager | Syed Jahanzaib Personal Blog to Share Knowledge ! — June 7, 2017 @ 2:29 PM
Salam Alekum,
I get sms with error ( could not fetch content. )
From playsms … how to solve it ?can you help?
LikeLike
Comment by Hazem — October 12, 2017 @ 10:01 PM
Probably the command or script is not found that is being tried to executed, look for proper folder names, if not create them,
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — October 16, 2017 @ 3:49 PM
Also make sure you have proper config in kannel.conf to facilitate playsms url
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — October 16, 2017 @ 3:55 PM
[…] post contains updated script for account renewal in radius manager with many controls added. Posting it for reference […]
LikeLike
Pingback by Sharing Ideas … Updated Script for Renew Expired User Account via SMS in DMASOFTLAB Radius Manager | Syed Jahanzaib Personal Blog to Share Knowledge ! — July 17, 2018 @ 1:12 PM
Please l need help. Paid service
LikeLike
Comment by Baba-Musah Mohammed — July 20, 2021 @ 5:57 AM
email to aacable at hotmail dot com
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — August 5, 2021 @ 8:09 PM
Please i need this system on my RM please i am willing to pay for help
You can contact me at Lebon@eurekacnt or whattsapp me at 0027 68 029 400
LikeLike
Comment by lebonbinja — October 3, 2021 @ 11:17 AM
You can contact me on email aacable @ hotmail . com
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — October 4, 2021 @ 3:15 PM