~ Article by ~
Syed Jahanzaib
DMASOFTLAB Radius Manager has a very nice feature of SMS notification for Before Account Expiry SMS / Email , New Account Activation Message, New Account Activation Verification Code / Password Recovery and many other cool functions that can be done using this feature, however activating it is a bit complex thing to do. As radius manager supplies clickatell HTTP gateway API with there default installation, and I really didn’t wanted to purchase the clickatell account because it would be expensive for any mid-large size network, even a small network wouldn’t want to pay extra amount. So I decided to create my own HTTP gateway which is connected with my GSM Modem. Following is the complete guide on how you can create your own SMS HTTP GATEWAY.
Once you have a working HTTP gateway , you can move on to RM configuration section.
Howto configure API to make it work with your KANNEL SMS HTTP gateway.
Login to your RM box using terminal.
For Rm 4.1.x ONLY ! Open the smsgateway.php file by
nano /var/www/radiusmanager/api/smsgateway.php
Now remove all lines and replace them with the following.
<?php /***************************************************************************** ** This script is provided by DMASOFTLAB RM. ** Modified by Syed Jahanzaib / https://aacable.wordpress.com / aacable@hotmail.com ** I am using KANNEL as GATEWAY with 10-sec delay via this PHP CODE ** First Modified: Somwhere-2013 *****************************************************************************/ function sendsms($recp, $body, &$errmsg) { // enter your LOCAL HTTP SMS GATEWAY here $api_user = "kannel"; $api_password = "KANNEL-PASSWORD"; // clean up HTML entities $body = html_entity_decode($body, ENT_COMPAT, "UTF-8"); // implement your own SMS gateway here $body = rawurlencode($body); $ch = curl_init(); // change the IP and id password in the below line to match your local config. syed jahanzaib curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:13013/cgi-bin/sendsms?user=$api_user&password=$api_password&to=$recp&text=$body"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); // uncomment the following line to see the result from the SMS gateway // print $res; // log result if (substr($res, 0 , 4) == "ERR:") $res_str = $res; else $res_str = "OK"; syslog(LOG_INFO, "[radiusmanager] Sending SMS with 10 sec delay in each SMS added by Syed_Jahanzaib to Mobile No " . $recp . " (" . $res_str . ")"); // Adding 10 seconds delay so that oru mobile SIM may not get blocked sleep(10); // error has occured, return FALSE if (substr($res, 0 , 4) == "ERR:") { $errmsg = $res; return false; } // no error, return TRUE return true; } ?>
That’s It. Your RM is ready to send sms using your local SMS HTTP gateway. Just make sure you enable sms for various events as described in RM ACP > Home Settings.
Howto send Account Expiry Warning to User via email/sms
Logon to RM Admin Panel,
Goto System/ System Settings
At the bottom of the page, You will see Notification’s section.
At the Expiry warning: Type the number of days you want RM to send account expiry warning before the account expires.
Also tick on all related options as showed in the image.
As showed in the image below . . .
Once the account reaches near its expiry, user will receive email like below . . .
Howto Recover User Password via FORGOT PASSWORD link at user.php (ver 4.x or above)
User can recover his forgotten password using Forgot my password at user.php
For Example
After submission the mobile number, user will receive A code on his mobile number (If he have defined valid number while registering the account. Then after entering the code in the below screen, he will receive new password.
As showed in the image below . . .
Howto change SMS templates (text)
You can edit the messages sent to users by modifying following files in
/var/www/radiusmanager/lang/English
Files are:
smsaccverify_tpl.txt smspswact_tpl.txt smspsw_tpl.txt smsselfregact_tpl.txt smswarnexp_tpl.txt smswarntraff_tpl.txt smswelcomeuser_tpl.txt
# Additional BASH Script to send General Announcement SMS to ACTIVE users only using local KANNEL sms gateway (who have mobile number mentioned)
#!/usr/bin/env bash ####!/bin/sh #set -x #trap "set +x; set -x" DEBUG # BASH base script to send sms to users from radius who are active and with mobile nos # the simple logic can be applied for about any other task as well. I tried to make it as simple as it can be # By Syed Jahanzaib # CREATED on : 16th July, 2015 # Modified on 25h June 2018 # Local Variables # Mysql credentials SQLID="root" SQLPASS="SQLROOTPASS" export MYSQL_PWD=$SQLPASS CMD="mysql -u$SQLID --skip-column-names -s -e" COMPANY="ZAIB" DB="radius" #Table which contain main users information TBL="rm_users" # Date Time Variables FULL_DATE=`date` TODAY=$(date +"%Y-%m-%d") # Kannel Server IP, if its local leave it as it is KURL="http://127.0.0.1:13013" KID="kannel" KPASS="KANNELPASS" ################################################## # Temp folder and files setup for various actions ################################################## ALLACTIVEUSERSLIST_TMP=/tmp/all_active_users_list_4_sms_tmp.txt ALLACTIVEUSERSLIST_FINAL=/tmp/all_active_users_list_4_sms_final.txt > $ALLACTIVEUSERSLIST_TMP > $ALLACTIVEUSERSLIST_FINAL ############################ ###### START thE script cOdE ############################ # Pull users that are ACTIVE only $CMD "use $DB; SELECT SQL_CALC_FOUND_ROWS username, firstname, lastname, address, city, zip, country, state, phone, mobile, email, company, taxid, srvid, downlimit, uplimit, comblimit, expiration, uptimelimit, credits, comment, enableuser, staticipcpe, staticipcm, ipmodecpe, ipmodecm, srvname, limitdl, limitul, limitcomb, limitexpiration, limituptime, createdon, verifycode, verified, selfreg, acctype, maccm, LEFT(lastlogoff, 10) , IF (limitdl = 1, downlimit - COALESCE((SELECT SUM(acctoutputoctets) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(dlbytes), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username), 0), 0), IF (limitul = 1, uplimit - COALESCE((SELECT SUM(acctinputoctets) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(ulbytes), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username), 0), 0), IF (limitcomb =1, comblimit - COALESCE((SELECT SUM(acctinputoctets + acctoutputoctets) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(ulbytes + dlbytes), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username), 0), 0), IF (limituptime = 1, uptimelimit - COALESCE((SELECT SUM(acctsessiontime) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(acctsessiontime), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username), 0), 0) FROM ( SELECT username, firstname, lastname, address, city, zip, country, state, phone, mobile, email, company, taxid, rm_users.srvid, rm_users.downlimit, rm_users.uplimit, rm_users.comblimit, rm_users.expiration, rm_users.uptimelimit, credits, comment, enableuser, staticipcpe, staticipcm, ipmodecpe, ipmodecm, srvname, limitdl, limitul, limitcomb, limitexpiration, limituptime, createdon, verifycode, verified, selfreg, acctype, maccm, mac, groupid, contractid, contractvalid, rm_users.owner, srvtype, lastlogoff FROM rm_users JOIN rm_services USING (srvid) ORDER BY username ASC ) AS tmp WHERE 1 AND (tmp.acctype = '0' OR tmp.acctype = '1' OR tmp.acctype = '2' OR tmp.acctype = '3' OR tmp.acctype = '4' OR tmp.acctype = '5' OR tmp.acctype = '6' ) AND tmp.enableuser = 1 AND (limitdl = 0 OR IF (limitdl =1, downlimit - (SELECT COALESCE(SUM(acctoutputoctets), 0) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(dlbytes), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username) , 1) > 0) AND (limitul = 0 OR IF (limitul =1, uplimit - (SELECT COALESCE(SUM(acctinputoctets), 0) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(ulbytes ), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username) , 1) > 0) AND (limitcomb = 0 OR IF (limitcomb =1, comblimit - (SELECT COALESCE(SUM(acctinputoctets + acctoutputoctets), 0) FROM radacct WHERE radacct.username = tmp.username) + (SELECT COALESCE(SUM(ulbytes + dlbytes), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username) , 1) > 0) AND (limituptime = 0 OR IF (limituptime=1, uptimelimit - (SELECT COALESCE(SUM(acctsessiontime), 0) FROM radacct WHERE radacct.username = tmp.username) - (SELECT COALESCE(SUM(acctsessiontime), 0) FROM rm_radacct WHERE rm_radacct.username = tmp.username) , 1) > 0) AND (limitexpiration = 0 OR IF (limitexpiration=1, UNIX_TIMESTAMP(expiration) - UNIX_TIMESTAMP(NOW()), 1) > 0) LIMIT 0, 5000;" | awk '{print $1}' |sort > $ALLACTIVEUSERSLIST_TMP #$CMD "use $DB; select username from $TBL where expiration ='$DAYS3';" |sort > $ALLACTIVEUSERSLIST_TMP # IF no user found , show error and exit - zaib CHK=`wc -m $ALLACTIVEUSERSLIST_TMP | awk {'print $1}'` if [ "$CHK" -eq 0 ] then echo "No active user found , exiting ..." exit 1 fi ACT_TOTAL=`cat $ALLACTIVEUSERSLIST_TMP | wc -l` echo "- Total Number of ACTIVE users : $ACT_TOTAL" echo "- Now sending sms to users ..." #sleep 10 # Apply formula num=0 cat $ALLACTIVEUSERSLIST_TMP |while read data do num=$[$num+1] USERNAME=`echo $data` MOBILE=`$CMD "use $DB; select mobile from $TBL where username='$USERNAME';" | sed -e 's/-//g'` FULLNAME=`$CMD "use $DB; select firstname,lastname from $TBL where username='$USERNAME';"` # IF user have NO mobile number ignore it if [ -z "$MOBILE" ]; then echo "$USERNAME does not have mobile number associated therefore no need to to send sms" else ##################### #### SEND SMS MESSAGE #### ##################### echo "$COMPANY Internet Alert:: International Bandwidth Submarine Cable Outage Notification. In addition to the trailing outage, we are observing outage on another International Submarine Cable. Internet speed Degradation. We are in follow up with authorities & further updates will be shared accordingly. Customer Care " > /tmp/$USERNAME.announce.sms echo $USERNAME / $MOBILE >> $ALLACTIVEUSERSLIST_FINAL cat /tmp/$USERNAME.announce.sms # Send SMS Alert via KANNEL curl "$KURL/cgi-bin/sendsms?username=$KID&password=$KPASS&to=$MOBILE" -G --data-urlencode text@/tmp/$USERNAME.announce.sms echo "ANNOUNCE SMS Sent to ID: $USERNAME - $FULLNAME $MOBILE , waiting 10 seconds for another SMS ... [TO AVOID SIM BLOCKING]" logger ANNOUNCE SMS Sent to ID: $USERNAME - $FULLNAME $MOBILE , waiting 10 seconds for another SMS ... TO AVOID SIM BLOCKING rm /tmp/$USERNAME.announce.sms fi echo "*********** Sleeping for 10 seconds to avoid sim blocking dueto bulk sms ... ************" sleep 10 done TOT_FINAL_NO=`cat $ALLACTIVEUSERSLIST_FINAL | wc -l` echo "Total Number of users to whom SMS was sent = $TOT_FINAL_NO"
Regard’s
Syed Jahanzaib