Domain Name Yahoo

Easy Help Troubleshoot Your Linux Box



  

Kannel SMS gateway running as daemon

It is important to make kannel running as daemon, so it will easily to start-stop this service

Create file kannel in /etc/init.d

#!/bin/sh
#
# kannel        This script takes care of starting and stopping the kannel \
#               WAP gateway services (bearer/wap/smsbox).
# chkconfig: - 97 03
# description:  The Kannel WAP and SMS gateway services
# config: /etc/kannel.conf

# Use start-stop-kannel
prog=”/usr/sbin/start-stop-kannel”
args=”–start –background –exec ”
config=”/etc/kannel.conf”

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ “${NETWORKING}” = “no” ] && exit 0

[ -f $config ] || exit 1

RETVAL=0
RETVAL_BEARER=0
RETVAL_WAP=0
RETVAL_SMS=0

start() {
# Start daemons.
echo -n “Starting kannel bearer box: ”
daemon $prog $args /usr/sbin/bearerbox $config
RETVAL_BEARER=$?
sleep 3s  # Sleep for a while before we try to start smsbox
echo

# Starting wap and sms only makes sense if bearerbox is running
if [ $RETVAL_BEARER -eq 0 ]; then
if grep “^group = wapbox” $config &>/dev/null; then
echo -n “Starting kannel wap box: ”
daemon $prog $args /usr/sbin/wapbox $config
RETVAL_WAP=$?
echo
fi
if grep “^group = smsbox” $config &>/dev/null; then
echo -n “Starting kannel sms box: ”
daemon $prog $args /usr/sbin/smsbox $config
RETVAL_SMS=$?
echo
fi
fi
[ $RETVAL_BEARER -eq 0 -a $RETVAL_WAP -eq 0 -a $RETVAL_SMS -eq 0 ] \
&& touch /var/lock/subsys/kannel || RETVAL=1
}

stop() {
# Stop daemons.
if grep “^group = smsbox” $config &>/dev/null; then
echo -n “Shutting down kannel sms box: ”
killproc /usr/sbin/smsbox
RETVAL_SMS=$?
echo
fi
if grep “^group = wapbox” $config &>/dev/null; then
echo -n “Shutting down kannel wap box: ”
killproc /usr/sbin/wapbox
RETVAL_WAP=$?
echo
fi
echo -n “Shutting down kannel bearer box: ”
killproc /usr/sbin/bearerbox
RETVAL_BEARER=$?
echo
[ $RETVAL_BEARER -eq 0 -a $RETVAL_WAP -eq 0 -a $RETVAL_SMS -eq 0 ] \
|| RETVAL=1
rm -f /var/lock/subsys/kannel
}

# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
status /usr/sbin/bearerbox
RETVAL_BEARER=$?
if grep “^group = wapbox” $config &>/dev/null; then
status /usr/sbin/wapbox
RETVAL_WAP=$?
fi
if grep “^group = smsbox” $config &>/dev/null; then
status /usr/sbin/smsbox
RETVAL_SMS=$?
fi
[ $RETVAL_BEARER -eq 0 -a $RETVAL_WAP -eq 0 -a $RETVAL_SMS -eq 0 ] \
|| RETVAL=1
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
RETVAL=1
esac

exit $RETVAL
Add a line at /etc/rc.local

sh /etc/init.d/kannel start

The service sytax is

# /etc/init.d/kannel status
# /etc/init.d/kannel stop
# /etc/init.d/kannel start

Thats all. Thanks.

April 14th, 2009 Posted by admin | SMS gateway | no comments

Configuring SMS Gateway kannel

I posted installing kannel sms gateway using Centos and Ubuntu

Now, i want to share how to configure the kannel.
Kannel configuration file is in /etc/kannel.conf
Here is my kannel.conf :

group = core
admin-port = 13000
admin-password = bar
admin-deny-ip = “”
admin-allow-ip = “*.*.*.*”
smsbox-port = 13001
wapbox-port = 13002
wdp-interface-name = “*”
log-file = “/var/log/kannel/bearerbox.log”
box-deny-ip = “”
box-allow-ip = “*.*.*.*”
include = “/etc/modems.conf”

group = wapbox
bearerbox-host = localhost
log-file = “/var/log/kannel/wapbox.log”

group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
# change global-sender to the appropriate cell service provider number
global-sender = +yournumberhere

group = smsc
smsc = at
device = /dev/ttyUSB0
modemtype = auto
my-number = “YourNumber”
sms-center = +your-sms-center-povider

speed = 9600
host = localhost
port = 13013
smsc-id = itegno

group = sendsms-user
username = smsgateway
password = password
group = sendsms-user

group = sms-service
keyword-regex= .*
catch-all = yes
max-messages = 1
get-url = “http://domain/sms/sms.php?phone=%p&text=%a”
Dont forget, you must copy file modems.conf into /etc/ the same directory as kannel.conf, Other way you have to copy all contents from modems.conf into kannel.conf

Modems.conf is included in the source gateway-1.4.3/doc/examples/modems.conf

There is group sms-service ( see above ), I need to know the server status by sending text messages into this number and kannel will reply me with the server status
group = sms-service
keyword-regex= .*
catch-all = yes
max-messages = 1
get-url = “http://domain/sms/sms.php?phone=%p&text=%a”
This group will catch all the incoming sms sent to this number, and process it in file http://domain/sms/sms.php
So, you have to make this file.
If you dont want this features, just simply remarked it all with #.

Here is sms.php
<?php
extract($_GET);
// phone=%p&text=%a”
// echo “telp :”.$phone.” “;
// echo “text :”.$text;
$info = ” Info From the server”;
if ( $phone!=”" || $text != “” ){
if (trim(strtolower($text)) == “status” ){
include(”jobs.include.php”);
echo urldecode($str_status);
}
echo $info;
}
?>

Here is jobs.include.php
<?
set_time_limit(0);
ini_set(’display_errors’,'0′);
function diffTime($bigTime,$smallTime)
{
list($h1,$m1,$s1)=split(”:”,$bigTime);
list($h2,$m2,$s2)=split(”:”,$smallTime);

$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime=”00:00:00″;
return $resultTime;
exit;
}
if ($second1<$second2)
{$second1=$second1+(24*60*60);}
$second3=$second1-$second2;

//print $second3;
if ($second3==0) {$h3=0;}
else {$h3=floor($second3/3600);}

$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0){$m3=0;}
else
{$m3=floor($remSecond/60);}
$s3=$remSecond-(60*$m3);
if ($h3 < 10) $h3 = “0″.$h3;
if ($m3 < 10) $m3 = “0″.$m3;
if ($s3 < 10) $s3 = “0″.$s3;

if($h3==0){$h3=”00″;}
if($m3==0){$m3=”00″;}
if($s3==0){$s3=”00″;}

if (($h3 >= 1) or ($m3 >= 1))
{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
$resultTime = “but WARNING “.$resultTime;
}else{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
}
return $resultTime;
}

$start = date(”g:i:s”);
if (!file_get_contents(”http://domainnameyahoo.info”)) {$status=”FAILED”;} else {$status = “OK”;}
$end = date(”g:i:s”);
$status_conn = trim(substr(”Conn:”.$status.” “.diffTime($end,$start).” “,0,100));
$str_status = urlencode($status_conn.” “);
?>
With this php script I will know how long the server will take only to open the homepage.
You can also modify the scrip, so you will be notified every 2 hours, :
# cp jobs.include.php jobs.test.php

and append this below the contents
$your_cell_number = “478273728239″;
$url = “http://yourdomain:13013/cgi-bin/sendsms?username=smsgateway&password=password&text=”.$str_status.”&sender=Helpdesk&to=”.$your_cell_number;
file_get_contents($url);

?>

add the jobs.test.php into the crontab -e

Here is php script only will notify you if the connection is failed. Named it jobs.fail.php

<?
set_time_limit(0);
ini_set(’display_errors’,'0′);
function diffTime($bigTime,$smallTime)
{
list($h1,$m1,$s1)=split(”:”,$bigTime);
list($h2,$m2,$s2)=split(”:”,$smallTime);

$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime=”00:00:00″;
return $resultTime;
exit;
}
if ($second1<$second2)
{$second1=$second1+(24*60*60);}
$second3=$second1-$second2;

//print $second3;
if ($second3==0) {$h3=0;}
else {$h3=floor($second3/3600);}

$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0){$m3=0;}
else
{$m3=floor($remSecond/60);}
$s3=$remSecond-(60*$m3);
if ($h3 < 10) $h3 = “0″.$h3;
if ($m3 < 10) $m3 = “0″.$m3;
if ($s3 < 10) $s3 = “0″.$s3;

if($h3==0){$h3=”00″;}
if($m3==0){$m3=”00″;}
if($s3==0){$s3=”00″;}

if (($h3 >= 1) or ($m3 >= 1))
{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
$resultTime = “but WARNING “.$resultTime;
}else{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
}
return $resultTime;
}

$start = date(”g:i:s”);
if (!file_get_contents(”http://domainnameyahoo.info”)) {$status=”FAILED”;} else {$status = “OK”;}
$end = date(”g:i:s”);
$str_status = “”;

if ($status == “FAILED”)
{
$status_conn = trim(substr(”Conn:”.$status.” “.diffTime($end,$start).” “,0,100));
$str_status .= urlencode($status_conn.” “);
echo urlencode($status_conn.” “);
}

if ( trim($str_status)!=”" ) {

$your_cell_number = “478273728239″;
$url = “http://yourdomain:13013/cgi-bin/sendsms?username=smsgateway&password=password&text=”.$str_status.”&sender=Helpdesk&to=”.$your_cell_number;
file_get_contents($url);

}
?>

Put jobs.fail.php into crontab -e with every 10 minutes.
It will check your server every 2 minutes, and notify you only if the connection is failed.

That is all the way I do to monitor my server.

April 14th, 2009 Posted by admin | SMS gateway | no comments

Building SMS Gateway using CENTOS

Another article, I posted how to setup sms-gateway on UBUNTU box.
Now I try to setup sms gateway on Centos Box.

# uname -a
Linux hardcorepolice 2.6.18-92.1.6.el5.centos.plusxen #1 SMP Thu Jun 26 13:43:14 EDT 2008 i686 i686 i386 GNU/Linux

Fedora repository

Fedora repository is available at http://freshrpms.net/packages/. (Contributed by Matthias Saou)
But I just simply run the command
# yum install kannel
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for kannel to pack into transaction set.
kannel-1.4.2-1.el5.rf.i38 100% |=========================| 9.2 kB    00:00
—> Package kannel.i386 0:1.4.2-1.el5.rf set to be updated
–> Running transaction check

Dependencies Resolved

=========================================================================
Package                 Arch       Version          Repository        Size
==========================================================================
Installing:
kannel                  i386       1.4.2-1.el5.rf   rpmforge          1.5 M

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): kannel-1.4.2-1.el5 100% |=========================| 1.5 MB    01:08
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: kannel                       ######################### [1/1]

Installed: kannel.i386 0:1.4.2-1.el5.rf
Complete!

See the rest of the setup on Building SMS Gateway using UBUNTU

Thanks, i will post another hack to customize your sms-service easily.

February 24th, 2009 Posted by admin | CentOS, SMS gateway | one comment

Building SMS Gateway using UBUNTU

Project Name : SMS Gateway using UBUNTU

Hi all, now I am building sms gateway using UBUNTU.

$ uname -a
kernel Linux hardcorepolice 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:20 UTC 2008 i686 GNU/Linux

I am using Nokia 6100 and DKU-5 as connector, free sms gateway source by Kannel version 1.4.3

source : http://www.kannel.org/download/1.4.3/gateway-1.4.3.tar.gz

download the source file, then extract it DO NOT compile. I only get the modems.conf from it

$ tar -zxvf gateway-1.4.3.tar.gz

The modems.conf located in gateway-1.4.3/doc/examples/modems.conf

Debian repository

Debian/apt repository is available at http://www.litux.org/debian.
Just apt-get install kannel for stable release or apt-get install kannel-devel for development release.

$ sudo apt-get install kannel
$ cp gateway-1.4.3/doc/examples/modems.conf /etc/kannel/
$ sudo gedit /etc/kannel/kannel.conf

#
# Sample configuration file for Kannel bearerbox on Debian.
# See the documentation for explanations of fields.
#

# HTTP administration is disabled by default. Make sure you set the
# password if you enable it.

group = core
admin-port = 13000
admin-password = bar
admin-deny-ip = “”
admin-allow-ip = “*.*.*.*”
smsbox-port = 13001
wapbox-port = 13002
wdp-interface-name = “*”
log-file = “/var/log/kannel/bearerbox.log”
box-deny-ip = “”
box-allow-ip = “*.*.*.*”
include = “/etc/kannel/modems.conf”
group = wapbox
bearerbox-host = localhost
log-file = “/var/log/kannel/wapbox.log”

group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
# change global-sender to the appropriate cell service provider number
global-sender = xxx

group = smsc
smsc = at
device = /dev/ttyUSB0
modemtype = auto
# change my-number and sms-center to the appropriate cell service provider number
my-number = xxx
sms-center = xxx
speed = 9600
pin = 2205
host = localhost
port = 13013
smsc-id = itegno

group = sendsms-user
username = simple
password = elpmis
group = sendsms-user

$ bearerbox -v 1 kannel.conf

Open another terminal window

$ smsbox -v 1 kannel.conf

Yes, you will see warnings and errors, but dont worry that all run properly.
You may configure all things you want.

Test your send sms using Internet browser :

http://localhost:13013/cgi-bin/sendsms?username=simple&password=elpmis&dlr-mask=31&text=Hello%20world&sender=Helpdesk&to=TARGETPHONE

wait a moment , there will be incoming sms in TARGETPHONE , cek your inbox.

SMS gateway run successfully.

Thats all for now, be back later.

February 23rd, 2009 Posted by admin | SMS gateway, Ubuntu | 6 comments